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);
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 {

View File

@ -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);