From 54e6bb4e9ea1712bcfc1b071702bada6a613e85c Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 23 May 2018 14:56:32 +0200 Subject: [PATCH] Add hide balance switch in drawer --- .../nauk/moodl/Activities/HomeActivity.java | 27 +++++++++++++++++++ .../HomeActivityFragments/Summary.java | 9 ++++++- .../HomeActivityFragments/Watchlist.java | 21 +-------------- .../moodl/Activities/SettingsActivity.java | 5 ++-- .../DataManagers/PreferencesManager.java | 9 +++++++ .../com/nauk/moodl/HideBalanceSwitch.java | 7 +++++ .../res/layout/activity_currency_summary.xml | 6 ++++- .../main/res/layout/summary_drawer_footer.xml | 14 ++++++++++ .../main/res/layout/summary_drawer_header.xml | 2 +- app/src/main/res/xml/pref_general.xml | 4 +-- 10 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 app/src/main/java/com/nauk/moodl/HideBalanceSwitch.java create mode 100644 app/src/main/res/layout/summary_drawer_footer.xml diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java index aae90a9..09e1a21 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java @@ -15,10 +15,13 @@ import android.view.Menu; import android.view.MenuItem; import android.view.Window; import android.view.WindowManager; +import android.widget.CompoundButton; +import android.widget.Switch; import com.nauk.moodl.Activities.HomeActivityFragments.MarketCapitalization; import com.nauk.moodl.Activities.HomeActivityFragments.Summary; import com.nauk.moodl.Activities.HomeActivityFragments.Watchlist; +import com.nauk.moodl.HideBalanceSwitch; import com.nauk.moodl.R; //Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart @@ -37,6 +40,9 @@ public class HomeActivity extends AppCompatActivity { private Fragment marketFragment; private Fragment currentFragment; + + private HideBalanceSwitch switchInterface; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -55,6 +61,8 @@ public class HomeActivity extends AppCompatActivity { drawerLayout = findViewById(R.id.drawer_layout); NavigationView navigationView = findViewById(R.id.nav_view); + setListener((HideBalanceSwitch) holdingsFragment); + showFragment(holdingsFragment); navigationView.setCheckedItem(R.id.navigation_currencies_list); @@ -89,11 +97,30 @@ public class HomeActivity extends AppCompatActivity { } }); + setupBalanceSwitch(); + //Objects initialization //Layouts setup } + public void setListener(HideBalanceSwitch switchInterface) + { + this.switchInterface = switchInterface; + } + + private void setupBalanceSwitch() + { + Switch balanceSwitch = findViewById(R.id.switchHideBalance); + + balanceSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + switchInterface.buttonCheckedChange(); + } + }); + } + private void showFragment(Fragment fragment) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java index ac4e7f5..ccdbcd8 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java @@ -34,6 +34,7 @@ import com.nauk.moodl.DataManagers.CurrencyData.Currency; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList; import com.nauk.moodl.DataManagers.PreferencesManager; +import com.nauk.moodl.HideBalanceSwitch; import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; @@ -50,7 +51,7 @@ import static java.lang.Math.abs; * Created by Tiji on 13/04/2018. */ -public class Summary extends Fragment { +public class Summary extends Fragment implements HideBalanceSwitch { private LinearLayout currencyLayout; private PreferencesManager preferencesManager; @@ -466,6 +467,12 @@ public class Summary extends Fragment { } } + @Override + public void buttonCheckedChange() { + preferencesManager.switchBalanceHiddenState(); + displayBalance(preferencesManager.isBalanceHidden()); + } + private class UiHeavyLoadCalculator extends AsyncTask { diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java index 4028081..0c2cbad 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -74,7 +74,7 @@ public class Watchlist extends Fragment { defaultCurrency = preferencesManager.getDefaultCurrency(); currencyTickerList = new CurrencyTickerList(getActivity()); tickerUpdated = false; - updateTickerList(); + checkUpdatedData(); editModeEnabled = false; @@ -98,25 +98,6 @@ public class Watchlist extends Fragment { return view; } - private void updateTickerList() - { - AsyncTask updater = new AsyncTask() { - @Override - protected Void doInBackground(Void... voids) { - currencyTickerList.update(new BalanceManager.IconCallBack() { - @Override - public void onSuccess() { - tickerUpdated = true; - checkUpdatedData(); - } - }); - return null; - } - }; - - updater.execute(); - } - private void setupEditButton() { ImageButton editButton = view.findViewById(R.id.edit_button); diff --git a/app/src/main/java/com/nauk/moodl/Activities/SettingsActivity.java b/app/src/main/java/com/nauk/moodl/Activities/SettingsActivity.java index 3f16f39..1369336 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/SettingsActivity.java @@ -164,7 +164,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupActionBar(); - } /** @@ -217,7 +216,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { addPreferencesFromResource(R.xml.pref_general); setHasOptionsMenu(true); - findPreference("hide_balance").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + /*findPreference("hide_balance").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { boolean isChecked = ((SwitchPreference) findPreference("hide_balance")).isChecked(); @@ -231,7 +230,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { return isChecked; } - }); + });*/ findPreference("version").setSummary(BuildConfig.VERSION_NAME); diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/PreferencesManager.java b/app/src/main/java/com/nauk/moodl/DataManagers/PreferencesManager.java index 47fd5f6..9172c06 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/PreferencesManager.java @@ -93,6 +93,15 @@ public class PreferencesManager { return settingPreferences.getBoolean("enable_hitbtc", false); } + public boolean switchBalanceHiddenState() + { + SharedPreferences.Editor editor = settingPreferences.edit(); + editor.putBoolean("hide_balance", !isBalanceHidden()); + editor.apply(); + + return isBalanceHidden(); + } + public boolean isBalanceHidden() { return settingPreferences.getBoolean("hide_balance", false); diff --git a/app/src/main/java/com/nauk/moodl/HideBalanceSwitch.java b/app/src/main/java/com/nauk/moodl/HideBalanceSwitch.java new file mode 100644 index 0000000..fce4858 --- /dev/null +++ b/app/src/main/java/com/nauk/moodl/HideBalanceSwitch.java @@ -0,0 +1,7 @@ +package com.nauk.moodl; + +public interface HideBalanceSwitch { + + void buttonCheckedChange(); + +} diff --git a/app/src/main/res/layout/activity_currency_summary.xml b/app/src/main/res/layout/activity_currency_summary.xml index 68dac42..0c30e2a 100644 --- a/app/src/main/res/layout/activity_currency_summary.xml +++ b/app/src/main/res/layout/activity_currency_summary.xml @@ -19,6 +19,10 @@ android:layout_height="match_parent" android:layout_gravity="start" app:menu="@menu/summary_navigation_drawer" - app:headerLayout="@layout/summary_drawer_header"/> + app:headerLayout="@layout/summary_drawer_header"> + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/summary_drawer_footer.xml b/app/src/main/res/layout/summary_drawer_footer.xml new file mode 100644 index 0000000..c2e5a6b --- /dev/null +++ b/app/src/main/res/layout/summary_drawer_footer.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/summary_drawer_header.xml b/app/src/main/res/layout/summary_drawer_header.xml index 81915db..1ce7122 100644 --- a/app/src/main/res/layout/summary_drawer_header.xml +++ b/app/src/main/res/layout/summary_drawer_header.xml @@ -16,7 +16,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher_moodl" - android:layout_marginRight="10dp"/> + android:layout_marginEnd="10dp"/> - + android:title="@string/pref_title_hide_balance" />-->