aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-04-01 00:33:17 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-04-01 00:33:17 +0000
commit398d53c162f32acb38feee588d2342d0876772ad (patch)
tree06030b179242253d74b2e20e9c49b9da87774a48 /app/src/main/java/ml
parent5976999131859779900181db222c68b60f8a9888 (diff)
downloadinfinity-for-reddit-398d53c162f32acb38feee588d2342d0876772ad.tar
infinity-for-reddit-398d53c162f32acb38feee588d2342d0876772ad.tar.gz
infinity-for-reddit-398d53c162f32acb38feee588d2342d0876772ad.tar.bz2
infinity-for-reddit-398d53c162f32acb38feee588d2342d0876772ad.tar.lz
infinity-for-reddit-398d53c162f32acb38feee588d2342d0876772ad.tar.xz
infinity-for-reddit-398d53c162f32acb38feee588d2342d0876772ad.tar.zst
infinity-for-reddit-398d53c162f32acb38feee588d2342d0876772ad.zip
New option in ViewPostDetailFragment: Add to Post Filter. Fix a bug when saving a Post Filter.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java46
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java68
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java6
4 files changed, 112 insertions, 10 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
index b517226e..c02d0687 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
@@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -49,6 +50,11 @@ public class CustomizePostFilterActivity extends BaseActivity {
public static final String EXTRA_POST_FILTER = "EPF";
public static final String EXTRA_FROM_SETTINGS = "EFS";
+ public static final String EXTRA_EXCLUDE_SUBREDDIT = "EES";
+ public static final String EXTRA_EXCLUDE_USER = "EEU";
+ public static final String EXTRA_EXCLUDE_FLAIR = "EEF";
+ public static final String EXTRA_CONTAIN_FLAIR = "ECF";
+ public static final String EXTRA_EXCLUDE_DOMAIN = "EED";
public static final String RETURN_EXTRA_POST_FILTER = "REPF";
private static final String POST_FILTER_STATE = "PFS";
private static final String ORIGINAL_NAME_STATE = "ONS";
@@ -309,6 +315,44 @@ public class CustomizePostFilterActivity extends BaseActivity {
maxCommentsTextInputEditText.setText(Integer.toString(postFilter.maxComments));
minAwardsTextInputEditText.setText(Integer.toString(postFilter.minAwards));
maxAwardsTextInputEditText.setText(Integer.toString(postFilter.maxAwards));
+
+ Intent intent = getIntent();
+ String excludeSubreddit = intent.getStringExtra(EXTRA_EXCLUDE_SUBREDDIT);
+ String excludeUser = intent.getStringExtra(EXTRA_EXCLUDE_USER);
+ String excludeFlair = intent.getStringExtra(EXTRA_EXCLUDE_FLAIR);
+ String containFlair = intent.getStringExtra(EXTRA_CONTAIN_FLAIR);
+ String excludeDomain = intent.getStringExtra(EXTRA_EXCLUDE_DOMAIN);
+
+ if (excludeSubreddit != null && !excludeSubreddit.equals("")) {
+ if (!excludesSubredditsTextInputEditText.getText().toString().equals("")) {
+ excludesSubredditsTextInputEditText.append(",");
+ }
+ excludesSubredditsTextInputEditText.append(excludeSubreddit);
+ }
+ if (excludeUser != null && !excludeUser.equals("")) {
+ if (!excludesUsersTextInputEditText.getText().toString().equals("")) {
+ excludesUsersTextInputEditText.append(",");
+ }
+ excludesUsersTextInputEditText.append(excludeUser);
+ }
+ if (excludeFlair != null && !excludeFlair.equals("")) {
+ if (!excludesFlairsTextInputEditText.getText().toString().equals("")) {
+ excludesFlairsTextInputEditText.append(",");
+ }
+ excludesFlairsTextInputEditText.append(excludeFlair);
+ }
+ if (containFlair != null && !containFlair.equals("")) {
+ if (!containsFlairsTextInputEditText.getText().toString().equals("")) {
+ containsFlairsTextInputEditText.append(",");
+ }
+ containsFlairsTextInputEditText.append(containFlair);
+ }
+ if (excludeDomain != null && !excludeDomain.equals("")) {
+ if (!excludesDomainsTextInputEditText.getText().toString().equals("")) {
+ excludesDomainsTextInputEditText.append(",");
+ }
+ excludesDomainsTextInputEditText.append(Uri.parse(excludeDomain).getHost());
+ }
}
@Override
@@ -496,7 +540,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
postFilter.postTitleExcludesStrings = titleExcludesStringsTextInputEditText.getText().toString();
postFilter.excludeSubreddits = excludesSubredditsTextInputEditText.getText().toString();
postFilter.excludeUsers = excludesUsersTextInputEditText.getText().toString();
- postFilter.excludeFlairs = excludesUsersTextInputEditText.getText().toString();
+ postFilter.excludeFlairs = excludesFlairsTextInputEditText.getText().toString();
postFilter.containFlairs = containsFlairsTextInputEditText.getText().toString();
postFilter.excludeDomains = excludesDomainsTextInputEditText.getText().toString();
postFilter.containTextType = postTypeTextCheckBox.isChecked();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java
index f75f08f7..e64bf21e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java
@@ -12,6 +12,7 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.concurrent.Executor;
@@ -27,12 +28,15 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.adapters.PostFilterRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostFilterOptionsBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.postfilter.DeletePostFilter;
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
import ml.docilealligator.infinityforreddit.postfilter.PostFilterViewModel;
public class PostFilterPreferenceActivity extends BaseActivity {
+ public static final String EXTRA_POST = "EP";
+
@BindView(R.id.coordinator_layout_post_filter_preference_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_post_filter_preference_activity)
@@ -71,18 +75,28 @@ public class PostFilterPreferenceActivity extends BaseActivity {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ Post post = getIntent().getParcelableExtra(EXTRA_POST);
+
fab.setOnClickListener(view -> {
- Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class);
- intent.putExtra(CustomizePostFilterActivity.EXTRA_FROM_SETTINGS, true);
- startActivity(intent);
+ if (post == null) {
+ Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class);
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_FROM_SETTINGS, true);
+ startActivity(intent);
+ } else {
+ showPostFilterOptions(post, null);
+ }
});
adapter = new PostFilterRecyclerViewAdapter(postFilter -> {
- PostFilterOptionsBottomSheetFragment postFilterOptionsBottomSheetFragment = new PostFilterOptionsBottomSheetFragment();
- Bundle bundle = new Bundle();
- bundle.putParcelable(PostFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, postFilter);
- postFilterOptionsBottomSheetFragment.setArguments(bundle);
- postFilterOptionsBottomSheetFragment.show(getSupportFragmentManager(), postFilterOptionsBottomSheetFragment.getTag());
+ if (post == null) {
+ PostFilterOptionsBottomSheetFragment postFilterOptionsBottomSheetFragment = new PostFilterOptionsBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(PostFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, postFilter);
+ postFilterOptionsBottomSheetFragment.setArguments(bundle);
+ postFilterOptionsBottomSheetFragment.show(getSupportFragmentManager(), postFilterOptionsBottomSheetFragment.getTag());
+ } else {
+ showPostFilterOptions(post, postFilter);
+ }
});
recyclerView.setAdapter(adapter);
@@ -93,6 +107,44 @@ public class PostFilterPreferenceActivity extends BaseActivity {
postFilterViewModel.getPostFilterListLiveData().observe(this, postFilters -> adapter.setPostFilterList(postFilters));
}
+ public void showPostFilterOptions(Post post, PostFilter postFilter) {
+ String[] options = getResources().getStringArray(R.array.add_to_post_filter_options);
+ boolean[] selectedOptions = new boolean[]{false, false, false, false, false};
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.select)
+ .setMultiChoiceItems(options, selectedOptions, (dialogInterface, i, b) -> selectedOptions[i] = b)
+ .setPositiveButton(R.string.ok, (dialogInterface, i) -> {
+ Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class);
+ if (postFilter != null) {
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter);
+ }
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_FROM_SETTINGS, true);
+ for (int j = 0; j < selectedOptions.length; j++) {
+ if (selectedOptions[j]) {
+ switch (j) {
+ case 0:
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_SUBREDDIT, post.getSubredditName());
+ break;
+ case 1:
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_USER, post.getAuthor());
+ break;
+ case 2:
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_FLAIR, post.getFlair());
+ break;
+ case 3:
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_CONTAIN_FLAIR, post.getFlair());
+ break;
+ case 4:
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_DOMAIN, post.getUrl());
+ break;
+ }
+ }
+ }
+ startActivity(intent);
+ })
+ .show();
+ }
+
public void editPostFilter(PostFilter postFilter) {
Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class);
intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java
index 344e968c..4faab908 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java
@@ -71,7 +71,7 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
super(itemView);
textView = (TextView) itemView;
itemView.setOnClickListener(view -> {
- onItemClickListener.onItemClick(postFilterList.get(getAdapterPosition() - 1));
+ onItemClickListener.onItemClick(postFilterList.get(getBindingAdapterPosition() - 1));
});
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index e9fb018c..91b82fdf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -72,6 +72,7 @@ import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.activities.CommentActivity;
import ml.docilealligator.infinityforreddit.activities.EditPostActivity;
import ml.docilealligator.infinityforreddit.activities.GiveAwardActivity;
+import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity;
import ml.docilealligator.infinityforreddit.activities.ReportActivity;
import ml.docilealligator.infinityforreddit.activities.SubmitCrosspostActivity;
import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity;
@@ -953,6 +954,11 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
submitCrosspostIntent.putExtra(SubmitCrosspostActivity.EXTRA_POST, mPost);
startActivity(submitCrosspostIntent);
return true;
+ } else if (itemId == R.id.action_add_to_post_filter_view_post_detail_fragment) {
+ Intent intent = new Intent(activity, PostFilterPreferenceActivity.class);
+ intent.putExtra(PostFilterPreferenceActivity.EXTRA_POST, mPost);
+ startActivity(intent);
+ return true;
}
return false;
}