]> git.ktnx.net Git - mobile-ledger.git/commitdiff
profile-level setting for showing commodify in new transaction screen by default
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 11 Apr 2020 14:22:29 +0000 (17:22 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 11 Apr 2020 14:22:29 +0000 (17:22 +0300)
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java
app/src/main/res/layout/profile_detail.xml
app/src/main/res/raw/create_db.sql
app/src/main/res/raw/sql_27.sql [new file with mode: 0644]
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

index 956878e9b12bd0065df61074b6d8001e161e39d2..3d8985fdea2d097c56a488de4568093364ea19fb 100644 (file)
@@ -46,6 +46,7 @@ public final class MobileLedgerProfile {
     private String uuid;
     private String name;
     private boolean permitPosting;
+    private boolean showCommodityByDefault;
     private String preferredAccountsFilter;
     private String url;
     private boolean authEnabled;
@@ -65,6 +66,7 @@ public final class MobileLedgerProfile {
         uuid = origin.uuid;
         name = origin.name;
         permitPosting = origin.permitPosting;
+        showCommodityByDefault = origin.showCommodityByDefault;
         preferredAccountsFilter = origin.preferredAccountsFilter;
         url = origin.url;
         authEnabled = origin.authEnabled;
@@ -83,8 +85,9 @@ public final class MobileLedgerProfile {
         SQLiteDatabase db = App.getDatabase();
         try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " +
                                          "auth_password, permit_posting, theme, order_no, " +
-                                         "preferred_accounts_filter, future_dates, api_version " +
-                                         "FROM " + "profiles order by order_no", null))
+                                         "preferred_accounts_filter, future_dates, api_version, " +
+                                         "show_commodity_by_default FROM " +
+                                         "profiles order by order_no", null))
         {
             while (cursor.moveToNext()) {
                 MobileLedgerProfile item = new MobileLedgerProfile(cursor.getString(0));
@@ -99,6 +102,7 @@ public final class MobileLedgerProfile {
                 item.setPreferredAccountsFilter(cursor.getString(9));
                 item.setFutureDates(cursor.getInt(10));
                 item.setApiVersion(cursor.getInt(11));
+                item.setShowCommodityByDefault(cursor.getInt(12) == 1);
                 list.add(item);
                 if (item.getUuid()
                         .equals(currentProfileUUID))
@@ -125,6 +129,12 @@ public final class MobileLedgerProfile {
             db.endTransaction();
         }
     }
+    public boolean getShowCommodityByDefault() {
+        return showCommodityByDefault;
+    }
+    public void setShowCommodityByDefault(boolean showCommodityByDefault) {
+        this.showCommodityByDefault = showCommodityByDefault;
+    }
     public SendTransactionTask.API getApiVersion() {
         return apiVersion;
     }
@@ -212,13 +222,15 @@ public final class MobileLedgerProfile {
 //                                            "themeHue=%d", uuid, name, url,
 //                    permitPosting ? "TRUE" : "FALSE", authEnabled ? "TRUE" : "FALSE", themeHue));
             db.execSQL("REPLACE INTO profiles(uuid, name, permit_posting, url, " +
-                       "use_authentication, auth_user, " +
-                       "auth_password, theme, order_no, preferred_accounts_filter, future_dates, " +
-                       "api_version) " + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+                       "use_authentication, auth_user, auth_password, theme, order_no, " +
+                       "preferred_accounts_filter, future_dates, api_version, " +
+                       "show_commodity_by_default) " +
+                       "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                     new Object[]{uuid, name, permitPosting, url, authEnabled,
                                  authEnabled ? authUserName : null,
                                  authEnabled ? authPassword : null, themeHue, orderNo,
-                                 preferredAccountsFilter, futureDates.toInt(), apiVersion.toInt()
+                                 preferredAccountsFilter, futureDates.toInt(), apiVersion.toInt(),
+                                 showCommodityByDefault
                     });
             db.setTransactionSuccessful();
         }
index f9ea5c2a360df48c47f6d1a6c5c91a502385fda3..d093778a367e816dd813cfdf19b4f43aa408b592 100644 (file)
@@ -105,6 +105,7 @@ public class NewTransactionFragment extends Fragment {
 
         list = activity.findViewById(R.id.new_transaction_accounts);
         viewModel = new ViewModelProvider(activity).get(NewTransactionModel.class);
+        viewModel.observeDataProfile(this);
         mProfile = Data.profile.getValue();
         listAdapter = new NewTransactionItemsAdapter(viewModel, mProfile);
         list.setAdapter(listAdapter);
index b0241b1ae0aaa8ff06b8cd2037ce765defea6c35..4fc1400e9fe69b7f26c6aedb0e41ce3584174dcd 100644 (file)
@@ -21,6 +21,7 @@ import android.annotation.SuppressLint;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.lifecycle.LifecycleOwner;
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
 import androidx.lifecycle.Observer;
@@ -28,7 +29,9 @@ import androidx.lifecycle.ViewModel;
 
 import net.ktnx.mobileledger.BuildConfig;
 import net.ktnx.mobileledger.model.Currency;
+import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.Misc;
 
@@ -69,6 +72,10 @@ public class NewTransactionModel extends ViewModel {
      */
     private final HashMap<String, List<Item>> slots = new HashMap<>();
     private int checkHoldCounter = 0;
+    private Observer<MobileLedgerProfile> profileObserver = profile ->showCurrency.postValue(profile.getShowCommodityByDefault());
+    public void observeDataProfile(LifecycleOwner activity) {
+        Data.profile.observe(activity, profileObserver);
+    }
     void holdSubmittableChecks() {
         checkHoldCounter++;
     }
index 1ca52ddd371c7a6e32ad05b664ed781e1afb47f4..bed7527ebf82063e61009624a1699ea355c092f0 100644 (file)
@@ -82,6 +82,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
     private MobileLedgerProfile mProfile;
     private TextView url;
     private Switch postingPermitted;
+    private Switch showCommodityByDefault;
     private TextInputLayout urlLayout;
     private LinearLayout authParams;
     private Switch useAuthentication;
@@ -203,6 +204,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
         url = context.findViewById(R.id.url);
         urlLayout = context.findViewById(R.id.url_layout);
         postingPermitted = context.findViewById(R.id.profile_permit_posting);
+        showCommodityByDefault = context.findViewById(R.id.profile_show_commodity);
         futureDatesLayout = context.findViewById(R.id.future_dates_layout);
         futureDatesText = context.findViewById(R.id.future_dates_text);
         context.findViewById(R.id.future_dates_layout)
@@ -304,6 +306,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
         if (mProfile != null) {
             profileName.setText(mProfile.getName());
             postingPermitted.setChecked(mProfile.isPostingPermitted());
+            showCommodityByDefault.setChecked(mProfile.getShowCommodityByDefault());
             futureDates = mProfile.getFutureDates();
             futureDatesText.setText(futureDates.getText(getResources()));
             apiVersion = mProfile.getApiVersion();
@@ -320,6 +323,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
             profileName.setText("");
             url.setText(HTTPS_URL_START);
             postingPermitted.setChecked(true);
+            showCommodityByDefault.setChecked(false);
             futureDates = MobileLedgerProfile.FutureDates.None;
             futureDatesText.setText(futureDates.getText(getResources()));
             apiVersion = SendTransactionTask.API.auto;
@@ -400,6 +404,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
         mProfile.setName(profileName.getText());
         mProfile.setUrl(url.getText());
         mProfile.setPostingPermitted(postingPermitted.isChecked());
+        mProfile.setShowCommodityByDefault(showCommodityByDefault.isChecked());
         mProfile.setPreferredAccountsFilter(preferredAccountsFilter.getText());
         mProfile.setAuthEnabled(useAuthentication.isChecked());
         mProfile.setAuthUserName(userName.getText());
index 7d73ee65f8ce397aa36e85bb5eb65f4bc8f0e87c..b8d1c3cce741a6c1855ec3ec079f1d5cbed49b21 100644 (file)
@@ -34,7 +34,7 @@ import static net.ktnx.mobileledger.utils.Logger.debug;
 
 public class MobileLedgerDatabase extends SQLiteOpenHelper {
     private static final String DB_NAME = "MoLe.db";
-    private static final int LATEST_REVISION = 26;
+    private static final int LATEST_REVISION = 27;
     private static final String CREATE_DB_SQL = "create_db";
 
     private final Application mContext;
index c1aea4dc3a1830e268bd040e90bf05684ad9b936..fd39b41d3e4b2d81895a2303e3238e89faf8cfbc 100644 (file)
             android:text="@string/posting_permitted"
             android:textAppearance="?android:textAppearanceListItem" />
 
+        <Switch
+            android:id="@+id/profile_show_commodity"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="16dp"
+            android:text="@string/currency_input_by_default"
+            android:textAppearance="?android:textAppearanceListItem"/>
+
         <LinearLayout
             android:id="@+id/future_dates_layout"
             android:layout_width="match_parent"
index e1467d6ce9bfde3991054743498a0315353e42f0..b1c3acd031e0a042673a816ba0a066ea93f11309 100644 (file)
@@ -5,7 +5,7 @@ create unique index un_options on options(profile,name);
 create table account_values(profile varchar not null, account varchar not null, currency varchar not null default '', keep boolean, value decimal not null );
 create unique index un_account_values on account_values(profile,account,currency);
 create table description_history(description varchar not null primary key, keep boolean, description_upper varchar);
-create table profiles(uuid varchar not null primary key, name not null, url not null, use_authentication boolean not null, auth_user varchar, auth_password varchar, order_no integer, permit_posting boolean default 0, theme integer default -1, preferred_accounts_filter varchar, future_dates integer, api_version integer);
+create table profiles(uuid varchar not null primary key, name not null, url not null, use_authentication boolean not null, auth_user varchar, auth_password varchar, order_no integer, permit_posting boolean default 0, theme integer default -1, preferred_accounts_filter varchar, future_dates integer, api_version integer, show_commodity_by_default boolean default 0);
 create table transactions(profile varchar not null, id integer not null, data_hash varchar not null, date varchar not null, description varchar not null, keep boolean not null default 0);
 create unique index un_transactions_id on transactions(profile,id);
 create unique index un_transactions_data_hash on transactions(profile,data_hash);
diff --git a/app/src/main/res/raw/sql_27.sql b/app/src/main/res/raw/sql_27.sql
new file mode 100644 (file)
index 0000000..0d1e41c
--- /dev/null
@@ -0,0 +1 @@
+alter table profiles add show_commodity_by_default boolean default 0;
\ No newline at end of file
index ffd28bbd0698717edd0bb700c5543a2712657bd1..382698008a52a48653debeffee0404369f68ae43 100644 (file)
     <string name="currency_position_right">Вдясно</string>
     <string name="new_currency_name_hint">валута/ценност</string>
     <string name="show_currency_input">Валута</string>
+    <string name="currency_input_by_default">Показване по подразбиране на полето за валута</string>
 
 </resources>
index 6daef63e88b61c823ef3afc6c630272ef07e0dab..6a4a42a87590f55a5f3374011ae0f58c26e2ca8b 100644 (file)
     <string name="currency_position_right">Right</string>
     <string name="currency_has_gap">Offset from the value</string>
     <string name="show_currency_input">Currency</string>
+    <string name="currency_input_by_default">Commodity input visible by default</string>
 </resources>