--- /dev/null
+package net.ktnx.mobileledger;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.LinearLayout;
+
+class AccountRowLayout extends LinearLayout {
+ private String accountName;
+
+ public
+ AccountRowLayout(Context context, String accountName) {
+ super(context);
+ this.accountName = accountName;
+ }
+
+ public
+ AccountRowLayout(Context context, AttributeSet attrs, String accountName) {
+ super(context, attrs);
+ this.accountName = accountName;
+ }
+
+ public
+ AccountRowLayout(Context context, AttributeSet attrs, int defStyleAttr, String accountName) {
+ super(context, attrs, defStyleAttr);
+ this.accountName = accountName;
+ }
+
+ public
+ AccountRowLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes,
+ String accountName) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ this.accountName = accountName;
+ }
+
+ public
+ String getAccountName() {
+ return accountName;
+ }
+}
import android.annotation.SuppressLint;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.res.Resources;
import android.database.Cursor;
+import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
-import android.widget.Toast;
import java.util.Date;
import java.util.regex.Matcher;
private static long account_list_last_updated;
private static boolean account_list_needs_update = true;
- private LinearLayout clickedAccountRow;
+ MenuItem mShowHiddenAccounts;
+ SharedPreferences.OnSharedPreferenceChangeListener sBindPreferenceSummaryToValueListener;
+ private AccountRowLayout clickedAccountRow;
public static void preferences_changed() {
account_list_needs_update = true;
getMenuInflater().inflate(R.menu.account_summary, menu);
mRefresh = menu.findItem(R.id.menu_acc_summary_refresh);
if (mRefresh == null) throw new AssertionError();
+
+ mShowHiddenAccounts = menu.findItem(R.id.menu_acc_summary_show_hidden);
+ if (mShowHiddenAccounts == null) throw new AssertionError();
+
+ sBindPreferenceSummaryToValueListener =
+ new SharedPreferences.OnSharedPreferenceChangeListener() {
+ @Override
+ public
+ void onSharedPreferenceChanged(SharedPreferences preference, String value) {
+ mShowHiddenAccounts
+ .setChecked(preference.getBoolean("show_hidden_accounts", false));
+ }
+ };
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
+ pref.registerOnSharedPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
+
+ mShowHiddenAccounts.setChecked(pref.getBoolean("show_hidden_accounts", false));
+
return true;
}
update_accounts(true);
}
+ public
+ void onShowHiddenAccountsClicked(MenuItem mi) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
+ boolean flag = pref.getBoolean("show_hidden_accounts", false);
+
+ SharedPreferences.Editor editor = pref.edit();
+ editor.putBoolean("show_hidden_accounts", !flag);
+ Log.d("pref", "Setting show_hidden_accounts to " + (flag ? "false" : "true"));
+ editor.apply();
+
+ update_account_table();
+ }
+
private void prepare_db() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
MobileLedgerDB.setDb_filename(this.getApplicationInfo().deviceProtectedDataDir + "/" + MobileLedgerDB.DATABASE_NAME);
}
public void hideAccountClicked(MenuItem item) {
- TextView textView = (TextView) clickedAccountRow.getChildAt(0);
- Toast.makeText(this, textView.getText(), Toast.LENGTH_SHORT).show();
+ db.execSQL("update accounts set hidden=1 where name=?",
+ new Object[]{clickedAccountRow.getAccountName()});
+ update_account_table();
}
@SuppressLint("DefaultLocale")
View.OnCreateContextMenuListener ccml = new View.OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
- clickedAccountRow = (LinearLayout) v;
+ clickedAccountRow = (AccountRowLayout) v;
getMenuInflater().inflate(R.menu.account_summary_account_menu, menu);
}
};
- int actionBarHeight =
- getTheme().obtainStyledAttributes(new int[]{android.R.attr.actionBarSize})
- .getDimensionPixelSize(0, dp2px(56));
+ int rowHeight =
+ (int) (getTheme().obtainStyledAttributes(new int[]{android.R.attr.actionBarSize})
+ .getDimensionPixelSize(0, dp2px(56)) * 0.75);
- try (Cursor cursor = db.rawQuery("SELECT name FROM accounts ORDER BY name;", null)) {
+ boolean showingHiddenAccounts = PreferenceManager.getDefaultSharedPreferences(this)
+ .getBoolean("show_hidden_accounts", false);
+ Log.d("pref", "show_hidden_accounts is " + (showingHiddenAccounts ? "true" : "false"));
+
+ try (Cursor cursor = db
+ .rawQuery("SELECT name, hidden FROM accounts ORDER BY name;", null))
+ {
boolean even = false;
+ String skippingAccountName = null;
while (cursor.moveToNext()) {
String acc_name = cursor.getString(0);
+ if (skippingAccountName != null) {
+ if (acc_name.startsWith(skippingAccountName + ":")) continue;
+
+ skippingAccountName = null;
+ }
+
+ boolean is_hidden = cursor.getInt(1) == 1;
+
+ if (!showingHiddenAccounts && is_hidden) {
+ skippingAccountName = acc_name;
+ continue;
+ }
- LinearLayout r = new LinearLayout(this);
+ LinearLayout r = new AccountRowLayout(this, acc_name);
r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
r.setGravity(Gravity.CENTER_VERTICAL);
r.setPadding(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(3), getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(4));
- r.setMinimumHeight(actionBarHeight);
+ r.setMinimumHeight(rowHeight);
if (even) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String short_acc_name = strip_higher_accounts(acc_name, indent_level);
acc_tv.setPadding(indent_level[0] * getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin) / 2, 0, 0, 0);
acc_tv.setText(short_acc_name);
+ if (is_hidden) acc_tv.setTypeface(null, Typeface.ITALIC);
r.addView(acc_tv);
TextView amt_tv = new TextView(this, null, R.style.account_summary_amounts);
}
}
amt_tv.setText(amt_text.toString());
+ if (is_hidden) amt_tv.setTypeface(null, Typeface.ITALIC);
r.addView(amt_tv);
// simple string representation.
preference.setSummary(stringValue);
}
+
return true;
};
return PreferenceFragment.class.getName().equals(fragmentName)
|| BackendPreferenceFragment.class.getName().equals(fragmentName)
|| DataSyncPreferenceFragment.class.getName().equals(fragmentName)
- || NotificationPreferenceFragment.class.getName().equals(fragmentName);
+ || NotificationPreferenceFragment.class.getName().equals(fragmentName)
+ || InterfacePreferenceFragment.class.getName().equals(fragmentName);
}
/**
}
}
+ /**
+ * This fragment shows general preferences only. It is used when the
+ * activity is showing a two-pane settings UI.
+ */
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
+ public static
+ class InterfacePreferenceFragment extends PreferenceFragment {
+ @Override
+ public
+ void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.pref_interface);
+ setHasOptionsMenu(true);
+
+ // Bind the summaries of EditText/List/Dialog/Ringtone preferences
+ // to their values. When their values change, their summaries are
+ // updated to reflect the new value, per the Android Design
+ // guidelines.
+// bindPreferenceSummaryToValue(findPreference("show_hidden_accounts"));
+
+ }
+
+ @Override
+ public
+ boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == android.R.id.home) {
+ startActivity(new Intent(getActivity(), SettingsActivity.class));
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
/**
* This fragment shows notification preferences only. It is used when the
* activity is showing a two-pane settings UI.