]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
collapseProfileList(): short-cut animations if the list was already collapsed
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index a2cf30ea42264a33c1c71f8da96c37e62f1283a0..54dd0c21c29576308c176d7bc845258d095ddbb4 100644 (file)
@@ -125,8 +125,7 @@ public class MainActivity extends ProfileThemedActivity {
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putInt(STATE_CURRENT_PAGE, mViewPager.getCurrentItem());
-        if (mAccountFilter != null)
-            outState.putString(STATE_ACC_FILTER, mAccountFilter);
+        if (mAccountFilter != null) outState.putString(STATE_ACC_FILTER, mAccountFilter);
     }
     @Override
     protected void onDestroy() {
@@ -271,15 +270,25 @@ public class MainActivity extends ProfileThemedActivity {
                     profileListHeadArrow.clearAnimation();
                     profileListHeadArrow.setVisibility(View.GONE);
                     profileListHeadMore.setVisibility(View.GONE);
+                    profileListHeadMore
+                            .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_out));
                     profileListHeadCancel.setVisibility(View.VISIBLE);
+                    profileListHeadCancel
+                            .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in));
                 }
                 else {
                     profileListHeadArrow.setRotation(180f);
                     profileListHeadArrow.setVisibility(View.VISIBLE);
                     profileListHeadCancel.setVisibility(View.GONE);
+                    profileListHeadCancel
+                            .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_out));
                     profileListHeadMore.setVisibility(View.GONE);
-                    profileListHeadMore
-                            .setVisibility(profileListExpanded ? View.VISIBLE : View.GONE);
+                    if (profileListExpanded) {
+                        profileListHeadMore.setVisibility(View.VISIBLE);
+                        profileListHeadMore
+                                .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in));
+                    }
+                    else profileListHeadMore.setVisibility(View.GONE);
                 }
             };
             mProfileListAdapter.addEditingProfilesObserver(editingProfilesObserver);
@@ -309,8 +318,9 @@ public class MainActivity extends ProfileThemedActivity {
         findViewById(R.id.nav_profile_list_head_layout)
                 .setOnClickListener(this::navProfilesHeadClicked);
         findViewById(R.id.nav_profiles_label).setOnClickListener(this::navProfilesHeadClicked);
+        boolean initialStart = Data.profile.get() == null;
         setupProfile();
-        onProfileChanged(null);
+        if (!initialStart) onProfileChanged(null);
 
         updateLastUpdateTextFromDB();
     }
@@ -367,13 +377,6 @@ public class MainActivity extends ProfileThemedActivity {
             findViewById(R.id.pager_layout)
                     .setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE);
 
-            Data.transactions.clear();
-            debug("transactions", "requesting list reload");
-            TransactionListViewModel.scheduleTransactionListReload();
-
-            Data.accounts.clear();
-            AccountSummaryViewModel.scheduleAccountListReload();
-
             if (profile == null) MainActivity.this.setTitle(R.string.app_name);
             else MainActivity.this.setTitle(profile.getName());
             MainActivity.this.updateLastUpdateTextFromDB();
@@ -405,6 +408,13 @@ public class MainActivity extends ProfileThemedActivity {
             }
             drawer.closeDrawers();
 
+            Data.transactions.clear();
+            debug("transactions", "requesting list reload");
+            TransactionListViewModel.scheduleTransactionListReload();
+
+            Data.accounts.clear();
+            AccountSummaryViewModel.scheduleAccountListReload();
+
             if (profile == null) {
                 mToolbar.setSubtitle(null);
                 fab.hide();
@@ -675,30 +685,51 @@ public class MainActivity extends ProfileThemedActivity {
                        Data.profiles.size()));
     }
     private void collapseProfileList() {
+        boolean wasExpanded = profileListExpanded;
         profileListExpanded = false;
 
-        final Animation animation = AnimationUtils.loadAnimation(this, R.anim.slide_up);
-        animation.setAnimationListener(new Animation.AnimationListener() {
-            @Override
-            public void onAnimationStart(Animation animation) {
-
-            }
-            @Override
-            public void onAnimationEnd(Animation animation) {
-                profileListContainer.setVisibility(View.GONE);
-            }
-            @Override
-            public void onAnimationRepeat(Animation animation) {
+        if (wasExpanded) {
+            final Animation animation = AnimationUtils.loadAnimation(this, R.anim.slide_up);
+            animation.setAnimationListener(new Animation.AnimationListener() {
+                @Override
+                public void onAnimationStart(Animation animation) {
 
-            }
-        });
-        mProfileListAdapter.stopEditingProfiles();
+                }
+                @Override
+                public void onAnimationEnd(Animation animation) {
+                    profileListContainer.setVisibility(View.GONE);
+                }
+                @Override
+                public void onAnimationRepeat(Animation animation) {
 
-        profileListContainer.startAnimation(animation);
-        profileListHeadArrow.setRotation(0f);
-        profileListHeadArrow
-                .startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_180_back));
-        profileListHeadMore.setVisibility(View.GONE);
+                }
+            });
+            mProfileListAdapter.stopEditingProfiles();
+
+            profileListContainer.startAnimation(animation);
+            profileListHeadArrow.setRotation(0f);
+            profileListHeadArrow
+                    .startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_180_back));
+            final Animation moreAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
+            moreAnimation.setAnimationListener(new Animation.AnimationListener() {
+                @Override
+                public void onAnimationStart(Animation animation) {
+                }
+                @Override
+                public void onAnimationEnd(Animation animation) {
+                    profileListHeadMore.setVisibility(View.GONE);
+                }
+                @Override
+                public void onAnimationRepeat(Animation animation) {
+                }
+            });
+            profileListHeadMore.startAnimation(moreAnimation);
+        }
+        else {
+            profileListContainer.setVisibility(View.GONE);
+            profileListHeadArrow.setRotation(0f);
+            profileListHeadMore.setVisibility(View.GONE);
+        }
     }
     public void onAccountSummaryRowViewClicked(View view) {
         ViewGroup row;