add backend API version setting to the profile details screen master
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Dec 2019 22:00:07 +0000 (00:00 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Dec 2019 22:00:07 +0000 (00:00 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
app/src/main/res/layout/profile_detail.xml
app/src/main/res/menu/api_version.xml [new file with mode: 0644]
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

index 8ec562b..e43e20e 100644 (file)
@@ -44,6 +44,7 @@ import com.google.android.material.textfield.TextInputLayout;
 
 import net.ktnx.mobileledger.BuildConfig;
 import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.async.SendTransactionTask;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.ui.HueRingDialog;
@@ -96,6 +97,9 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
     private TextView futureDatesText;
     private MobileLedgerProfile.FutureDates futureDates;
     private View futureDatesLayout;
+    private TextView apiVersionText;
+    private View apiVersionLayout;
+    private SendTransactionTask.API apiVersion;
 
     /**
      * Mandatory empty constructor for the fragment manager to instantiate the
@@ -234,6 +238,34 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
                    });
                    menu.show();
                });
+        apiVersionLayout = context.findViewById(R.id.api_version_layout);
+        apiVersionText = context.findViewById(R.id.api_version_text);
+        apiVersionLayout.setOnClickListener(v -> {
+            MenuInflater mi = new MenuInflater(context);
+            PopupMenu menu = new PopupMenu(context, v);
+            menu.inflate(R.menu.api_version);
+            menu.setOnMenuItemClickListener(item -> {
+                switch (item.getItemId()) {
+                    case R.id.api_version_menu_auto:
+                        apiVersion = SendTransactionTask.API.auto;
+                        break;
+                    case R.id.api_version_menu_html:
+                        apiVersion = SendTransactionTask.API.html;
+                        break;
+                    case R.id.api_version_menu_post_1_14:
+                        apiVersion = SendTransactionTask.API.post_1_14;
+                        break;
+                    case R.id.api_version_menu_pre_1_15:
+                        apiVersion = SendTransactionTask.API.pre_1_15;
+                        break;
+                    default:
+                        apiVersion = SendTransactionTask.API.auto;
+                }
+                apiVersionText.setText(apiVersion.getDescription(getResources()));
+                return true;
+            });
+            menu.show();
+        });
         authParams = context.findViewById(R.id.auth_params);
         useAuthentication = context.findViewById(R.id.enable_http_auth);
         userName = context.findViewById(R.id.auth_user_name);
@@ -270,6 +302,8 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
             postingPermitted.setChecked(mProfile.isPostingPermitted());
             futureDates = mProfile.getFutureDates();
             futureDatesText.setText(futureDates.getText(getResources()));
+            apiVersion = mProfile.getApiVersion();
+            apiVersionText.setText(apiVersion.getDescription(getResources()));
             url.setText(mProfile.getUrl());
             useAuthentication.setChecked(mProfile.isAuthEnabled());
             authParams.setVisibility(mProfile.isAuthEnabled() ? View.VISIBLE : View.GONE);
@@ -284,6 +318,8 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
             postingPermitted.setChecked(true);
             futureDates = MobileLedgerProfile.FutureDates.None;
             futureDatesText.setText(futureDates.getText(getResources()));
+            apiVersion = SendTransactionTask.API.auto;
+            apiVersionText.setText(apiVersion.getDescription(getResources()));
             useAuthentication.setChecked(false);
             authParams.setVisibility(View.GONE);
             userName.setText("");
@@ -366,6 +402,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
         mProfile.setAuthPassword(password.getText());
         mProfile.setThemeId(huePickerView.getTag());
         mProfile.setFutureDates(futureDates);
+        mProfile.setApiVersion(apiVersion);
     }
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
index d095f09..c1aea4d 100644 (file)
 
         </LinearLayout>
 
+        <LinearLayout
+            android:id="@+id/api_version_layout"
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="16dp">
+
+            <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/profile_api_version_title"
+                android:textAppearance="?android:textAppearanceListItem" />
+
+            <TextView
+                android:id="@+id/api_version_text"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:textAppearanceListItemSecondary"
+                android:textColor="?attr/textColor" />
+        </LinearLayout>
+
         <Switch
             android:id="@+id/profile_permit_posting"
             android:layout_width="match_parent"
diff --git a/app/src/main/res/menu/api_version.xml b/app/src/main/res/menu/api_version.xml
new file mode 100644 (file)
index 0000000..5fcb1de
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright © 2019 Damyan Ivanov.
+  ~ This file is part of MoLe.
+  ~ MoLe 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.
+  ~
+  ~ MoLe 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 MoLe. If not, see <https://www.gnu.org/licenses/>.
+  -->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:id="@+id/api_version_menu_auto"
+        android:title="@string/api_auto" />
+    <item
+        android:id="@+id/api_version_menu_post_1_14"
+        android:title="@string/api_post_1_14" />
+    <item
+        android:id="@+id/api_version_menu_pre_1_15"
+        android:title="@string/api_pre_1_15" />
+    <item
+        android:id="@+id/api_version_menu_html"
+        android:title="@string/api_html" />
+</menu>
\ No newline at end of file
index b1f6c4d..43bab68 100644 (file)
     <string name="future_dates_none">Без въвеждане на бъдещи дати</string>
     <string name="profile_future_dates_label">Въвеждане на дати в бъдещето</string>
     <string name="api_auto">Автоматично откриване</string>
-    <string name="api_html">Симулиране на заявка от браузър</string>
-    <string name="api_post_1_14">версия 1.15 и по-нови</string>
-    <string name="api_pre_1_15">версии преди 1.15</string>
+    <string name="api_html">Версия преди 1.14</string>
+    <string name="api_post_1_14">Версия 1.15 или по-нова</string>
+    <string name="api_pre_1_15">Версия 1.14.x</string>
+    <string name="profile_api_version_title">Версия на сървъра</string>
 
 </resources>
index 5f98037..d51f7e2 100644 (file)
     <string name="future_dates_180">Up to six months</string>
     <string name="future_dates_365">Up to a year</string>
     <string name="future_dates_all">Without restrictions</string>
-    <string name="api_html">Simulate HTML form</string>
-    <string name="api_pre_1_15">version before 1.15</string>
-    <string name="api_post_1_14">version 1.15 and above</string>
+    <string name="api_html">Version before 1.14</string>
+    <string name="api_pre_1_15">Version 1.14.x</string>
+    <string name="api_post_1_14">Version 1.15 and above</string>
     <string name="api_auto">Detect automaticaly</string>
+    <string name="profile_api_version_title">Backend server version</string>
 </resources>