Add hide balance switch in drawer

This commit is contained in:
Tanguy Herbron 2018-05-23 14:56:32 +02:00
parent bdc36f149f
commit 54e6bb4e9e
10 changed files with 76 additions and 28 deletions

View File

@ -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();

View File

@ -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<Void, Integer, Void>
{

View File

@ -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<Void, Integer, Void> updater = new AsyncTask<Void, Integer, Void>() {
@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);

View File

@ -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);

View File

@ -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);

View File

@ -0,0 +1,7 @@
package com.nauk.moodl;
public interface HideBalanceSwitch {
void buttonCheckedChange();
}

View File

@ -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">
<include layout="@layout/summary_drawer_footer"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<Switch
android:id="@+id/switchHideBalance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pref_title_hide_balance"
android:layout_margin="10dp"/>
</LinearLayout>

View File

@ -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"/>
<TextView
android:layout_width="wrap_content"

View File

@ -1,9 +1,9 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
<!--<SwitchPreference
android:defaultValue="false"
android:key="hide_balance"
android:title="@string/pref_title_hide_balance" />
android:title="@string/pref_title_hide_balance" />-->
<ListPreference
android:defaultValue="USD"