Send PostFilter to CustomizePostFilterActivity. Rename FilteredThingActivity to FilteredPostsActivity.

This commit is contained in:
Alex Ning 2020-12-23 11:54:20 +08:00
parent e4b7556844
commit 6747efbccb
9 changed files with 105 additions and 86 deletions

View File

@ -199,7 +199,7 @@
android:theme="@style/AppTheme.Slidable"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".activities.FilteredThingActivity"
android:name=".activities.FilteredPostsActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity

View File

@ -16,7 +16,7 @@ import ml.docilealligator.infinityforreddit.activities.EditCommentActivity;
import ml.docilealligator.infinityforreddit.activities.EditMultiRedditActivity;
import ml.docilealligator.infinityforreddit.activities.EditPostActivity;
import ml.docilealligator.infinityforreddit.activities.FetchRandomSubredditOrPostActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
import ml.docilealligator.infinityforreddit.activities.GiveAwardActivity;
import ml.docilealligator.infinityforreddit.activities.InboxActivity;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
@ -119,7 +119,7 @@ public interface AppComponent {
void inject(SubmitPostService submitPostService);
void inject(FilteredThingActivity filteredPostsActivity);
void inject(FilteredPostsActivity filteredPostsActivity);
void inject(SearchResultActivity searchResultActivity);

View File

@ -42,6 +42,10 @@ public interface FragmentCommunicator {
default void changePostFilter(PostFilter postFilter) {
}
default PostFilter getPostFilter() {
return null;
}
default void filterPosts() {
};

View File

@ -100,7 +100,7 @@ public class PostFilter implements Parcelable {
if (postFilter.excludesSubreddits != null && !postFilter.excludesSubreddits.equals("")) {
String[] subreddits = postFilter.excludesSubreddits.split(",", 0);
for (String s : subreddits) {
if (post.getSubredditName().equals(s)) {
if (post.getSubredditName().equalsIgnoreCase(s)) {
return false;
}
}
@ -108,7 +108,7 @@ public class PostFilter implements Parcelable {
if (postFilter.excludesUsers != null && !postFilter.excludesUsers.equals("")) {
String[] users = postFilter.excludesUsers.split(",", 0);
for (String u : users) {
if (post.getAuthor().equals(u)) {
if (post.getAuthor().equalsIgnoreCase(u)) {
return false;
}
}
@ -116,7 +116,7 @@ public class PostFilter implements Parcelable {
if (postFilter.excludesFlairs != null && !postFilter.excludesFlairs.equals("")) {
String[] flairs = postFilter.excludesFlairs.split(",", 0);
for (String f : flairs) {
if (post.getFlair().equals(f)) {
if (post.getFlair().equalsIgnoreCase(f)) {
return false;
}
}
@ -124,7 +124,7 @@ public class PostFilter implements Parcelable {
if (postFilter.containsFlairs != null && !postFilter.containsFlairs.equals("")) {
String[] flairs = postFilter.containsFlairs.split(",", 0);
for (String f : flairs) {
if (post.getFlair().equals(f)) {
if (post.getFlair().equalsIgnoreCase(f)) {
return false;
}
}

View File

@ -53,7 +53,7 @@ import ml.docilealligator.infinityforreddit.post.PostDataSource;
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback,
public class FilteredPostsActivity extends BaseActivity implements SortTypeSelectionCallback,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface,
MarkPostAsReadInterface, FilteredThingFABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback {
@ -364,6 +364,9 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
fab.setOnClickListener(view -> {
Intent intent = new Intent(this, CustomizePostFilterActivity.class);
if (mFragment != null) {
intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, mFragment.getPostFilter());
}
startActivityForResult(intent, CUSTOMIZE_POST_FILTER_ACTIVITY_REQUEST_CODE);
});

View File

@ -86,7 +86,7 @@ import io.noties.markwon.simple.ext.SimpleExtPlugin;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.activities.CommentActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity;
import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity;
@ -2135,18 +2135,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
});
mTypeTextView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, mPost.getPostType());
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, mPost.getPostType());
mActivity.startActivity(intent);
});
mNSFWTextView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
mActivity.startActivity(intent);
});

View File

@ -76,7 +76,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SaveThing;
import ml.docilealligator.infinityforreddit.VoteThing;
import ml.docilealligator.infinityforreddit.activities.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity;
import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity;
@ -1662,7 +1662,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
iconGifImageView.setOnClickListener(view -> userTextView.performClick());
}
if (!(mActivity instanceof FilteredThingActivity)) {
if (!(mActivity instanceof FilteredPostsActivity)) {
nsfwTextView.setOnClickListener(view -> {
int position = getAdapterPosition();
if (position < 0) {
@ -2655,7 +2655,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
return;
}
Post post = getItem(position);
if (post != null && !(mActivity instanceof FilteredThingActivity)) {
if (post != null && !(mActivity instanceof FilteredPostsActivity)) {
mCallback.nsfwChipClicked();
}
});
@ -2666,7 +2666,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
return;
}
Post post = getItem(position);
if (post != null && !(mActivity instanceof FilteredThingActivity)) {
if (post != null && !(mActivity instanceof FilteredPostsActivity)) {
mCallback.typeChipClicked(post.getPostType());
}
});

View File

@ -70,7 +70,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
import ml.docilealligator.infinityforreddit.activities.MainActivity;
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
@ -427,14 +427,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
});
} else if (activity instanceof FilteredThingActivity) {
} else if (activity instanceof FilteredPostsActivity) {
mPostRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
((FilteredThingActivity) activity).contentScrollDown();
((FilteredPostsActivity) activity).contentScrollDown();
} else if (dy < 0) {
((FilteredThingActivity) activity).contentScrollUp();
((FilteredPostsActivity) activity).contentScrollUp();
}
}
});
@ -475,21 +475,21 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void typeChipClicked(int filter) {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredThingActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
startActivity(intent);
}
@Override
public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredThingActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
startActivity(intent);
}
@ -534,19 +534,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void typeChipClicked(int filter) {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
startActivity(intent);
}
@Override
public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
startActivity(intent);
}
@ -593,19 +593,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void typeChipClicked(int filter) {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, multiRedditPath);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
startActivity(intent);
}
@Override
public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, multiRedditPath);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
startActivity(intent);
}
@ -650,21 +650,21 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void typeChipClicked(int filter) {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, username);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_USER_WHERE, where);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, username);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_USER_WHERE, where);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
startActivity(intent);
}
@Override
public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, username);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_USER_WHERE, where);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, username);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_USER_WHERE, where);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
startActivity(intent);
}
@ -701,19 +701,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void typeChipClicked(int filter) {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, activity.getString(R.string.best));
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best));
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
startActivity(intent);
}
@Override
public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, activity.getString(R.string.best));
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best));
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
startActivity(intent);
}
@ -1257,34 +1257,42 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
@Override
public PostFilter getPostFilter() {
if (mPostViewModel != null) {
return mPostViewModel.getPostFilter();
}
return null;
}
@Override
public void filterPosts() {
if (postType == PostDataSource.TYPE_SEARCH) {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredThingActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
startActivity(intent);
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
startActivity(intent);
} else if(postType == PostDataSource.TYPE_MULTI_REDDIT) {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, multiRedditPath);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
startActivity(intent);
} else if (postType == PostDataSource.TYPE_USER) {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, username);
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredThingActivity.EXTRA_USER_WHERE, where);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, username);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_USER_WHERE, where);
startActivity(intent);
} else {
Intent intent = new Intent(activity, FilteredThingActivity.class);
intent.putExtra(FilteredThingActivity.EXTRA_NAME, activity.getString(R.string.best));
intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType);
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best));
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
startActivity(intent);
}
}

View File

@ -200,6 +200,10 @@ public class PostViewModel extends ViewModel {
postFilterLiveData.postValue(postFilter);
}
public PostFilter getPostFilter() {
return postFilterLiveData.getValue();
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private Retrofit retrofit;
private String accessToken;