import static net.ktnx.mobileledger.utils.Logger.debug;
public final class MobileLedgerProfile {
+ // N.B. when adding new fields, update the copy-constructor below
private String uuid;
private String name;
private boolean permitPosting;
+ private boolean showCommentsByDefault;
private boolean showCommodityByDefault;
private String defaultCommodity;
private String preferredAccountsFilter;
private String authPassword;
private int themeHue;
private int orderNo = -1;
+ // N.B. when adding new fields, update the copy-constructor below
private FutureDates futureDates = FutureDates.None;
private SendTransactionTask.API apiVersion = SendTransactionTask.API.auto;
public MobileLedgerProfile() {
uuid = origin.uuid;
name = origin.name;
permitPosting = origin.permitPosting;
+ showCommentsByDefault = origin.showCommentsByDefault;
showCommodityByDefault = origin.showCommodityByDefault;
preferredAccountsFilter = origin.preferredAccountsFilter;
url = origin.url;
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, " +
- "show_commodity_by_default, default_commodity FROM " +
+ "show_commodity_by_default, default_commodity, " +
+ "show_comments_by_default FROM " +
"profiles order by order_no", null))
{
while (cursor.moveToNext()) {
item.setApiVersion(cursor.getInt(11));
item.setShowCommodityByDefault(cursor.getInt(12) == 1);
item.setDefaultCommodity(cursor.getString(13));
+ item.setShowCommentsByDefault(cursor.getInt(14) == 1);
list.add(item);
if (item.getUuid()
.equals(currentProfileUUID))
db.endTransaction();
}
}
+ public boolean getShowCommentsByDefault() {
+ return showCommentsByDefault;
+ }
+ public void setShowCommentsByDefault(boolean newValue) {
+ this.showCommentsByDefault = newValue;
+ }
public boolean getShowCommodityByDefault() {
return showCommodityByDefault;
}
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, " +
- "show_commodity_by_default, default_commodity) " +
- "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ "show_commodity_by_default, default_commodity, show_comments_by_default) " +
+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
new Object[]{uuid, name, permitPosting, url, authEnabled,
authEnabled ? authUserName : null,
authEnabled ? authPassword : null, themeHue, orderNo,
preferredAccountsFilter, futureDates.toInt(), apiVersion.toInt(),
- showCommodityByDefault, defaultCommodity
+ showCommodityByDefault, defaultCommodity, showCommentsByDefault
});
db.setTransactionSuccessful();
}
private final AtomicInteger busyCounter = new AtomicInteger(0);
private final MutableLiveData<Boolean> busyFlag = new MutableLiveData<>(false);
private boolean observingDataProfile;
- private Observer<MobileLedgerProfile> profileObserver =
- profile -> showCurrency.postValue(profile.getShowCommodityByDefault());
+ private Observer<MobileLedgerProfile> profileObserver = profile -> {
+ showCurrency.postValue(profile.getShowCommodityByDefault());
+ showComments.postValue(profile.getShowCommentsByDefault());
+ };
void observeShowComments(LifecycleOwner owner, Observer<? super Boolean> observer) {
showComments.observe(owner, observer);
}
postingPermitted.setOnCheckedChangeListener(
((buttonView, isChecked) -> model.setPostingPermitted(isChecked)));
+ Switch showCommentsByDefault = context.findViewById(R.id.profile_show_comments);
+ model.observeShowCommentsByDefault(viewLifecycleOwner, isChecked -> {
+ showCommentsByDefault.setChecked(isChecked);
+ });
+ showCommentsByDefault.setOnCheckedChangeListener(
+ ((buttonView, isChecked) -> model.setShowCommentsByDefault(isChecked)));
+
defaultCommodity = context.findViewById(R.id.default_commodity_text);
futureDatesLayout = context.findViewById(R.id.future_dates_layout);
private final MutableLiveData<MobileLedgerProfile.FutureDates> futureDates =
new MutableLiveData<>(MobileLedgerProfile.FutureDates.None);
private final MutableLiveData<Boolean> showCommodityByDefault = new MutableLiveData<>(false);
+ private final MutableLiveData<Boolean> showCommentsByDefault = new MutableLiveData<>(true);
private final MutableLiveData<Boolean> useAuthentication = new MutableLiveData<>(false);
private final MutableLiveData<SendTransactionTask.API> apiVersion =
new MutableLiveData<>(SendTransactionTask.API.auto);
void observePostingPermitted(LifecycleOwner lfo, Observer<Boolean> o) {
postingPermitted.observe(lfo, o);
}
+ public void setShowCommentsByDefault(boolean newValue) {
+ if (newValue != showCommentsByDefault.getValue())
+ showCommentsByDefault.setValue(newValue);
+ }
+ void observeShowCommentsByDefault(LifecycleOwner lfo, Observer<Boolean> o) {
+ showCommentsByDefault.observe(lfo, o);
+ }
MobileLedgerProfile.FutureDates getFutureDates() {
return futureDates.getValue();
}
if (mProfile != null) {
profileName.setValue(mProfile.getName());
postingPermitted.setValue(mProfile.isPostingPermitted());
+ showCommentsByDefault.setValue(mProfile.getShowCommentsByDefault());
showCommodityByDefault.setValue(mProfile.getShowCommodityByDefault());
{
String comm = mProfile.getDefaultCommodity();
profileName.setValue(null);
url.setValue(HTTPS_URL_START);
postingPermitted.setValue(true);
+ showCommentsByDefault.setValue(true);
showCommodityByDefault.setValue(false);
setFutureDates(MobileLedgerProfile.FutureDates.None);
setApiVersion(SendTransactionTask.API.auto);
mProfile.setName(profileName.getValue());
mProfile.setUrl(url.getValue());
mProfile.setPostingPermitted(postingPermitted.getValue());
+ mProfile.setShowCommentsByDefault(showCommentsByDefault.getValue());
Currency c = defaultCommodity.getValue();
mProfile.setDefaultCommodity((c == null) ? null : c.getName());
mProfile.setShowCommodityByDefault(showCommodityByDefault.getValue());
public class MobileLedgerDatabase extends SQLiteOpenHelper {
private static final String DB_NAME = "MoLe.db";
- private static final int LATEST_REVISION = 30;
+ private static final int LATEST_REVISION = 32;
private static final String CREATE_DB_SQL = "create_db";
private final Application mContext;
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, show_commodity_by_default boolean default 0, default_commodity 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, show_commodity_by_default boolean default 0, default_commodity varchar, show_comments_by_default boolean default 1);
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);
--- /dev/null
+alter table profiles add show_comments_by_default boolean default 0;
\ No newline at end of file
--- /dev/null
+update profiles set show_comments_by_default = 1;
\ No newline at end of file