replace in-activity copy of account name filter value with the global item in Data
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 1 Jun 2019 16:49:31 +0000 (19:49 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 1 Jun 2019 16:49:31 +0000 (19:49 +0300)
also solves filter disappearing when switching back to the app

app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java

index afa9c71..bd28ab2 100644 (file)
@@ -94,7 +94,6 @@ public class MainActivity extends ProfileThemedActivity {
     private FloatingActionButton fab;
     private ProfilesRecyclerViewAdapter mProfileListAdapter;
     private int mCurrentPage;
-    private String mAccountFilter;
     private boolean mBackMeansToAccountList = false;
     private Toolbar mToolbar;
     private DrawerLayout.SimpleDrawerListener drawerListener;
@@ -105,19 +104,14 @@ public class MainActivity extends ProfileThemedActivity {
     protected void onStart() {
         super.onStart();
 
-        debug("flow", String.format(Locale.ENGLISH,
-                "MainActivity.onStart(), currentPage is %d, accountFilter is %s", mCurrentPage,
-                (mAccountFilter == null) ? "<NULL>" : mAccountFilter));
         mViewPager.setCurrentItem(mCurrentPage, false);
-        if (mAccountFilter != null) showTransactionsFragment(mAccountFilter);
-        else Data.accountFilter.setValue(null);
-
     }
     @Override
     protected void onSaveInstanceState(@NotNull Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putInt(STATE_CURRENT_PAGE, mViewPager.getCurrentItem());
-        if (mAccountFilter != null) outState.putString(STATE_ACC_FILTER, mAccountFilter);
+        if (Data.accountFilter.getValue() != null)
+            outState.putString(STATE_ACC_FILTER, Data.accountFilter.getValue());
     }
     @Override
     protected void onDestroy() {
@@ -225,9 +219,8 @@ public class MainActivity extends ProfileThemedActivity {
             if (currentPage != -1) {
                 mCurrentPage = currentPage;
             }
-            mAccountFilter = savedInstanceState.getString(STATE_ACC_FILTER, null);
+            Data.accountFilter.setValue(savedInstanceState.getString(STATE_ACC_FILTER, null));
         }
-        else mAccountFilter = null;
 
         Data.lastUpdateDate.observe(this, this::updateLastUpdateDisplay);