Add hide balance switch in drawer
This commit is contained in:
parent
bdc36f149f
commit
54e6bb4e9e
@ -15,10 +15,13 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
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.MarketCapitalization;
|
||||||
import com.nauk.moodl.Activities.HomeActivityFragments.Summary;
|
import com.nauk.moodl.Activities.HomeActivityFragments.Summary;
|
||||||
import com.nauk.moodl.Activities.HomeActivityFragments.Watchlist;
|
import com.nauk.moodl.Activities.HomeActivityFragments.Watchlist;
|
||||||
|
import com.nauk.moodl.HideBalanceSwitch;
|
||||||
import com.nauk.moodl.R;
|
import com.nauk.moodl.R;
|
||||||
|
|
||||||
//Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart
|
//Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart
|
||||||
@ -37,6 +40,9 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
private Fragment marketFragment;
|
private Fragment marketFragment;
|
||||||
private Fragment currentFragment;
|
private Fragment currentFragment;
|
||||||
|
|
||||||
|
|
||||||
|
private HideBalanceSwitch switchInterface;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -55,6 +61,8 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
drawerLayout = findViewById(R.id.drawer_layout);
|
drawerLayout = findViewById(R.id.drawer_layout);
|
||||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||||
|
|
||||||
|
setListener((HideBalanceSwitch) holdingsFragment);
|
||||||
|
|
||||||
showFragment(holdingsFragment);
|
showFragment(holdingsFragment);
|
||||||
|
|
||||||
navigationView.setCheckedItem(R.id.navigation_currencies_list);
|
navigationView.setCheckedItem(R.id.navigation_currencies_list);
|
||||||
@ -89,11 +97,30 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setupBalanceSwitch();
|
||||||
|
|
||||||
//Objects initialization
|
//Objects initialization
|
||||||
|
|
||||||
//Layouts setup
|
//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) {
|
private void showFragment(Fragment fragment) {
|
||||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
|
@ -34,6 +34,7 @@ import com.nauk.moodl.DataManagers.CurrencyData.Currency;
|
|||||||
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
||||||
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
||||||
import com.nauk.moodl.DataManagers.PreferencesManager;
|
import com.nauk.moodl.DataManagers.PreferencesManager;
|
||||||
|
import com.nauk.moodl.HideBalanceSwitch;
|
||||||
import com.nauk.moodl.PlaceholderManager;
|
import com.nauk.moodl.PlaceholderManager;
|
||||||
import com.nauk.moodl.R;
|
import com.nauk.moodl.R;
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ import static java.lang.Math.abs;
|
|||||||
* Created by Tiji on 13/04/2018.
|
* Created by Tiji on 13/04/2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Summary extends Fragment {
|
public class Summary extends Fragment implements HideBalanceSwitch {
|
||||||
|
|
||||||
private LinearLayout currencyLayout;
|
private LinearLayout currencyLayout;
|
||||||
private PreferencesManager preferencesManager;
|
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>
|
private class UiHeavyLoadCalculator extends AsyncTask<Void, Integer, Void>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class Watchlist extends Fragment {
|
|||||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||||
currencyTickerList = new CurrencyTickerList(getActivity());
|
currencyTickerList = new CurrencyTickerList(getActivity());
|
||||||
tickerUpdated = false;
|
tickerUpdated = false;
|
||||||
updateTickerList();
|
checkUpdatedData();
|
||||||
|
|
||||||
editModeEnabled = false;
|
editModeEnabled = false;
|
||||||
|
|
||||||
@ -98,25 +98,6 @@ public class Watchlist extends Fragment {
|
|||||||
return view;
|
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()
|
private void setupEditButton()
|
||||||
{
|
{
|
||||||
ImageButton editButton = view.findViewById(R.id.edit_button);
|
ImageButton editButton = view.findViewById(R.id.edit_button);
|
||||||
|
@ -164,7 +164,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setupActionBar();
|
setupActionBar();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,7 +216,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||||||
addPreferencesFromResource(R.xml.pref_general);
|
addPreferencesFromResource(R.xml.pref_general);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
findPreference("hide_balance").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
/*findPreference("hide_balance").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
boolean isChecked = ((SwitchPreference) findPreference("hide_balance")).isChecked();
|
boolean isChecked = ((SwitchPreference) findPreference("hide_balance")).isChecked();
|
||||||
@ -231,7 +230,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||||||
|
|
||||||
return isChecked;
|
return isChecked;
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
|
|
||||||
findPreference("version").setSummary(BuildConfig.VERSION_NAME);
|
findPreference("version").setSummary(BuildConfig.VERSION_NAME);
|
||||||
|
|
||||||
|
@ -93,6 +93,15 @@ public class PreferencesManager {
|
|||||||
return settingPreferences.getBoolean("enable_hitbtc", false);
|
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()
|
public boolean isBalanceHidden()
|
||||||
{
|
{
|
||||||
return settingPreferences.getBoolean("hide_balance", false);
|
return settingPreferences.getBoolean("hide_balance", false);
|
||||||
|
7
app/src/main/java/com/nauk/moodl/HideBalanceSwitch.java
Normal file
7
app/src/main/java/com/nauk/moodl/HideBalanceSwitch.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package com.nauk.moodl;
|
||||||
|
|
||||||
|
public interface HideBalanceSwitch {
|
||||||
|
|
||||||
|
void buttonCheckedChange();
|
||||||
|
|
||||||
|
}
|
@ -19,6 +19,10 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="start"
|
android:layout_gravity="start"
|
||||||
app:menu="@menu/summary_navigation_drawer"
|
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>
|
</android.support.v4.widget.DrawerLayout>
|
14
app/src/main/res/layout/summary_drawer_footer.xml
Normal file
14
app/src/main/res/layout/summary_drawer_footer.xml
Normal 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>
|
@ -16,7 +16,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@mipmap/ic_launcher_moodl"
|
android:src="@mipmap/ic_launcher_moodl"
|
||||||
android:layout_marginRight="10dp"/>
|
android:layout_marginEnd="10dp"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<SwitchPreference
|
<!--<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="hide_balance"
|
android:key="hide_balance"
|
||||||
android:title="@string/pref_title_hide_balance" />
|
android:title="@string/pref_title_hide_balance" />-->
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:defaultValue="USD"
|
android:defaultValue="USD"
|
||||||
|
Loading…
Reference in New Issue
Block a user