]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
allow removal of the last profile
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfileDetailFragment.java
index ee01017e792eac8fc26d3fdbaf24a7797c34b347..fafd8b41123b1014cb8b05cc4143de16edd55aff 100644 (file)
@@ -61,6 +61,7 @@ import org.jetbrains.annotations.NotNull;
 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;
@@ -82,7 +83,6 @@ public class ProfileDetailFragment extends Fragment {
     private MobileLedgerProfile mProfile;
     private TextView url;
     private TextView defaultCommodity;
-    private View defaultCommodityLayout;
     private boolean defaultCommoditySet;
     private TextInputLayout urlLayout;
     private LinearLayout authParams;
@@ -94,11 +94,9 @@ public class ProfileDetailFragment extends Fragment {
     private TextView profileName;
     private TextInputLayout profileNameLayout;
     private TextView preferredAccountsFilter;
-    private TextInputLayout preferredAccountsFilterLayout;
     private View huePickerView;
     private View insecureWarningText;
     private TextView futureDatesText;
-    private View futureDatesLayout;
     private TextView apiVersionText;
     private boolean syncingModelFromUI = false;
     /**
@@ -141,8 +139,6 @@ public class ProfileDetailFragment extends Fragment {
             return false;
         });
         final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
-        menuDeleteProfile.setVisible(
-                (mProfile != null) && (profiles != null) && (profiles.size() > 1));
 
         if (BuildConfig.DEBUG) {
             final MenuItem menuWipeProfileData = menu.findItem(R.id.menuWipeData);
@@ -160,9 +156,8 @@ public class ProfileDetailFragment extends Fragment {
     private void triggerProfileChange() {
         int index = Data.getProfileIndex(mProfile);
         MobileLedgerProfile newProfile = new MobileLedgerProfile(mProfile);
-        final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
-        if (profiles == null)
-            throw new AssertionError();
+        final ArrayList<MobileLedgerProfile> profiles =
+                Objects.requireNonNull(Data.profiles.getValue());
         profiles.set(index, newProfile);
 
         ProfilesRecyclerViewAdapter viewAdapter = ProfilesRecyclerViewAdapter.getInstance();
@@ -238,14 +233,14 @@ public class ProfileDetailFragment extends Fragment {
 
         urlLayout = context.findViewById(R.id.url_layout);
 
-        defaultCommodityLayout = context.findViewById(R.id.default_commodity_layout);
-        defaultCommodityLayout.setOnClickListener(v -> {
-            CurrencySelectorFragment cpf = CurrencySelectorFragment.newInstance(
-                    CurrencySelectorFragment.DEFAULT_COLUMN_COUNT, false);
-            cpf.setOnCurrencySelectedListener(model::setDefaultCommodity);
-            final AppCompatActivity activity = (AppCompatActivity) v.getContext();
-            cpf.show(activity.getSupportFragmentManager(), "currency-selector");
-        });
+        context.findViewById(R.id.default_commodity_layout)
+               .setOnClickListener(v -> {
+                   CurrencySelectorFragment cpf = CurrencySelectorFragment.newInstance(
+                           CurrencySelectorFragment.DEFAULT_COLUMN_COUNT, false);
+                   cpf.setOnCurrencySelectedListener(model::setDefaultCommodity);
+                   final AppCompatActivity activity = (AppCompatActivity) v.getContext();
+                   cpf.show(activity.getSupportFragmentManager(), "currency-selector");
+               });
 
         Switch showCommodityByDefault = context.findViewById(R.id.profile_show_commodity);
         showCommodityByDefault.setOnCheckedChangeListener(
@@ -269,7 +264,6 @@ public class ProfileDetailFragment extends Fragment {
 
         defaultCommodity = context.findViewById(R.id.default_commodity_text);
 
-        futureDatesLayout = context.findViewById(R.id.future_dates_layout);
         futureDatesText = context.findViewById(R.id.future_dates_text);
         context.findViewById(R.id.future_dates_layout)
                .setOnClickListener(v -> {
@@ -359,8 +353,6 @@ public class ProfileDetailFragment extends Fragment {
                 preferredAccountsFilter.setText(text);
         });
         hookTextChangeSyncRoutine(preferredAccountsFilter, model::setPreferredAccountsFilter);
-        preferredAccountsFilterLayout =
-                context.findViewById(R.id.preferred_accounts_accounts_filter_layout);
 
         insecureWarningText = context.findViewById(R.id.insecure_scheme_text);