From: Damyan Ivanov Date: Sun, 27 Jan 2019 18:11:36 +0000 (+0200) Subject: profile flag for enabling/disabling addition of new transactions X-Git-Tag: v0.4~10 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=649f399014447df347d0fd5c76219b6549f53ee0;p=mobile-ledger.git profile flag for enabling/disabling addition of new transactions --- 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 6c7fb195..bbd9a2be 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -31,23 +31,27 @@ import java.util.UUID; public final class MobileLedgerProfile { private String uuid; private String name; + private boolean permitPosting; private String url; private boolean authEnabled; private String authUserName; private String authPassword; - public MobileLedgerProfile(String uuid, String name, String url, boolean authEnabled, - String authUserName, String authPassword) { + public MobileLedgerProfile(String uuid, String name, boolean permitPosting, String url, + boolean authEnabled, String authUserName, String authPassword) { this.uuid = uuid; this.name = name; + this.permitPosting = permitPosting; this.url = url; this.authEnabled = authEnabled; this.authUserName = authUserName; this.authPassword = authPassword; } - public MobileLedgerProfile(CharSequence name, CharSequence url, boolean authEnabled, - CharSequence authUserName, CharSequence authPassword) { + public MobileLedgerProfile(CharSequence name, boolean permitPosting, CharSequence url, + boolean authEnabled, CharSequence authUserName, + CharSequence authPassword) { this.uuid = String.valueOf(UUID.randomUUID()); this.name = String.valueOf(name); + this.permitPosting = permitPosting; this.url = String.valueOf(url); this.authEnabled = authEnabled; this.authUserName = String.valueOf(authUserName); @@ -60,13 +64,14 @@ public final class MobileLedgerProfile { List list = new ArrayList<>(); SQLiteDatabase db = MLDB.getReadableDatabase(); try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " + - "auth_password FROM profiles order by order_no", null)) + "auth_password, permit_posting FROM profiles order by " + + "order_no", null)) { while (cursor.moveToNext()) { MobileLedgerProfile item = new MobileLedgerProfile(cursor.getString(0), cursor.getString(1), - cursor.getString(2), cursor.getInt(3) == 1, cursor.getString(4), - cursor.getString(5)); + cursor.getInt(6) == 1, cursor.getString(2), cursor.getInt(3) == 1, + cursor.getString(4), cursor.getString(5)); list.add(item); if (item.getUuid().equals(currentProfileUUID)) result = item; } @@ -91,6 +96,9 @@ public final class MobileLedgerProfile { } } + public boolean isPostingPermitted() { + return permitPosting; + } public String getUuid() { return uuid; } @@ -140,9 +148,11 @@ public final class MobileLedgerProfile { SQLiteDatabase db = MLDB.getWritableDatabase(); db.beginTransaction(); try { - db.execSQL("REPLACE INTO profiles(uuid, name, url, use_authentication, auth_user, " + - "auth_password) VALUES(?, ?, ?, ?, ?, ?)", - new Object[]{uuid, name, url, authEnabled, authEnabled ? authUserName : null, + db.execSQL("REPLACE INTO profiles(uuid, name, permit_posting, url, " + + "use_authentication, auth_user, " + + "auth_password) VALUES(?, ?, ?, ?, ?, ?, ?)", + new Object[]{uuid, name, permitPosting, url, authEnabled, + authEnabled ? authUserName : null, authEnabled ? authPassword : null }); db.setTransactionSuccessful(); 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 7ef511d0..7cbfa0e7 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 @@ -61,6 +61,7 @@ public class ProfileDetailFragment extends Fragment { */ private MobileLedgerProfile mProfile; private TextView url; + private Switch postingPermitted; private TextInputLayout urlLayout; private LinearLayout authParams; private Switch useAuthentication; @@ -140,8 +141,9 @@ public class ProfileDetailFragment extends Fragment { } } else { - mProfile = new MobileLedgerProfile(profileName.getText(), url.getText(), - useAuthentication.isChecked(), userName.getText(), password.getText()); + mProfile = new MobileLedgerProfile(profileName.getText(), postingPermitted.isChecked(), + url.getText(), useAuthentication.isChecked(), userName.getText(), + password.getText()); mProfile.storeInDB(); Data.profiles.add(mProfile); MobileLedgerProfile.storeProfilesOrder(); @@ -165,6 +167,7 @@ public class ProfileDetailFragment extends Fragment { profileNameLayout = rootView.findViewById(R.id.profile_name_layout); url = rootView.findViewById(R.id.url); urlLayout = rootView.findViewById(R.id.url_layout); + postingPermitted = rootView.findViewById(R.id.profile_permit_posting); authParams = rootView.findViewById(R.id.auth_params); useAuthentication = rootView.findViewById(R.id.enable_http_auth); userName = rootView.findViewById(R.id.auth_user_name); @@ -185,6 +188,7 @@ public class ProfileDetailFragment extends Fragment { if (mProfile != null) { profileName.setText(mProfile.getName()); + postingPermitted.setChecked(mProfile.isPostingPermitted()); url.setText(mProfile.getUrl()); useAuthentication.setChecked(mProfile.isAuthEnabled()); authParams.setVisibility(mProfile.isAuthEnabled() ? View.VISIBLE : View.GONE); @@ -194,6 +198,7 @@ public class ProfileDetailFragment extends Fragment { else { profileName.setText(""); url.setText(""); + postingPermitted.setChecked(true); useAuthentication.setChecked(false); authParams.setVisibility(View.GONE); userName.setText(""); diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java index 76763d01..3d17facf 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java @@ -217,7 +217,7 @@ public final class MLDB { class MobileLedgerDatabase extends SQLiteOpenHelper implements AutoCloseable { public static final String DB_NAME = "mobile-ledger.db"; - public static final int LATEST_REVISION = 16; + public static final int LATEST_REVISION = 17; 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 43c74383..04e60dd0 100644 --- a/app/src/main/res/layout/profile_detail.xml +++ b/app/src/main/res/layout/profile_detail.xml @@ -63,6 +63,13 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + Моля, въведете адрес, например https://server/location Въвеждането на потребителско име е задължително когато се използва удостоверяване Паролата е задължителна + Позволяване на добавянето на нови трансакции \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d894ffae..dc800351 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -131,4 +131,5 @@ November December + Posting of new transactions enabled