X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FMainActivity.java;h=d7447f070c86262fa885eaba61ae40e105ad995a;hp=00b26525ad59597ba54febf31e1295d56001ba41;hb=3e32f8fd2bd81f5a17545db7f6235640179eecc9;hpb=42a7a36fcd870c6bd22d1a407f51ff0ea3ca5260 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 00b26525..d7447f07 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -66,7 +66,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; -import java.util.Observer; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.widget.Toolbar; @@ -96,7 +95,6 @@ public class MainActivity extends ProfileThemedActivity { private SectionsPagerAdapter mSectionsPagerAdapter; private ViewPager mViewPager; private FloatingActionButton fab; - private boolean profileListExpanded = false; private ProfilesRecyclerViewAdapter mProfileListAdapter; private int mCurrentPage; private String mAccountFilter; @@ -105,13 +103,14 @@ public class MainActivity extends ProfileThemedActivity { private DrawerLayout.SimpleDrawerListener drawerListener; private ActionBarDrawerToggle barDrawerToggle; private ViewPager.SimpleOnPageChangeListener pageChangeListener; - private Observer editingProfilesObserver; private MobileLedgerProfile profile; @Override 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) ? "" : mAccountFilter)); mViewPager.setCurrentItem(mCurrentPage, false); if (mAccountFilter != null) showTransactionsFragment(mAccountFilter); else Data.accountFilter.setValue(null); @@ -134,9 +133,6 @@ public class MainActivity extends ProfileThemedActivity { barDrawerToggle = null; if (mViewPager != null) mViewPager.removeOnPageChangeListener(pageChangeListener); pageChangeListener = null; - if (mProfileListAdapter != null) - mProfileListAdapter.deleteEditingProfilesObserver(editingProfilesObserver); - editingProfilesObserver = null; super.onDestroy(); } @Override @@ -255,33 +251,36 @@ public class MainActivity extends ProfileThemedActivity { if (mProfileListAdapter == null) mProfileListAdapter = new ProfilesRecyclerViewAdapter(); root.setAdapter(mProfileListAdapter); - if (editingProfilesObserver == null) { - editingProfilesObserver = (o, arg) -> { - if (mProfileListAdapter.isEditingProfiles()) { - 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)); - profileListHeadAddProfile.setVisibility(View.VISIBLE); - profileListHeadAddProfile - .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in)); + mProfileListAdapter.editingProfiles.observe(this, newValue -> { + if (newValue) { + profileListHeadMore.setVisibility(View.GONE); + profileListHeadCancel.setVisibility(View.VISIBLE); + profileListHeadAddProfile.setVisibility(View.VISIBLE); + if (drawer.isDrawerOpen(GravityCompat.START)) { + profileListHeadMore.startAnimation( + AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out)); + profileListHeadCancel.startAnimation( + AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in)); + profileListHeadAddProfile.startAnimation( + AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in)); } - else { - profileListHeadCancel.setVisibility(View.GONE); - profileListHeadCancel - .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_out)); - profileListHeadMore.setVisibility(View.VISIBLE); - profileListHeadMore - .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in)); - profileListHeadAddProfile.setVisibility(View.GONE); - profileListHeadAddProfile - .startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_out)); + } + else { + profileListHeadCancel.setVisibility(View.GONE); + profileListHeadMore.setVisibility(View.VISIBLE); + profileListHeadAddProfile.setVisibility(View.GONE); + if (drawer.isDrawerOpen(GravityCompat.START)) { + profileListHeadCancel.startAnimation( + AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out)); + profileListHeadMore.startAnimation( + AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in)); + profileListHeadAddProfile.startAnimation( + AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out)); } - }; - mProfileListAdapter.addEditingProfilesObserver(editingProfilesObserver); - } + } + + mProfileListAdapter.notifyDataSetChanged(); + }); LinearLayoutManager llm = new LinearLayoutManager(this); @@ -292,7 +291,22 @@ public class MainActivity extends ProfileThemedActivity { profileListHeadCancel.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles()); profileListHeadMoreAndCancel .setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles()); - + if (drawerListener == null) { + drawerListener = new DrawerLayout.SimpleDrawerListener() { + @Override + public void onDrawerClosed(View drawerView) { + super.onDrawerClosed(drawerView); + mProfileListAdapter.setAnimationsEnabled(false); + mProfileListAdapter.editingProfiles.setValue(false); + } + @Override + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + mProfileListAdapter.setAnimationsEnabled(true); + } + }; + drawer.addDrawerListener(drawerListener); + } setupProfile(); } private void scheduleDataRetrievalIfStale(Date lastUpdate) {