diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2a593e27..6ab2cc0d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,7 +19,7 @@ STEAM_WEB_API_KEY=DUMMY_KEY - You need a steam web API key (http://steamcommunity.com/dev/apikey) in order to be able to download steam user data. ## Technologies -It would be really if you were somewhat familiar with the technologies and concepts. If not, I provided some userful links for you. +It would be really if you were somewhat familiar with the technologies and concepts. If not, I provided some useful links for you. - Dependency using dagger 2 - https://guides.codepath.com/android/Dependency-Injection-with-Dagger-2 - Model-View-Presenter design pattern diff --git a/README.md b/README.md index 10014ba0..1c9240a7 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ The unofficial backpack.tf mobile application Fork this repository and contribute by creating a pull request. Notable contributions will be credited in the application. See the [contributing guidelines](https://github.com/Longi94/bptf/blob/master/CONTRIBUTING.md) before contributing. ### 3rd party libraries +- [Answers](https://fabric.io/kits/android/answers) - [Butter Knife](http://jakewharton.github.io/butterknife/) +- [Crashlytics](https://try.crashlytics.com/) - [Dagger 2](http://google.github.io/dagger/) - [Dart 2](https://github.com/f2prateek/dart) - [Glide](https://github.com/bumptech/glide) diff --git a/app/build.gradle b/app/build.gradle index 8d39d23e..46ffe660 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { applicationId "com.tlongdev.bktf" minSdkVersion 14 targetSdkVersion 23 - versionCode 41 + versionCode 42 versionName "2.1.0" applicationVariants.all { variant -> @@ -60,6 +60,7 @@ dependencies { testCompile 'org.mockito:mockito-core:1.10.19' testCompile "org.robolectric:robolectric:3.1-SNAPSHOT" + apt 'com.jakewharton:butterknife-compiler:8.0.0' apt 'com.google.dagger:dagger-compiler:2.0.2' provided 'com.f2prateek.dart:dart-processor:2.0.0' provided 'org.glassfish:javax.annotation:10.0-b28' @@ -84,7 +85,7 @@ dependencies { compile 'com.google.dagger:dagger:2.0.2' compile 'com.github.PhilJay:MPAndroidChart:v2.2.3' compile 'com.github.bumptech.glide:glide:3.7.0' - compile 'com.jakewharton:butterknife:7.0.1' + compile 'com.jakewharton:butterknife:8.0.1' compile('com.squareup.okhttp3:okhttp:3.2.0') { exclude group: 'com.squareup.okio', module: 'okio' } diff --git a/app/proguard_general.pro b/app/proguard_general.pro index e6a55578..85fdc34e 100644 --- a/app/proguard_general.pro +++ b/app/proguard_general.pro @@ -1,3 +1,6 @@ +-dontobfuscate +-optimizations !code/allocation/variable + -dontwarn android.support.** -keep class android.support.** { *; } -keep interface android.support.** { *; } diff --git a/app/src/main/java/com/tlongdev/bktf/BptfApplication.java b/app/src/main/java/com/tlongdev/bktf/BptfApplication.java index dda06db2..d81f44d6 100644 --- a/app/src/main/java/com/tlongdev/bktf/BptfApplication.java +++ b/app/src/main/java/com/tlongdev/bktf/BptfApplication.java @@ -26,11 +26,13 @@ import com.tlongdev.bktf.component.AdapterComponent; import com.tlongdev.bktf.component.DaggerActivityComponent; import com.tlongdev.bktf.component.DaggerAdapterComponent; +import com.tlongdev.bktf.component.DaggerDrawerManagerComponent; import com.tlongdev.bktf.component.DaggerFragmentComponent; import com.tlongdev.bktf.component.DaggerInteractorComponent; import com.tlongdev.bktf.component.DaggerPresenterComponent; import com.tlongdev.bktf.component.DaggerProfileManagerComponent; import com.tlongdev.bktf.component.DaggerServiceComponent; +import com.tlongdev.bktf.component.DrawerManagerComponent; import com.tlongdev.bktf.component.FragmentComponent; import com.tlongdev.bktf.component.InteractorComponent; import com.tlongdev.bktf.component.PresenterComponent; @@ -38,6 +40,7 @@ import com.tlongdev.bktf.component.ServiceComponent; import com.tlongdev.bktf.module.BptfAppModule; import com.tlongdev.bktf.module.NetworkModule; +import com.tlongdev.bktf.module.PresenterModule; import com.tlongdev.bktf.module.StorageModule; import com.tlongdev.bktf.util.ProfileManager; @@ -63,6 +66,8 @@ public class BptfApplication extends Application { private ServiceComponent mServiceComponent; + private DrawerManagerComponent mDrawerManagerComponent; + @Override public void onCreate() { super.onCreate(); @@ -73,13 +78,16 @@ public void onCreate() { BptfAppModule appModule = new BptfAppModule(this); StorageModule storageModule = new StorageModule(); NetworkModule networkModule = new NetworkModule(); + PresenterModule presenterModule = new PresenterModule(); mActivityComponent = DaggerActivityComponent.builder() .bptfAppModule(appModule) + .presenterModule(presenterModule) .build(); mFragmentComponent = DaggerFragmentComponent.builder() .bptfAppModule(appModule) + .presenterModule(presenterModule) .build(); mInteractorComponent = DaggerInteractorComponent.builder() @@ -106,6 +114,10 @@ public void onCreate() { .storageModule(storageModule) .build(); + mDrawerManagerComponent = DaggerDrawerManagerComponent.builder() + .bptfAppModule(appModule) + .build(); + if (!BuildConfig.DEBUG) { ProfileManager manager = new ProfileManager(this); if (manager.isSignedIn()) { @@ -160,4 +172,8 @@ public AdapterComponent getAdapterComponent() { public ServiceComponent getServiceComponent() { return mServiceComponent; } + + public DrawerManagerComponent getDrawerManagerComponent() { + return mDrawerManagerComponent; + } } \ No newline at end of file diff --git a/app/src/main/java/com/tlongdev/bktf/adapter/BackpackAdapter.java b/app/src/main/java/com/tlongdev/bktf/adapter/BackpackAdapter.java index add14b6e..42e654bd 100644 --- a/app/src/main/java/com/tlongdev/bktf/adapter/BackpackAdapter.java +++ b/app/src/main/java/com/tlongdev/bktf/adapter/BackpackAdapter.java @@ -36,7 +36,7 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -230,11 +230,11 @@ public void setListener(OnItemClickedListener listener) { */ public static class ViewHolder extends RecyclerView.ViewHolder { - @Nullable @Bind(R.id.text_view_header) public TextView header = null; - @Nullable @Bind(R.id.icon) public ImageView icon = null; - @Nullable @Bind(R.id.effect) public ImageView effect = null; - @Nullable @Bind(R.id.paint) public ImageView paint = null; - @Nullable @Bind(R.id.quality) public ImageView quality; + @Nullable @BindView(R.id.text_view_header) public TextView header = null; + @Nullable @BindView(R.id.icon) public ImageView icon = null; + @Nullable @BindView(R.id.effect) public ImageView effect = null; + @Nullable @BindView(R.id.paint) public ImageView paint = null; + @Nullable @BindView(R.id.quality) public ImageView quality; public CardView root = null; /** diff --git a/app/src/main/java/com/tlongdev/bktf/adapter/CalculatorAdapter.java b/app/src/main/java/com/tlongdev/bktf/adapter/CalculatorAdapter.java index d71df4d2..dab09c9c 100644 --- a/app/src/main/java/com/tlongdev/bktf/adapter/CalculatorAdapter.java +++ b/app/src/main/java/com/tlongdev/bktf/adapter/CalculatorAdapter.java @@ -34,7 +34,7 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -182,14 +182,14 @@ public void clearDataSet() { */ public static class ViewHolder extends RecyclerView.ViewHolder { - @Bind(R.id.icon) ImageView icon; - @Bind(R.id.name) TextView name; - @Bind(R.id.price) TextView price; - @Bind(R.id.effect) ImageView effect; - @Bind(R.id.delete) ImageView delete; - @Bind(R.id.quality) ImageView quality; - @Bind(R.id.count) EditText count; - @Bind(R.id.icon_background) View background; + @BindView(R.id.icon) ImageView icon; + @BindView(R.id.name) TextView name; + @BindView(R.id.price) TextView price; + @BindView(R.id.effect) ImageView effect; + @BindView(R.id.delete) ImageView delete; + @BindView(R.id.quality) ImageView quality; + @BindView(R.id.count) EditText count; + @BindView(R.id.icon_background) View background; /** * Constructor diff --git a/app/src/main/java/com/tlongdev/bktf/adapter/FavoritesAdapter.java b/app/src/main/java/com/tlongdev/bktf/adapter/FavoritesAdapter.java index a4f58b4f..194046bc 100644 --- a/app/src/main/java/com/tlongdev/bktf/adapter/FavoritesAdapter.java +++ b/app/src/main/java/com/tlongdev/bktf/adapter/FavoritesAdapter.java @@ -34,7 +34,7 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; public class FavoritesAdapter extends RecyclerView.Adapter { @@ -139,16 +139,16 @@ public void removeItem(Item item) { public class ViewHolder extends RecyclerView.ViewHolder { final View root; - @Bind(R.id.more) View more; - @Bind(R.id.icon_background) View background; + @BindView(R.id.more) View more; + @BindView(R.id.icon_background) View background; - @Bind(R.id.icon) ImageView icon; - @Bind(R.id.effect) ImageView effect; - @Bind(R.id.quality) ImageView quality; + @BindView(R.id.icon) ImageView icon; + @BindView(R.id.effect) ImageView effect; + @BindView(R.id.quality) ImageView quality; - @Bind(R.id.name) TextView name; - @Bind(R.id.price) TextView price; - @Bind(R.id.difference) TextView difference; + @BindView(R.id.name) TextView name; + @BindView(R.id.price) TextView price; + @BindView(R.id.difference) TextView difference; /** * Constructor. diff --git a/app/src/main/java/com/tlongdev/bktf/adapter/HistoryAdapter.java b/app/src/main/java/com/tlongdev/bktf/adapter/HistoryAdapter.java index 95465714..00e848b4 100644 --- a/app/src/main/java/com/tlongdev/bktf/adapter/HistoryAdapter.java +++ b/app/src/main/java/com/tlongdev/bktf/adapter/HistoryAdapter.java @@ -54,7 +54,7 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -263,16 +263,16 @@ public static class ViewHolder extends RecyclerView.ViewHolder { /** * The views of the element */ - @Nullable @Bind(R.id.effect) ImageView effect; - @Nullable @Bind(R.id.icon) ImageView icon; - @Nullable @Bind(R.id.quality) ImageView quality; - @Nullable @Bind(R.id.name) TextView name; - @Nullable @Bind(R.id.history_chart) LineChart historyChart; - @Nullable @Bind(R.id.icon_card) CardView iconCard; - - @Nullable @Bind(R.id.price) TextView price; - @Nullable @Bind(R.id.date) TextView date; - @Nullable @Bind(R.id.separator) View separator; + @Nullable @BindView(R.id.effect) ImageView effect; + @Nullable @BindView(R.id.icon) ImageView icon; + @Nullable @BindView(R.id.quality) ImageView quality; + @Nullable @BindView(R.id.name) TextView name; + @Nullable @BindView(R.id.history_chart) LineChart historyChart; + @Nullable @BindView(R.id.icon_card) CardView iconCard; + + @Nullable @BindView(R.id.price) TextView price; + @Nullable @BindView(R.id.date) TextView date; + @Nullable @BindView(R.id.separator) View separator; /** * Constructor diff --git a/app/src/main/java/com/tlongdev/bktf/adapter/LicensesAdapter.java b/app/src/main/java/com/tlongdev/bktf/adapter/LicensesAdapter.java index e3bae343..097b672f 100644 --- a/app/src/main/java/com/tlongdev/bktf/adapter/LicensesAdapter.java +++ b/app/src/main/java/com/tlongdev/bktf/adapter/LicensesAdapter.java @@ -28,7 +28,7 @@ import java.util.List; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; public class LicensesAdapter extends RecyclerView.Adapter{ @@ -77,9 +77,9 @@ public void setListener(OnClickListener listener) { public class ViewHolder extends RecyclerView.ViewHolder { - @Bind(R.id.name) TextView name; - @Bind(R.id.link) TextView link; - @Bind(R.id.license) TextView license; + @BindView(R.id.name) TextView name; + @BindView(R.id.link) TextView link; + @BindView(R.id.license) TextView license; public ViewHolder(View view) { super(view); diff --git a/app/src/main/java/com/tlongdev/bktf/adapter/RecentsAdapter.java b/app/src/main/java/com/tlongdev/bktf/adapter/RecentsAdapter.java index e93d6065..0772f321 100644 --- a/app/src/main/java/com/tlongdev/bktf/adapter/RecentsAdapter.java +++ b/app/src/main/java/com/tlongdev/bktf/adapter/RecentsAdapter.java @@ -36,7 +36,7 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -160,14 +160,14 @@ public void setListener(OnMoreListener listener) { public static class ViewHolder extends RecyclerView.ViewHolder { final View root; - @Bind(R.id.more) View more; - @Bind(R.id.icon_background) View background; - @Bind(R.id.icon) ImageView icon; - @Bind(R.id.effect) ImageView effect; - @Bind(R.id.quality) ImageView quality; - @Bind(R.id.name) TextView name; - @Bind(R.id.price) TextView price; - @Bind(R.id.difference) TextView difference; + @BindView(R.id.more) View more; + @BindView(R.id.icon_background) View background; + @BindView(R.id.icon) ImageView icon; + @BindView(R.id.effect) ImageView effect; + @BindView(R.id.quality) ImageView quality; + @BindView(R.id.name) TextView name; + @BindView(R.id.price) TextView price; + @BindView(R.id.difference) TextView difference; public ViewHolder(View view) { super(view); diff --git a/app/src/main/java/com/tlongdev/bktf/adapter/SearchAdapter.java b/app/src/main/java/com/tlongdev/bktf/adapter/SearchAdapter.java index 2bf571fb..d8d99d63 100644 --- a/app/src/main/java/com/tlongdev/bktf/adapter/SearchAdapter.java +++ b/app/src/main/java/com/tlongdev/bktf/adapter/SearchAdapter.java @@ -38,7 +38,7 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -222,15 +222,15 @@ public void setListener(OnSearchClickListener listener) { class ViewHolder extends RecyclerView.ViewHolder { final View root; - @Bind(R.id.loading_layout) View loading; - @Bind(R.id.price_layout) View priceLayout; - @Bind(R.id.icon) ImageView icon; - @Bind(R.id.icon_background) View background; - @Bind(R.id.effect) ImageView effect; - @Bind(R.id.more) ImageView more; - @Bind(R.id.quality) ImageView quality; - @Bind(R.id.name) TextView name; - @Bind(R.id.price) TextView price; + @BindView(R.id.loading_layout) View loading; + @BindView(R.id.price_layout) View priceLayout; + @BindView(R.id.icon) ImageView icon; + @BindView(R.id.icon_background) View background; + @BindView(R.id.effect) ImageView effect; + @BindView(R.id.more) ImageView more; + @BindView(R.id.quality) ImageView quality; + @BindView(R.id.name) TextView name; + @BindView(R.id.price) TextView price; public ViewHolder(View view) { super(view); diff --git a/app/src/main/java/com/tlongdev/bktf/adapter/SelectItemAdapter.java b/app/src/main/java/com/tlongdev/bktf/adapter/SelectItemAdapter.java index a0394306..0268d6ca 100644 --- a/app/src/main/java/com/tlongdev/bktf/adapter/SelectItemAdapter.java +++ b/app/src/main/java/com/tlongdev/bktf/adapter/SelectItemAdapter.java @@ -33,7 +33,7 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; public class SelectItemAdapter extends RecyclerView.Adapter { @@ -99,8 +99,8 @@ public void setListener(OnItemSelectedListener listener) { public class ViewHolder extends RecyclerView.ViewHolder { - @Bind(R.id.icon) ImageView icon; - @Bind(R.id.name) TextView name; + @BindView(R.id.icon) ImageView icon; + @BindView(R.id.name) TextView name; final View root; public ViewHolder(View view) { diff --git a/app/src/main/java/com/tlongdev/bktf/adapter/UnusualAdapter.java b/app/src/main/java/com/tlongdev/bktf/adapter/UnusualAdapter.java index ca9238f6..e5587ccd 100644 --- a/app/src/main/java/com/tlongdev/bktf/adapter/UnusualAdapter.java +++ b/app/src/main/java/com/tlongdev/bktf/adapter/UnusualAdapter.java @@ -38,7 +38,7 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -180,11 +180,11 @@ class ViewHolder extends RecyclerView.ViewHolder { final View root; - @Bind(R.id.icon) ImageView icon; - @Bind(R.id.effect) ImageView effect; - @Bind(R.id.price) TextView price; - @Bind(R.id.name) TextView name; - @Bind(R.id.more) View more; + @BindView(R.id.icon) ImageView icon; + @BindView(R.id.effect) ImageView effect; + @BindView(R.id.price) TextView price; + @BindView(R.id.name) TextView name; + @BindView(R.id.more) View more; public ViewHolder(View view) { super(view); diff --git a/app/src/main/java/com/tlongdev/bktf/ads/AdManager.java b/app/src/main/java/com/tlongdev/bktf/ads/AdManager.java index b16d212f..a440980c 100644 --- a/app/src/main/java/com/tlongdev/bktf/ads/AdManager.java +++ b/app/src/main/java/com/tlongdev/bktf/ads/AdManager.java @@ -1,7 +1,24 @@ +/** + * Copyright 2016 Long Tran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.tlongdev.bktf.ads; import android.content.Context; import android.content.SharedPreferences; +import android.os.Handler; import android.preference.PreferenceManager; import android.view.View; @@ -23,6 +40,8 @@ public class AdManager implements SharedPreferences.OnSharedPreferenceChangeList private boolean mAdsEnabled; + private boolean mInit = true; + private Set mAdViews = new HashSet<>(); public AdManager(Context context) { @@ -44,18 +63,30 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin for (AdView adView : mAdViews) { adView.setVisibility(mAdsEnabled ? View.VISIBLE : View.GONE); - if (mAdsEnabled && !((AppearAdListener)adView.getAdListener()).isLoaded()) { + if (mAdsEnabled && !((AppearAdListener) adView.getAdListener()).isLoaded()) { adView.loadAd(new AdRequest.Builder().build()); } } } } - public void addAdView(AdView adView) { + public void addAdView(final AdView adView) { mAdViews.add(adView); adView.setAdListener(new AppearAdListener(adView)); if (mAdsEnabled) { - adView.loadAd(new AdRequest.Builder().build()); + if (!mInit) { + adView.loadAd(new AdRequest.Builder().build()); + } else { + mInit = false; + final Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + AdRequest adRequest = new AdRequest.Builder().build(); + adView.loadAd(adRequest); + } + }, 1000); + } } } diff --git a/app/src/main/java/com/tlongdev/bktf/component/ActivityComponent.java b/app/src/main/java/com/tlongdev/bktf/component/ActivityComponent.java index 0432d9f1..136aaa01 100644 --- a/app/src/main/java/com/tlongdev/bktf/component/ActivityComponent.java +++ b/app/src/main/java/com/tlongdev/bktf/component/ActivityComponent.java @@ -17,9 +17,20 @@ package com.tlongdev.bktf.component; import com.tlongdev.bktf.module.BptfAppModule; +import com.tlongdev.bktf.module.PresenterModule; import com.tlongdev.bktf.ui.activity.AppCompatPreferenceActivity; import com.tlongdev.bktf.ui.activity.BptfActivity; +import com.tlongdev.bktf.ui.activity.ItemChooserActivity; +import com.tlongdev.bktf.ui.activity.ItemDetailActivity; +import com.tlongdev.bktf.ui.activity.LicensesActivity; +import com.tlongdev.bktf.ui.activity.LoginActivity; import com.tlongdev.bktf.ui.activity.MainActivity; +import com.tlongdev.bktf.ui.activity.PriceHistoryActivity; +import com.tlongdev.bktf.ui.activity.SearchActivity; +import com.tlongdev.bktf.ui.activity.SelectItemActivity; +import com.tlongdev.bktf.ui.activity.UnusualActivity; +import com.tlongdev.bktf.ui.activity.UserActivity; +import com.tlongdev.bktf.ui.activity.UserBackpackActivity; import javax.inject.Singleton; @@ -30,7 +41,7 @@ * @since 2016. 03. 10. */ @Singleton -@Component(modules = BptfAppModule.class) +@Component(modules = {PresenterModule.class, BptfAppModule.class}) public interface ActivityComponent { void inject(BptfActivity bptfActivity); @@ -38,4 +49,24 @@ public interface ActivityComponent { void inject(AppCompatPreferenceActivity appCompatPreferenceActivity); void inject(MainActivity mainActivity); + + void inject(ItemChooserActivity itemChooserActivity); + + void inject(ItemDetailActivity itemDetailActivity); + + void inject(LicensesActivity licensesActivity); + + void inject(LoginActivity loginActivity); + + void inject(PriceHistoryActivity priceHistoryActivity); + + void inject(SearchActivity searchActivity); + + void inject(SelectItemActivity selectItemActivity); + + void inject(UnusualActivity unusualActivity); + + void inject(UserActivity userActivity); + + void inject(UserBackpackActivity userBackpackActivity); } \ No newline at end of file diff --git a/app/src/main/java/com/tlongdev/bktf/component/DrawerManagerComponent.java b/app/src/main/java/com/tlongdev/bktf/component/DrawerManagerComponent.java new file mode 100644 index 00000000..dbc753ce --- /dev/null +++ b/app/src/main/java/com/tlongdev/bktf/component/DrawerManagerComponent.java @@ -0,0 +1,34 @@ +/** + * Copyright 2016 Long Tran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.tlongdev.bktf.component; + +import com.tlongdev.bktf.module.BptfAppModule; +import com.tlongdev.bktf.ui.NavigationDrawerManager; + +import javax.inject.Singleton; + +import dagger.Component; + +/** + * @author longi + * @since 2016.04.29. + */ +@Singleton +@Component(modules = {BptfAppModule.class}) +public interface DrawerManagerComponent { + void inject(NavigationDrawerManager navigationDrawerManager); +} diff --git a/app/src/main/java/com/tlongdev/bktf/component/FragmentComponent.java b/app/src/main/java/com/tlongdev/bktf/component/FragmentComponent.java index a015452a..1ad6841a 100644 --- a/app/src/main/java/com/tlongdev/bktf/component/FragmentComponent.java +++ b/app/src/main/java/com/tlongdev/bktf/component/FragmentComponent.java @@ -17,7 +17,12 @@ package com.tlongdev.bktf.component; import com.tlongdev.bktf.module.BptfAppModule; +import com.tlongdev.bktf.module.PresenterModule; import com.tlongdev.bktf.ui.fragment.BptfFragment; +import com.tlongdev.bktf.ui.fragment.CalculatorFragment; +import com.tlongdev.bktf.ui.fragment.ConverterFragment; +import com.tlongdev.bktf.ui.fragment.FavoritesFragment; +import com.tlongdev.bktf.ui.fragment.RecentsFragment; import com.tlongdev.bktf.ui.fragment.UnusualFragment; import com.tlongdev.bktf.ui.fragment.UserFragment; @@ -30,7 +35,7 @@ * @since 2016. 03. 10. */ @Singleton -@Component(modules = BptfAppModule.class) +@Component(modules = {PresenterModule.class, BptfAppModule.class}) public interface FragmentComponent { void inject(BptfFragment bptfFragment); @@ -38,4 +43,12 @@ public interface FragmentComponent { void inject(UserFragment userFragment); void inject(UnusualFragment unusualFragment); + + void inject(CalculatorFragment calculatorFragment); + + void inject(ConverterFragment converterFragment); + + void inject(FavoritesFragment favoritesFragment); + + void inject(RecentsFragment recentsFragment); } diff --git a/app/src/main/java/com/tlongdev/bktf/component/ServiceComponent.java b/app/src/main/java/com/tlongdev/bktf/component/ServiceComponent.java index c4130708..dea6ba40 100644 --- a/app/src/main/java/com/tlongdev/bktf/component/ServiceComponent.java +++ b/app/src/main/java/com/tlongdev/bktf/component/ServiceComponent.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Long Tran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.tlongdev.bktf.component; import com.tlongdev.bktf.gcm.GcmMessageHandler; diff --git a/app/src/main/java/com/tlongdev/bktf/customtabs/CustomTabActivityHelper.java b/app/src/main/java/com/tlongdev/bktf/customtabs/CustomTabActivityHelper.java index a40cc7f7..29248d78 100644 --- a/app/src/main/java/com/tlongdev/bktf/customtabs/CustomTabActivityHelper.java +++ b/app/src/main/java/com/tlongdev/bktf/customtabs/CustomTabActivityHelper.java @@ -25,7 +25,7 @@ public class CustomTabActivityHelper implements ServiceConnectionCallback { private ConnectionCallback mConnectionCallback; /** - * Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView. + * Opens the URL on a Custom Tab if possible. Otherwise falls back to opening it on a WebView. * * @param activity The host activity. * @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available. @@ -38,7 +38,7 @@ public static void openCustomTab(Activity activity, CustomTabFallback fallback) { String packageName = CustomTabsHelper.getPackageNameToUse(activity); - //If we cant find a package name, it means theres no browser that supports + //If we cant find a package name, it means there's no browser that supports //Chrome Custom Tabs installed. So, we fallback to the webview if (packageName == null || Build.VERSION.SDK_INT < 15) { if (fallback != null) { @@ -88,7 +88,7 @@ public void setConnectionCallback(ConnectionCallback connectionCallback) { /** * Binds the Activity to the Custom Tabs Service. - * @param activity the activity to be binded to the service. + * @param activity the activity to be bound to the service. */ public void bindCustomTabsService(Activity activity) { if (mClient != null) return; diff --git a/app/src/main/java/com/tlongdev/bktf/customtabs/CustomTabsHelper.java b/app/src/main/java/com/tlongdev/bktf/customtabs/CustomTabsHelper.java index b852923e..624d3b55 100644 --- a/app/src/main/java/com/tlongdev/bktf/customtabs/CustomTabsHelper.java +++ b/app/src/main/java/com/tlongdev/bktf/customtabs/CustomTabsHelper.java @@ -37,7 +37,7 @@ public static void addKeepAliveExtra(Context context, Intent intent) { } /** - * Goes through all apps that handle VIEW intents and have a warmup service. Picks + * Goes through all apps that handle VIEW intents and have a warm up service. Picks * the one chosen by the user if there is one, otherwise makes a best effort to return a * valid package name. * diff --git a/app/src/main/java/com/tlongdev/bktf/interactor/GetSearchedUserDataInteractor.java b/app/src/main/java/com/tlongdev/bktf/interactor/GetSearchedUserDataInteractor.java index 1758b5f0..b5fd09fc 100644 --- a/app/src/main/java/com/tlongdev/bktf/interactor/GetSearchedUserDataInteractor.java +++ b/app/src/main/java/com/tlongdev/bktf/interactor/GetSearchedUserDataInteractor.java @@ -204,7 +204,7 @@ private void saveUserData(BackpackTfPayload payload) { mUser.setVacBanned(player.getBanVac()); if (player.getBackpackTfTrust() != null) { - mUser.setTrustNegatvie(player.getBackpackTfTrust().getAgainst()); + mUser.setTrustNegative(player.getBackpackTfTrust().getAgainst()); mUser.setTrustPositive(player.getBackpackTfTrust().getFor()); } } diff --git a/app/src/main/java/com/tlongdev/bktf/interactor/GetUserDataInteractor.java b/app/src/main/java/com/tlongdev/bktf/interactor/GetUserDataInteractor.java index d591a6a0..59d39152 100644 --- a/app/src/main/java/com/tlongdev/bktf/interactor/GetUserDataInteractor.java +++ b/app/src/main/java/com/tlongdev/bktf/interactor/GetUserDataInteractor.java @@ -230,7 +230,7 @@ private void saveUserData(BackpackTfPayload payload) { mUser.setVacBanned(player.getBanVac()); if (player.getBackpackTfTrust() != null) { - mUser.setTrustNegatvie(player.getBackpackTfTrust().getAgainst()); + mUser.setTrustNegative(player.getBackpackTfTrust().getAgainst()); mUser.setTrustPositive(player.getBackpackTfTrust().getFor()); } } diff --git a/app/src/main/java/com/tlongdev/bktf/interactor/LoadAllPricesInteractor.java b/app/src/main/java/com/tlongdev/bktf/interactor/LoadAllPricesInteractor.java index 324c657b..74832bfe 100644 --- a/app/src/main/java/com/tlongdev/bktf/interactor/LoadAllPricesInteractor.java +++ b/app/src/main/java/com/tlongdev/bktf/interactor/LoadAllPricesInteractor.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package com.tlongdev.bktf.interactor; import android.content.Context; @@ -85,16 +84,7 @@ protected void onPostExecute(Cursor cursor) { } } - @Override - protected void onCancelled(Cursor cursor) { - if (mCallback != null) { - mCallback.onLoadPricesFailed(); - } - } - public interface Callback { void onLoadPricesFinished(Cursor prices); - - void onLoadPricesFailed(); } } diff --git a/app/src/main/java/com/tlongdev/bktf/interactor/LoadBackpackItemsInteractor.java b/app/src/main/java/com/tlongdev/bktf/interactor/LoadBackpackItemsInteractor.java index ab843468..090edd9f 100644 --- a/app/src/main/java/com/tlongdev/bktf/interactor/LoadBackpackItemsInteractor.java +++ b/app/src/main/java/com/tlongdev/bktf/interactor/LoadBackpackItemsInteractor.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Long Tran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.tlongdev.bktf.interactor; import android.content.ContentResolver; diff --git a/app/src/main/java/com/tlongdev/bktf/interactor/Tf2UserBackpackInteractor.java b/app/src/main/java/com/tlongdev/bktf/interactor/Tf2UserBackpackInteractor.java index a8630610..51adea2b 100644 --- a/app/src/main/java/com/tlongdev/bktf/interactor/Tf2UserBackpackInteractor.java +++ b/app/src/main/java/com/tlongdev/bktf/interactor/Tf2UserBackpackInteractor.java @@ -116,11 +116,11 @@ protected Integer doInBackground(Void... params) { protected void onPostExecute(Integer integer) { if (mCallback != null) { if (integer == 0) { - //Notify the listener that the backpack was private - mCallback.onPrivateBackpack(); - } else if (integer >= 1) { //Notify the user that the fetching finished and pass on the data mCallback.onUserBackpackFinished(mUser); + } else if (integer >= 1) { + //Notify the listener that the backpack was private + mCallback.onPrivateBackpack(); } else { mCallback.onUserBackpackFailed(errorMessage); } @@ -159,7 +159,7 @@ private int saveItems(PlayerItemsPayload payload) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); - //Content uri based on which talbe to insert into + //Content uri based on which table to insert into Uri contentUri; if (!mIsGuest) { contentUri = UserBackpackEntry.CONTENT_URI; @@ -187,12 +187,12 @@ private int saveItems(PlayerItemsPayload payload) { mProfileManager.saveUser(mUser); } } - return 1; + return 0; case 8: //Invalid ID, shouldn't reach throw new IllegalStateException( "Steam ID provided for backpack fetching was invalid: " + mUser.getResolvedSteamId()); case 15: //Backpack is private - return 2; + return 1; case 18: //ID doesn't exist, shouldn't reach throw new IllegalStateException( "Steam ID provided for backpack fetching doesn't exist: " + mUser.getResolvedSteamId()); diff --git a/app/src/main/java/com/tlongdev/bktf/model/Item.java b/app/src/main/java/com/tlongdev/bktf/model/Item.java index ed91fa8c..952cede1 100644 --- a/app/src/main/java/com/tlongdev/bktf/model/Item.java +++ b/app/src/main/java/com/tlongdev/bktf/model/Item.java @@ -205,7 +205,7 @@ public String getFormattedName(Context context, boolean isProper) { DatabaseContract.ItemSchemaEntry.CONTENT_URI, new String[]{ItemSchemaEntry.COLUMN_ITEM_NAME, ItemSchemaEntry.COLUMN_TYPE_NAME, ItemSchemaEntry.COLUMN_PROPER_NAME}, ItemSchemaEntry.TABLE_NAME + "." + ItemSchemaEntry.COLUMN_DEFINDEX + " = ?", - new String[]{String.valueOf(defindex)}, + new String[]{String.valueOf(priceIndex)}, null ); diff --git a/app/src/main/java/com/tlongdev/bktf/model/User.java b/app/src/main/java/com/tlongdev/bktf/model/User.java index 2c53008b..97e20fb1 100644 --- a/app/src/main/java/com/tlongdev/bktf/model/User.java +++ b/app/src/main/java/com/tlongdev/bktf/model/User.java @@ -59,7 +59,7 @@ public class User implements Parcelable { private int trustPositive; - private int trustNegatvie; + private int trustNegative; private int rawKeys; @@ -101,7 +101,7 @@ public User(Parcel source) { backpackValue = source.readDouble(); lastUpdated = source.readLong(); trustPositive = source.readInt(); - trustNegatvie = source.readInt(); + trustNegative = source.readInt(); rawKeys = source.readInt(); rawMetal = source.readDouble(); backpackSlots = source.readInt(); @@ -132,7 +132,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeDouble(backpackValue); dest.writeLong(lastUpdated); dest.writeInt(trustPositive); - dest.writeInt(trustNegatvie); + dest.writeInt(trustNegative); dest.writeInt(rawKeys); dest.writeDouble(rawMetal); dest.writeInt(backpackSlots); @@ -259,12 +259,12 @@ public void setTrustPositive(int trustPositive) { this.trustPositive = trustPositive; } - public int getTrustNegatvie() { - return trustNegatvie; + public int getTrustNegative() { + return trustNegative; } - public void setTrustNegatvie(int trustNegatvie) { - this.trustNegatvie = trustNegatvie; + public void setTrustNegative(int trustNegative) { + this.trustNegative = trustNegative; } public int getRawKeys() { diff --git a/app/src/main/java/com/tlongdev/bktf/module/BptfAppModule.java b/app/src/main/java/com/tlongdev/bktf/module/BptfAppModule.java index 6b299a96..bdac745f 100644 --- a/app/src/main/java/com/tlongdev/bktf/module/BptfAppModule.java +++ b/app/src/main/java/com/tlongdev/bktf/module/BptfAppModule.java @@ -25,6 +25,7 @@ import com.google.gson.Gson; import com.tlongdev.bktf.BptfApplication; import com.tlongdev.bktf.ads.AdManager; +import com.tlongdev.bktf.ui.NavigationDrawerManager; import com.tlongdev.bktf.util.ProfileManager; import javax.inject.Singleton; @@ -92,4 +93,10 @@ ProfileManager provideProfileManager(Application application) { AdManager provideAdManager(Application application) { return new AdManager(application); } + + @Provides + @Singleton + NavigationDrawerManager provideNavigationDrawerManager(Application application) { + return new NavigationDrawerManager((BptfApplication) application); + } } diff --git a/app/src/main/java/com/tlongdev/bktf/module/PresenterModule.java b/app/src/main/java/com/tlongdev/bktf/module/PresenterModule.java new file mode 100644 index 00000000..4a79253a --- /dev/null +++ b/app/src/main/java/com/tlongdev/bktf/module/PresenterModule.java @@ -0,0 +1,137 @@ +/** + * Copyright 2016 Long Tran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.tlongdev.bktf.module; + +import android.app.Application; + +import com.tlongdev.bktf.BptfApplication; +import com.tlongdev.bktf.presenter.activity.ItemChooserPresenter; +import com.tlongdev.bktf.presenter.activity.ItemDetailPresenter; +import com.tlongdev.bktf.presenter.activity.LicensesPresenter; +import com.tlongdev.bktf.presenter.activity.LoginPresenter; +import com.tlongdev.bktf.presenter.activity.PriceHistoryPresenter; +import com.tlongdev.bktf.presenter.activity.SearchPresenter; +import com.tlongdev.bktf.presenter.activity.SelectItemPresenter; +import com.tlongdev.bktf.presenter.activity.UnusualPresenter; +import com.tlongdev.bktf.presenter.activity.UserBackpackPresenter; +import com.tlongdev.bktf.presenter.activity.UserPresenter; +import com.tlongdev.bktf.presenter.fragment.CalculatorPresenter; +import com.tlongdev.bktf.presenter.fragment.FavoritesPresenter; +import com.tlongdev.bktf.presenter.fragment.RecentsPresenter; + +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; + +/** + * @author lngtr + * @since 2016. 04. 27. + */ +@Module +public class PresenterModule { + + @Provides + @Singleton + ItemChooserPresenter provideItemChooserPresenter(Application application) { + return new ItemChooserPresenter((BptfApplication) application); + } + + @Provides + @Singleton + ItemDetailPresenter provideItemDetailPresenter(Application application) { + return new ItemDetailPresenter((BptfApplication) application); + } + + @Provides + @Singleton + LicensesPresenter provideLicensesPresenter(Application application) { + return new LicensesPresenter((BptfApplication) application); + } + + @Provides + @Singleton + LoginPresenter provideLoginPresenter(Application application) { + return new LoginPresenter((BptfApplication) application); + } + + @Provides + @Singleton + PriceHistoryPresenter providePriceHistoryPresenter(Application application) { + return new PriceHistoryPresenter((BptfApplication) application); + } + + @Provides + @Singleton + SearchPresenter provideSearchPresenter(Application application) { + return new SearchPresenter((BptfApplication) application); + } + + @Provides + @Singleton + SelectItemPresenter provideSelectItemPresenter(Application application) { + return new SelectItemPresenter((BptfApplication) application); + } + + @Provides + @Singleton + UnusualPresenter provideUnusualPresenter(Application application) { + return new UnusualPresenter((BptfApplication) application); + } + + @Provides + @Singleton + UserBackpackPresenter provideUserBackpackPresenter(Application application) { + return new UserBackpackPresenter((BptfApplication) application); + } + + @Provides + @Singleton + UserPresenter provideUserPresenter(Application application) { + return new UserPresenter((BptfApplication) application); + } + + @Provides + @Singleton + CalculatorPresenter provideCalculatorPresenter(Application application) { + return new CalculatorPresenter((BptfApplication) application); + } + + @Provides + @Singleton + FavoritesPresenter provideFavoritesPresenter(Application application) { + return new FavoritesPresenter((BptfApplication) application); + } + + @Provides + @Singleton + RecentsPresenter provideRecentsPresenter(Application application) { + return new RecentsPresenter((BptfApplication) application); + } + + @Provides + @Singleton + com.tlongdev.bktf.presenter.fragment.UnusualPresenter provideUnusualFragmentPresenter(Application application) { + return new com.tlongdev.bktf.presenter.fragment.UnusualPresenter((BptfApplication) application); + } + + @Provides + @Singleton + com.tlongdev.bktf.presenter.fragment.UserPresenter provideUserFragmentPresenter(Application application) { + return new com.tlongdev.bktf.presenter.fragment.UserPresenter((BptfApplication) application); + } +} diff --git a/app/src/main/java/com/tlongdev/bktf/presenter/activity/UserPresenter.java b/app/src/main/java/com/tlongdev/bktf/presenter/activity/UserPresenter.java index 641c0899..3b45d01b 100644 --- a/app/src/main/java/com/tlongdev/bktf/presenter/activity/UserPresenter.java +++ b/app/src/main/java/com/tlongdev/bktf/presenter/activity/UserPresenter.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Long Tran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.tlongdev.bktf.presenter.activity; import android.os.AsyncTask; diff --git a/app/src/main/java/com/tlongdev/bktf/presenter/fragment/RecentsPresenter.java b/app/src/main/java/com/tlongdev/bktf/presenter/fragment/RecentsPresenter.java index 939626be..335988b2 100644 --- a/app/src/main/java/com/tlongdev/bktf/presenter/fragment/RecentsPresenter.java +++ b/app/src/main/java/com/tlongdev/bktf/presenter/fragment/RecentsPresenter.java @@ -41,7 +41,8 @@ * @author Long * @since 2016. 03. 10. */ -public class RecentsPresenter implements Presenter, LoadAllPricesInteractor.Callback, TlongdevPriceListInteractor.Callback, TlongdevItemSchemaInteractor.Callback, LoadCurrencyPricesInteractor.Callback { +public class RecentsPresenter implements Presenter, LoadAllPricesInteractor.Callback, + TlongdevPriceListInteractor.Callback, TlongdevItemSchemaInteractor.Callback, LoadCurrencyPricesInteractor.Callback { @Inject SharedPreferences mPrefs; @Inject SharedPreferences.Editor mEditor; @@ -51,6 +52,8 @@ public class RecentsPresenter implements Presenter, LoadAllPricesIn private RecentsView mView; private final BptfApplication mApplication; + private boolean mLoading = false; + public RecentsPresenter(BptfApplication application) { mApplication = application; application.getPresenterComponent().inject(this); @@ -59,6 +62,10 @@ public RecentsPresenter(BptfApplication application) { @Override public void attachView(RecentsView view) { mView = view; + + if (mView != null && mLoading) { + mView.showRefreshAnimation(); + } } @Override @@ -73,28 +80,13 @@ public void onLoadPricesFinished(Cursor prices) { } } - @Override - public void onLoadPricesFailed() { - if (mView != null) { - mView.showError(); - } - } - public void loadPrices() { //Download whole database when the app is first opened. if (mPrefs.getBoolean(mContext.getString(R.string.pref_initial_load_v2), true)) { if (Utility.isNetworkAvailable(mContext)) { - TlongdevPriceListInteractor task = new TlongdevPriceListInteractor(mApplication, false, true, this); - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - + callTlongdevPrices(false, true); //Show the progress dialog mView.showLoadingDialog("Downloading prices..."); - - mTracker.send(new HitBuilders.EventBuilder() - .setCategory("Request") - .setAction("Refresh") - .setLabel("Prices") - .build()); } else { mView.showErrorDialog(); } @@ -105,16 +97,8 @@ public void loadPrices() { //Update database if the last update happened more than an hour ago if (System.currentTimeMillis() - mPrefs.getLong(mContext.getString(R.string.pref_last_price_list_update), 0) >= 3600000L && Utility.isNetworkAvailable(mContext)) { - TlongdevPriceListInteractor interactor1 = new TlongdevPriceListInteractor(mApplication, true, false, this); - interactor1.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - + callTlongdevPrices(true, false); mView.showRefreshAnimation(); - - mTracker.send(new HitBuilders.EventBuilder() - .setCategory("Request") - .setAction("Refresh") - .setLabel("Prices") - .build()); } } } @@ -122,20 +106,40 @@ public void loadPrices() { public void downloadPrices() { //Manual update if (Utility.isNetworkAvailable(mContext)) { - TlongdevPriceListInteractor interactor = new TlongdevPriceListInteractor(mApplication, true, true, this); - interactor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - mTracker.send(new HitBuilders.EventBuilder() - .setCategory("Request") - .setAction("Refresh") - .setLabel("Prices") - .build()); + callTlongdevPrices(true, true); } else { + mLoading = false; mView.showToast("bptf: " + mContext.getString(R.string.error_no_network), Toast.LENGTH_SHORT); mView.hideRefreshingAnimation(); } } + private void callTlongdevPrices(boolean updateDatabase, boolean manualSync) { + TlongdevPriceListInteractor interactor = new TlongdevPriceListInteractor( + mApplication, updateDatabase, manualSync, this + ); + interactor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + mLoading = true; + + mTracker.send(new HitBuilders.EventBuilder() + .setCategory("Request") + .setAction("Refresh") + .setLabel("Prices") + .build()); + } + + private void callTlongdevItemSchema() { + TlongdevItemSchemaInteractor task = new TlongdevItemSchemaInteractor(mApplication, this); + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + mTracker.send(new HitBuilders.EventBuilder() + .setCategory("Request") + .setAction("Refresh") + .setLabel("ItemSchema") + .build()); + } + public void loadCurrencyPrices() { LoadCurrencyPricesInteractor interactor = new LoadCurrencyPricesInteractor( mApplication, this @@ -154,19 +158,10 @@ public void onPriceListFinished(int newItems, long sinceParam) { } if (mPrefs.getBoolean(mContext.getString(R.string.pref_initial_load_v2), true)) { - - TlongdevItemSchemaInteractor task = new TlongdevItemSchemaInteractor(mApplication, this); - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - + callTlongdevItemSchema(); if (mView != null) { mView.showLoadingDialog("Downloading item schema..."); } - - mTracker.send(new HitBuilders.EventBuilder() - .setCategory("Request") - .setAction("Refresh") - .setLabel("ItemSchema") - .build()); } else { if (newItems > 0) { loadPrices(); @@ -174,15 +169,9 @@ public void onPriceListFinished(int newItems, long sinceParam) { if (System.currentTimeMillis() - mPrefs.getLong(mContext.getString(R.string.pref_last_item_schema_update), 0) >= 172800000L //2days && Utility.isNetworkAvailable(mContext)) { - TlongdevItemSchemaInteractor task = new TlongdevItemSchemaInteractor(mApplication, this); - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - mTracker.send(new HitBuilders.EventBuilder() - .setCategory("Request") - .setAction("Refresh") - .setLabel("ItemSchema") - .build()); + callTlongdevItemSchema(); } else { + mLoading = false; if (mView != null) { mView.hideRefreshingAnimation(); loadCurrencyPrices(); @@ -217,6 +206,7 @@ public void onItemSchemaFinished() { mEditor.putBoolean(mContext.getString(R.string.pref_initial_load_v2), false); mEditor.apply(); + mLoading = false; if (mView != null) { //Stop animation mView.hideRefreshingAnimation(); diff --git a/app/src/main/java/com/tlongdev/bktf/presenter/fragment/UserPresenter.java b/app/src/main/java/com/tlongdev/bktf/presenter/fragment/UserPresenter.java index 76202b24..a60d4a36 100644 --- a/app/src/main/java/com/tlongdev/bktf/presenter/fragment/UserPresenter.java +++ b/app/src/main/java/com/tlongdev/bktf/presenter/fragment/UserPresenter.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -40,7 +40,7 @@ * @author Long * @since 2016. 03. 15. */ -public class UserPresenter implements Presenter,GetUserDataInteractor.Callback, SwipeRefreshLayout.OnRefreshListener, Tf2UserBackpackInteractor.Callback { +public class UserPresenter implements Presenter, GetUserDataInteractor.Callback, SwipeRefreshLayout.OnRefreshListener, Tf2UserBackpackInteractor.Callback { @Inject SharedPreferences mPrefs; @Inject SharedPreferences.Editor mEditor; @@ -52,6 +52,8 @@ public class UserPresenter implements Presenter,GetUserDataInteractor. private final BptfApplication mApplication; private boolean mSearchedUser; + private boolean mLoading = false; + public UserPresenter(BptfApplication application) { mApplication = application; application.getPresenterComponent().inject(this); @@ -60,6 +62,10 @@ public UserPresenter(BptfApplication application) { @Override public void attachView(UserView view) { mView = view; + + if (mView != null && mLoading) { + mView.showRefreshingAnimation(); + } } @Override @@ -74,16 +80,8 @@ public void getUserDataIfNeeded() { - user.getLastUpdated() >= 3600000L) { //Start the task and listen for the end - GetUserDataInteractor task = new GetUserDataInteractor(mApplication, - mProfileManager.getUser(), false, this); - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - + getUserData(false); mView.showRefreshingAnimation(); - - mTracker.send(new HitBuilders.EventBuilder() - .setCategory("Request") - .setAction("UserData") - .build()); } } @@ -102,24 +100,31 @@ public void onUserInfoFinished(User user) { @Override public void onUserInfoFailed(String errorMessage) { + mLoading = false; if (mView != null) { mView.hideRefreshingAnimation(); mView.showToast("bptf: " + errorMessage, Toast.LENGTH_SHORT); } } + private void getUserData(boolean isGuest) { + //Start fetching the data and listen for the end + GetUserDataInteractor interactor = new GetUserDataInteractor(mApplication, + mProfileManager.getUser(), isGuest, this); + interactor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + mLoading = true; + + mTracker.send(new HitBuilders.EventBuilder() + .setCategory("Request") + .setAction("UserData") + .build()); + } + @Override public void onRefresh() { if (Utility.isNetworkAvailable(mContext)) { - //Start fetching the data and listen for the end - GetUserDataInteractor interactor = new GetUserDataInteractor(mApplication, - mProfileManager.getUser(), true, this); - interactor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - mTracker.send(new HitBuilders.EventBuilder() - .setCategory("Request") - .setAction("UserData") - .build()); + getUserData(true); } else { //There is no internet connection, notify the user mView.showToast("bptf: " + mContext.getString(R.string.error_no_network), Toast.LENGTH_SHORT); @@ -129,11 +134,11 @@ public void onRefresh() { @Override public void onUserBackpackFinished(User user) { + mLoading = false; if (mView != null) { mView.backpack(false); mView.updateUserPage(mProfileManager.getUser()); mView.hideRefreshingAnimation(); - mView.updateDrawer(); } } @@ -147,17 +152,18 @@ public void onPrivateBackpack() { user.setRawMetal(-1); mProfileManager.saveUser(user); + mLoading = false; if (mView != null) { mView.backpack(true); mView.updateUserPage(user); mView.hideRefreshingAnimation(); - mView.updateDrawer(); } } @Override public void onUserBackpackFailed(String errorMessage) { //Stop the refreshing animation and update the UI + mLoading = false; if (mView != null) { mView.updateUserPage(mProfileManager.getUser()); mView.hideRefreshingAnimation(); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/NavigationDrawerManager.java b/app/src/main/java/com/tlongdev/bktf/ui/NavigationDrawerManager.java new file mode 100644 index 00000000..78b9b467 --- /dev/null +++ b/app/src/main/java/com/tlongdev/bktf/ui/NavigationDrawerManager.java @@ -0,0 +1,132 @@ +/** + * Copyright 2016 Long Tran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.tlongdev.bktf.ui; + +import android.content.Context; +import android.content.SharedPreferences; +import android.view.MenuItem; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.tlongdev.bktf.BptfApplication; +import com.tlongdev.bktf.R; +import com.tlongdev.bktf.model.User; +import com.tlongdev.bktf.util.CircleTransform; +import com.tlongdev.bktf.util.ProfileManager; + +import javax.inject.Inject; + +import butterknife.BindView; +import butterknife.ButterKnife; + +/** + * @author longi + * @since 2016.04.29. + */ +public class NavigationDrawerManager implements SharedPreferences.OnSharedPreferenceChangeListener { + + @Inject ProfileManager mProfileManager; + @Inject SharedPreferences mPrefs; + @Inject Context mContext; + + @BindView(R.id.user_name) TextView mName; + @BindView(R.id.backpack_value) TextView mBackpack; + @BindView(R.id.avatar) ImageView mAvatar; + + private MenuItem mUserMenuItem; + + public NavigationDrawerManager(BptfApplication application) { + application.getDrawerManagerComponent().inject(this); + //mProfileManager.addOnProfileUpdateListener(this); + mPrefs.registerOnSharedPreferenceChangeListener(this); + } + + public void attachView(View header) { + ButterKnife.bind(this, header); + + mContext = header.getContext(); + if (mProfileManager.isSignedIn()) { + update(mProfileManager.getUser()); + } + } + + public void detachView() { + mName = null; + mBackpack = null; + mAvatar = null; + mContext = null; + } + + public void onLogOut() { + Glide.with(mContext) + .load(R.drawable.steam_default_avatar) + .diskCacheStrategy(DiskCacheStrategy.ALL) + .transform(new CircleTransform(mContext)) + .into(mAvatar); + mName.setText(null); + mBackpack.setText(null); + + if (mUserMenuItem != null) { + mUserMenuItem.setEnabled(false); + } + } + + public void update(User user) { + //Set the name + mName.setText(user.getName()); + + //Set the backpack value + double bpValue = user.getBackpackValue(); + if (bpValue >= 0) { + mBackpack.setText(String.format("Backpack: %s", + mContext.getString(R.string.currency_metal, + String.valueOf(Math.round(bpValue))))); + } else { + mBackpack.setText("Private backpack"); + } + + //Download the avatar (if needed) and set it + Glide.with(mContext) + .load(user.getAvatarUrl()) + .diskCacheStrategy(DiskCacheStrategy.ALL) + .transform(new CircleTransform(mContext)) + .into(mAvatar); + if (mUserMenuItem != null) { + mUserMenuItem.setEnabled(true); + } + } + + public void setUserMenuItem(MenuItem userMenuItem) { + mUserMenuItem = userMenuItem; + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (!key.equals(mContext.getString(R.string.pref_user_data))) { + return; + } + + if (mProfileManager.isSignedIn()) { + update(mProfileManager.getUser()); + } else { + onLogOut(); + } + } +} diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/AboutActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/AboutActivity.java index 6bc3708d..76f19f7a 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/AboutActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/AboutActivity.java @@ -39,7 +39,7 @@ * handset devices, settings are presented as a single list. On tablets, * settings are split by category, with category headers shown to the left of * the list of settings. - *

+ * * See * Android Design: Settings for design guidelines and the Settings diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/ItemChooserActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/ItemChooserActivity.java index f469b1ef..832ce7cc 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/ItemChooserActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/ItemChooserActivity.java @@ -44,7 +44,9 @@ import java.util.List; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -58,18 +60,20 @@ public class ItemChooserActivity extends BptfActivity implements ItemChooserView public static final String EXTRA_ITEM = "item"; public static final String EXTRA_IS_FROM_CALCULATOR = "calculator"; - @Bind(R.id.quality) Spinner qualitySpinner; - @Bind(R.id.effect) Spinner effectSpinner; - @Bind(R.id.weapon_wear) Spinner wearSpinner; - @Bind(R.id.title_effect) TextView titleEffect; - @Bind(R.id.title_wear) TextView titleWear; - @Bind(R.id.icon) ImageView icon; - @Bind(R.id.item_text) TextView itemText; - @Bind(R.id.item_name) TextView itemName; - @Bind(R.id.tradable) CheckBox tradable; - @Bind(R.id.craftable) CheckBox craftable; - @Bind(R.id.australium) CheckBox australium; - @Bind(R.id.fab) FloatingActionButton fab; + @Inject ItemChooserPresenter mPresenter; + + @BindView(R.id.quality) Spinner qualitySpinner; + @BindView(R.id.effect) Spinner effectSpinner; + @BindView(R.id.weapon_wear) Spinner wearSpinner; + @BindView(R.id.title_effect) TextView titleEffect; + @BindView(R.id.title_wear) TextView titleWear; + @BindView(R.id.icon) ImageView icon; + @BindView(R.id.item_text) TextView itemText; + @BindView(R.id.item_name) TextView itemName; + @BindView(R.id.tradable) CheckBox tradable; + @BindView(R.id.craftable) CheckBox craftable; + @BindView(R.id.australium) CheckBox australium; + @BindView(R.id.fab) FloatingActionButton fab; @SuppressWarnings("NullableProblems") @Nullable @@ -79,7 +83,6 @@ public class ItemChooserActivity extends BptfActivity implements ItemChooserView private QualityAdapter qualityAdapter; private WeaponWearAdapter wearAdapter; private EffectAdapter effectAdapter; - private ItemChooserPresenter mPresenter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -88,7 +91,8 @@ protected void onCreate(Bundle savedInstanceState) { ButterKnife.bind(this); Dart.inject(this); - mPresenter = new ItemChooserPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); setTitle(null); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/ItemDetailActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/ItemDetailActivity.java index 5a3ddb87..fc6000ca 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/ItemDetailActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/ItemDetailActivity.java @@ -36,7 +36,9 @@ import com.tlongdev.bktf.ui.view.activity.ItemDetailView; import com.tlongdev.bktf.util.Utility; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -51,6 +53,8 @@ public class ItemDetailActivity extends BptfActivity implements ItemDetailView { public static final String EXTRA_ITEM_TYPE = "type"; public static final String EXTRA_PROPER_NAME = "proper"; + @Inject ItemDetailPresenter mPresenter; + @InjectExtra(EXTRA_GUEST) boolean isGuest; @InjectExtra(EXTRA_ITEM_ID) int mId; @InjectExtra(EXTRA_PROPER_NAME) int mProperName; @@ -58,26 +62,24 @@ public class ItemDetailActivity extends BptfActivity implements ItemDetailView { @InjectExtra(EXTRA_ITEM_TYPE) String mItemType; //References to all the text views in the view - @Bind(R.id.text_view_name) TextView name; - @Bind(R.id.text_view_level) TextView level; - @Bind(R.id.text_view_effect_name) TextView effect; - @Bind(R.id.text_view_custom_name) TextView customName; - @Bind(R.id.text_view_custom_desc) TextView customDesc; - @Bind(R.id.text_view_crafted) TextView crafterName; - @Bind(R.id.text_view_gifted) TextView gifterName; - @Bind(R.id.text_view_origin) TextView origin; - @Bind(R.id.text_view_paint) TextView paint; - @Bind(R.id.text_view_price) TextView priceView; - @Bind(R.id.image_layout) FrameLayout layout; + @BindView(R.id.text_view_name) TextView name; + @BindView(R.id.text_view_level) TextView level; + @BindView(R.id.text_view_effect_name) TextView effect; + @BindView(R.id.text_view_custom_name) TextView customName; + @BindView(R.id.text_view_custom_desc) TextView customDesc; + @BindView(R.id.text_view_crafted) TextView crafterName; + @BindView(R.id.text_view_gifted) TextView gifterName; + @BindView(R.id.text_view_origin) TextView origin; + @BindView(R.id.text_view_paint) TextView paint; + @BindView(R.id.text_view_price) TextView priceView; + @BindView(R.id.image_layout) FrameLayout layout; //References to the image view - @Bind(R.id.icon) ImageView icon; - @Bind(R.id.effect) ImageView effectView; - @Bind(R.id.paint) ImageView paintView; - @Bind(R.id.quality) ImageView quality; - @Bind(R.id.card_view) CardView cardView; - - private ItemDetailPresenter mPresenter; + @BindView(R.id.icon) ImageView icon; + @BindView(R.id.effect) ImageView effectView; + @BindView(R.id.paint) ImageView paintView; + @BindView(R.id.quality) ImageView quality; + @BindView(R.id.card_view) CardView cardView; @Override protected void onCreate(Bundle savedInstanceState) { @@ -86,7 +88,8 @@ protected void onCreate(Bundle savedInstanceState) { ButterKnife.bind(this); Dart.inject(this); - mPresenter = new ItemDetailPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); //Scale the icon, so the width of the image view is on third of the screen's width @@ -211,8 +214,7 @@ public void showItemDetails(BackpackItem item) { Price price = item.getPrice(); - if (price != null) - { + if (price != null) { //Show the priceView priceView.setVisibility(View.VISIBLE); priceView.setText(String.format("%s: %s", diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/LicensesActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/LicensesActivity.java index 54d4661f..92f45d96 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/LicensesActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/LicensesActivity.java @@ -32,15 +32,17 @@ import java.util.List; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; public class LicensesActivity extends BptfActivity implements LicensesView, LicensesAdapter.OnClickListener { - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.toolbar) Toolbar mToolbar; + @Inject LicensesPresenter mPresenter; - private LicensesPresenter mPresenter; + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.toolbar) Toolbar mToolbar; @Override protected void onCreate(Bundle savedInstanceState) { @@ -48,7 +50,8 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_licenses); ButterKnife.bind(this); - mPresenter = new LicensesPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); setSupportActionBar(mToolbar); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/LoginActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/LoginActivity.java index c1d13d99..2d1c328b 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/LoginActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/LoginActivity.java @@ -31,17 +31,20 @@ import com.tlongdev.bktf.presenter.activity.LoginPresenter; import com.tlongdev.bktf.ui.view.activity.LoginView; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; public class LoginActivity extends BptfActivity implements LoginView { - @Bind(R.id.steam_id) EditText steamIdInput; - @Bind(R.id.toolbar) Toolbar mToolbar; + @Inject LoginPresenter mPresenter; + + @BindView(R.id.steam_id) EditText steamIdInput; + @BindView(R.id.toolbar) Toolbar mToolbar; private ProgressDialog loadingDialog; - private LoginPresenter mPresenter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -49,7 +52,8 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_login); ButterKnife.bind(this); - mPresenter = new LoginPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); setSupportActionBar(mToolbar); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/MainActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/MainActivity.java index 4df727ce..0b0d51cf 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/MainActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/MainActivity.java @@ -33,28 +33,23 @@ import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.tlongdev.bktf.BptfApplication; import com.tlongdev.bktf.R; import com.tlongdev.bktf.gcm.GcmRegisterPriceUpdatesService; -import com.tlongdev.bktf.model.User; +import com.tlongdev.bktf.ui.NavigationDrawerManager; import com.tlongdev.bktf.ui.fragment.CalculatorFragment; import com.tlongdev.bktf.ui.fragment.ConverterFragment; import com.tlongdev.bktf.ui.fragment.FavoritesFragment; import com.tlongdev.bktf.ui.fragment.RecentsFragment; import com.tlongdev.bktf.ui.fragment.UnusualFragment; import com.tlongdev.bktf.ui.fragment.UserFragment; -import com.tlongdev.bktf.util.CircleTransform; import com.tlongdev.bktf.util.ProfileManager; import com.tlongdev.bktf.util.Utility; import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -69,23 +64,12 @@ public class MainActivity extends AppCompatActivity { private static final int REQUEST_SETTINGS = 100; public static final int REQUEST_NEW_ITEM = 101; - private static final String FRAGMENT_TAG_RECENTS = "recents"; - private static final String FRAGMENT_TAG_UNUSUALS = "unusuals"; - private static final String FRAGMENT_TAG_USER = "user"; - private static final String FRAGMENT_TAG_FAVORITES = "favorites"; - private static final String FRAGMENT_TAG_CONVERTER = "converter"; - private static final String FRAGMENT_TAG_CALCULATOR = "calculator"; - - /** - * Remember the position of the selected item. - */ - private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; - @Inject SharedPreferences mPrefs; @Inject ProfileManager mProfileManager; + @Inject NavigationDrawerManager mNavigationDrawerManager; - @Bind(R.id.drawer_layout) DrawerLayout mDrawerLayout; - @Bind(R.id.navigation_view) NavigationView mNavigationView; + @BindView(R.id.drawer_layout) DrawerLayout mDrawerLayout; + @BindView(R.id.navigation_view) NavigationView mNavigationView; /** * Helper component that ties the action bar to the navigation drawer. @@ -108,15 +92,6 @@ public class MainActivity extends AppCompatActivity { */ private OnDrawerOpenedListener mDrawerListener; - /** - * Views of the navigation header view. - */ - private TextView mName; - private TextView mBackpack; - private ImageView mAvatar; - - private MenuItem mUserMenuItem; - /** * Listener for the navigation drawer. */ @@ -178,21 +153,11 @@ protected void onCreate(Bundle savedInstanceState) { //The navigation view mNavigationView.setNavigationItemSelectedListener(navigationListener); - //User clicked on the header - View navigationHeader = mNavigationView.getHeaderView(0); - - //Find the views of the navigation drawer header - mName = (TextView) navigationHeader.findViewById(R.id.user_name); - mBackpack = (TextView) navigationHeader.findViewById(R.id.backpack_value); - mAvatar = (ImageView) navigationHeader.findViewById(R.id.avatar); - - mUserMenuItem = mNavigationView.getMenu().getItem(2); + mNavigationDrawerManager.attachView(mNavigationView.getHeaderView(0)); + mNavigationDrawerManager.setUserMenuItem(mNavigationView.getMenu().getItem(2)); //Check if there is a fragment to be restored - if (savedInstanceState != null) { - switchFragment(savedInstanceState.getInt(STATE_SELECTED_POSITION)); - mNavigationView.getMenu().getItem(mCurrentSelectedPosition).setChecked(true); - } else { + if (savedInstanceState == null) { mNavigationView.getMenu().getItem(0).setChecked(true); // Select either the default item (0) or the last selected item. switchFragment(0); @@ -217,7 +182,6 @@ protected void onResume() { } mUserStateChanged = false; } - updateDrawer(); boolean autoSync = !mPrefs.getString(getString(R.string.pref_auto_sync), "1").equals("0"); @@ -231,10 +195,9 @@ protected void onResume() { } @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - //Save the current fragment to be restored. - outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); + protected void onDestroy() { + super.onDestroy(); + mNavigationDrawerManager.detachView(); } @Override @@ -264,7 +227,7 @@ public boolean onOptionsItemSelected(MenuItem item) { @Override public void setSupportActionBar(Toolbar toolbar) { super.setSupportActionBar(toolbar); - //Since each fragment has it's own toolbar we need to re add the drawer toggle everytime we + //Since each fragment has it's own toolbar we need to re add the drawer toggle every time we //switch fragments restoreNavigationIcon(); } @@ -301,52 +264,34 @@ private void switchFragment(int position) { //Initialize fragments and add them is the drawer listener switch (position) { case 0: - newFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_RECENTS); - if (newFragment == null) { - newFragment = new RecentsFragment(); - } + newFragment = new RecentsFragment(); mDrawerListener = (RecentsFragment) newFragment; - transaction.replace(R.id.container, newFragment, FRAGMENT_TAG_RECENTS); + transaction.replace(R.id.container, newFragment); break; case 1: - newFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_UNUSUALS); - if (newFragment == null) { - newFragment = new UnusualFragment(); - } + newFragment = new UnusualFragment(); mDrawerListener = (UnusualFragment) newFragment; - transaction.replace(R.id.container, newFragment, FRAGMENT_TAG_UNUSUALS); + transaction.replace(R.id.container, newFragment); break; case 2: - newFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_USER); - if (newFragment == null) { - newFragment = UserFragment.newInstance(); - } + newFragment = UserFragment.newInstance(); mDrawerListener = (UserFragment) newFragment; - transaction.replace(R.id.container, newFragment, FRAGMENT_TAG_USER); + transaction.replace(R.id.container, newFragment); break; case 3: - newFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_FAVORITES); - if (newFragment == null) { - newFragment = new FavoritesFragment(); - } + newFragment = new FavoritesFragment(); mDrawerListener = (FavoritesFragment) newFragment; - transaction.replace(R.id.container, newFragment, FRAGMENT_TAG_FAVORITES); + transaction.replace(R.id.container, newFragment); break; case 4: - newFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_CONVERTER); - if (newFragment == null) { - newFragment = new ConverterFragment(); - } + newFragment = new ConverterFragment(); mDrawerListener = null; - transaction.replace(R.id.container, newFragment, FRAGMENT_TAG_CONVERTER); + transaction.replace(R.id.container, newFragment); break; case 5: - newFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_CALCULATOR); - if (newFragment == null) { - newFragment = new CalculatorFragment(); - } + newFragment = new CalculatorFragment(); mDrawerListener = (CalculatorFragment) newFragment; - transaction.replace(R.id.container, newFragment, FRAGMENT_TAG_CALCULATOR); + transaction.replace(R.id.container, newFragment); break; default: throw new IllegalArgumentException("unknown fragment to switch to: " + position); @@ -356,44 +301,6 @@ private void switchFragment(int position) { transaction.commit(); } - /** - * Updates the information in the navigation drawer header. - */ - public void updateDrawer() { - if (mProfileManager.isSignedIn()) { - User user = mProfileManager.getUser(); - - //Set the name - mName.setText(user.getName()); - - //Set the backpack value - double bpValue = user.getBackpackValue(); - if (bpValue >= 0) { - mBackpack.setText(String.format("Backpack: %s", getString(R.string.currency_metal, - String.valueOf(Math.round(bpValue))))); - } else { - mBackpack.setText("Private backpack"); - } - - //Download the avatar (if needed) and set it - Glide.with(this) - .load(user.getAvatarUrl()) - .diskCacheStrategy(DiskCacheStrategy.ALL) - .transform(new CircleTransform(this)) - .into(mAvatar); - mUserMenuItem.setEnabled(true); - } else { - Glide.with(this) - .load(R.drawable.steam_default_avatar) - .diskCacheStrategy(DiskCacheStrategy.ALL) - .transform(new CircleTransform(this)) - .into(mAvatar); - mName.setText(null); - mBackpack.setText(null); - mUserMenuItem.setEnabled(false); - } - } - /** * Restores the navigation icon of the toolbar. */ @@ -431,7 +338,7 @@ public void run() { } }); - mDrawerLayout.setDrawerListener(mDrawerToggle); + mDrawerLayout.addDrawerListener(mDrawerToggle); } /** diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/PriceHistoryActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/PriceHistoryActivity.java index 383de534..b87f433a 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/PriceHistoryActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/PriceHistoryActivity.java @@ -44,7 +44,9 @@ import java.util.List; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; public class PriceHistoryActivity extends BptfActivity implements PriceHistoryView { @@ -53,15 +55,15 @@ public class PriceHistoryActivity extends BptfActivity implements PriceHistoryVi public static final String EXTRA_ITEM = "item"; - @InjectExtra(EXTRA_ITEM) Item mItem; + @Inject PriceHistoryPresenter mPresenter; - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.progress_bar) ProgressBar progressBar; - @Bind(R.id.fail_text) TextView failText; - @Bind(R.id.toolbar) Toolbar mToolbar; - @Bind(R.id.ad_view) AdView mAdView; + @InjectExtra(EXTRA_ITEM) Item mItem; - private PriceHistoryPresenter mPresenter; + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.progress_bar) ProgressBar progressBar; + @BindView(R.id.fail_text) TextView failText; + @BindView(R.id.toolbar) Toolbar mToolbar; + @BindView(R.id.ad_view) AdView mAdView; @Override protected void onCreate(Bundle savedInstanceState) { @@ -70,7 +72,8 @@ protected void onCreate(Bundle savedInstanceState) { ButterKnife.bind(this); Dart.inject(this); - mPresenter = new PriceHistoryPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); setSupportActionBar(mToolbar); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/SearchActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/SearchActivity.java index 11e586ca..0aff741e 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/SearchActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/SearchActivity.java @@ -43,15 +43,19 @@ import com.tlongdev.bktf.presenter.activity.SearchPresenter; import com.tlongdev.bktf.util.Utility; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; public class SearchActivity extends BptfActivity implements com.tlongdev.bktf.ui.view.activity.SearchView, SearchAdapter.OnSearchClickListener { - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.toolbar) Toolbar mToolbar; - @Bind(R.id.ad_view) AdView mAdView; + @Inject SearchPresenter mPresenter; + + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.toolbar) Toolbar mToolbar; + @BindView(R.id.ad_view) AdView mAdView; //The adapter of the recyclerview private SearchAdapter mAdapter; @@ -63,15 +67,14 @@ public class SearchActivity extends BptfActivity implements com.tlongdev.bktf.ui private int filterQuality = Quality.UNIQUE; private String mQuery; - private SearchPresenter mPresenter; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); ButterKnife.bind(this); - mPresenter = new SearchPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); setSupportActionBar(mToolbar); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/SearchFilterActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/SearchFilterActivity.java index 7ad7ba46..5687dd8a 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/SearchFilterActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/SearchFilterActivity.java @@ -35,7 +35,7 @@ import java.util.Arrays; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -63,11 +63,11 @@ public class SearchFilterActivity extends BptfActivity { @Nullable @InjectExtra(EXTRA_AUSTRALIUM) boolean mAustralium = true; - @Bind(R.id.quality) Spinner qualitySpinner; - @Bind(R.id.tradable) CheckBox tradable; - @Bind(R.id.craftable) CheckBox craftable; - @Bind(R.id.australium) CheckBox australium; - @Bind(R.id.enable) Switch enableSwitch; + @BindView(R.id.quality) Spinner qualitySpinner; + @BindView(R.id.tradable) CheckBox tradable; + @BindView(R.id.craftable) CheckBox craftable; + @BindView(R.id.australium) CheckBox australium; + @BindView(R.id.enable) Switch enableSwitch; private QualityAdapter qualityAdapter; diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/SelectItemActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/SelectItemActivity.java index 2e6f6226..dcd34ca3 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/SelectItemActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/SelectItemActivity.java @@ -30,7 +30,9 @@ import com.tlongdev.bktf.presenter.activity.SelectItemPresenter; import com.tlongdev.bktf.ui.view.activity.SelectItemView; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; public class SelectItemActivity extends BptfActivity implements SelectItemView, TextWatcher, @@ -39,10 +41,11 @@ public class SelectItemActivity extends BptfActivity implements SelectItemView, public static final String EXTRA_DEFINDEX = "defindex"; public static final String EXTRA_NAME = "name"; - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.item_name) EditText inputName; + @Inject SelectItemPresenter mPresenter; + + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.item_name) EditText inputName; - private SelectItemPresenter mPresenter; private SelectItemAdapter mAdapter; @Override @@ -51,7 +54,8 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_select_item); ButterKnife.bind(this); - mPresenter = new SelectItemPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); setFinishOnTouchOutside(false); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/SettingsActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/SettingsActivity.java index 37727455..19ce75f4 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/SettingsActivity.java @@ -40,7 +40,7 @@ * handset devices, settings are presented as a single list. On tablets, * settings are split by category, with category headers shown to the left of * the list of settings. - *

+ * * See * Android Design: Settings for design guidelines and the Settings @@ -206,7 +206,7 @@ public boolean onPreferenceClick(Preference preference) { */ @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - //Start the appropiate services if these settings have been changed + //Start the appropriate services if these settings have been changed } @Override diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/UnusualActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/UnusualActivity.java index 47f14198..2cb3694d 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/UnusualActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/UnusualActivity.java @@ -47,7 +47,9 @@ import java.util.List; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -59,6 +61,8 @@ public class UnusualActivity extends BptfActivity implements UnusualView, TextWa public static final String EXTRA_NAME = "name"; public static final String EXTRA_PRICE_INDEX = "index"; + @Inject UnusualPresenter mPresenter; + @SuppressWarnings("NullableProblems") @Nullable @InjectExtra(EXTRA_DEFINDEX) int mDefindex = -1; @@ -67,13 +71,12 @@ public class UnusualActivity extends BptfActivity implements UnusualView, TextWa @InjectExtra(EXTRA_PRICE_INDEX) int mIndex = -1; @InjectExtra(EXTRA_NAME) String mName; - @Bind(R.id.search) EditText mSearchInput; - @Bind(R.id.toolbar) Toolbar mToolbar; - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.ad_view) AdView mAdView; + @BindView(R.id.search) EditText mSearchInput; + @BindView(R.id.toolbar) Toolbar mToolbar; + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.ad_view) AdView mAdView; private UnusualAdapter mAdapter; - private UnusualPresenter mPresenter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -82,7 +85,8 @@ protected void onCreate(Bundle savedInstanceState) { ButterKnife.bind(this); Dart.inject(this); - mPresenter = new UnusualPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); setSupportActionBar(mToolbar); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/UserActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/UserActivity.java index 042e3dc3..c08164a9 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/UserActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/UserActivity.java @@ -33,7 +33,9 @@ import com.tlongdev.bktf.ui.fragment.UserFragment; import com.tlongdev.bktf.ui.view.activity.UserView; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -50,13 +52,13 @@ public class UserActivity extends BptfActivity implements UserView{ //Keys for extra data in the intent. public static final String STEAM_ID_KEY = "steamid"; + @Inject UserPresenter mPresenter; + //Progress bar that indicates downloading user data. - @Bind(R.id.progress_bar) ProgressBar progressBar; + @BindView(R.id.progress_bar) ProgressBar progressBar; @InjectExtra(STEAM_ID_KEY) String steamId; - private UserPresenter mPresenter; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -64,7 +66,8 @@ protected void onCreate(Bundle savedInstanceState) { ButterKnife.bind(this); Dart.inject(this); - mPresenter = new UserPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/UserBackpackActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/UserBackpackActivity.java index a843329b..2222df29 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/UserBackpackActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/UserBackpackActivity.java @@ -40,7 +40,9 @@ import java.util.List; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; /** @@ -52,8 +54,10 @@ public class UserBackpackActivity extends BptfActivity implements UserBackpackVi public static final String EXTRA_NAME = "name"; public static final String EXTRA_GUEST = "guest"; - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.ad_view) AdView mAdView; + @Inject UserBackpackPresenter mPresenter; + + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.ad_view) AdView mAdView; //Adapters used for the listview private BackpackAdapter mAdapter; @@ -61,8 +65,6 @@ public class UserBackpackActivity extends BptfActivity implements UserBackpackVi //Boolean to decide which database table to load from private boolean isGuest; - private UserBackpackPresenter mPresenter; - /** * {@inheritDoc} */ @@ -72,7 +74,8 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_user_backpack); ButterKnife.bind(this); - mPresenter = new UserBackpackPresenter(mApplication); + mApplication.getActivityComponent().inject(this); + mPresenter.attachView(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/activity/WebActivity.java b/app/src/main/java/com/tlongdev/bktf/ui/activity/WebActivity.java index 98d4b8cc..78154602 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/activity/WebActivity.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/activity/WebActivity.java @@ -31,16 +31,16 @@ import com.f2prateek.dart.InjectExtra; import com.tlongdev.bktf.R; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; public class WebActivity extends BptfActivity { public static final String EXTRA_URL = "url"; - @Bind(R.id.web_view) WebView webView; - @Bind(R.id.toolbar) Toolbar mToolbar; - @Bind(R.id.progress_bar) ProgressBar mProgressBar; + @BindView(R.id.web_view) WebView webView; + @BindView(R.id.toolbar) Toolbar mToolbar; + @BindView(R.id.progress_bar) ProgressBar mProgressBar; @InjectExtra(EXTRA_URL) String mUrl; diff --git a/app/src/main/java/com/tlongdev/bktf/ui/fragment/CalculatorFragment.java b/app/src/main/java/com/tlongdev/bktf/ui/fragment/CalculatorFragment.java index 6183a58f..fdcde13b 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/fragment/CalculatorFragment.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/fragment/CalculatorFragment.java @@ -51,9 +51,12 @@ import java.util.List; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import butterknife.Unbinder; /** * Calculator fragment. Let's the user create a list of items and it will calculate the total value @@ -61,37 +64,39 @@ */ public class CalculatorFragment extends BptfFragment implements CalculatorView, MainActivity.OnDrawerOpenedListener{ - @Bind(R.id.text_view_price_metal) TextView priceMetal; - @Bind(R.id.text_view_price_keys) TextView priceKeys; - @Bind(R.id.text_view_price_buds) TextView priceBuds; - @Bind(R.id.text_view_price_usd) TextView priceUsd; - @Bind(R.id.app_bar_layout) AppBarLayout mAppBarLayout; - @Bind(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.ad_view) AdView mAdView; + @Inject CalculatorPresenter mPresenter; + + @BindView(R.id.text_view_price_metal) TextView priceMetal; + @BindView(R.id.text_view_price_keys) TextView priceKeys; + @BindView(R.id.text_view_price_buds) TextView priceBuds; + @BindView(R.id.text_view_price_usd) TextView priceUsd; + @BindView(R.id.app_bar_layout) AppBarLayout mAppBarLayout; + @BindView(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.ad_view) AdView mAdView; private CalculatorAdapter mAdapter; - private CalculatorPresenter mPresenter; + private Unbinder mUnbinder; public CalculatorFragment() { // Required empty public constructor } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true); - setRetainInstance(true); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - mPresenter = new CalculatorPresenter(mApplication); - mPresenter.attachView(this); - View rootView = inflater.inflate(R.layout.fragment_calculator, container, false); - ButterKnife.bind(this, rootView); + mUnbinder = ButterKnife.bind(this, rootView); + + mApplication.getFragmentComponent().inject(this); + + mPresenter.attachView(this); //Set the toolbar to the main activity's action bar ((AppCompatActivity) getActivity()).setSupportActionBar((Toolbar) rootView.findViewById(R.id.toolbar)); @@ -137,10 +142,11 @@ public void onResume() { } @Override - public void onDestroy() { - super.onDestroy(); + public void onDestroyView() { + super.onDestroyView(); mPresenter.detachView(); mAdManager.removeAdView(mAdView); + mUnbinder.unbind(); } @OnClick(R.id.fab) diff --git a/app/src/main/java/com/tlongdev/bktf/ui/fragment/ConverterFragment.java b/app/src/main/java/com/tlongdev/bktf/ui/fragment/ConverterFragment.java index 8cd390d9..5ba5a289 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/fragment/ConverterFragment.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/fragment/ConverterFragment.java @@ -43,11 +43,12 @@ import com.tlongdev.bktf.ui.activity.SearchActivity; import com.tlongdev.bktf.util.Utility; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import butterknife.OnFocusChange; import butterknife.OnTouch; +import butterknife.Unbinder; /** * Converter fragment. Let's the user quickly convert between currencies. @@ -63,17 +64,19 @@ public class ConverterFragment extends BptfFragment implements View.OnClickListe /** * Inputs */ - @Bind(R.id.edit_text_earbuds) EditText inputEarbuds; - @Bind(R.id.edit_text_keys) EditText inputKeys; - @Bind(R.id.edit_text_metal) EditText inputMetal; - @Bind(R.id.edit_text_usd) EditText inputUsd; - @Bind(R.id.ad_view) AdView mAdView; + @BindView(R.id.edit_text_earbuds) EditText inputEarbuds; + @BindView(R.id.edit_text_keys) EditText inputKeys; + @BindView(R.id.edit_text_metal) EditText inputMetal; + @BindView(R.id.edit_text_usd) EditText inputUsd; + @BindView(R.id.ad_view) AdView mAdView; /** * the view that is currently in focus */ private EditText focus; + private Unbinder mUnbinder; + /** * Constructor. */ @@ -82,10 +85,9 @@ public ConverterFragment() { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true); - setRetainInstance(true); } @Override @@ -93,8 +95,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_converter, container, false); - - ButterKnife.bind(this, rootView); + mUnbinder = ButterKnife.bind(this, rootView); //Set the toolbar to the main activity's action bar ((AppCompatActivity) getActivity()).setSupportActionBar((Toolbar) rootView.findViewById(R.id.toolbar)); @@ -252,9 +253,10 @@ public void onResume() { } @Override - public void onDestroy() { - super.onDestroy(); + public void onDestroyView() { + super.onDestroyView(); mAdManager.removeAdView(mAdView); + mUnbinder.unbind(); } @Override diff --git a/app/src/main/java/com/tlongdev/bktf/ui/fragment/FavoritesFragment.java b/app/src/main/java/com/tlongdev/bktf/ui/fragment/FavoritesFragment.java index 2676034f..0c3a608e 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/fragment/FavoritesFragment.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/fragment/FavoritesFragment.java @@ -52,9 +52,12 @@ import java.util.List; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import butterknife.Unbinder; /** * A simple {@link Fragment} subclass. @@ -62,13 +65,15 @@ public class FavoritesFragment extends BptfFragment implements FavoritesView, MainActivity.OnDrawerOpenedListener, FavoritesAdapter.OnMoreListener { - @Bind(R.id.app_bar_layout) AppBarLayout mAppBarLayout; - @Bind(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.ad_view) AdView mAdView; + @Inject FavoritesPresenter mPresenter; + + @BindView(R.id.app_bar_layout) AppBarLayout mAppBarLayout; + @BindView(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.ad_view) AdView mAdView; - private FavoritesPresenter mPresenter; private FavoritesAdapter mAdapter; + private Unbinder mUnbinder; /** * Constructor @@ -77,12 +82,6 @@ public FavoritesFragment() { // Required empty public constructor } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setRetainInstance(true); - } - @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -92,12 +91,13 @@ public void onActivityCreated(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - mPresenter = new FavoritesPresenter(mApplication); - mPresenter.attachView(this); - // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_favorites, container, false); - ButterKnife.bind(this, rootView); + mUnbinder = ButterKnife.bind(this, rootView); + + mApplication.getFragmentComponent().inject(this); + + mPresenter.attachView(this); //Set the toolbar to the main activity's action bar ((AppCompatActivity) getActivity()).setSupportActionBar((Toolbar) rootView.findViewById(R.id.toolbar)); @@ -138,10 +138,11 @@ public void onResume() { } @Override - public void onDestroy() { - super.onDestroy(); - mPresenter.detachView(); + public void onDestroyView() { + super.onDestroyView(); mAdManager.removeAdView(mAdView); + mPresenter.detachView(); + mUnbinder.unbind(); } @Override diff --git a/app/src/main/java/com/tlongdev/bktf/ui/fragment/RecentsFragment.java b/app/src/main/java/com/tlongdev/bktf/ui/fragment/RecentsFragment.java index 72fa6343..d43abe6d 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/fragment/RecentsFragment.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/fragment/RecentsFragment.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -62,8 +62,11 @@ import com.tlongdev.bktf.ui.view.fragment.RecentsView; import com.tlongdev.bktf.util.Utility; -import butterknife.Bind; +import javax.inject.Inject; + +import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.Unbinder; /** * recents fragment. Shows a list of all the prices orderd by the time of the price update. @@ -71,18 +74,20 @@ public class RecentsFragment extends BptfFragment implements RecentsView, SwipeRefreshLayout.OnRefreshListener, MainActivity.OnDrawerOpenedListener, RecentsAdapter.OnMoreListener { - @Bind(R.id.progress_bar) ProgressBar progressBar; - @Bind(R.id.swipe_refresh) SwipeRefreshLayout mSwipeRefreshLayout; - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.app_bar_layout) AppBarLayout mAppBarLayout; - @Bind(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; - @Bind(R.id.text_view_metal_price) TextView mMetalPrice; - @Bind(R.id.text_view_key_price) TextView mKeyPrice; - @Bind(R.id.text_view_buds_price) TextView mBudsPrice; - @Bind(R.id.image_view_metal_price) View metalPriceImage; - @Bind(R.id.image_view_key_price) View keyPriceImage; - @Bind(R.id.image_view_buds_price) View budsPriceImage; - @Bind(R.id.ad_view) AdView mAdView; + @Inject RecentsPresenter mPresenter; + + @BindView(R.id.progress_bar) ProgressBar progressBar; + @BindView(R.id.swipe_refresh) SwipeRefreshLayout mSwipeRefreshLayout; + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.app_bar_layout) AppBarLayout mAppBarLayout; + @BindView(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; + @BindView(R.id.text_view_metal_price) TextView mMetalPrice; + @BindView(R.id.text_view_key_price) TextView mKeyPrice; + @BindView(R.id.text_view_buds_price) TextView mBudsPrice; + @BindView(R.id.image_view_metal_price) View metalPriceImage; + @BindView(R.id.image_view_key_price) View keyPriceImage; + @BindView(R.id.image_view_buds_price) View budsPriceImage; + @BindView(R.id.ad_view) AdView mAdView; /** * Adapter of the recycler view @@ -93,7 +98,7 @@ public class RecentsFragment extends BptfFragment implements RecentsView, private Context mContext; - private RecentsPresenter mPresenter; + private Unbinder mUnbinder; /** * Constructor @@ -102,12 +107,6 @@ public RecentsFragment() { //Required empty constructor } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setRetainInstance(true); - } - @Override public void onAttach(Context context) { super.onAttach(context); @@ -123,11 +122,12 @@ public void onActivityCreated(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - mPresenter = new RecentsPresenter(mApplication); - mPresenter.attachView(this); - View rootView = inflater.inflate(R.layout.fragment_recents, container, false); - ButterKnife.bind(this, rootView); + mUnbinder = ButterKnife.bind(this, rootView); + + mApplication.getFragmentComponent().inject(this); + + mPresenter.attachView(this); //Set the toolbar to the main activity's action bar ((AppCompatActivity) mContext).setSupportActionBar((Toolbar) rootView.findViewById(R.id.toolbar)); @@ -173,10 +173,11 @@ public void onResume() { } @Override - public void onDestroy() { - super.onDestroy(); + public void onDestroyView() { + super.onDestroyView(); mPresenter.detachView(); mAdManager.removeAdView(mAdView); + mUnbinder.unbind(); } @Override @@ -210,7 +211,8 @@ public void onDrawerOpened() { * Fully expand the toolbar with animation. */ private void expandToolbar() { - AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams()).getBehavior(); + AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) + mAppBarLayout.getLayoutParams()).getBehavior(); behavior.onNestedFling(mCoordinatorLayout, mAppBarLayout, null, 0, -1000, true); } @@ -234,11 +236,6 @@ public void showPrices(Cursor prices) { } } - @Override - public void showError() { - mAdapter.swapCursor(null); - } - @Override public void showRefreshAnimation() { //Workaround for the circle not appearing diff --git a/app/src/main/java/com/tlongdev/bktf/ui/fragment/UnusualFragment.java b/app/src/main/java/com/tlongdev/bktf/ui/fragment/UnusualFragment.java index 54c1ad5b..ec89d9de 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/fragment/UnusualFragment.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/fragment/UnusualFragment.java @@ -53,8 +53,9 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.Unbinder; /** * The unusual fragment, that shows a list of unusual item categories. Either categorized by @@ -63,13 +64,14 @@ public class UnusualFragment extends BptfFragment implements UnusualView, MainActivity.OnDrawerOpenedListener, TextWatcher, UnusualAdapter.OnItemClickListener { + @Inject UnusualPresenter mPresenter; @Inject Context mContext; - @Bind(R.id.app_bar_layout) AppBarLayout mAppBarLayout; - @Bind(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; - @Bind(R.id.search) EditText mSearchInput; - @Bind(R.id.recycler_view) RecyclerView mRecyclerView; - @Bind(R.id.ad_view) AdView mAdView; + @BindView(R.id.app_bar_layout) AppBarLayout mAppBarLayout; + @BindView(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; + @BindView(R.id.search) EditText mSearchInput; + @BindView(R.id.recycler_view) RecyclerView mRecyclerView; + @BindView(R.id.ad_view) AdView mAdView; /** * the current sort type @@ -92,7 +94,7 @@ public class UnusualFragment extends BptfFragment implements UnusualView, */ private MenuItem effectMenuItem; - private UnusualPresenter mPresenter; + private Unbinder mUnbinder; /** * Constructor. @@ -102,10 +104,9 @@ public UnusualFragment() { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true); - setRetainInstance(true); } @Override @@ -113,10 +114,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_unusual, container, false); - ButterKnife.bind(this, rootView); + mUnbinder = ButterKnife.bind(this, rootView); + mApplication.getFragmentComponent().inject(this); - mPresenter = new UnusualPresenter(mApplication); mPresenter.attachView(this); //Set the toolbar to the main activity's action bar @@ -152,10 +153,11 @@ public void onResume() { } @Override - public void onDestroy() { - super.onDestroy(); + public void onDestroyView() { + super.onDestroyView(); mPresenter.detachView(); mAdManager.removeAdView(mAdView); + mUnbinder.unbind(); } @Override diff --git a/app/src/main/java/com/tlongdev/bktf/ui/fragment/UserFragment.java b/app/src/main/java/com/tlongdev/bktf/ui/fragment/UserFragment.java index 695cf086..531e05cc 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/fragment/UserFragment.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/fragment/UserFragment.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -60,9 +60,10 @@ import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import butterknife.Unbinder; /** * Fragment for displaying the user profile. @@ -71,39 +72,43 @@ public class UserFragment extends BptfFragment implements UserView, View.OnClick private static final String USER_PARAM = "user_param"; + @Inject UserPresenter mPresenter; @Inject SharedPreferences mPrefs; @Inject ProfileManager mProfileManager; @Inject Context mContext; - @Bind(R.id.text_view_player_reputation) TextView playerReputation; - @Bind(R.id.trust_positive) TextView trustPositive; - @Bind(R.id.trust_negative) TextView trustNegative; - @Bind(R.id.steamrep_status) ImageView steamRepStatus; - @Bind(R.id.vac_status) ImageView vacStatus; - @Bind(R.id.trade_status) ImageView tradeStatus; - @Bind(R.id.community_status) ImageView communityStatus; - @Bind(R.id.text_view_bp_refined) TextView backpackValueRefined; - @Bind(R.id.text_view_bp_raw_metal) TextView backpackRawMetal; - @Bind(R.id.text_view_bp_raw_keys) TextView backpackRawKeys; - @Bind(R.id.text_view_bp_usd) TextView backpackValueUsd; - @Bind(R.id.text_view_bp_slots) TextView backpackSlots; - @Bind(R.id.text_view_user_since) TextView userSinceText; - @Bind(R.id.text_view_user_last_online) TextView lastOnlineText; - @Bind(R.id.avatar) ImageView avatar; - @Bind(R.id.swipe_refresh) SwipeRefreshLayout mSwipeRefreshLayout; - @Bind(R.id.app_bar_layout) AppBarLayout mAppBarLayout; - @Bind(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; - @Bind(R.id.collapsing_toolbar) CollapsingToolbarLayout mCollapsingToolbarLayout; - @Bind(R.id.ad_view) AdView mAdView; + @BindView(R.id.text_view_player_reputation) TextView playerReputation; + @BindView(R.id.trust_positive) TextView trustPositive; + @BindView(R.id.trust_negative) TextView trustNegative; + @BindView(R.id.steamrep_status) ImageView steamRepStatus; + @BindView(R.id.vac_status) ImageView vacStatus; + @BindView(R.id.trade_status) ImageView tradeStatus; + @BindView(R.id.community_status) ImageView communityStatus; + @BindView(R.id.text_view_bp_refined) TextView backpackValueRefined; + @BindView(R.id.text_view_bp_raw_metal) TextView backpackRawMetal; + @BindView(R.id.text_view_bp_raw_keys) TextView backpackRawKeys; + @BindView(R.id.text_view_bp_usd) TextView backpackValueUsd; + @BindView(R.id.text_view_bp_slots) TextView backpackSlots; + @BindView(R.id.text_view_user_since) TextView userSinceText; + @BindView(R.id.text_view_user_last_online) TextView lastOnlineText; + @BindView(R.id.avatar) ImageView avatar; + @BindView(R.id.swipe_refresh) SwipeRefreshLayout mSwipeRefreshLayout; + @BindView(R.id.app_bar_layout) AppBarLayout mAppBarLayout; + @BindView(R.id.coordinator_layout) CoordinatorLayout mCoordinatorLayout; + @BindView(R.id.collapsing_toolbar) CollapsingToolbarLayout mCollapsingToolbarLayout; + @BindView(R.id.ad_view) AdView mAdView; + @BindView(R.id.private_text) TextView mPrivateBackpackText; + @BindView(R.id.backpack) ImageView mBackpackButton; + @BindView(R.id.backpack_content) View mBackpackContent; //Stores whether the backpack is private or not private boolean privateBackpack = false; - private UserPresenter mPresenter; - private User mUser; private boolean searchedUser; + private Unbinder mUnbinder; + /** * Constructor */ @@ -124,10 +129,9 @@ public static UserFragment newInstance(User user) { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true); - setRetainInstance(true); } /** @@ -141,15 +145,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, searchedUser = true; } + View rootView = inflater.inflate(R.layout.fragment_user, container, false); + mUnbinder = ButterKnife.bind(this, rootView); + mApplication.getFragmentComponent().inject(this); - mPresenter = new UserPresenter(mApplication); mPresenter.attachView(this); mPresenter.setSearchedUser(searchedUser); - View rootView = inflater.inflate(R.layout.fragment_user, container, false); - ButterKnife.bind(this, rootView); - //Set the toolbar to the main activity's action bar ((AppCompatActivity) getActivity()).setSupportActionBar((Toolbar) rootView.findViewById(R.id.toolbar)); @@ -183,10 +186,11 @@ public void onResume() { } @Override - public void onDestroy() { - super.onDestroy(); + public void onDestroyView() { + super.onDestroyView(); mPresenter.detachView(); mAdManager.removeAdView(mAdView); + mUnbinder.unbind(); } @Override @@ -208,61 +212,53 @@ public boolean onOptionsItemSelected(MenuItem item) { } @OnClick({R.id.button_bazaar_tf, R.id.button_steamrep, R.id.button_tf2op, R.id.button_tf2tp, - R.id.button_steam_community, R.id.backpack}) + R.id.button_steam_community}) public void onClick(View v) { //Handle all the buttons here //Get the steam id, do nothing if there is no steam id String steamId = mUser.getResolvedSteamId(); if (steamId.equals("")) { - showToast( "bptf: " + getString(R.string.error_no_steam_id), Toast.LENGTH_SHORT); + showToast("bptf: " + getString(R.string.error_no_steam_id), Toast.LENGTH_SHORT); return; } - //All buttons (except the backpack one) open a link in the browser - if (v.getId() != R.id.backpack) { - - String url; - switch (v.getId()) { - case R.id.button_bazaar_tf: - url = getString(R.string.link_bazaar_tf); - break; - case R.id.button_steamrep: - url = getString(R.string.link_steamrep); - break; - case R.id.button_tf2op: - url = getString(R.string.link_tf2op); - break; - case R.id.button_tf2tp: - url = getString(R.string.link_tf2tp); - break; - case R.id.button_steam_community: - url = getString(R.string.link_steam_community); - break; - default: - return; - } + String url; + switch (v.getId()) { + case R.id.button_bazaar_tf: + url = getString(R.string.link_bazaar_tf); + break; + case R.id.button_steamrep: + url = getString(R.string.link_steamrep); + break; + case R.id.button_tf2op: + url = getString(R.string.link_tf2op); + break; + case R.id.button_tf2tp: + url = getString(R.string.link_tf2tp); + break; + case R.id.button_steam_community: + url = getString(R.string.link_steam_community); + break; + default: + return; + } - //Create an URI for the intent. - Uri webPage = Uri.parse(url + steamId); + //Create an URI for the intent. + Uri webPage = Uri.parse(url + steamId); - //Open link in the device default web browser - CustomTabsIntent intent = new CustomTabsIntent.Builder().build(); - CustomTabActivityHelper.openCustomTab(getActivity(), intent, webPage, - new WebViewFallback()); - } else { - if (privateBackpack) { - //The backpack is private, do nothing - showToast(getString(R.string.message_private_backpack_own), Toast.LENGTH_SHORT); - } else { - //Else the user clicked on the backpack button. Start the backpack activity. Pass - //the steamId and whether it's the user's backpack or not - Intent i = new Intent(getActivity(), UserBackpackActivity.class); - i.putExtra(UserBackpackActivity.EXTRA_NAME, mCollapsingToolbarLayout.getTitle()); - i.putExtra(UserBackpackActivity.EXTRA_GUEST, searchedUser); - startActivity(i); - } - } + //Open link in the device default web browser + CustomTabsIntent intent = new CustomTabsIntent.Builder().build(); + CustomTabActivityHelper.openCustomTab(getActivity(), intent, webPage, + new WebViewFallback()); + } + + @OnClick(R.id.backpack) + public void onBackpackClick() { + Intent i = new Intent(getActivity(), UserBackpackActivity.class); + i.putExtra(UserBackpackActivity.EXTRA_NAME, mCollapsingToolbarLayout.getTitle()); + i.putExtra(UserBackpackActivity.EXTRA_GUEST, searchedUser); + startActivity(i); } @Override @@ -373,11 +369,14 @@ public void updateUserPage(User user) { //Backpack value double bpValue = mUser.getBackpackValue(); + + backpack(privateBackpack); + if (bpValue == -1) { //Value is unknown (probably private) backpackValueRefined.setText("?"); backpackValueUsd.setText("?"); - } else if (!privateBackpack) { + } else { //Properly format the backpack value (is int, does it have a fraction smaller than 0.01) backpackValueRefined.setText(String.valueOf(Math.round(bpValue))); @@ -388,7 +387,7 @@ public void updateUserPage(User user) { //Set the trust score and color the background according to it. trustPositive.setText(String.format(Locale.ENGLISH, "+%d", mUser.getTrustPositive())); - trustNegative.setText(String.format(Locale.ENGLISH, "-%d", mUser.getTrustNegatvie())); + trustNegative.setText(String.format(Locale.ENGLISH, "-%d", mUser.getTrustNegative())); //Raw keys int rawKeys = mUser.getRawKeys(); @@ -444,10 +443,19 @@ public void hideRefreshingAnimation() { @Override public void backpack(boolean _private) { privateBackpack = _private; - } - @Override - public void updateDrawer() { - ((MainActivity) getActivity()).updateDrawer(); + if (mPrivateBackpackText != null) { + if (_private) { + mPrivateBackpackText.setVisibility(View.VISIBLE); + mBackpackButton.setEnabled(false); + mBackpackButton.setVisibility(View.GONE); + mBackpackContent.setVisibility(View.GONE); + } else { + mPrivateBackpackText.setVisibility(View.GONE); + mBackpackButton.setEnabled(true); + mBackpackButton.setVisibility(View.VISIBLE); + mBackpackContent.setVisibility(View.VISIBLE); + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/tlongdev/bktf/ui/view/AppearAdListener.java b/app/src/main/java/com/tlongdev/bktf/ui/view/AppearAdListener.java index fe52093f..7a96ac04 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/view/AppearAdListener.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/view/AppearAdListener.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Long Tran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.tlongdev.bktf.ui.view; import android.view.View; diff --git a/app/src/main/java/com/tlongdev/bktf/ui/view/fragment/RecentsView.java b/app/src/main/java/com/tlongdev/bktf/ui/view/fragment/RecentsView.java index 01e2cf35..3c87a39f 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/view/fragment/RecentsView.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/view/fragment/RecentsView.java @@ -28,8 +28,6 @@ public interface RecentsView extends BaseView { void showPrices(Cursor prices); - void showError(); - void showRefreshAnimation(); void hideRefreshingAnimation(); diff --git a/app/src/main/java/com/tlongdev/bktf/ui/view/fragment/UserView.java b/app/src/main/java/com/tlongdev/bktf/ui/view/fragment/UserView.java index 9a27cd83..d30e3837 100644 --- a/app/src/main/java/com/tlongdev/bktf/ui/view/fragment/UserView.java +++ b/app/src/main/java/com/tlongdev/bktf/ui/view/fragment/UserView.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Long Tran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.tlongdev.bktf.ui.view.fragment; import com.tlongdev.bktf.model.User; @@ -15,6 +31,4 @@ public interface UserView extends BaseView { void updateUserPage(User user); void backpack(boolean _private); - - void updateDrawer(); } \ No newline at end of file diff --git a/app/src/main/java/com/tlongdev/bktf/util/ProfileManager.java b/app/src/main/java/com/tlongdev/bktf/util/ProfileManager.java index b4d2c4a5..ea5a76f5 100644 --- a/app/src/main/java/com/tlongdev/bktf/util/ProfileManager.java +++ b/app/src/main/java/com/tlongdev/bktf/util/ProfileManager.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,6 +24,9 @@ import com.tlongdev.bktf.R; import com.tlongdev.bktf.model.User; +import java.util.LinkedList; +import java.util.List; + import javax.inject.Inject; /** @@ -38,6 +41,8 @@ public class ProfileManager { private User mUserCache; + private List mListeners = new LinkedList<>(); + public ProfileManager(BptfApplication application) { application.getProfileManagerComponent().inject(this); } @@ -76,6 +81,10 @@ public void saveUser(User user) { String json = mGson.toJson(user); mEditor.putString(mContext.getString(R.string.pref_user_data), json); mEditor.apply(); + + for (OnUpdateListener listener : mListeners) { + listener.onUpdate(mUserCache); + } } /** @@ -96,5 +105,23 @@ public String getResolvedSteamId() { public void logOut() { mEditor.remove(mContext.getString(R.string.pref_user_data)); mEditor.apply(); + + for (OnUpdateListener listener : mListeners) { + listener.onLogOut(); + } + } + + public void addOnProfileUpdateListener(OnUpdateListener listener) { + mListeners.add(listener); + } + + public void removeOnUpdateListener(OnUpdateListener listener) { + mListeners.remove(listener); + } + + public interface OnUpdateListener { + void onLogOut(); + + void onUpdate(User user); } } diff --git a/app/src/main/res/drawable-nodpi/favorites_appwidget_preview.png b/app/src/main/res/drawable-nodpi/favorites_appwidget_preview.png index e4c8be00..798a7a64 100644 Binary files a/app/src/main/res/drawable-nodpi/favorites_appwidget_preview.png and b/app/src/main/res/drawable-nodpi/favorites_appwidget_preview.png differ diff --git a/app/src/main/res/drawable/hat.png b/app/src/main/res/drawable/hat.png index 24972c4a..b7372cb9 100644 Binary files a/app/src/main/res/drawable/hat.png and b/app/src/main/res/drawable/hat.png differ diff --git a/app/src/main/res/layout-v21/content_user_backpack.xml b/app/src/main/res/layout-v21/content_user_backpack.xml index d9154ffe..b5ff3d17 100644 --- a/app/src/main/res/layout-v21/content_user_backpack.xml +++ b/app/src/main/res/layout-v21/content_user_backpack.xml @@ -1,10 +1,10 @@ @@ -20,7 +20,7 @@ android:layout_weight="1" android:text="Backpack" android:textColor="@color/accent" - android:textSize="16sp" /> + android:textSize="16sp"/> @@ -37,136 +37,162 @@ + android:background="@color/separator_color"/> - - - - - + android:layout_height="wrap_content"> - - - - - - - - - - - - - - - + android:layout_gravity="center" + android:padding="16dp" + android:text="PRIVATE BACKPACK" + android:textColor="@color/text_primary" + android:textSize="24sp" + android:visibility="gone"/> + android:orientation="vertical"> - - - + + + + + + + + + + + + + + + + + + + + - - - - + android:baselineAligned="false" + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + android:textSize="32sp"/> + android:layout_marginBottom="16dp" + android:text="@string/user_page_slots"/> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_user.xml b/app/src/main/res/layout/activity_user.xml index 606dec25..912e3eff 100644 --- a/app/src/main/res/layout/activity_user.xml +++ b/app/src/main/res/layout/activity_user.xml @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/content_user_backpack.xml b/app/src/main/res/layout/content_user_backpack.xml index cd27482f..e7fb50a9 100644 --- a/app/src/main/res/layout/content_user_backpack.xml +++ b/app/src/main/res/layout/content_user_backpack.xml @@ -39,134 +39,160 @@ android:layout_height="1dp" android:background="@color/separator_color"/> - - - - - - - + android:layout_height="wrap_content"> - - - - - - - - - - - - - + android:layout_gravity="center" + android:padding="16dp" + android:text="PRIVATE BACKPACK" + android:textColor="@color/text_primary" + android:textSize="24sp" + android:visibility="gone"/> + android:orientation="vertical"> - - - + + + + + + + + + + + + + + + + + + + + - - - - + android:baselineAligned="false" + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + android:layout_marginBottom="16dp" + android:text="@string/user_page_slots"/> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/favorites_widget.xml b/app/src/main/res/layout/favorites_widget.xml index 158d8be5..bb491eb7 100644 --- a/app/src/main/res/layout/favorites_widget.xml +++ b/app/src/main/res/layout/favorites_widget.xml @@ -2,7 +2,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/card_color" android:padding="@dimen/widget_margin">