]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
drop unused/unneeded variables
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfileDetailFragment.java
index 6ead2af668029934d22046ced859dc746df2f361..46a0ea6e6abbe7dcd3c9dca6e24e81f5db89f4a9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 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
@@ -61,6 +61,7 @@ import org.jetbrains.annotations.NotNull;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.UUID;
 
 import static net.ktnx.mobileledger.utils.Logger.debug;
 
@@ -78,12 +79,9 @@ public class ProfileDetailFragment extends Fragment {
     public static final String ARG_HUE = "hue";
     @NonNls
 
-    /**
-     * The content this fragment is presenting.
-     */ private MobileLedgerProfile mProfile;
+    private MobileLedgerProfile mProfile;
     private TextView url;
     private TextView defaultCommodity;
-    private View defaultCommodityLayout;
     private boolean defaultCommoditySet;
     private TextInputLayout urlLayout;
     private LinearLayout authParams;
@@ -95,11 +93,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;
     /**
@@ -129,7 +125,7 @@ public class ProfileDetailFragment extends Fragment {
                 ArrayList<MobileLedgerProfile> newList = new ArrayList<>(oldList);
                 newList.remove(mProfile);
                 Data.profiles.setValue(newList);
-                if (mProfile.equals(Data.profile.getValue())) {
+                if (mProfile.equals(Data.getProfile())) {
                     debug("profiles", "[fragment] setting current profile to 0");
                     Data.setCurrentProfile(newList.get(0));
                 }
@@ -154,7 +150,7 @@ public class ProfileDetailFragment extends Fragment {
     private boolean onWipeDataMenuClicked() {
         // this is a development option, so no confirmation
         mProfile.wipeAllData();
-        if (mProfile.equals(Data.profile.getValue()))
+        if (mProfile.equals(Data.getProfile()))
             triggerProfileChange();
         return true;
     }
@@ -170,10 +166,10 @@ public class ProfileDetailFragment extends Fragment {
         if (viewAdapter != null)
             viewAdapter.notifyItemChanged(index);
 
-        if (mProfile.equals(Data.profile.getValue()))
-            Data.profile.setValue(newProfile);
+        if (mProfile.equals(Data.getProfile()))
+            Data.setCurrentProfile(newProfile);
     }
-    private void hookTextChangeSyncRoutine(TextView view, TextChangeSyncProc syncRoutine) {
+    private void hookTextChangeSyncRoutine(TextView view, TextChangeSyncRoutine syncRoutine) {
         view.addTextChangedListener(new TextWatcher() {
             @Override
             public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@@ -239,14 +235,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(
@@ -264,15 +260,12 @@ public class ProfileDetailFragment extends Fragment {
                 ((buttonView, isChecked) -> model.setPostingPermitted(isChecked)));
 
         Switch showCommentsByDefault = context.findViewById(R.id.profile_show_comments);
-        model.observeShowCommentsByDefault(viewLifecycleOwner, isChecked -> {
-            showCommentsByDefault.setChecked(isChecked);
-        });
+        model.observeShowCommentsByDefault(viewLifecycleOwner, showCommentsByDefault::setChecked);
         showCommentsByDefault.setOnCheckedChangeListener(
                 ((buttonView, isChecked) -> model.setShowCommentsByDefault(isChecked)));
 
         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 -> {
@@ -289,9 +282,8 @@ public class ProfileDetailFragment extends Fragment {
                 v -> futureDatesText.setText(v.getText(getResources())));
 
         apiVersionText = context.findViewById(R.id.api_version_text);
-        model.observeApiVersion(viewLifecycleOwner, apiVer -> {
-            apiVersionText.setText(apiVer.getDescription(getResources()));
-        });
+        model.observeApiVersion(viewLifecycleOwner,
+                apiVer -> apiVersionText.setText(apiVer.getDescription(getResources())));
         context.findViewById(R.id.api_version_layout)
                .setOnClickListener(v -> {
                    MenuInflater mi = new MenuInflater(context);
@@ -363,8 +355,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);
 
@@ -391,8 +381,7 @@ public class ProfileDetailFragment extends Fragment {
 
         huePickerView.setOnClickListener(v -> {
             HueRingDialog d = new HueRingDialog(ProfileDetailFragment.this.requireContext(),
-                    model.initialThemeHue,
-                    (Integer) v.getTag());
+                    model.initialThemeHue, (Integer) v.getTag());
             d.show();
             d.setColorSelectedListener(model::setThemeId);
         });
@@ -439,7 +428,7 @@ public class ProfileDetailFragment extends Fragment {
             triggerProfileChange();
         }
         else {
-            mProfile = new MobileLedgerProfile();
+            mProfile = new MobileLedgerProfile(String.valueOf(UUID.randomUUID()));
             model.updateProfile(mProfile);
             mProfile.storeInDB();
             final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
@@ -452,7 +441,7 @@ public class ProfileDetailFragment extends Fragment {
 
             // first profile ever?
             if (newList.size() == 1)
-                Data.profile.setValue(mProfile);
+                Data.setCurrentProfile(mProfile);
         }
 
         Activity activity = getActivity();
@@ -586,9 +575,9 @@ public class ProfileDetailFragment extends Fragment {
     private void setDefaultCommodity(@NonNull @NotNull String name) {
         defaultCommoditySet = true;
         defaultCommodity.setText(name);
-        defaultCommodity.setTypeface(defaultCommodity.getTypeface(), Typeface.BOLD);
+        defaultCommodity.setTypeface(Typeface.DEFAULT);
     }
-    interface TextChangeSyncProc {
+    interface TextChangeSyncRoutine {
         void onTextChanged(String text);
     }
 }