]> git.ktnx.net Git - mobile-ledger-staging.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
6eb5239d95cbb36ce8a41a63b2323db2a2e64220
[mobile-ledger-staging.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfileDetailFragment.java
1 /*
2  * Copyright © 2020 Damyan Ivanov.
3  * This file is part of MoLe.
4  * MoLe is free software: you can distribute it and/or modify it
5  * under the term of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your opinion), any later version.
8  *
9  * MoLe is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License terms for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
16  */
17
18 package net.ktnx.mobileledger.ui.profiles;
19
20 import android.app.Activity;
21 import android.app.AlertDialog;
22 import android.graphics.Typeface;
23 import android.os.Bundle;
24 import android.text.Editable;
25 import android.text.TextWatcher;
26 import android.view.Menu;
27 import android.view.MenuInflater;
28 import android.view.MenuItem;
29 import android.view.View;
30 import android.widget.LinearLayout;
31 import android.widget.PopupMenu;
32 import android.widget.TextView;
33
34 import androidx.annotation.NonNull;
35 import androidx.annotation.Nullable;
36 import androidx.appcompat.app.AppCompatActivity;
37 import androidx.fragment.app.Fragment;
38 import androidx.fragment.app.FragmentActivity;
39 import androidx.lifecycle.LifecycleOwner;
40 import androidx.lifecycle.ViewModelProvider;
41
42 import com.google.android.material.appbar.CollapsingToolbarLayout;
43 import com.google.android.material.floatingactionbutton.FloatingActionButton;
44 import com.google.android.material.switchmaterial.SwitchMaterial;
45 import com.google.android.material.textfield.TextInputLayout;
46
47 import net.ktnx.mobileledger.BuildConfig;
48 import net.ktnx.mobileledger.R;
49 import net.ktnx.mobileledger.json.API;
50 import net.ktnx.mobileledger.model.Data;
51 import net.ktnx.mobileledger.model.MobileLedgerProfile;
52 import net.ktnx.mobileledger.ui.CurrencySelectorFragment;
53 import net.ktnx.mobileledger.ui.HueRingDialog;
54 import net.ktnx.mobileledger.ui.activity.ProfileDetailActivity;
55 import net.ktnx.mobileledger.utils.Colors;
56 import net.ktnx.mobileledger.utils.Misc;
57
58 import org.jetbrains.annotations.NonNls;
59 import org.jetbrains.annotations.NotNull;
60
61 import java.net.MalformedURLException;
62 import java.net.URL;
63 import java.util.ArrayList;
64 import java.util.Objects;
65 import java.util.UUID;
66
67 import static net.ktnx.mobileledger.utils.Logger.debug;
68
69 /**
70  * A fragment representing a single Profile detail screen.
71  * a {@link ProfileDetailActivity}
72  * on handsets.
73  */
74 public class ProfileDetailFragment extends Fragment {
75     /**
76      * The fragment argument representing the item ID that this fragment
77      * represents.
78      */
79     public static final String ARG_ITEM_ID = "item_id";
80     public static final String ARG_HUE = "hue";
81     @NonNls
82
83     private MobileLedgerProfile mProfile;
84     private TextView url;
85     private TextView defaultCommodity;
86     private boolean defaultCommoditySet;
87     private TextInputLayout urlLayout;
88     private LinearLayout authParams;
89     private SwitchMaterial useAuthentication;
90     private TextView userName;
91     private TextInputLayout userNameLayout;
92     private TextView password;
93     private TextInputLayout passwordLayout;
94     private TextView profileName;
95     private TextInputLayout profileNameLayout;
96     private TextView preferredAccountsFilter;
97     private View huePickerView;
98     private View insecureWarningText;
99     private TextView futureDatesText;
100     private TextView apiVersionText;
101     private boolean syncingModelFromUI = false;
102     /**
103      * Mandatory empty constructor for the fragment manager to instantiate the
104      * fragment (e.g. upon screen orientation changes).
105      */
106     public ProfileDetailFragment() {
107         super(R.layout.profile_detail);
108     }
109     @Override
110     public void onCreateOptionsMenu(@NotNull Menu menu, @NotNull MenuInflater inflater) {
111         debug("profiles", "[fragment] Creating profile details options menu");
112         super.onCreateOptionsMenu(menu, inflater);
113         inflater.inflate(R.menu.profile_details, menu);
114         final MenuItem menuDeleteProfile = menu.findItem(R.id.menuDelete);
115         menuDeleteProfile.setOnMenuItemClickListener(item -> onDeleteProfile());
116         final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
117
118         if (BuildConfig.DEBUG) {
119             final MenuItem menuWipeProfileData = menu.findItem(R.id.menuWipeData);
120             menuWipeProfileData.setOnMenuItemClickListener(ignored -> onWipeDataMenuClicked());
121             menuWipeProfileData.setVisible(mProfile != null);
122         }
123     }
124     private boolean onDeleteProfile() {
125         AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
126         builder.setTitle(mProfile.getName());
127         builder.setMessage(R.string.remove_profile_dialog_message);
128         builder.setPositiveButton(R.string.Remove, (dialog, which) -> {
129             debug("profiles", String.format("[fragment] removing profile %s", mProfile.getUuid()));
130             mProfile.removeFromDB();
131             ArrayList<MobileLedgerProfile> oldList = Data.profiles.getValue();
132             if (oldList == null)
133                 throw new AssertionError();
134             ArrayList<MobileLedgerProfile> newList = new ArrayList<>(oldList);
135             newList.remove(mProfile);
136             Data.profiles.setValue(newList);
137             if (mProfile.equals(Data.getProfile())) {
138                 debug("profiles", "[fragment] setting current profile to 0");
139                 Data.setCurrentProfile(newList.get(0));
140             }
141
142             final FragmentActivity activity = getActivity();
143             if (activity != null)
144                 activity.finish();
145         });
146         builder.show();
147         return false;
148     }
149     private boolean onWipeDataMenuClicked() {
150         // this is a development option, so no confirmation
151         mProfile.wipeAllData();
152         if (mProfile.equals(Data.getProfile()))
153             triggerProfileChange();
154         return true;
155     }
156     private void triggerProfileChange() {
157         int index = Data.getProfileIndex(mProfile);
158         MobileLedgerProfile newProfile = new MobileLedgerProfile(mProfile);
159         final ArrayList<MobileLedgerProfile> profiles =
160                 Objects.requireNonNull(Data.profiles.getValue());
161         profiles.set(index, newProfile);
162
163         ProfilesRecyclerViewAdapter viewAdapter = ProfilesRecyclerViewAdapter.getInstance();
164         if (viewAdapter != null)
165             viewAdapter.notifyItemChanged(index);
166
167         if (mProfile.equals(Data.getProfile()))
168             Data.setCurrentProfile(newProfile);
169     }
170     private void hookTextChangeSyncRoutine(TextView view, TextChangeSyncRoutine syncRoutine) {
171         view.addTextChangedListener(new TextWatcher() {
172             @Override
173             public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
174             @Override
175             public void onTextChanged(CharSequence s, int start, int before, int count) {}
176             @Override
177             public void afterTextChanged(Editable s) { syncRoutine.onTextChanged(s.toString());}
178         });
179     }
180     @Override
181     public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
182         super.onViewCreated(view, savedInstanceState);
183         Activity context = getActivity();
184         if (context == null)
185             return;
186
187         if ((getArguments() != null) && getArguments().containsKey(ARG_ITEM_ID)) {
188             int index = getArguments().getInt(ARG_ITEM_ID, -1);
189             ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
190             if ((profiles != null) && (index != -1) && (index < profiles.size()))
191                 mProfile = profiles.get(index);
192
193             Activity activity = this.getActivity();
194             if (activity == null)
195                 throw new AssertionError();
196             CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout);
197             if (appBarLayout != null) {
198                 if (mProfile != null)
199                     appBarLayout.setTitle(mProfile.getName());
200                 else
201                     appBarLayout.setTitle(getResources().getString(R.string.new_profile_title));
202             }
203         }
204
205         final LifecycleOwner viewLifecycleOwner = getViewLifecycleOwner();
206         final ProfileDetailModel model = getModel();
207
208         model.observeDefaultCommodity(viewLifecycleOwner, c -> {
209             if (c != null)
210                 setDefaultCommodity(c.getName());
211             else
212                 resetDefaultCommodity();
213         });
214
215         FloatingActionButton fab = context.findViewById(R.id.fab);
216         fab.setOnClickListener(v -> onSaveFabClicked());
217
218         profileName = context.findViewById(R.id.profile_name);
219         hookTextChangeSyncRoutine(profileName, model::setProfileName);
220         model.observeProfileName(viewLifecycleOwner, pn -> {
221             if (!Misc.equalStrings(pn, profileName.getText()))
222                 profileName.setText(pn);
223         });
224
225         profileNameLayout = context.findViewById(R.id.profile_name_layout);
226
227         url = context.findViewById(R.id.url);
228         hookTextChangeSyncRoutine(url, model::setUrl);
229         model.observeUrl(viewLifecycleOwner, u -> {
230             if (!Misc.equalStrings(u, url.getText()))
231                 url.setText(u);
232         });
233
234         urlLayout = context.findViewById(R.id.url_layout);
235
236         context.findViewById(R.id.default_commodity_layout)
237                .setOnClickListener(v -> {
238                    CurrencySelectorFragment cpf = CurrencySelectorFragment.newInstance(
239                            CurrencySelectorFragment.DEFAULT_COLUMN_COUNT, false);
240                    cpf.setOnCurrencySelectedListener(model::setDefaultCommodity);
241                    final AppCompatActivity activity = (AppCompatActivity) v.getContext();
242                    cpf.show(activity.getSupportFragmentManager(), "currency-selector");
243                });
244
245         SwitchMaterial showCommodityByDefault = context.findViewById(R.id.profile_show_commodity);
246         showCommodityByDefault.setOnCheckedChangeListener(
247                 (buttonView, isChecked) -> model.setShowCommodityByDefault(isChecked));
248         model.observeShowCommodityByDefault(viewLifecycleOwner, showCommodityByDefault::setChecked);
249
250         View postingSubItems = context.findViewById(R.id.posting_sub_items);
251
252         SwitchMaterial postingPermitted = context.findViewById(R.id.profile_permit_posting);
253         model.observePostingPermitted(viewLifecycleOwner, isChecked -> {
254             postingPermitted.setChecked(isChecked);
255             postingSubItems.setVisibility(isChecked ? View.VISIBLE : View.GONE);
256         });
257         postingPermitted.setOnCheckedChangeListener(
258                 ((buttonView, isChecked) -> model.setPostingPermitted(isChecked)));
259
260         SwitchMaterial showCommentsByDefault = context.findViewById(R.id.profile_show_comments);
261         model.observeShowCommentsByDefault(viewLifecycleOwner, showCommentsByDefault::setChecked);
262         showCommentsByDefault.setOnCheckedChangeListener(
263                 ((buttonView, isChecked) -> model.setShowCommentsByDefault(isChecked)));
264
265         defaultCommodity = context.findViewById(R.id.default_commodity_text);
266
267         futureDatesText = context.findViewById(R.id.future_dates_text);
268         context.findViewById(R.id.future_dates_layout)
269                .setOnClickListener(v -> {
270                    MenuInflater mi = new MenuInflater(context);
271                    PopupMenu menu = new PopupMenu(context, v);
272                    menu.inflate(R.menu.future_dates);
273                    menu.setOnMenuItemClickListener(item -> {
274                        model.setFutureDates(futureDatesSettingFromMenuItemId(item.getItemId()));
275                        return true;
276                    });
277                    menu.show();
278                });
279         model.observeFutureDates(viewLifecycleOwner,
280                 v -> futureDatesText.setText(v.getText(getResources())));
281
282         apiVersionText = context.findViewById(R.id.api_version_text);
283         model.observeApiVersion(viewLifecycleOwner,
284                 apiVer -> apiVersionText.setText(apiVer.getDescription(getResources())));
285         context.findViewById(R.id.api_version_label)
286                .setOnClickListener(this::chooseAPIVersion);
287         context.findViewById(R.id.api_version_text)
288                .setOnClickListener(this::chooseAPIVersion);
289
290         context.findViewById(R.id.server_version_label)
291                .setOnClickListener(v -> model.triggerVersionDetection());
292         TextView detectedServerVersion = context.findViewById(R.id.detected_server_version_text);
293         model.observeDetectedVersion(viewLifecycleOwner, ver -> {
294             if (ver == null)
295                 detectedServerVersion.setText(context.getResources()
296                                                      .getString(
297                                                              R.string.server_version_unknown_label));
298             else if (ver.isPre_1_20_1())
299                 detectedServerVersion.setText(context.getResources()
300                                                      .getString(
301                                                              R.string.detected_server_pre_1_20_1));
302             else
303                 detectedServerVersion.setText(ver.toString());
304         });
305         detectedServerVersion.setOnClickListener(v -> model.triggerVersionDetection());
306         final View detectButton = context.findViewById(R.id.server_version_detect_button);
307         detectButton.setOnClickListener(v -> model.triggerVersionDetection());
308         model.observeDetectingHledgerVersion(viewLifecycleOwner, running -> {
309             detectButton.setVisibility(running ? View.VISIBLE : View.INVISIBLE);
310         });
311
312         authParams = context.findViewById(R.id.auth_params);
313
314         useAuthentication = context.findViewById(R.id.enable_http_auth);
315         useAuthentication.setOnCheckedChangeListener((buttonView, isChecked) -> {
316             model.setUseAuthentication(isChecked);
317             if (isChecked)
318                 userName.requestFocus();
319         });
320         model.observeUseAuthentication(viewLifecycleOwner, isChecked -> {
321             useAuthentication.setChecked(isChecked);
322             authParams.setVisibility(isChecked ? View.VISIBLE : View.GONE);
323             checkInsecureSchemeWithAuth();
324         });
325
326         userName = context.findViewById(R.id.auth_user_name);
327         model.observeUserName(viewLifecycleOwner, text -> {
328             if (!Misc.equalStrings(text, userName.getText()))
329                 userName.setText(text);
330         });
331         hookTextChangeSyncRoutine(userName, model::setAuthUserName);
332         userNameLayout = context.findViewById(R.id.auth_user_name_layout);
333
334         password = context.findViewById(R.id.password);
335         model.observePassword(viewLifecycleOwner, text -> {
336             if (!Misc.equalStrings(text, password.getText()))
337                 password.setText(text);
338         });
339         hookTextChangeSyncRoutine(password, model::setAuthPassword);
340         passwordLayout = context.findViewById(R.id.password_layout);
341
342         huePickerView = context.findViewById(R.id.btn_pick_ring_color);
343         model.observeThemeId(viewLifecycleOwner, themeId -> {
344             final int hue = (themeId == -1) ? Colors.DEFAULT_HUE_DEG : themeId;
345             final int profileColor = Colors.getPrimaryColorForHue(hue);
346             huePickerView.setBackgroundColor(profileColor);
347             huePickerView.setTag(hue);
348         });
349
350         preferredAccountsFilter = context.findViewById(R.id.preferred_accounts_filter_filter);
351         model.observePreferredAccountsFilter(viewLifecycleOwner, text -> {
352             if (!Misc.equalStrings(text, preferredAccountsFilter.getText()))
353                 preferredAccountsFilter.setText(text);
354         });
355         hookTextChangeSyncRoutine(preferredAccountsFilter, model::setPreferredAccountsFilter);
356
357         insecureWarningText = context.findViewById(R.id.insecure_scheme_text);
358
359         hookClearErrorOnFocusListener(profileName, profileNameLayout);
360         hookClearErrorOnFocusListener(url, urlLayout);
361         hookClearErrorOnFocusListener(userName, userNameLayout);
362         hookClearErrorOnFocusListener(password, passwordLayout);
363
364         if (savedInstanceState == null) {
365             model.setValuesFromProfile(mProfile, getArguments().getInt(ARG_HUE, -1));
366         }
367         checkInsecureSchemeWithAuth();
368
369         url.addTextChangedListener(new TextWatcher() {
370             @Override
371             public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
372             @Override
373             public void onTextChanged(CharSequence s, int start, int before, int count) {}
374             @Override
375             public void afterTextChanged(Editable s) {
376                 checkInsecureSchemeWithAuth();
377             }
378         });
379
380         huePickerView.setOnClickListener(v -> {
381             HueRingDialog d = new HueRingDialog(ProfileDetailFragment.this.requireContext(),
382                     model.initialThemeHue, (Integer) v.getTag());
383             d.show();
384             d.setColorSelectedListener(model::setThemeId);
385         });
386
387         profileName.requestFocus();
388     }
389     private void chooseAPIVersion(View v) {
390         Activity context = getActivity();
391         ProfileDetailModel model = getModel();
392         MenuInflater mi = new MenuInflater(context);
393         PopupMenu menu = new PopupMenu(context, v);
394         menu.inflate(R.menu.api_version);
395         menu.setOnMenuItemClickListener(item -> {
396             API apiVer;
397             switch (item.getItemId()) {
398                 case R.id.api_version_menu_html:
399                     apiVer = API.html;
400                     break;
401                 case R.id.api_version_menu_1_19_1:
402                     apiVer = API.v1_19_1;
403                     break;
404                 case R.id.api_version_menu_1_15:
405                     apiVer = API.v1_15;
406                     break;
407                 case R.id.api_version_menu_1_14:
408                     apiVer = API.v1_14;
409                     break;
410                 case R.id.api_version_menu_auto:
411                 default:
412                     apiVer = API.auto;
413             }
414             model.setApiVersion(apiVer);
415             apiVersionText.setText(apiVer.getDescription(getResources()));
416             return true;
417         });
418         menu.show();
419     }
420     private MobileLedgerProfile.FutureDates futureDatesSettingFromMenuItemId(int itemId) {
421         switch (itemId) {
422             case R.id.menu_future_dates_7:
423                 return MobileLedgerProfile.FutureDates.OneWeek;
424             case R.id.menu_future_dates_14:
425                 return MobileLedgerProfile.FutureDates.TwoWeeks;
426             case R.id.menu_future_dates_30:
427                 return MobileLedgerProfile.FutureDates.OneMonth;
428             case R.id.menu_future_dates_60:
429                 return MobileLedgerProfile.FutureDates.TwoMonths;
430             case R.id.menu_future_dates_90:
431                 return MobileLedgerProfile.FutureDates.ThreeMonths;
432             case R.id.menu_future_dates_180:
433                 return MobileLedgerProfile.FutureDates.SixMonths;
434             case R.id.menu_future_dates_365:
435                 return MobileLedgerProfile.FutureDates.OneYear;
436             case R.id.menu_future_dates_all:
437                 return MobileLedgerProfile.FutureDates.All;
438             default:
439                 return MobileLedgerProfile.FutureDates.None;
440         }
441     }
442     @NotNull
443     private ProfileDetailModel getModel() {
444         return new ViewModelProvider(requireActivity()).get(ProfileDetailModel.class);
445     }
446     private void onSaveFabClicked() {
447         if (!checkValidity())
448             return;
449
450         ProfileDetailModel model = getModel();
451         final ArrayList<MobileLedgerProfile> profiles =
452                 Objects.requireNonNull(Data.profiles.getValue());
453
454         if (mProfile != null) {
455             int pos = Data.profiles.getValue()
456                                    .indexOf(mProfile);
457             mProfile = new MobileLedgerProfile(mProfile);
458             model.updateProfile(mProfile);
459             mProfile.storeInDB();
460             debug("profiles", "profile stored in DB");
461             profiles.set(pos, mProfile);
462 //                debug("profiles", String.format("Selected item is %d", mProfile.getThemeHue()));
463
464             final MobileLedgerProfile currentProfile = Data.getProfile();
465             if (mProfile.getUuid()
466                         .equals(currentProfile.getUuid()))
467             {
468                 Data.setCurrentProfile(mProfile);
469             }
470
471             ProfilesRecyclerViewAdapter viewAdapter = ProfilesRecyclerViewAdapter.getInstance();
472             if (viewAdapter != null)
473                 viewAdapter.notifyItemChanged(pos);
474         }
475         else {
476             mProfile = new MobileLedgerProfile(String.valueOf(UUID.randomUUID()));
477             model.updateProfile(mProfile);
478             mProfile.storeInDB();
479             final ArrayList<MobileLedgerProfile> newList = new ArrayList<>(profiles);
480             newList.add(mProfile);
481             Data.profiles.setValue(newList);
482             MobileLedgerProfile.storeProfilesOrder();
483
484             // first profile ever?
485             if (newList.size() == 1)
486                 Data.setCurrentProfile(mProfile);
487         }
488
489         Activity activity = getActivity();
490         if (activity != null)
491             activity.finish();
492     }
493     private boolean checkUrlValidity() {
494         boolean valid = true;
495
496         ProfileDetailModel model = getModel();
497
498         String val = model.getUrl()
499                           .trim();
500         if (val.isEmpty()) {
501             valid = false;
502             urlLayout.setError(getResources().getText(R.string.err_profile_url_empty));
503         }
504         try {
505             URL url = new URL(val);
506             String host = url.getHost();
507             if (host == null || host.isEmpty())
508                 throw new MalformedURLException("Missing host");
509             String protocol = url.getProtocol()
510                                  .toUpperCase();
511             if (!protocol.equals("HTTP") && !protocol.equals("HTTPS")) {
512                 valid = false;
513                 urlLayout.setError(getResources().getText(R.string.err_invalid_url));
514             }
515         }
516         catch (MalformedURLException e) {
517             valid = false;
518             urlLayout.setError(getResources().getText(R.string.err_invalid_url));
519         }
520
521         return valid;
522     }
523     private void checkInsecureSchemeWithAuth() {
524         boolean showWarning = false;
525
526         final ProfileDetailModel model = getModel();
527
528         if (model.getUseAuthentication()) {
529             String urlText = model.getUrl();
530             if (urlText.startsWith("http") && !urlText.startsWith("https"))
531                 showWarning = true;
532         }
533
534         if (showWarning)
535             insecureWarningText.setVisibility(View.VISIBLE);
536         else
537             insecureWarningText.setVisibility(View.GONE);
538     }
539     private void hookClearErrorOnFocusListener(TextView view, TextInputLayout layout) {
540         view.setOnFocusChangeListener((v, hasFocus) -> {
541             if (hasFocus)
542                 layout.setError(null);
543         });
544         view.addTextChangedListener(new TextWatcher() {
545             @Override
546             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
547             }
548             @Override
549             public void onTextChanged(CharSequence s, int start, int before, int count) {
550                 layout.setError(null);
551             }
552             @Override
553             public void afterTextChanged(Editable s) {
554             }
555         });
556     }
557     private void syncModelFromUI() {
558         if (syncingModelFromUI)
559             return;
560
561         syncingModelFromUI = true;
562
563         try {
564             ProfileDetailModel model = getModel();
565
566             model.setProfileName(profileName.getText());
567             model.setUrl(url.getText());
568             model.setPreferredAccountsFilter(preferredAccountsFilter.getText());
569             model.setAuthUserName(userName.getText());
570             model.setAuthPassword(password.getText());
571         }
572         finally {
573             syncingModelFromUI = false;
574         }
575     }
576     private boolean checkValidity() {
577         boolean valid = true;
578
579         String val = String.valueOf(profileName.getText());
580         if (val.trim()
581                .isEmpty())
582         {
583             valid = false;
584             profileNameLayout.setError(getResources().getText(R.string.err_profile_name_empty));
585         }
586
587         if (!checkUrlValidity())
588             valid = false;
589
590         if (useAuthentication.isChecked()) {
591             val = String.valueOf(userName.getText());
592             if (val.trim()
593                    .isEmpty())
594             {
595                 valid = false;
596                 userNameLayout.setError(
597                         getResources().getText(R.string.err_profile_user_name_empty));
598             }
599
600             val = String.valueOf(password.getText());
601             if (val.trim()
602                    .isEmpty())
603             {
604                 valid = false;
605                 passwordLayout.setError(
606                         getResources().getText(R.string.err_profile_password_empty));
607             }
608         }
609
610         return valid;
611     }
612     private void resetDefaultCommodity() {
613         defaultCommoditySet = false;
614         defaultCommodity.setText(R.string.btn_no_currency);
615         defaultCommodity.setTypeface(defaultCommodity.getTypeface(), Typeface.ITALIC);
616     }
617     private void setDefaultCommodity(@NonNull @NotNull String name) {
618         defaultCommoditySet = true;
619         defaultCommodity.setText(name);
620         defaultCommodity.setTypeface(Typeface.DEFAULT);
621     }
622     interface TextChangeSyncRoutine {
623         void onTextChanged(String text);
624     }
625 }