Fix issues related to hiding account karma in the navigation drawer.

This commit is contained in:
Docile-Alligator 2022-11-03 15:34:45 +11:00
parent 814617b674
commit e362f2ecf0
5 changed files with 43 additions and 6 deletions

View File

@ -30,7 +30,6 @@ import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
@ -100,6 +99,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeLockBottomAppBarEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent; import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent;
import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent; import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideKarmaEvent;
import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.fragments.PostFragment;
@ -1276,6 +1276,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} }
} }
@Subscribe
public void onChangeHideKarmaEvent(ChangeHideKarmaEvent event) {
if (adapter != null) {
adapter.setHideKarma(event.hideKarma);
}
}
@Override @Override
public void onLongPress() { public void onLongPress() {
if (sectionsPagerAdapter != null) { if (sectionsPagerAdapter != null) {

View File

@ -47,7 +47,7 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
private boolean isLoggedIn; private boolean isLoggedIn;
private boolean isInMainPage = true; private boolean isInMainPage = true;
private PageToggle pageToggle; private PageToggle pageToggle;
private boolean showKarma; private boolean hideKarma;
public HeaderSectionRecyclerViewAdapter(BaseActivity baseActivity, CustomThemeWrapper customThemeWrapper, public HeaderSectionRecyclerViewAdapter(BaseActivity baseActivity, CustomThemeWrapper customThemeWrapper,
RequestManager glide, String accountName, RequestManager glide, String accountName,
@ -65,7 +65,7 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
requireAuthToAccountSection = securitySharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false); requireAuthToAccountSection = securitySharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false);
showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false); showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false);
showAvatarOnTheRightInTheNavigationDrawer = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false); showAvatarOnTheRightInTheNavigationDrawer = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false);
this.showKarma = !navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_ACCOUNT_KARMA_NAV_BAR, false); this.hideKarma = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_ACCOUNT_KARMA_NAV_BAR, false);
} }
@NonNull @NonNull
@ -86,11 +86,14 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
} }
((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params); ((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params);
if (isLoggedIn) { if (isLoggedIn) {
if (showKarma) { if (hideKarma) {
((NavHeaderViewHolder) holder).karmaTextView.setText(baseActivity.getString(R.string.karma_info, karma));
} else {
int karmaTextHeight = ((NavHeaderViewHolder) holder).karmaTextView.getHeight(); int karmaTextHeight = ((NavHeaderViewHolder) holder).karmaTextView.getHeight();
((NavHeaderViewHolder) holder).karmaTextView.setVisibility(View.GONE);
((NavHeaderViewHolder) holder).accountNameTextView.setTranslationY(karmaTextHeight / 2); ((NavHeaderViewHolder) holder).accountNameTextView.setTranslationY(karmaTextHeight / 2);
} else {
((NavHeaderViewHolder) holder).karmaTextView.setVisibility(View.VISIBLE);
((NavHeaderViewHolder) holder).karmaTextView.setText(baseActivity.getString(R.string.karma_info, karma));
((NavHeaderViewHolder) holder).accountNameTextView.setTranslationY(0);
} }
((NavHeaderViewHolder) holder).accountNameTextView.setText(accountName); ((NavHeaderViewHolder) holder).accountNameTextView.setText(accountName);
if (profileImageUrl != null && !profileImageUrl.equals("")) { if (profileImageUrl != null && !profileImageUrl.equals("")) {
@ -197,6 +200,11 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
this.showAvatarOnTheRightInTheNavigationDrawer = showAvatarOnTheRightInTheNavigationDrawer; this.showAvatarOnTheRightInTheNavigationDrawer = showAvatarOnTheRightInTheNavigationDrawer;
} }
public void setHideKarma(boolean hideKarma) {
this.hideKarma = hideKarma;
notifyItemChanged(0);
}
class NavHeaderViewHolder extends RecyclerView.ViewHolder { class NavHeaderViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.name_text_view_nav_header_main) @BindView(R.id.name_text_view_nav_header_main)
TextView accountNameTextView; TextView accountNameTextView;

View File

@ -135,6 +135,10 @@ public class NavigationDrawerRecyclerViewMergedAdapter {
subscribedSubredditsRecyclerViewAdapter.setSubscribedSubreddits(subscribedSubreddits); subscribedSubredditsRecyclerViewAdapter.setSubscribedSubreddits(subscribedSubreddits);
} }
public void setHideKarma(boolean hideKarma) {
headerSectionRecyclerViewAdapter.setHideKarma(hideKarma);
}
public interface ItemClickListener { public interface ItemClickListener {
void onMenuClick(int stringId); void onMenuClick(int stringId);
void onSubscribedSubredditClick(String subredditName); void onSubscribedSubredditClick(String subredditName);

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.events;
public class ChangeHideKarmaEvent {
public boolean hideKarma;
public ChangeHideKarmaEvent(boolean showKarma) {
this.hideKarma = showKarma;
}
}

View File

@ -9,6 +9,7 @@ import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat;
import ml.docilealligator.infinityforreddit.events.ChangeHideKarmaEvent;
import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent; import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@ -21,6 +22,7 @@ public class NavigationDrawerPreferenceFragment extends CustomFontPreferenceFrag
setPreferencesFromResource(R.xml.navigation_drawer_preferences, rootKey); setPreferencesFromResource(R.xml.navigation_drawer_preferences, rootKey);
SwitchPreference showAvatarOnTheRightSwitch = findPreference(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT); SwitchPreference showAvatarOnTheRightSwitch = findPreference(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT);
SwitchPreference hideKarmaSwitch = findPreference(SharedPreferencesUtils.HIDE_ACCOUNT_KARMA_NAV_BAR);
if (showAvatarOnTheRightSwitch != null) { if (showAvatarOnTheRightSwitch != null) {
showAvatarOnTheRightSwitch.setOnPreferenceChangeListener((preference, newValue) -> { showAvatarOnTheRightSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
@ -28,5 +30,12 @@ public class NavigationDrawerPreferenceFragment extends CustomFontPreferenceFrag
return true; return true;
}); });
} }
if (hideKarmaSwitch != null) {
hideKarmaSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeHideKarmaEvent((Boolean) newValue));
return true;
});
}
} }
} }