]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
finish support for multiple server APIs when retrieving data
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfileDetailFragment.java
index e4fa95aebc817576afe68deb37e77e43e3e8559f..10f43667992fb27bfb17e5e74fe404230de26b92 100644 (file)
@@ -29,7 +29,6 @@ import android.view.MenuItem;
 import android.view.View;
 import android.widget.LinearLayout;
 import android.widget.PopupMenu;
-import android.widget.Switch;
 import android.widget.TextView;
 
 import androidx.annotation.NonNull;
@@ -42,6 +41,7 @@ import androidx.lifecycle.ViewModelProvider;
 
 import com.google.android.material.appbar.CollapsingToolbarLayout;
 import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.google.android.material.switchmaterial.SwitchMaterial;
 import com.google.android.material.textfield.TextInputLayout;
 
 import net.ktnx.mobileledger.BuildConfig;
@@ -86,7 +86,7 @@ public class ProfileDetailFragment extends Fragment {
     private boolean defaultCommoditySet;
     private TextInputLayout urlLayout;
     private LinearLayout authParams;
-    private Switch useAuthentication;
+    private SwitchMaterial useAuthentication;
     private TextView userName;
     private TextInputLayout userNameLayout;
     private TextView password;
@@ -242,14 +242,14 @@ public class ProfileDetailFragment extends Fragment {
                    cpf.show(activity.getSupportFragmentManager(), "currency-selector");
                });
 
-        Switch showCommodityByDefault = context.findViewById(R.id.profile_show_commodity);
+        SwitchMaterial showCommodityByDefault = context.findViewById(R.id.profile_show_commodity);
         showCommodityByDefault.setOnCheckedChangeListener(
                 (buttonView, isChecked) -> model.setShowCommodityByDefault(isChecked));
         model.observeShowCommodityByDefault(viewLifecycleOwner, showCommodityByDefault::setChecked);
 
         View postingSubItems = context.findViewById(R.id.posting_sub_items);
 
-        Switch postingPermitted = context.findViewById(R.id.profile_permit_posting);
+        SwitchMaterial postingPermitted = context.findViewById(R.id.profile_permit_posting);
         model.observePostingPermitted(viewLifecycleOwner, isChecked -> {
             postingPermitted.setChecked(isChecked);
             postingSubItems.setVisibility(isChecked ? View.VISIBLE : View.GONE);
@@ -257,7 +257,7 @@ public class ProfileDetailFragment extends Fragment {
         postingPermitted.setOnCheckedChangeListener(
                 ((buttonView, isChecked) -> model.setPostingPermitted(isChecked)));
 
-        Switch showCommentsByDefault = context.findViewById(R.id.profile_show_comments);
+        SwitchMaterial showCommentsByDefault = context.findViewById(R.id.profile_show_comments);
         model.observeShowCommentsByDefault(viewLifecycleOwner, showCommentsByDefault::setChecked);
         showCommentsByDefault.setOnCheckedChangeListener(
                 ((buttonView, isChecked) -> model.setShowCommentsByDefault(isChecked)));
@@ -287,19 +287,23 @@ public class ProfileDetailFragment extends Fragment {
         context.findViewById(R.id.api_version_text)
                .setOnClickListener(this::chooseAPIVersion);
 
-        TextView detectedApiVersion = context.findViewById(R.id.detected_version_text);
+        context.findViewById(R.id.server_version_label)
+               .setOnClickListener(v -> model.triggerVersionDetection());
+        TextView detectedServerVersion = context.findViewById(R.id.detected_server_version_text);
         model.observeDetectedVersion(viewLifecycleOwner, ver -> {
             if (ver == null)
-                detectedApiVersion.setText(context.getResources()
-                                                  .getString(R.string.api_version_unknown_label));
-            else if (ver.isPre_1_20())
-                detectedApiVersion.setText(context.getResources()
-                                                  .getString(R.string.api_pre_1_19));
+                detectedServerVersion.setText(context.getResources()
+                                                     .getString(
+                                                             R.string.server_version_unknown_label));
+            else if (ver.isPre_1_20_1())
+                detectedServerVersion.setText(context.getResources()
+                                                     .getString(
+                                                             R.string.detected_server_pre_1_20_1));
             else
-                detectedApiVersion.setText(ver.toString());
+                detectedServerVersion.setText(ver.toString());
         });
-        detectedApiVersion.setOnClickListener(v -> model.triggerVersionDetection());
-        final View detectButton = context.findViewById(R.id.api_version_detect_button);
+        detectedServerVersion.setOnClickListener(v -> model.triggerVersionDetection());
+        final View detectButton = context.findViewById(R.id.server_version_detect_button);
         detectButton.setOnClickListener(v -> model.triggerVersionDetection());
         model.observeDetectingHledgerVersion(viewLifecycleOwner, running -> {
             detectButton.setVisibility(running ? View.VISIBLE : View.INVISIBLE);
@@ -394,11 +398,14 @@ public class ProfileDetailFragment extends Fragment {
                 case R.id.api_version_menu_html:
                     apiVer = SendTransactionTask.API.html;
                     break;
-                case R.id.api_version_menu_post_1_14:
-                    apiVer = SendTransactionTask.API.post_1_14;
+                case R.id.api_version_menu_1_19_1:
+                    apiVer = SendTransactionTask.API.v1_19_1;
                     break;
-                case R.id.api_version_menu_pre_1_15:
-                    apiVer = SendTransactionTask.API.pre_1_15;
+                case R.id.api_version_menu_1_15:
+                    apiVer = SendTransactionTask.API.v1_15;
+                    break;
+                case R.id.api_version_menu_1_14:
+                    apiVer = SendTransactionTask.API.v1_14;
                     break;
                 case R.id.api_version_menu_auto:
                 default: