import java.util.Date;
import java.util.List;
+import static net.ktnx.mobileledger.SettingsActivity.PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS;
+
public class AccountSummary extends AppCompatActivity {
DrawerLayout drawer;
modelAdapter.startSelection();
if (optMenu != null) {
optMenu.findItem(R.id.menu_acc_summary_cancel_selection).setVisible(true);
- optMenu.findItem(R.id.menu_acc_summary_hide_selected).setVisible(true);
+ optMenu.findItem(R.id.menu_acc_summary_confirm_selection).setVisible(true);
+ optMenu.findItem(R.id.menu_acc_summary_only_starred).setVisible(false);
+ }
+ {
+ FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.btn_add_transaction);
+ if (fab != null) fab.hide();
}
}
}));
if (mShowHiddenAccounts == null) throw new AssertionError();
sBindPreferenceSummaryToValueListener = (preference, value) -> mShowHiddenAccounts
- .setChecked(preference.getBoolean("show_hidden_accounts", false));
+ .setChecked(preference.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
pref.registerOnSharedPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
- mShowHiddenAccounts.setChecked(pref.getBoolean("show_hidden_accounts", false));
+ mShowHiddenAccounts.setChecked(pref.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
return true;
}
public
void onShowOnlyStarredClicked(MenuItem mi) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
- boolean flag = pref.getBoolean("show_hidden_accounts", false);
+ boolean flag = pref.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_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.putBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, !flag);
+ Log.d("pref", "Setting show only starred accounts pref to " + (flag ? "false" : "true"));
editor.apply();
update_account_table();
model.reloadAccounts();
modelAdapter.notifyDataSetChanged();
}
- public void onCancelAccSelection(MenuItem item) {
+ void stopSelection() {
modelAdapter.stopSelection();
if (optMenu != null) {
optMenu.findItem(R.id.menu_acc_summary_cancel_selection).setVisible(false);
- optMenu.findItem(R.id.menu_acc_summary_hide_selected).setVisible(false);
+ optMenu.findItem(R.id.menu_acc_summary_confirm_selection).setVisible(false);
+ optMenu.findItem(R.id.menu_acc_summary_only_starred).setVisible(true);
+ }
+ {
+ FloatingActionButton fab = findViewById(R.id.btn_add_transaction);
+ if (fab != null) fab.show();
}
}
+ public void onCancelAccSelection(MenuItem item) {
+ stopSelection();
+ }
+ public void onConfirmAccSelection(MenuItem item) {
+ model.commitSelections();
+ stopSelection();
+ }
}
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
+import static net.ktnx.mobileledger.SettingsActivity.PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS;
+
class AccountSummaryViewModel extends AndroidViewModel {
private MobileLedgerDatabase dbh;
private List<LedgerAccount> accounts;
void reloadAccounts() {
accounts.clear();
- boolean showingHiddenAccounts =
+ boolean showingOnlyStarred =
PreferenceManager.getDefaultSharedPreferences(getApplication())
- .getBoolean("show_hidden_accounts", false);
+ .getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false);
String sql = "SELECT name, hidden FROM accounts";
- if (!showingHiddenAccounts) sql += " WHERE hidden = 0";
+ if (showingOnlyStarred) sql += " WHERE hidden = 0";
sql += " ORDER BY name";
try (SQLiteDatabase db = dbh.getReadableDatabase()) {
}
}
}
+ void commitSelections() {
+ try(SQLiteDatabase db = dbh.getWritableDatabase()) {
+ db.beginTransaction();
+ try {
+ for (LedgerAccount acc : accounts) {
+ 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.setTransactionSuccessful();
+ for (LedgerAccount acc : accounts ) { acc.setHidden(acc.isHiddenToBe()); }
+ }
+ finally { db.endTransaction(); }
+ }
+ }
}
class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.LedgerRowHolder> {
}
holder.selectionCb.setVisibility( selectionActive ? View.VISIBLE : View.GONE);
- holder.selectionCb.setChecked(acc.isSelected());
+ holder.selectionCb.setChecked(!acc.isHiddenToBe());
holder.row.setTag(R.id.POS, position);
}
public int getItemCount() {
return accounts.size();
}
-
public void startSelection() {
- for( LedgerAccount acc : accounts ) acc.setSelected(false);
+ for( LedgerAccount acc : accounts ) acc.setHiddenToBe(acc.isHidden());
this.selectionActive = true;
notifyDataSetChanged();
}
}
public void selectItem(int position) {
- accounts.get(position).toggleSelected();
- notifyItemChanged(position);
+ LedgerAccount acc = accounts.get(position);
+ acc.toggleHiddenToBe();
+ toggleChildrenOf(acc, acc.isHiddenToBe());
+ notifyDataSetChanged();
+ }
+ void toggleChildrenOf(LedgerAccount parent, boolean hiddenToBe) {
+ for (LedgerAccount acc : accounts) {
+ String acc_parent = acc.getParentName();
+ if ((acc_parent != null) && acc.getParentName().equals(parent.getName())) {
+ acc.setHiddenToBe(hiddenToBe);
+ toggleChildrenOf(acc, hiddenToBe);
+ }
+ }
}
class LedgerRowHolder extends RecyclerView.ViewHolder {
CheckBox selectionCb;
private int level;
private String parentName;
private boolean hidden;
+ private boolean hiddenToBe;
private List<LedgerAmount> amounts;
- private boolean selected;
static Pattern higher_account = Pattern.compile("^[^:]+:");
LedgerAccount(String name) {
this.setName(name);
hidden = false;
- selected = false;
}
public boolean isHidden() {
public String getParentName() {
return parentName;
}
-
- public boolean isSelected() {
- return selected;
+ public void togglehidden() {
+ hidden = !hidden;
}
- public void setSelected(boolean selected) {
- this.selected = selected;
+ public boolean isHiddenToBe() {
+ return hiddenToBe;
}
-
- public void toggleSelected() {
- selected = !selected;
+ public void setHiddenToBe(boolean hiddenToBe) {
+ this.hiddenToBe = hiddenToBe;
+ }
+ public void toggleHiddenToBe() {
+ setHiddenToBe(!hiddenToBe);
}
}
* API Guide</a> for more information on developing a Settings UI.
*/
public class SettingsActivity extends AppCompatPreferenceActivity {
+ public static String PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS = "pref_show_only_starred_accounts";
/**
* A preference value change listener that updates the preference's summary
// 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"));
}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright © 2018 Damyan Ivanov.
+ ~ This file is part of Mobile-Ledger.
+ ~ Mobile-Ledger is free software: you can distribute it and/or modify it
+ ~ under the term of the GNU General Public License as published by
+ ~ the Free Software Foundation, either version 3 of the License, or
+ ~ (at your opinion), any later version.
+ ~
+ ~ Mobile-Ledger is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License terms for details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
+ -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@drawable/ic_star_border_black_24dp"
+ android:state_checked="false"/>
+ <item android:drawable="@drawable/ic_star_black_24dp"
+ android:state_checked="true"/>
+ <item android:drawable="@drawable/ic_star_border_black_24dp" />
+</selector>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright © 2018 Damyan Ivanov.
+ ~ This file is part of Mobile-Ledger.
+ ~ Mobile-Ledger is free software: you can distribute it and/or modify it
+ ~ under the term of the GNU General Public License as published by
+ ~ the Free Software Foundation, either version 3 of the License, or
+ ~ (at your opinion), any later version.
+ ~
+ ~ Mobile-Ledger is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License terms for details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
+ -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@drawable/ic_star_border_white_24dp"
+ android:state_checked="false"/>
+ <item android:drawable="@drawable/ic_star_white_24dp"
+ android:state_checked="true"/>
+ <item android:drawable="@drawable/ic_star_border_white_24dp" />
+</selector>
\ No newline at end of file
--- /dev/null
+<vector android:height="24dp" android:tint="#313131"
+ android:viewportHeight="24.0" android:viewportWidth="24.0"
+ android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+ <path android:fillColor="#FF000000" android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
+</vector>
--- /dev/null
+<vector android:height="24dp" android:tint="#313131"
+ android:viewportHeight="24.0" android:viewportWidth="24.0"
+ android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+ <path android:fillColor="#FF000000" android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z"/>
+</vector>
--- /dev/null
+<vector android:height="24dp" android:tint="#EEEEEE"
+ android:viewportHeight="24.0" android:viewportWidth="24.0"
+ android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+ <path android:fillColor="#FF000000" android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z"/>
+</vector>
<CheckBox
android:id="@+id/account_row_check"
android:layout_width="wrap_content"
- android:layout_height="match_parent" />
+ android:layout_height="match_parent"
+ android:button="@drawable/checkbox_star_black" />
<TextView
android:id="@+id/account_row_acc_name"
android:visible="false"
android:onClick="onCancelAccSelection"
android:icon="@drawable/ic_cancel_white_24dp" />
+ <item android:id="@+id/menu_acc_summary_confirm_selection"
+ android:title="@string/menu_acc_summary_confirm_selection_title"
+ app:showAsAction="always"
+ android:visible="false"
+ android:onClick="onConfirmAccSelection"
+ android:icon="@drawable/ic_check_white_24dp" />
</menu>
\ No newline at end of file
<string name="pref_show_only_starred_on_summary">Only starred accounts are shown</string>
<string name="menu_acc_summary_hide_selected_title">Hide selected accounts</string>
<string name="menu_acc_summary_cancel_selection_title">Cancel selection</string>
+ <string name="menu_acc_summary_confirm_selection_title">Confirm selectin</string>
</resources>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
- android:id="@+id/pref_show_hidden_accounts"
+ android:id="@+id/pref_show_only_starred_accounts"
android:defaultValue="false"
- android:key="show_hidden_accounts"
+ android:key="pref_show_only_starred_accounts"
android:summaryOff="@string/pref_show_only_starred_off_summary"
android:summaryOn="@string/pref_show_only_starred_on_summary"
android:title="@string/menu_acc_summary_show_only_starred_title" />