Always close the account section in the navigation drawer when dismissed.

This commit is contained in:
Alex Ning 2020-09-23 12:28:42 +08:00
parent 05ea54a7c9
commit d730b719b8
2 changed files with 28 additions and 16 deletions

View File

@ -256,11 +256,19 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
setToolbarGoToTop(toolbar); setToolbarGoToTop(toolbar);
drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
toggle.getDrawerArrowDrawable().setColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor()); toggle.getDrawerArrowDrawable().setColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
drawer.addDrawerListener(toggle); drawer.addDrawerListener(toggle);
drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerClosed(View drawerView) {
if (adapter != null) {
adapter.closeAccountSectionWithoutChangeIconResource();
adapter.notifyItemChanged(0);
}
}
});
toggle.syncState(); toggle.syncState();
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams(); params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@ -799,8 +807,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} }
@Override @Override
public void onBackPressed() { public void onBackPressed() {;
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) { if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START); drawer.closeDrawer(GravityCompat.START);
} else { } else {

View File

@ -14,6 +14,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.biometric.BiometricManager; import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt; import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
@ -221,18 +222,8 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
openAccountSection(((NavHeaderViewHolder) holder).dropIconImageView); openAccountSection(((NavHeaderViewHolder) holder).dropIconImageView);
} }
} else { } else {
((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_down_24px)); ((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_arrow_drop_down_24px, null));
notifyItemRangeRemoved(1, getItemCount() - 1); closeAccountSectionWithoutChangeIconResource();
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;
} }
}); });
} else if (holder instanceof MenuGroupTitleViewHolder) { } 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) { 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); notifyItemRangeRemoved(1, getItemCount() - 1);
if (accounts != null) { if (accounts != null) {
notifyItemRangeInserted(1, accounts.size() + 3); notifyItemRangeInserted(1, accounts.size() + 3);