]> git.ktnx.net Git - mobile-ledger.git/commitdiff
move handling of new transaction date setting into a new method
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 9 Feb 2019 09:28:30 +0000 (11:28 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 9 Feb 2019 09:28:30 +0000 (11:28 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/DatePickerFragment.java

index cb2726a6aaeba4f34d53f07865f6210a4ecc4b70..9b416e2c5343c82e8e907518b66e338942474667 100644 (file)
@@ -83,9 +83,7 @@ public class DatePickerFragment extends AppCompatDialogFragment
 
         return dpd;
     }
-
-    @TargetApi(Build.VERSION_CODES.O)
-    public void onDateSet(DatePicker view, int year, int month, int day) {
+    private void updateDateInput(int year, int month, int day) {
         TextView date =
                 Objects.requireNonNull(getActivity()).findViewById(R.id.new_transaction_date);
 
@@ -101,26 +99,14 @@ public class DatePickerFragment extends AppCompatDialogFragment
                 .findViewById(R.id.new_transaction_description);
         description.requestFocus();
     }
+    @TargetApi(Build.VERSION_CODES.O)
+    public void onDateSet(DatePicker view, int year, int month, int day) {
+        updateDateInput(year, month, day);
+    }
 
     @Override
     public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
-        TextView date =
-                Objects.requireNonNull(getActivity()).findViewById(R.id.new_transaction_date);
-
-        final Calendar c = GregorianCalendar.getInstance();
-        if (c.get(GregorianCalendar.YEAR) == year) {
-            if (c.get(GregorianCalendar.MONTH) == monthOfYear) {
-                date.setText(String.format(Locale.US, "%d", dayOfMonth));
-            }
-            else {
-                date.setText(String.format(Locale.US, "%d/%d", monthOfYear + 1, dayOfMonth));
-            }
-        }
-        else date.setText(String.format(Locale.US, "%d/%d/%d", year, monthOfYear + 1, dayOfMonth));
-
-        TextView description = Objects.requireNonNull(getActivity())
-                .findViewById(R.id.new_transaction_description);
-        description.requestFocus();
+        updateDateInput(year, monthOfYear, dayOfMonth);
 
         this.dismiss();
     }