Add badge in the drawer when an exchange account is disabled

This commit is contained in:
Tanguy Herbron 2018-08-16 03:23:19 +02:00
parent 727e803b8b
commit e194d362ba
5 changed files with 64 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
@ -19,11 +20,13 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;
@ -61,6 +64,8 @@ public class HomeActivity extends AppCompatActivity implements BalanceUpdateInte
private Fragment overviewFragment;
private Fragment currentFragment;
private DatabaseManager databaseManager;
private TextView alertTextView;
private BalanceSwitchManagerInterface switchInterface;
@ -81,6 +86,7 @@ public class HomeActivity extends AppCompatActivity implements BalanceUpdateInte
drawerLayout = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
databaseManager = new DatabaseManager(this);
setListener((BalanceSwitchManagerInterface) holdingsFragment);
@ -123,9 +129,35 @@ public class HomeActivity extends AppCompatActivity implements BalanceUpdateInte
}
});
setupSettingsAlert(navigationView);
setupBalanceSwitch();
}
private void setupSettingsAlert(NavigationView navigationView)
{
alertTextView = (TextView) navigationView.getMenu().findItem(R.id.navigation_settings).getActionView();
alertTextView.setTextColor(getResources().getColor(R.color.decreaseCandle));
alertTextView.setGravity(Gravity.CENTER);
alertTextView.setTypeface(null, Typeface.BOLD);
updateSettingsAlertNumber();
}
private void updateSettingsAlertNumber()
{
int disabledNumber = databaseManager.getDisabledExchangeAccountsNumber();
if(disabledNumber > 0)
{
alertTextView.setText(String.valueOf(disabledNumber));
}
else
{
alertTextView.setText("");
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setStatusBarGradiant(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@ -197,6 +229,7 @@ public class HomeActivity extends AppCompatActivity implements BalanceUpdateInte
protected void onResume() {
super.onResume();
updateSettingsAlertNumber();
}
@Override

View File

@ -22,6 +22,7 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyPermanentlyInvalidatedException;
@ -811,7 +812,16 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
});
findPreference("exchange").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
DatabaseManager databaseManager = new DatabaseManager(getActivity().getBaseContext());
int disabledAcount = databaseManager.getDisabledExchangeAccountsNumber();
PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("exchange");
if(disabledAcount > 0)
{
preferenceScreen.setWidgetLayoutResource(R.layout.alert_layout);
}
preferenceScreen.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {

View File

@ -211,6 +211,17 @@ public class DatabaseManager extends SQLiteOpenHelper{
return result.getInt(0);
}
public int getDisabledExchangeAccountsNumber()
{
SQLiteDatabase db = this.getWritableDatabase();
String countQuerry = "SELECT COUNT() FROM " + TABLE_EXCHANGE_KEYS + " WHERE " + KEY_EXCHANGE_IS_ENABLED + "=0";
Cursor result = db.rawQuery(countQuerry, null);
result.moveToFirst();
return result.getInt(0);
}
public void deleteExchangeAccountFromId(int id)
{
SQLiteDatabase db = this.getWritableDatabase();

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_error_24dp"/>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
@ -31,6 +32,7 @@
<item
android:id="@+id/navigation_settings"
android:icon="@drawable/ic_settings_black_24dp"
app:actionViewClass="android.widget.TextView"
android:title="@string/title_activity_settings" />
</group>