Add option to disable automatic post hide

This commit adds two new options:
- Do not hide saved posts automatically: When enabled, read posts will also be visible on the saved posts page
- Do not hide your own posts: When enabled, your own posts will be visible, even if it's read

Closes #219
Closes #125
This commit is contained in:
Balazs Toldi 2024-07-19 17:02:23 +02:00
parent 9ecbaba3d4
commit cafd3c6025
13 changed files with 129 additions and 20 deletions

View File

@ -286,7 +286,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountQualifiedName);
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
bundle.putBoolean(PostFragment.EXTRA_DISABLE_READ_POSTS, true);
fragment.setArguments(bundle);
return fragment;

View File

@ -317,7 +317,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
bundle.putInt(PostFragment.EXTRA_POST_TYPE, postType);
bundle.putParcelable(PostFragment.EXTRA_FILTER, postFilter);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
if (postType == PostPagingSource.TYPE_USER) {
bundle.putString(PostFragment.EXTRA_USER_NAME, name);
bundle.putString(PostFragment.EXTRA_USER_WHERE, userWhere);

View File

@ -1840,7 +1840,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL) {
@ -1849,7 +1849,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_NAME, "all");
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT) {
@ -1858,7 +1858,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_NAME, name);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT) {
@ -1867,7 +1867,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putString(PostFragment.EXTRA_NAME, name);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT : PostPagingSource.TYPE_MULTI_REDDIT);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER) {
@ -1877,7 +1877,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putString(PostFragment.EXTRA_USER_NAME, name);
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SUBMITTED);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_UPVOTED
@ -1890,7 +1890,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
bundle.putBoolean(PostFragment.EXTRA_DISABLE_READ_POSTS, true);
if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_UPVOTED) {
@ -1913,7 +1913,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_NAME, "local");
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
}

View File

@ -59,8 +59,6 @@ import eu.toldi.infinityforlemmy.bottomsheetfragments.FABMoreOptionsBottomSheetF
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostLayoutBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.RandomBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SearchPostSortTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SearchUserAndSubredditSortTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SortTimeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SortTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
@ -781,7 +779,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
mFragment.setArguments(bundle);
return mFragment;
}

View File

@ -81,7 +81,7 @@ public class SettingsActivity extends BaseActivity implements
setSupportActionBar(binding.toolbarSettingsActivity);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
if (savedInstanceState == null) {
getSupportFragmentManager()

View File

@ -428,7 +428,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
bundle.putString(PostFragment.EXTRA_NAME, multiPath);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT : PostPagingSource.TYPE_MULTI_REDDIT);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_multi_reddit_detail_activity, mFragment).commit();
}

View File

@ -1751,7 +1751,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
bundle.putString(PostFragment.EXTRA_NAME, qualifiedName);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
}

View File

@ -1765,7 +1765,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
bundle.putString(PostFragment.EXTRA_USER_NAME, qualifiedName);
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SUBMITTED);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
}

View File

@ -178,9 +178,10 @@ public class PostViewModel extends ViewModel {
postPagingData -> PagingDataTransforms.filter(
postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
boolean dontHideSaved = postHistorySharedPreferences != null && postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.DONT_HIDE_SAVED_READ_POSTS, false) && userWhere.equals(PostPagingSource.USER_WHERE_SAVED);
boolean dontHideOwn = postHistorySharedPreferences != null && postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.DONT_HIDE_OWN_READ_POSTS, false) && name.equals(accountName);
currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false) && !userWhere.equals(PostPagingSource.USER_WHERE_SAVED));
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false) && !dontHideSaved && !dontHideOwn);
}
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,

View File

@ -56,6 +56,18 @@ public class PostHistoryFragment extends Fragment {
TextView hideReadPostsAutomaticallyTextView;
@BindView(R.id.hide_read_posts_automatically_switch_post_history_fragment)
MaterialSwitch hideReadPostsAutomaticallySwitch;
@BindView(R.id.dont_hide_saved_read_posts_automatically_linear_layout_post_history_fragment)
LinearLayout dontHideSavedReadPostsAutomaticallyLinearLayout;
@BindView(R.id.dont_hide_saved_read_posts_automatically_text_view_post_history_fragment)
TextView dontHideSavedReadPostsAutomaticallyTextView;
@BindView(R.id.dont_hide_saved_read_posts_automatically_switch_post_history_fragment)
MaterialSwitch dontHideSavedReadPostsAutomaticallySwitch;
@BindView(R.id.dont_hide_own_read_posts_automatically_linear_layout_post_history_fragment)
LinearLayout dontHideOwnReadPostsAutomaticallyLinearLayout;
@BindView(R.id.dont_hide_own_read_posts_automatically_text_view_post_history_fragment)
TextView dontHideOwnReadPostsAutomaticallyTextView;
@BindView(R.id.dont_hide_own_read_posts_automatically_switch_post_history_fragment)
MaterialSwitch dontHideOwnReadPostsAutomaticallySwitch;
@Inject
@Named("post_history")
SharedPreferences postHistorySharedPreferences;
@ -100,6 +112,18 @@ public class PostHistoryFragment extends Fragment {
accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false));
hideReadPostsAutomaticallySwitch.setChecked(postHistorySharedPreferences.getBoolean(
accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
dontHideSavedReadPostsAutomaticallySwitch.setChecked(postHistorySharedPreferences.getBoolean(
accountName + SharedPreferencesUtils.DONT_HIDE_SAVED_READ_POSTS, false));
dontHideOwnReadPostsAutomaticallySwitch.setChecked(postHistorySharedPreferences.getBoolean(
accountName + SharedPreferencesUtils.DONT_HIDE_OWN_READ_POSTS, false));
if (hideReadPostsAutomaticallySwitch.isChecked()) {
dontHideSavedReadPostsAutomaticallyLinearLayout.setVisibility(View.VISIBLE);
dontHideOwnReadPostsAutomaticallyLinearLayout.setVisibility(View.VISIBLE);
} else {
dontHideSavedReadPostsAutomaticallyLinearLayout.setVisibility(View.GONE);
dontHideOwnReadPostsAutomaticallyLinearLayout.setVisibility(View.GONE);
}
markPostsAsReadLinearLayout.setOnClickListener(view -> {
markPostsAsReadSwitch.performClick();
@ -119,7 +143,24 @@ public class PostHistoryFragment extends Fragment {
hideReadPostsAutomaticallyLinearLayout.setOnClickListener(view -> hideReadPostsAutomaticallySwitch.performClick());
hideReadPostsAutomaticallySwitch.setOnCheckedChangeListener((compoundButton, b) -> postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, b).apply());
hideReadPostsAutomaticallySwitch.setOnCheckedChangeListener((compoundButton, b) -> {
postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, b).apply();
if (b) {
dontHideSavedReadPostsAutomaticallyLinearLayout.setVisibility(View.VISIBLE);
dontHideOwnReadPostsAutomaticallyLinearLayout.setVisibility(View.VISIBLE);
} else {
dontHideSavedReadPostsAutomaticallyLinearLayout.setVisibility(View.GONE);
dontHideOwnReadPostsAutomaticallyLinearLayout.setVisibility(View.GONE);
}
});
dontHideSavedReadPostsAutomaticallyLinearLayout.setOnClickListener(view -> dontHideSavedReadPostsAutomaticallySwitch.performClick());
dontHideSavedReadPostsAutomaticallySwitch.setOnCheckedChangeListener((compoundButton, b) -> postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.DONT_HIDE_SAVED_READ_POSTS, b).apply());
dontHideOwnReadPostsAutomaticallyLinearLayout.setOnClickListener(view -> dontHideOwnReadPostsAutomaticallySwitch.performClick());
dontHideOwnReadPostsAutomaticallySwitch.setOnCheckedChangeListener((compoundButton, b) -> postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.DONT_HIDE_OWN_READ_POSTS, b).apply());
return rootView;
}
@ -133,6 +174,8 @@ public class PostHistoryFragment extends Fragment {
markPostsAsReadAfterVotingTextView.setTextColor(primaryTextColor);
markPostsAsReadOnScrollTextView.setTextColor(primaryTextColor);
hideReadPostsAutomaticallyTextView.setTextColor(primaryTextColor);
dontHideSavedReadPostsAutomaticallyTextView.setTextColor(primaryTextColor);
dontHideOwnReadPostsAutomaticallyTextView.setTextColor(primaryTextColor);
}
@Override

View File

@ -358,6 +358,8 @@ public class SharedPreferencesUtils {
public static final String MARK_POSTS_AS_READ_AFTER_VOTING_BASE = "_mark_posts_as_read_after_voting";
public static final String MARK_POSTS_AS_READ_ON_SCROLL_BASE = "_mark_posts_as_read_on_scroll";
public static final String HIDE_READ_POSTS_AUTOMATICALLY_BASE = "_hide_read_posts_automatically";
public static final String DONT_HIDE_SAVED_READ_POSTS = "dont_hide_saved_posts";
public static final String DONT_HIDE_OWN_READ_POSTS = "dont_hide_own_posts";
public static final String CURRENT_ACCOUNT_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.current_account";
public static final String ACCOUNT_NAME = "account_name";

View File

@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".settings.PostHistoryFragment">
<LinearLayout
@ -156,6 +155,70 @@
</LinearLayout>
<LinearLayout
android:id="@+id/dont_hide_saved_read_posts_automatically_linear_layout_post_history_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingStart="72dp"
android:paddingEnd="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/dont_hide_saved_read_posts_automatically_text_view_post_history_fragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="16dp"
android:layout_gravity="center_vertical"
android:text="@string/settings_dont_hide_saved_read_posts_automatically"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_16"
android:fontFamily="?attr/font_family" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/dont_hide_saved_read_posts_automatically_switch_post_history_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:id="@+id/dont_hide_own_read_posts_automatically_linear_layout_post_history_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingStart="72dp"
android:paddingEnd="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/dont_hide_own_read_posts_automatically_text_view_post_history_fragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="16dp"
android:layout_gravity="center_vertical"
android:text="@string/settings_dont_hide_your_own_read_posts_automatically"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_16"
android:fontFamily="?attr/font_family" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/dont_hide_own_read_posts_automatically_switch_post_history_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -1330,4 +1330,6 @@
<string name="block_instance_failed">Failed to block instance</string>
<string name="block_instance_success">Instance Blocked!</string>
<string name="unblock_instance_success">Instance unblocked!</string>
<string name="settings_dont_hide_saved_read_posts_automatically">Don\'t hide saved read posts automatically</string>
<string name="settings_dont_hide_your_own_read_posts_automatically">Don\'t hide your own read posts automatically</string>
</resources>