]> git.ktnx.net Git - mobile-ledger.git/commitdiff
make use of currency parameters in the new currency dialog
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 6 May 2021 17:18:42 +0000 (20:18 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 6 May 2021 17:18:42 +0000 (20:18 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java

index 4ec2abfea13125eda0767c65e0873cdaf95658e2..bcd62d99fc95225fb7114f24f2cf1a174ebaa475 100644 (file)
@@ -130,6 +130,8 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment
         final TextView tvNoCurrBtn = csd.findViewById(R.id.btn_no_currency);
         final TextView tvAddCurrOkBtn = csd.findViewById(R.id.btn_add_currency);
         final TextView tvAddCurrBtn = csd.findViewById(R.id.btn_add_new);
+        final SwitchMaterial gap = csd.findViewById(R.id.currency_gap);
+        final RadioGroup rgPosition = csd.findViewById(R.id.position_radio_group);
 
         tvNewCurrName.setVisibility(View.GONE);
         tvAddCurrOkBtn.setVisibility(View.GONE);
@@ -149,15 +151,14 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment
         });
 
         tvAddCurrOkBtn.setOnClickListener(v -> {
-
-
             String currName = String.valueOf(tvNewCurrName.getText());
             if (!currName.isEmpty()) {
                 DB.get()
                   .getCurrencyDAO()
                   .insert(new net.ktnx.mobileledger.db.Currency(0,
-                          String.valueOf(tvNewCurrName.getText()), "after", false));
-                // FIXME hardcoded position and gap setting
+                          String.valueOf(tvNewCurrName.getText()),
+                          (rgPosition.getCheckedRadioButtonId() == R.id.currency_position_left)
+                          ? "before" : "after", gap.isChecked()));
             }
 
             tvNewCurrName.setVisibility(View.GONE);
@@ -180,7 +181,6 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment
         else
             rbPositionRight.toggle();
 
-        RadioGroup rgPosition = csd.findViewById(R.id.position_radio_group);
         rgPosition.setOnCheckedChangeListener((group, checkedId) -> {
             if (checkedId == R.id.currency_position_left)
                 Data.currencySymbolPosition.setValue(Currency.Position.before);
@@ -188,8 +188,6 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment
                 Data.currencySymbolPosition.setValue(Currency.Position.after);
         });
 
-        SwitchMaterial gap = csd.findViewById(R.id.currency_gap);
-
         gap.setChecked(Data.currencyGap.getValue());
 
         gap.setOnCheckedChangeListener((v, checked) -> Data.currencyGap.setValue(checked));