]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
fix profile list header arrow direction when editing mode is ended
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index 958c0e919745f6dd96dc6820db772c6be6bc2081..51ddf6e8bcb00cf99a3333e301cf170dee6bb4e9 100644 (file)
@@ -21,6 +21,7 @@ import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.content.res.ColorStateList;
 import android.graphics.Color;
+import android.os.AsyncTask;
 import android.os.Build;
 import android.os.Bundle;
 import android.util.Log;
@@ -51,6 +52,8 @@ import net.ktnx.mobileledger.utils.MLDB;
 import java.lang.ref.WeakReference;
 import java.text.DateFormat;
 import java.util.Date;
+import java.util.Observable;
+import java.util.Observer;
 
 import androidx.appcompat.app.ActionBarDrawerToggle;
 import androidx.appcompat.widget.Toolbar;
@@ -68,7 +71,7 @@ public class MainActivity extends CrashReportingActivity {
     private static final String BUNDLE_SAVED_STATE = "bundle_savedState";
     DrawerLayout drawer;
     private LinearLayout profileListContainer;
-    private View profileListHeadArrow;
+    private View profileListHeadArrow, profileListHeadMore, profileListHeadCancel;
     private FragmentManager fragmentManager;
     private TextView tvLastUpdate;
     private RetrieveTransactionsTask retrieveTransactionsTask;
@@ -114,6 +117,8 @@ public class MainActivity extends CrashReportingActivity {
         fab = findViewById(R.id.btn_add_transaction);
         profileListContainer = findViewById(R.id.nav_profile_list_container);
         profileListHeadArrow = findViewById(R.id.nav_profiles_arrow);
+        profileListHeadMore = findViewById(R.id.nav_profiles_start_edit);
+        profileListHeadCancel = findViewById(R.id.nav_profiles_cancel_edit);
         drawer = findViewById(R.id.drawer_layout);
         tvLastUpdate = findViewById(R.id.transactions_last_update);
         bTransactionListCancelDownload = findViewById(R.id.transaction_list_cancel_download);
@@ -235,10 +240,41 @@ public class MainActivity extends CrashReportingActivity {
         mProfileListAdapter = new ProfilesRecyclerViewAdapter();
         root.setAdapter(mProfileListAdapter);
 
+        mProfileListAdapter.addEditingProfilesObserver(new Observer() {
+            @Override
+            public void update(Observable o, Object arg) {
+                if (mProfileListAdapter.isEditingProfiles()) {
+                    profileListHeadArrow.clearAnimation();
+                    profileListHeadArrow.setVisibility(View.GONE);
+                    profileListHeadMore.setVisibility(View.GONE);
+                    profileListHeadCancel.setVisibility(View.VISIBLE);
+                }
+                else {
+                    profileListHeadArrow.setRotation(180f);
+                    profileListHeadArrow.setVisibility(View.VISIBLE);
+                    profileListHeadCancel.setVisibility(View.GONE);
+                    profileListHeadMore.setVisibility(View.GONE);
+                    profileListHeadMore
+                            .setVisibility(profileListExpanded ? View.VISIBLE : View.GONE);
+                }
+            }
+        });
+
         LinearLayoutManager llm = new LinearLayoutManager(this);
 
         llm.setOrientation(RecyclerView.VERTICAL);
         root.setLayoutManager(llm);
+
+        profileListHeadMore.setOnClickListener((v) -> mProfileListAdapter.startEditingProfiles());
+        profileListHeadCancel.setOnClickListener((v) -> mProfileListAdapter.stopEditingProfiles());
+
+        drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
+            @Override
+            public void onDrawerClosed(View drawerView) {
+                super.onDrawerClosed(drawerView);
+                collapseProfileList();
+            }
+        });
     }
     private void profileThemeChanged() {
         setupProfileColors();
@@ -389,7 +425,6 @@ public class MainActivity extends CrashReportingActivity {
         retrieveTransactionsTask = new RetrieveTransactionsTask(new WeakReference<>(this));
 
         retrieveTransactionsTask.execute();
-        bTransactionListCancelDownload.setEnabled(true);
     }
     public void onStopTransactionRefreshClick(View view) {
         Log.d("interactive", "Cancelling transactions refresh");
@@ -402,11 +437,12 @@ public class MainActivity extends CrashReportingActivity {
         if (error == null) {
             updateLastUpdateTextFromDB();
 
-            new RefreshDescriptionsTask().execute();
+            new RefreshDescriptionsTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
         }
         else Toast.makeText(this, error, Toast.LENGTH_LONG).show();
     }
     public void onRetrieveStart() {
+        bTransactionListCancelDownload.setEnabled(true);
         progressBar.setIndeterminateTintList(ColorStateList.valueOf(Colors.primary));
         progressBar.setProgressTintList(ColorStateList.valueOf(Colors.primary));
         progressBar.setIndeterminate(true);
@@ -451,6 +487,8 @@ public class MainActivity extends CrashReportingActivity {
         profileListContainer.setVisibility(View.VISIBLE);
         profileListContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_down));
         profileListHeadArrow.startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_180));
+        profileListHeadMore.setVisibility(View.VISIBLE);
+        profileListHeadMore.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in));
     }
     private void collapseProfileList() {
         profileListExpanded = false;
@@ -470,11 +508,13 @@ public class MainActivity extends CrashReportingActivity {
 
             }
         });
+        mProfileListAdapter.stopEditingProfiles();
+
         profileListContainer.startAnimation(animation);
+        profileListHeadArrow.setRotation(0f);
         profileListHeadArrow
                 .startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_180_back));
-
-        mProfileListAdapter.stopEditingProfiles();
+        profileListHeadMore.setVisibility(View.GONE);
     }
     public void onProfileRowClicked(View v) {
         Data.setCurrentProfile((MobileLedgerProfile) v.getTag());