From 9426344c9fb587ecb12926bd5802baa31c1aad33 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 11 Apr 2020 17:22:29 +0300 Subject: [PATCH] profile-level setting for showing commodify in new transaction screen by default --- .../model/MobileLedgerProfile.java | 24 ++++++++++++++----- .../ui/activity/NewTransactionFragment.java | 1 + .../ui/activity/NewTransactionModel.java | 7 ++++++ .../ui/profiles/ProfileDetailFragment.java | 5 ++++ .../utils/MobileLedgerDatabase.java | 2 +- app/src/main/res/layout/profile_detail.xml | 8 +++++++ app/src/main/res/raw/create_db.sql | 2 +- app/src/main/res/raw/sql_27.sql | 1 + app/src/main/res/values-bg/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/raw/sql_27.sql diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index 956878e9..3d8985fd 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -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(); } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java index f9ea5c2a..d093778a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java @@ -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); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java index b0241b1a..4fc1400e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java @@ -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> slots = new HashMap<>(); private int checkHoldCounter = 0; + private Observer profileObserver = profile ->showCurrency.postValue(profile.getShowCommodityByDefault()); + public void observeDataProfile(LifecycleOwner activity) { + Data.profile.observe(activity, profileObserver); + } void holdSubmittableChecks() { checkHoldCounter++; } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index 1ca52ddd..bed7527e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -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()); diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java b/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java index 7d73ee65..b8d1c3cc 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java @@ -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; diff --git a/app/src/main/res/layout/profile_detail.xml b/app/src/main/res/layout/profile_detail.xml index c1aea4dc..fd39b41d 100644 --- a/app/src/main/res/layout/profile_detail.xml +++ b/app/src/main/res/layout/profile_detail.xml @@ -161,6 +161,14 @@ android:text="@string/posting_permitted" android:textAppearance="?android:textAppearanceListItem" /> + + Вдясно валута/ценност Валута + Показване по подразбиране на полето за валута diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6daef63e..6a4a42a8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -155,4 +155,5 @@ Right Offset from the value Currency + Commodity input visible by default -- 2.39.5