mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Fix issues related to hiding account karma in the navigation drawer.
This commit is contained in:
parent
814617b674
commit
e362f2ecf0
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -0,0 +1,9 @@
|
||||
package ml.docilealligator.infinityforreddit.events;
|
||||
|
||||
public class ChangeHideKarmaEvent {
|
||||
public boolean hideKarma;
|
||||
|
||||
public ChangeHideKarmaEvent(boolean showKarma) {
|
||||
this.hideKarma = showKarma;
|
||||
}
|
||||
}
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user