]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
migrate to surrogate IDs for all database objects
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfileDetailFragment.java
index 1efdb965408c3bd278883767000f1a4a517ac381..f5b48aef3e22c5dc4d0ec52f9ef8670f6bbdd485 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2020 Damyan Ivanov.
+ * Copyright © 2021 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
@@ -52,7 +52,6 @@ import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.ui.CurrencySelectorFragment;
 import net.ktnx.mobileledger.ui.HueRingDialog;
-import net.ktnx.mobileledger.ui.activity.ProfileDetailActivity;
 import net.ktnx.mobileledger.utils.Colors;
 import net.ktnx.mobileledger.utils.Misc;
 
@@ -63,7 +62,6 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Objects;
-import java.util.UUID;
 
 import static net.ktnx.mobileledger.utils.Logger.debug;
 
@@ -112,7 +110,7 @@ public class ProfileDetailFragment extends Fragment {
         builder.setTitle(mProfile.getName());
         builder.setMessage(R.string.remove_profile_dialog_message);
         builder.setPositiveButton(R.string.Remove, (dialog, which) -> {
-            debug("profiles", String.format("[fragment] removing profile %s", mProfile.getUuid()));
+            debug("profiles", String.format("[fragment] removing profile %s", mProfile.getId()));
             mProfile.removeFromDB();
             ArrayList<MobileLedgerProfile> oldList = Data.profiles.getValue();
             if (oldList == null)
@@ -206,7 +204,7 @@ public class ProfileDetailFragment extends Fragment {
                 resetDefaultCommodity();
         });
 
-        FloatingActionButton fab = context.findViewById(R.id.fab);
+        FloatingActionButton fab = context.findViewById(R.id.fabAdd);
         fab.setOnClickListener(v -> onSaveFabClicked());
 
         hookTextChangeSyncRoutine(binding.profileName, model::setProfileName);
@@ -360,22 +358,21 @@ public class ProfileDetailFragment extends Fragment {
         menu.inflate(R.menu.api_version);
         menu.setOnMenuItemClickListener(item -> {
             API apiVer;
-            switch (item.getItemId()) {
-                case R.id.api_version_menu_html:
-                    apiVer = API.html;
-                    break;
-                case R.id.api_version_menu_1_19_1:
-                    apiVer = API.v1_19_1;
-                    break;
-                case R.id.api_version_menu_1_15:
-                    apiVer = API.v1_15;
-                    break;
-                case R.id.api_version_menu_1_14:
-                    apiVer = API.v1_14;
-                    break;
-                case R.id.api_version_menu_auto:
-                default:
-                    apiVer = API.auto;
+            int itemId = item.getItemId();
+            if (itemId == R.id.api_version_menu_html) {
+                apiVer = API.html;
+            }
+            else if (itemId == R.id.api_version_menu_1_19_1) {
+                apiVer = API.v1_19_1;
+            }
+            else if (itemId == R.id.api_version_menu_1_15) {
+                apiVer = API.v1_15;
+            }
+            else if (itemId == R.id.api_version_menu_1_14) {
+                apiVer = API.v1_14;
+            }
+            else {
+                apiVer = API.auto;
             }
             model.setApiVersion(apiVer);
             binding.apiVersionText.setText(apiVer.getDescription(getResources()));
@@ -384,26 +381,31 @@ public class ProfileDetailFragment extends Fragment {
         menu.show();
     }
     private MobileLedgerProfile.FutureDates futureDatesSettingFromMenuItemId(int itemId) {
-        switch (itemId) {
-            case R.id.menu_future_dates_7:
-                return MobileLedgerProfile.FutureDates.OneWeek;
-            case R.id.menu_future_dates_14:
-                return MobileLedgerProfile.FutureDates.TwoWeeks;
-            case R.id.menu_future_dates_30:
-                return MobileLedgerProfile.FutureDates.OneMonth;
-            case R.id.menu_future_dates_60:
-                return MobileLedgerProfile.FutureDates.TwoMonths;
-            case R.id.menu_future_dates_90:
-                return MobileLedgerProfile.FutureDates.ThreeMonths;
-            case R.id.menu_future_dates_180:
-                return MobileLedgerProfile.FutureDates.SixMonths;
-            case R.id.menu_future_dates_365:
-                return MobileLedgerProfile.FutureDates.OneYear;
-            case R.id.menu_future_dates_all:
-                return MobileLedgerProfile.FutureDates.All;
-            default:
-                return MobileLedgerProfile.FutureDates.None;
+        if (itemId == R.id.menu_future_dates_7) {
+            return MobileLedgerProfile.FutureDates.OneWeek;
+        }
+        else if (itemId == R.id.menu_future_dates_14) {
+            return MobileLedgerProfile.FutureDates.TwoWeeks;
+        }
+        else if (itemId == R.id.menu_future_dates_30) {
+            return MobileLedgerProfile.FutureDates.OneMonth;
         }
+        else if (itemId == R.id.menu_future_dates_60) {
+            return MobileLedgerProfile.FutureDates.TwoMonths;
+        }
+        else if (itemId == R.id.menu_future_dates_90) {
+            return MobileLedgerProfile.FutureDates.ThreeMonths;
+        }
+        else if (itemId == R.id.menu_future_dates_180) {
+            return MobileLedgerProfile.FutureDates.SixMonths;
+        }
+        else if (itemId == R.id.menu_future_dates_365) {
+            return MobileLedgerProfile.FutureDates.OneYear;
+        }
+        else if (itemId == R.id.menu_future_dates_all) {
+            return MobileLedgerProfile.FutureDates.All;
+        }
+        return MobileLedgerProfile.FutureDates.None;
     }
     @NotNull
     private ProfileDetailModel getModel() {
@@ -428,9 +430,7 @@ public class ProfileDetailFragment extends Fragment {
 //                debug("profiles", String.format("Selected item is %d", mProfile.getThemeHue()));
 
             final MobileLedgerProfile currentProfile = Data.getProfile();
-            if (mProfile.getUuid()
-                        .equals(currentProfile.getUuid()))
-            {
+            if (mProfile.getId() == currentProfile.getId()) {
                 Data.setCurrentProfile(mProfile);
             }
 
@@ -439,7 +439,7 @@ public class ProfileDetailFragment extends Fragment {
                 viewAdapter.notifyItemChanged(pos);
         }
         else {
-            mProfile = new MobileLedgerProfile(String.valueOf(UUID.randomUUID()));
+            mProfile = new MobileLedgerProfile(0);
             model.updateProfile(mProfile);
             mProfile.storeInDB();
             final ArrayList<MobileLedgerProfile> newList = new ArrayList<>(profiles);
@@ -493,7 +493,8 @@ public class ProfileDetailFragment extends Fragment {
 
         if (model.getUseAuthentication()) {
             String urlText = model.getUrl();
-            if (urlText.startsWith("http") && !urlText.startsWith("https"))
+            if (urlText.startsWith("http://") ||
+                urlText.length() >= 8 && !urlText.startsWith("https://"))
                 showWarning = true;
         }