diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-09-23 04:28:42 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-09-23 04:28:42 +0000 |
commit | d730b719b8811eca930e5a0e88faba0737098a55 (patch) | |
tree | 149824c0f2acd7bfd4df16de9c902f5aef36a123 | |
parent | 05ea54a7c958e14d225fcb95642da71da42d658f (diff) | |
download | infinity-for-reddit-d730b719b8811eca930e5a0e88faba0737098a55.tar infinity-for-reddit-d730b719b8811eca930e5a0e88faba0737098a55.tar.gz infinity-for-reddit-d730b719b8811eca930e5a0e88faba0737098a55.tar.bz2 infinity-for-reddit-d730b719b8811eca930e5a0e88faba0737098a55.tar.lz infinity-for-reddit-d730b719b8811eca930e5a0e88faba0737098a55.tar.xz infinity-for-reddit-d730b719b8811eca930e5a0e88faba0737098a55.tar.zst infinity-for-reddit-d730b719b8811eca930e5a0e88faba0737098a55.zip |
Always close the account section in the navigation drawer when dismissed.
2 files changed, 28 insertions, 16 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 58c05954..6d78ad7b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -256,11 +256,19 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb setSupportActionBar(toolbar); setToolbarGoToTop(toolbar); - drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); toggle.getDrawerArrowDrawable().setColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor()); drawer.addDrawerListener(toggle); + drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() { + @Override + public void onDrawerClosed(View drawerView) { + if (adapter != null) { + adapter.closeAccountSectionWithoutChangeIconResource(); + adapter.notifyItemChanged(0); + } + } + }); toggle.syncState(); params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams(); @@ -799,8 +807,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } @Override - public void onBackPressed() { - DrawerLayout drawer = findViewById(R.id.drawer_layout); + public void onBackPressed() {; if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java index 2bd5d4b2..fc330b00 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java @@ -14,6 +14,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.biometric.BiometricManager; import androidx.biometric.BiometricPrompt; import androidx.core.content.ContextCompat; +import androidx.core.content.res.ResourcesCompat; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -221,18 +222,8 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re openAccountSection(((NavHeaderViewHolder) holder).dropIconImageView); } } else { - ((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_down_24px)); - notifyItemRangeRemoved(1, getItemCount() - 1); - if (isLoggedIn) { - if (subscribedSubreddits != null) { - notifyItemRangeInserted(1, subscribedSubreddits.size() + CURRENT_MENU_ITEMS - 1); - } else { - notifyItemRangeInserted(1, CURRENT_MENU_ITEMS - 1); - } - } else { - notifyItemRangeInserted(1, 2); - } - isInMainPage = true; + ((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_arrow_drop_down_24px, null)); + closeAccountSectionWithoutChangeIconResource(); } }); } else if (holder instanceof MenuGroupTitleViewHolder) { @@ -422,8 +413,22 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re } } + public void closeAccountSectionWithoutChangeIconResource() { + notifyItemRangeRemoved(1, getItemCount() - 1); + if (isLoggedIn) { + if (subscribedSubreddits != null) { + notifyItemRangeInserted(1, subscribedSubreddits.size() + CURRENT_MENU_ITEMS - 1); + } else { + notifyItemRangeInserted(1, CURRENT_MENU_ITEMS - 1); + } + } else { + notifyItemRangeInserted(1, 2); + } + isInMainPage = true; + } + private void openAccountSection(ImageView dropIconImageView) { - dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_up_24px)); + dropIconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_arrow_drop_up_24px, null)); notifyItemRangeRemoved(1, getItemCount() - 1); if (accounts != null) { notifyItemRangeInserted(1, accounts.size() + 3); |