Skip to content

Commit

Permalink
Merge pull request #2 from w9jds/develop
Browse files Browse the repository at this point in the history
v1.0.1 - v1.0.3
  • Loading branch information
w9jds committed Apr 4, 2016
2 parents 9b6c13e + 37abadb commit fd8c5db
Show file tree
Hide file tree
Showing 38 changed files with 1,140 additions and 951 deletions.
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,40 @@ I used Android Material design standards and made sure it uses as many transitio

Make sure to tap on the market orders, because they open to give you more info, like range and location.

# Future
I have also been working on adding it a "bot" feature that tracks specific items in specific regions of space and notify you when the price of buy or sell orders pass your threshold. Along with that I added network caching so you can still use quite a bit of it in offline mode, and working on building it into the database so it if quicker and requires internet only for specific calls to update info or ones not stored.


# Intent Integration

Courtesy of EvaNova, here is the class needed to open MarketBot from any app that you would like:

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import java.util.List;
public class MarketBot {
private MarketBot() {}
public static void launch(
final Context context,
final long itemID,
final long regionID) {
final Intent intent = new Intent("com.w9jds.marketbot.intent.action.OPEN_TYPE");
intent.putExtra("typeId", itemID);
intent.putExtra("regionId", regionID);
context.startActivity(intent);
}
public static boolean isAvailable(final Context context) {
final Intent intent = new Intent("com.w9jds.marketbot.intent.action.OPEN_TYPE");
return isIntentAvailable(context, intent);
}
private static boolean isIntentAvailable(Context ctx, Intent intent) {
final PackageManager mgr = ctx.getPackageManager();
List<ResolveInfo> list = mgr.queryIntentActivities(intent, 0);
return list.size() > 0;
}
}
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
applicationId "com.w9jds.marketbot"
minSdkVersion 21
versionCode 5
versionName "v1.0.0"
versionCode 8
versionName "v1.0.3"
}
buildTypes {
release {
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,43 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MarketBot">

<activity
android:name=".activities.MainActivity"
android:theme="@style/MarketBot.Activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

<meta-data
android:name="android.app.default_searchable"
android:value=".activities.SearchActivity" />
</activity>

<activity
android:name=".activities.ItemActivity"
android:theme="@style/MarketBot.Activities.ItemActivity"></activity>

android:theme="@style/MarketBot.Activities.ItemActivity">

<intent-filter>
<action android:name="com.w9jds.marketbot.intent.action.OPEN_TYPE" />
<category android:name="android.intent.category.DEFAULT"/>

</intent-filter>

</activity>
<activity
android:name=".activities.SearchActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Expand All @@ -46,15 +57,10 @@
android:resource="@xml/searchable" />
</activity>

<receiver
android:name=".services.receivers.OpenItemReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.w9jds.marketbot.intent.action.OPEN_TYPE" />
</intent-filter>
</receiver>
<activity android:name=".activities.InfoActivity">

</activity>

<activity android:name=".activities.InfoActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_info);
ButterKnife.bind(this);

MarketBot.getStorageComponent().inject(this);
MarketBot.createNewStorageSession().inject(this);

setSupportActionBar(toolbar);
actionBar = getSupportActionBar();
Expand Down
144 changes: 112 additions & 32 deletions app/src/main/java/com/w9jds/marketbot/activities/ItemActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.w9jds.marketbot.activities;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
Expand All @@ -12,42 +18,49 @@
import android.widget.AdapterView;
import android.widget.Spinner;

import com.w9jds.eveapi.Models.MarketGroup;
import com.w9jds.eveapi.Models.MarketItemBase;
import com.w9jds.eveapi.Models.Region;
import com.w9jds.eveapi.Models.Type;
import com.w9jds.marketbot.R;
import com.w9jds.marketbot.adapters.OrdersTabAdapter;
import com.w9jds.marketbot.adapters.RegionAdapter;
import com.w9jds.marketbot.classes.MarketBot;
import com.w9jds.marketbot.data.BaseDataManager;
import com.w9jds.marketbot.data.DataManager;
import com.w9jds.marketbot.data.loader.DataManager;
import com.w9jds.marketbot.data.storage.MarketTypeEntry;
import com.w9jds.marketbot.ui.fragments.OrdersTab;

import java.util.HashMap;
import java.util.List;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
* Created by Jeremy Shore on 2/22/16.
*/
public class ItemActivity extends AppCompatActivity implements BaseDataManager.DataLoadingCallbacks, AdapterView.OnItemSelectedListener {

@Bind(R.id.region_spinner)
Spinner regionSpinner;
public class ItemActivity extends AppCompatActivity implements BaseDataManager.DataUpdatingCallbacks,
AdapterView.OnItemSelectedListener {

@Bind(R.id.content_pager)
ViewPager pager;
@Inject boolean isFirstRun;

@Bind(R.id.sliding_tabs)
TabLayout tabLayout;
@Bind(R.id.item_content) CoordinatorLayout baseView;
@Bind(R.id.main_toolbar) Toolbar toolbar;
@Bind(R.id.region_spinner) Spinner regionSpinner;
@Bind(R.id.content_pager) ViewPager pager;
@Bind(R.id.sliding_tabs) TabLayout tabLayout;

private ActionBar actionBar;
private ProgressDialog progressDialog;
private DataManager dataManager;
private Type currentType;
private RegionAdapter regionAdapter;
private OrdersTabAdapter tabAdapter;
private int defaultRegionId;
private boolean updateRun = false;
private long defaultRegionId;
private long typeIdExtra;

private HashMap<Integer, OrdersTab> orderTabs = new HashMap<>();

Expand All @@ -57,10 +70,10 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_market_item);
ButterKnife.bind(this);

Toolbar toolbar = ButterKnife.findById(this, R.id.main_toolbar);
updateStorageSession();

setSupportActionBar(toolbar);
actionBar = getSupportActionBar();
ActionBar actionBar = getSupportActionBar();

if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
Expand All @@ -70,28 +83,44 @@ public void onCreate(Bundle savedInstanceState) {
}

Intent intent = getIntent();
currentType = intent.getParcelableExtra("currentType");

if (intent.hasExtra("selectedRegion")) {
defaultRegionId = intent.getIntExtra("selectedRegion", -1);
}
typeIdExtra = intent.getLongExtra("typeId", -1);
defaultRegionId = intent.getLongExtra("regionId", -1);

regionAdapter = new RegionAdapter(this);
dataManager = new DataManager(getApplication()) {
@Override
public void onProgressUpdate(final int page, final int totalPages) {
if (progressDialog.isIndeterminate()) {
progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
updateProgressDialog(page, totalPages, true);
}
});

progressDialog.dismiss();
}

updateProgressDialog(page, totalPages, false);
}

@Override
public void onDataLoaded(List<? extends MarketItemBase> data) {
if (data.size() > 0) {
if (data.get(0) instanceof Region) {
regionAdapter.addAllItems(data);
if (data.size() > 0 && data.get(0) instanceof Region) {
regionAdapter.addAllItems(data);

if (defaultRegionId == 0) {
regionSpinner.setSelection(regionAdapter.getPositionfromId(10000002), true);
}
else {
regionSpinner.setSelection(regionAdapter.getPositionfromId(defaultRegionId), true);
}
if (defaultRegionId == -1) {
regionSpinner.setSelection(regionAdapter.getPositionfromId(10000002), true);
}
else {
regionSpinner.setSelection(regionAdapter.getPositionfromId((int)defaultRegionId), true);
}
}

if (data.size() > 0 && data.get(0) instanceof MarketGroup) {
updateStorageSession();
checkExtras();
}
}

@Override
Expand All @@ -100,17 +129,62 @@ public void onDataLoaded(Object data) {
}
};

dataManager.registerCallback(this);
regionSpinner.setAdapter(regionAdapter);
regionSpinner.setOnItemSelectedListener(this);

checkExtras();
}

private void updateStorageSession() {
MarketBot.createNewStorageSession().inject(this);
}

private void updateProgressDialog(int page, int max, boolean isNewWindow) {
if (isNewWindow) {
progressDialog = new ProgressDialog(this);
progressDialog.setIndeterminate(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Updating Items Cache...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
}

progressDialog.setMax(max);
progressDialog.setProgress(page);

if (isNewWindow) {
progressDialog.show();
}
}

private void checkExtras() {
if (!isFirstRun) {
if (typeIdExtra != -1) {
currentType = MarketTypeEntry.getType(this, typeIdExtra);
} else {
currentType = getIntent().getParcelableExtra("currentType");
}

loadTypeData();
}
else if (!updateRun) {
dataManager.updateAndLoad();
}
else {
Snackbar.make(baseView, "Update failed, Please try again.", Snackbar.LENGTH_LONG).show();
}
}

private void loadTypeData() {
tabAdapter = new OrdersTabAdapter(getSupportFragmentManager(), this, currentType.getId());
pager.setOffscreenPageLimit(4);
pager.setAdapter(tabAdapter);
tabLayout.setupWithViewPager(pager);

tabLayout.setTabsFromPagerAdapter(tabAdapter);

dataManager.loadRegions();
dataManager.loadRegions(false);
}

public String getCurrentTypeIcon() {
Expand All @@ -128,13 +202,19 @@ public boolean onNavigateUp() {
}

@Override
public void dataStartedLoading() {

public void dataUpdatingStarted() {
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Updating Market Cache...");
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}

@Override
public void dataFinishedLoading() {

public void dataUpdatingFinished() {
progressDialog.dismiss();
updateRun = true;
}

@Override
Expand Down
Loading

0 comments on commit fd8c5db

Please sign in to comment.