diff options
Diffstat (limited to 'app')
5 files changed, 43 insertions, 6 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 5eff56e8..194ddd0f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -30,7 +30,6 @@ import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AppCompatDelegate; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.app.ActivityCompat; -import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; 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.ChangeRequireAuthToAccountSectionEvent; import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent; +import ml.docilealligator.infinityforreddit.events.ChangeHideKarmaEvent; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; 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 public void onLongPress() { if (sectionsPagerAdapter != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java index bc051f76..270de60b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java @@ -47,7 +47,7 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc private boolean isLoggedIn; private boolean isInMainPage = true; private PageToggle pageToggle; - private boolean showKarma; + private boolean hideKarma; public HeaderSectionRecyclerViewAdapter(BaseActivity baseActivity, CustomThemeWrapper customThemeWrapper, 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); showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.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 @@ -86,11 +86,14 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc } ((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params); if (isLoggedIn) { - if (showKarma) { - ((NavHeaderViewHolder) holder).karmaTextView.setText(baseActivity.getString(R.string.karma_info, karma)); - } else { + if (hideKarma) { int karmaTextHeight = ((NavHeaderViewHolder) holder).karmaTextView.getHeight(); + ((NavHeaderViewHolder) holder).karmaTextView.setVisibility(View.GONE); ((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); if (profileImageUrl != null && !profileImageUrl.equals("")) { @@ -197,6 +200,11 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc this.showAvatarOnTheRightInTheNavigationDrawer = showAvatarOnTheRightInTheNavigationDrawer; } + public void setHideKarma(boolean hideKarma) { + this.hideKarma = hideKarma; + notifyItemChanged(0); + } + class NavHeaderViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.name_text_view_nav_header_main) TextView accountNameTextView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java index 923af7eb..ec67fd1f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java @@ -135,6 +135,10 @@ public class NavigationDrawerRecyclerViewMergedAdapter { subscribedSubredditsRecyclerViewAdapter.setSubscribedSubreddits(subscribedSubreddits); } + public void setHideKarma(boolean hideKarma) { + headerSectionRecyclerViewAdapter.setHideKarma(hideKarma); + } + public interface ItemClickListener { void onMenuClick(int stringId); void onSubscribedSubredditClick(String subredditName); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideKarmaEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideKarmaEvent.java new file mode 100644 index 00000000..bc90b6a0 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeHideKarmaEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.events; + +public class ChangeHideKarmaEvent { + public boolean hideKarma; + + public ChangeHideKarmaEvent(boolean showKarma) { + this.hideKarma = showKarma; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java index 883f2f80..55bec462 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java @@ -9,6 +9,7 @@ import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; +import ml.docilealligator.infinityforreddit.events.ChangeHideKarmaEvent; import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -21,6 +22,7 @@ public class NavigationDrawerPreferenceFragment extends CustomFontPreferenceFrag setPreferencesFromResource(R.xml.navigation_drawer_preferences, rootKey); SwitchPreference showAvatarOnTheRightSwitch = findPreference(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT); + SwitchPreference hideKarmaSwitch = findPreference(SharedPreferencesUtils.HIDE_ACCOUNT_KARMA_NAV_BAR); if (showAvatarOnTheRightSwitch != null) { showAvatarOnTheRightSwitch.setOnPreferenceChangeListener((preference, newValue) -> { @@ -28,5 +30,12 @@ public class NavigationDrawerPreferenceFragment extends CustomFontPreferenceFrag return true; }); } + + if (hideKarmaSwitch != null) { + hideKarmaSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeHideKarmaEvent((Boolean) newValue)); + return true; + }); + } } }
\ No newline at end of file |