]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
move last update and progress bar from transaction list fragment to the main activity
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index ad124667f5b788088a7009e8151c7420fadd94ec..b98ccbe06678921a4cbdf04752842123cd3db89a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -21,6 +21,7 @@ import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.os.Build;
 import android.os.Bundle;
+import android.support.annotation.ColorInt;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
@@ -34,11 +35,17 @@ import android.view.ContextMenu;
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.LinearLayout;
+import android.widget.TextView;
 
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
 import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment;
+import net.ktnx.mobileledger.utils.MLDB;
+
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Date;
 
 public class MainActivity extends AppCompatActivity {
     DrawerLayout drawer;
@@ -46,6 +53,7 @@ public class MainActivity extends AppCompatActivity {
     private TransactionListFragment transactionListFragment;
     private Fragment currentFragment = null;
     private FragmentManager fragmentManager;
+    private TextView tvLastUpdate;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -72,35 +80,16 @@ public class MainActivity extends AppCompatActivity {
             e.printStackTrace();
         }
 
+        tvLastUpdate = findViewById(R.id.transactions_last_update);
+        updateLastUpdateText();
+        long last_update = MLDB.get_option_value(MLDB.OPT_TRANSACTION_LIST_STAMP, 0L);
+        Log.d("transactions", String.format("Last update = %d", last_update));
+
+
         fragmentManager = getSupportFragmentManager();
 
         onAccountSummaryClicked(null);
     }
-
-    @Override
-    protected void onStart() {
-        super.onStart();
-        LinearLayout grp = drawer.findViewById(R.id.nav_actions);
-        for (int i = 0; i < grp.getChildCount(); i++) {
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-                grp.getChildAt(i).setBackgroundColor(
-                        getResources().getColor(R.color.drawer_background, getTheme()));
-            }
-            else {
-                grp.getChildAt(i)
-                        .setBackgroundColor(getResources().getColor(R.color.drawer_background));
-            }
-        }
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-            drawer.findViewById(R.id.nav_account_summary).setBackgroundColor(
-                    getResources().getColor(R.color.table_row_even_bg, getTheme()));
-        }
-        else {
-            drawer.findViewById(R.id.nav_account_summary)
-                    .setBackgroundColor(getResources().getColor(R.color.table_row_even_bg));
-        }
-    }
-
     public void fab_new_transaction_clicked(View view) {
         Intent intent = new Intent(this, NewTransactionActivity.class);
         startActivity(intent);
@@ -117,7 +106,7 @@ public class MainActivity extends AppCompatActivity {
         startActivity(intent);
     }
     public void markDrawerItemCurrent(int id) {
-        View item = drawer.findViewById(id);
+        TextView item = drawer.findViewById(id);
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             item.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
         }
@@ -125,11 +114,15 @@ public class MainActivity extends AppCompatActivity {
             item.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg));
         }
 
+        setTitle(item.getText());
+
+        @ColorInt int transparent = getResources().getColor(android.R.color.transparent);
+
         LinearLayout actions = drawer.findViewById(R.id.nav_actions);
         for (int i = 0; i < actions.getChildCount(); i++) {
             View view = actions.getChildAt(i);
             if (view.getId() != id) {
-                view.setBackgroundColor(getResources().getColor(android.R.color.transparent));
+                view.setBackgroundColor(transparent);
             }
         }
     }
@@ -225,5 +218,24 @@ public class MainActivity extends AppCompatActivity {
             super.onBackPressed();
         }
     }
+    public void updateLastUpdateText() {
+        {
+            long last_update = MLDB.get_option_value(MLDB.OPT_TRANSACTION_LIST_STAMP, 0L);
+            Log.d("transactions", String.format("Last update = %d", last_update));
+            if (last_update == 0) {
+                tvLastUpdate.setText(getString(R.string.transaction_last_update_never));
+            }
+            else {
+                Date date = new Date(last_update);
+                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());
+                }
+            }
+        }
+    }
 
 }