New option: Hide Text Post Content.

This commit is contained in:
Alex Ning 2022-01-20 15:00:26 +08:00
parent 5eaf4ab8fe
commit 25fff4064c
8 changed files with 48 additions and 9 deletions

View File

@ -207,6 +207,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private boolean mHideTheNumberOfComments;
private boolean mLegacyAutoplayVideoControllerUI;
private boolean mFixedHeightPreviewInCard;
private boolean mHideTextPostContent;
private Drawable mCommentIcon;
private ExoCreator mExoCreator;
private Callback mCallback;
@ -284,6 +285,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mHideTheNumberOfComments = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false);
mLegacyAutoplayVideoControllerUI = sharedPreferences.getBoolean(SharedPreferencesUtils.LEGACY_AUTOPLAY_VIDEO_CONTROLLER_UI, false);
mFixedHeightPreviewInCard = sharedPreferences.getBoolean(SharedPreferencesUtils.FIXED_HEIGHT_PREVIEW_IN_CARD, false);
mHideTextPostContent = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_TEXT_POST_CONTENT, false);
mPostLayout = postLayout;
mDefaultLinkPostLayout = Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.DEFAULT_LINK_POST_LAYOUT_KEY, "-1"));
@ -825,7 +827,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
}
} else if (holder instanceof PostTextTypeViewHolder) {
if (!post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) {
if (!mHideTextPostContent && !post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) {
((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE);
if (post.isRead()) {
((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mReadPostContentColor);
@ -980,7 +982,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
}
} else if (holder instanceof PostCard2TextTypeViewHolder) {
if (!post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) {
if (!mHideTextPostContent && !post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) {
((PostCard2TextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE);
if (post.isRead()) {
((PostCard2TextTypeViewHolder) holder).contentTextView.setTextColor(mReadPostContentColor);
@ -1737,6 +1739,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mFixedHeightPreviewInCard = fixedHeightPreviewInCard;
}
public void setHideTextPostContent(boolean hideTextPostContent) {
mHideTextPostContent = hideTextPostContent;
}
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);

View File

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

View File

@ -99,6 +99,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeFixedHeightPreviewInCar
import ml.docilealligator.infinityforreddit.events.ChangeHidePostFlairEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTextPostContent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfCommentsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfVotesEvent;
@ -1728,6 +1729,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
post.setTitle(event.post.getTitle());
post.setVoteType(event.post.getVoteType());
post.setScore(event.post.getScore());
post.setNComments(event.post.getNComments());
post.setNSFW(event.post.isNSFW());
post.setHidden(event.post.isHidden());
post.setSpoiler(event.post.isSpoiler());
@ -2074,6 +2076,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
@Subscribe
public void onChangeHideTextPostContentEvent(ChangeHideTextPostContent event) {
if (mAdapter != null) {
mAdapter.setHideTextPostContent(event.hideTextPostContent);
refreshAdapter();
}
}
private void refreshAdapter() {
int previousPosition = -1;
if (mLinearLayoutManager != null) {

View File

@ -706,6 +706,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
if (mPostAdapter != null) {
mPostAdapter.addOneComment();
}
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
}
public void addChildComment(Comment comment, String parentFullname, int parentPosition) {
@ -715,6 +716,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
if (mPostAdapter != null) {
mPostAdapter.addOneComment();
}
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
}
public void editComment(String commentAuthor, String commentContentMarkdown, int position) {

View File

@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.settings;
import android.os.Bundle;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus;
@ -17,6 +16,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeFixedHeightPreviewInCar
import ml.docilealligator.infinityforreddit.events.ChangeHidePostFlairEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTextPostContent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfAwardsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfCommentsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHideTheNumberOfVotesEvent;
@ -49,6 +49,7 @@ public class PostPreferenceFragment extends CustomFontPreferenceFragmentCompat {
SwitchPreference hideSubredditAndUserPrefixSwitch = findPreference(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX);
SwitchPreference hideTheNumberOfVotesSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES);
SwitchPreference hideTheNumberOfCommentsSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS);
SwitchPreference hideTextPostContentSwitch = findPreference(SharedPreferencesUtils.HIDE_TEXT_POST_CONTENT);
SwitchPreference fixedHeightPreviewInCardSwitch = findPreference(SharedPreferencesUtils.FIXED_HEIGHT_PREVIEW_IN_CARD);
if (defaultPostLayoutList != null) {
@ -136,12 +137,16 @@ public class PostPreferenceFragment extends CustomFontPreferenceFragmentCompat {
}
if (hideTheNumberOfCommentsSwitch != null) {
hideTheNumberOfCommentsSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
EventBus.getDefault().post(new ChangeHideTheNumberOfCommentsEvent((Boolean) newValue));
return true;
}
hideTheNumberOfCommentsSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeHideTheNumberOfCommentsEvent((Boolean) newValue));
return true;
});
}
if (hideTextPostContentSwitch != null) {
hideTextPostContentSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeHideTextPostContent((Boolean) newValue));
return true;
});
}

View File

@ -201,6 +201,7 @@ public class SharedPreferencesUtils {
public static final String LEGACY_AUTOPLAY_VIDEO_CONTROLLER_UI = "legacy_autoplay_video_controller_ui";
public static final String PINCH_TO_ZOOM_VIDEO = "pinch_to_zoom_video";
public static final String FIXED_HEIGHT_PREVIEW_IN_CARD = "fixed_height_preview_in_card";
public static final String HIDE_TEXT_POST_CONTENT = "hide_text_post_content";
public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";

View File

@ -625,6 +625,7 @@
<string name="settings_custom_title_font_family_title">Custom Title Font Family</string>
<string name="settings_custom_content_font_family_title">Custom Content Font Family</string>
<string name="settings_fixed_height_preview_in_card_title">Fixed Height in Card</string>
<string name="settings_hide_text_post_content">Hide Text Post Content</string>
<string name="no_link_available">Cannot get the link</string>

View File

@ -52,6 +52,11 @@
app:key="hide_the_number_of_comments"
app:title="@string/settings_hide_the_number_of_comments" />
<ml.docilealligator.infinityforreddit.customviews.CustomFontSwitchPreference
app:defaultValue="false"
app:key="hide_text_post_content"
app:title="@string/settings_hide_text_post_content" />
<ml.docilealligator.infinityforreddit.customviews.CustomFontSwitchPreference
app:defaultValue="false"
app:key="fixed_height_preview_in_card"