]> git.ktnx.net Git - mobile-ledger.git/commitdiff
convert two switch() statements to if/else
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 28 Dec 2020 13:46:52 +0000 (15:46 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 28 Dec 2020 15:52:19 +0000 (15:52 +0000)
preparing for gradle 5, where resource IDs will no longer be declared
as final

app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java

index 1efdb965408c3bd278883767000f1a4a517ac381..36e39af20dfb712e798a6668e07c82d5c75e5ac6 100644 (file)
@@ -360,22 +360,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 +383,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() {