]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
hide all of the "Last update" text when there was never a successful update
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index 9f2777b2fa01b24bf0257f1803b3b0ee3c8bc574..86463aac20c22bc34d7f50ec4cec5fc00ee74541 100644 (file)
@@ -44,6 +44,7 @@ import net.ktnx.mobileledger.async.RetrieveTransactionsTask;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.ui.account_summary.AccountSummaryAdapter;
 import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
 import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment;
 import net.ktnx.mobileledger.ui.profiles.ProfilesRecyclerViewAdapter;
@@ -72,8 +73,9 @@ import androidx.recyclerview.widget.RecyclerView;
 import androidx.viewpager.widget.ViewPager;
 
 public class MainActivity extends ProfileThemedActivity {
-    private static final String STATE_CURRENT_PAGE = "current_page";
-    private static final String BUNDLE_SAVED_STATE = "bundle_savedState";
+    public static final String STATE_CURRENT_PAGE = "current_page";
+    public static final String BUNDLE_SAVED_STATE = "bundle_savedState";
+    public static final String STATE_ACC_FILTER = "account_filter";
     public AccountSummaryFragment mAccountSummaryFragment;
     DrawerLayout drawer;
     private LinearLayout profileListContainer;
@@ -91,6 +93,9 @@ public class MainActivity extends ProfileThemedActivity {
     private boolean profileModificationEnabled = false;
     private boolean profileListExpanded = false;
     private ProfilesRecyclerViewAdapter mProfileListAdapter;
+    private int mCurrentPage;
+    private String mAccountFilter;
+    private boolean mBackMeansToAccountList = false;
     @Override
     protected void onStart() {
         super.onStart();
@@ -109,11 +114,17 @@ public class MainActivity extends ProfileThemedActivity {
 
             scheduleTransactionListRetrieval();
         }
+
+        mViewPager.setCurrentItem(mCurrentPage, false);
+        if (mAccountFilter != null) showTransactionsFragment(mAccountFilter);
+
     }
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putInt(STATE_CURRENT_PAGE, mViewPager.getCurrentItem());
+        if (TransactionListFragment.accountFilter.get() != null)
+            outState.putString(STATE_ACC_FILTER, TransactionListFragment.accountFilter.get());
     }
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -217,11 +228,13 @@ public class MainActivity extends ProfileThemedActivity {
             }
         });
 
+        mCurrentPage = 0;
         if (savedInstanceState != null) {
             int currentPage = savedInstanceState.getInt(STATE_CURRENT_PAGE, -1);
             if (currentPage != -1) {
-                mViewPager.setCurrentItem(currentPage, false);
+                mCurrentPage = currentPage;
             }
+            mAccountFilter = savedInstanceState.getString(STATE_ACC_FILTER, null);
         }
 
         Data.lastUpdateDate.addObserver((o, arg) -> {
@@ -285,15 +298,17 @@ public class MainActivity extends ProfileThemedActivity {
         });
     }
     private void updateLastUpdateDisplay() {
+        LinearLayout l = findViewById(R.id.transactions_last_update_layout);
         TextView v = findViewById(R.id.transactions_last_update);
         Date date = Data.lastUpdateDate.get();
         if (date == null) {
-            v.setText(R.string.transaction_last_update_never);
+            l.setVisibility(View.INVISIBLE);
             Log.d("main", "no last update date :(");
         }
         else {
             final String text = DateFormat.getDateTimeInstance().format(date);
             v.setText(text);
+            l.setVisibility(View.VISIBLE);
             Log.d("main", String.format("Date formatted: %s", text));
         }
     }
@@ -409,6 +424,7 @@ public class MainActivity extends ProfileThemedActivity {
 //        currentFragment = transactionListFragment;
     }
     public void showAccountTransactions(LedgerAccount account) {
+        mBackMeansToAccountList = true;
         showTransactionsFragment(account);
     }
     @Override
@@ -418,10 +434,16 @@ public class MainActivity extends ProfileThemedActivity {
             drawer.closeDrawer(GravityCompat.START);
         }
         else {
-            Log.d("fragments",
-                    String.format("manager stack: %d", fragmentManager.getBackStackEntryCount()));
+            if (mBackMeansToAccountList && (mViewPager.getCurrentItem() == 1)) {
+                TransactionListFragment.accountFilter.set(null);
+                showAccountSummaryFragment();
+                mBackMeansToAccountList = false;
+            }
+            else {
+                Log.d("fragments", String.format("manager stack: %d", fragmentManager.getBackStackEntryCount()));
 
-            super.onBackPressed();
+                super.onBackPressed();
+            }
         }
     }
     public void updateLastUpdateTextFromDB() {
@@ -643,7 +665,15 @@ public class MainActivity extends ProfileThemedActivity {
                 }
                 break;
             case R.id.account_row_acc_amounts:
-                showAccountTransactions(acc);
+                if (acc.getAmountCount() > AccountSummaryAdapter.AMOUNT_LIMIT) {
+                    acc.toggleAmountsExpanded();
+                    DbOpQueue
+                            .add("update accounts set amounts_expanded=? where name=? and profile=?",
+                                    new Object[]{acc.amountsExpanded(), acc.getName(),
+                                                 Data.profile.get().getUuid()
+                                    });
+                    Data.accounts.triggerItemChangedNotification(acc);
+                }
                 break;
         }
     }