]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
multi-color progress indicators
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index 12957e97e9e7c8e02c14e37ba674f40456433a8f..afa9c71e2916c3df0e8c2ed163db4663f7a56053 100644 (file)
@@ -88,10 +88,7 @@ public class MainActivity extends ProfileThemedActivity {
     public AccountSummaryFragment mAccountSummaryFragment;
     DrawerLayout drawer;
     private View profileListHeadMore, profileListHeadCancel, profileListHeadAddProfile;
-    private FragmentManager fragmentManager;
     private View bTransactionListCancelDownload;
-    private ProgressBar progressBar;
-    private LinearLayout progressLayout;
     private SectionsPagerAdapter mSectionsPagerAdapter;
     private ViewPager mViewPager;
     private FloatingActionButton fab;
@@ -108,7 +105,9 @@ public class MainActivity extends ProfileThemedActivity {
     protected void onStart() {
         super.onStart();
 
-        debug("flow", "MainActivity.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);
@@ -143,6 +142,11 @@ public class MainActivity extends ProfileThemedActivity {
         storeThemeIdInPrefs(profileColor);
     }
     @Override
+    protected void onResume() {
+        super.onResume();
+        fabShouldShow();
+    }
+    @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         debug("flow", "MainActivity.onCreate()");
@@ -156,10 +160,7 @@ public class MainActivity extends ProfileThemedActivity {
         profileListHeadAddProfile = findViewById(R.id.nav_new_profile_button);
         drawer = findViewById(R.id.drawer_layout);
         bTransactionListCancelDownload = findViewById(R.id.transaction_list_cancel_download);
-        progressBar = findViewById(R.id.transaction_list_progress_bar);
-        progressLayout = findViewById(R.id.transaction_progress_layout);
-        fragmentManager = getSupportFragmentManager();
-        mSectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager);
+        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
         mViewPager = findViewById(R.id.root_frame);
 
         Bundle extra = getIntent().getBundleExtra(BUNDLE_SAVED_STATE);
@@ -191,11 +192,6 @@ public class MainActivity extends ProfileThemedActivity {
             e.printStackTrace();
         }
 
-        if (progressBar == null)
-            throw new RuntimeException("Can't get hold on the transaction value progress bar");
-        if (progressLayout == null) throw new RuntimeException(
-                "Can't get hold on the transaction value progress bar layout");
-
         markDrawerItemCurrent(R.id.nav_account_summary);
 
         mViewPager.setAdapter(mSectionsPagerAdapter);
@@ -204,6 +200,7 @@ public class MainActivity extends ProfileThemedActivity {
             pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
                 @Override
                 public void onPageSelected(int position) {
+                    mCurrentPage = position;
                     switch (position) {
                         case 0:
                             markDrawerItemCurrent(R.id.nav_account_summary);
@@ -541,7 +538,7 @@ public class MainActivity extends ProfileThemedActivity {
             }
             else {
                 debug("fragments", String.format(Locale.ENGLISH, "manager stack: %d",
-                        fragmentManager.getBackStackEntryCount()));
+                        getSupportFragmentManager().getBackStackEntryCount()));
 
                 super.onBackPressed();
             }
@@ -567,7 +564,7 @@ public class MainActivity extends ProfileThemedActivity {
     }
     public void onRetrieveDone(String error) {
         Data.transactionRetrievalDone();
-        progressLayout.setVisibility(View.GONE);
+        findViewById(R.id.transaction_progress_layout).setVisibility(View.GONE);
 
         if (error == null) {
             updateLastUpdateTextFromDB();
@@ -578,15 +575,18 @@ public class MainActivity extends ProfileThemedActivity {
         else Toast.makeText(this, error, Toast.LENGTH_LONG).show();
     }
     public void onRetrieveStart() {
+        ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
         bTransactionListCancelDownload.setEnabled(true);
-        progressBar.setIndeterminateTintList(ColorStateList.valueOf(Colors.primary));
-        progressBar.setProgressTintList(ColorStateList.valueOf(Colors.primary));
+        ColorStateList csl = Colors.getColorStateList();
+        progressBar.setIndeterminateTintList(csl);
+        progressBar.setProgressTintList(csl);
         progressBar.setIndeterminate(true);
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progressBar.setProgress(0, false);
         else progressBar.setProgress(0);
-        progressLayout.setVisibility(View.VISIBLE);
+        findViewById(R.id.transaction_progress_layout).setVisibility(View.VISIBLE);
     }
     public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
+        ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
         if ((progress.getTotal() == RetrieveTransactionsTask.Progress.INDETERMINATE) ||
             (progress.getTotal() == 0))
         {