]> git.ktnx.net Git - mobile-ledger.git/commitdiff
proper date/time formatting
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 9 Jan 2019 05:28:27 +0000 (05:28 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 9 Jan 2019 05:28:27 +0000 (05:28 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java

index 2c9724a9672a38e1f460f0f1cf74c8245a16d28d..760f6aacfbbdfffda4d69ede20cf59dcd4a5f9be 100644 (file)
@@ -52,6 +52,7 @@ import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment;
 import net.ktnx.mobileledger.utils.MLDB;
 
 import java.lang.ref.WeakReference;
+import java.text.DateFormat;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.Date;
@@ -161,26 +162,23 @@ public class MainActivity extends AppCompatActivity {
             }
         });
 
-        Data.lastUpdateDate.addObserver(new Observer() {
-            @Override
-            public void update(Observable o, Object arg) {
-                Log.d("main", "lastUpdateDate changed");
-                runOnUiThread(() -> {
-                    Date date = Data.lastUpdateDate.get();
-                    if (date == null) {
-                        tvLastUpdate.setText(R.string.transaction_last_update_never);
+        Data.lastUpdateDate.addObserver((o, arg) -> {
+            Log.d("main", "lastUpdateDate changed");
+            runOnUiThread(() -> {
+                Date date = Data.lastUpdateDate.get();
+                if (date == null) {
+                    tvLastUpdate.setText(R.string.transaction_last_update_never);
+                }
+                else {
+                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+                        tvLastUpdate.setText(date.toInstant().atZone(ZoneId.systemDefault())
+                                .format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
                     }
                     else {
-                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-                            tvLastUpdate.setText(date.toInstant().atZone(ZoneId.systemDefault())
-                                    .format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
-                        }
-                        else {
-                            tvLastUpdate.setText(date.toLocaleString());
-                        }
+                        tvLastUpdate.setText(DateFormat.getDateTimeInstance().format(date));
                     }
-                });
-            }
+                }
+            });
         });
     }
     private void setupProfile() {