protected ArrayList<LedgerAccount> doInBackground(CommitAccountsTaskParams... params) {
Data.backgroundTaskCount.incrementAndGet();
ArrayList<LedgerAccount> newList = new ArrayList<>();
+ String profile = Data.profile.get().getUuid();
try {
SQLiteDatabase db = MLDB.getWritableDatabase();
for (LedgerAccount acc : params[0].accountList) {
Log.d("db", String.format("Setting %s to %s", acc.getName(),
acc.isHidden() ? "hidden" : "starred"));
- db.execSQL("UPDATE accounts SET hidden=? WHERE name=?",
- new Object[]{acc.isHiddenToBe() ? 1 : 0, acc.getName()});
+ db.execSQL("UPDATE accounts SET hidden=? WHERE profile=? AND name=?",
+ new Object[]{acc.isHiddenToBe() ? 1 : 0, profile, acc.getName()});
acc.setHidden(acc.isHiddenToBe());
if (!params[0].showOnlyStarred || !acc.isHidden()) newList.add(acc);
import java.util.ArrayList;
-public class UpdateAccountsTask extends AsyncTask<Boolean, Void, ArrayList<LedgerAccount>> {
- protected ArrayList<LedgerAccount> doInBackground(Boolean[] onlyStarred) {
+public class UpdateAccountsTask extends AsyncTask<Void, Void, ArrayList<LedgerAccount>> {
+ protected ArrayList<LedgerAccount> doInBackground(Void... params) {
Data.backgroundTaskCount.incrementAndGet();
String profileUUID = Data.profile.get().getUuid();
+ boolean onlyStarred = Data.optShowOnlyStarred.get();
try {
ArrayList<LedgerAccount> newList = new ArrayList<>();
String sql = "SELECT name, hidden FROM accounts WHERE profile = ?";
- if (onlyStarred[0]) sql += " AND hidden = 0";
+ if (onlyStarred) sql += " AND hidden = 0";
sql += " ORDER BY name";
SQLiteDatabase db = MLDB.getReadableDatabase();
Data.profile.addObserver(new Observer() {
@Override
public void update(Observable o, Object arg) {
- mActivity.runOnUiThread(() -> model.scheduleAccountListReload(mActivity));
+ mActivity.runOnUiThread(() -> model.scheduleAccountListReload());
}
});
update_account_table();
private void update_account_table() {
if (this.getContext() == null) return;
- model.scheduleAccountListReload(this.getContext());
+ model.scheduleAccountListReload();
}
void stopSelection() {
modelAdapter.stopSelection();
mShowOnlyStarred = menu.findItem(R.id.menu_acc_summary_only_starred);
if (mShowOnlyStarred == null) throw new AssertionError();
-
- Data.optShowOnlyStarred.addObserver(new Observer() {
- @Override
- public void update(Observable o, Object arg) {
- boolean newValue = Data.optShowOnlyStarred.get();
- Log.d("pref", String.format("pref change came (%s)", newValue ? "true" : "false"));
- mShowOnlyStarred.setChecked(newValue);
- update_account_table();
- }
+ MenuItem mCancelSelection = menu.findItem(R.id.menu_acc_summary_cancel_selection);
+ if (mCancelSelection == null) throw new AssertionError();
+ MenuItem mConfirmSelection = menu.findItem(R.id.menu_acc_summary_confirm_selection);
+ if (mConfirmSelection == null) throw new AssertionError();
+
+ Data.optShowOnlyStarred.addObserver((o, arg) -> {
+ boolean newValue = Data.optShowOnlyStarred.get();
+ Log.d("pref", String.format("pref change came (%s)", newValue ? "true" : "false"));
+ mShowOnlyStarred.setChecked(newValue);
+ update_account_table();
});
mShowOnlyStarred.setChecked(Data.optShowOnlyStarred.get());
"Setting show only starred accounts pref to " + (flag ? "false" : "true"));
editor.apply();
+ return true;
+ });
+
+ mCancelSelection.setOnMenuItemClickListener(item -> {
+ stopSelection();
+ return true;
+ });
+
+ mConfirmSelection.setOnMenuItemClickListener(item -> {
+ AccountSummaryViewModel.commitSelections(mActivity);
+ stopSelection();
return true;
});
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Build;
-import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import java.util.ArrayList;
-import static net.ktnx.mobileledger.ui.activity.SettingsActivity.PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS;
-
class AccountSummaryViewModel extends ViewModel {
- void scheduleAccountListReload(Context context) {
- boolean showingOnlyStarred = PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false);
-
- UAT task = new UAT();
- task.execute(showingOnlyStarred);
-
- }
static void commitSelections(Context context) {
- boolean showingOnlyStarred = PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false);
CAT task = new CAT();
- //noinspection unchecked
- task.execute(new CommitAccountsTaskParams(Data.accounts.get(), showingOnlyStarred));
+ task.execute(
+ new CommitAccountsTaskParams(Data.accounts.get(), Data.optShowOnlyStarred.get()));
}
+ void scheduleAccountListReload() {
+ UAT task = new UAT();
+ task.execute();
+
+ }
+
private static class UAT extends UpdateAccountsTask {
@Override
protected void onPostExecute(ArrayList<LedgerAccount> list) {
}
}
}
+
private static class CAT extends CommitAccountsTask {
@Override
protected void onPostExecute(ArrayList<LedgerAccount> list) {
public void selectItem(int position) {
LedgerAccount acc = Data.accounts.get().get(position);
acc.toggleHiddenToBe();
- toggleChildrenOf(acc, acc.isHiddenToBe());
- notifyDataSetChanged();
+ toggleChildrenOf(acc, acc.isHiddenToBe(), position);
+ notifyItemChanged(position);
}
- void toggleChildrenOf(LedgerAccount parent, boolean hiddenToBe) {
+ void toggleChildrenOf(LedgerAccount parent, boolean hiddenToBe, int parentPosition) {
+ int i = parentPosition + 1;
for (LedgerAccount acc : Data.accounts.get()) {
String acc_parent = acc.getParentName();
if ((acc_parent != null) && acc.getParentName().equals(parent.getName())) {
acc.setHiddenToBe(hiddenToBe);
- toggleChildrenOf(acc, hiddenToBe);
+ notifyItemChanged(i);
+ toggleChildrenOf(acc, hiddenToBe, i);
+ i++;
}
}
}