aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java18
-rw-r--r--app/src/main/res/layout/activity_customize_post_filter.xml20
-rw-r--r--app/src/main/res/values/strings.xml1
6 files changed, 60 insertions, 3 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java
index 49f706e9..4cb5cd43 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java
@@ -35,7 +35,7 @@ import ml.docilealligator.infinityforreddit.user.UserData;
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class,
- ReadPost.class, PostFilter.class, PostFilterUsage.class}, version = 19)
+ ReadPost.class, PostFilter.class, PostFilterUsage.class}, version = 20)
public abstract class RedditDataRoomDatabase extends RoomDatabase {
private static RedditDataRoomDatabase INSTANCE;
@@ -49,7 +49,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13,
MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17,
- MIGRATION_17_18, MIGRATION_18_19)
+ MIGRATION_17_18, MIGRATION_18_19, MIGRATION_19_20)
.build();
}
}
@@ -332,4 +332,11 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
database.execSQL("INSERT INTO accounts(username, karma, is_current_user) VALUES (\"-\", 0, false)");
}
};
+
+ private static final Migration MIGRATION_19_20 = new Migration(19, 20) {
+ @Override
+ public void migrate(@NonNull SupportSQLiteDatabase database) {
+ database.execSQL("ALTER TABLE post_filter ADD COLUMN exclude_domains TEXT");
+ }
+ };
}
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 7e89c508..b517226e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
@@ -144,6 +144,10 @@ public class CustomizePostFilterActivity extends BaseActivity {
TextInputLayout containsFlairsTextInputLayout;
@BindView(R.id.contains_flairs_text_input_edit_text_customize_post_filter_activity)
TextInputEditText containsFlairsTextInputEditText;
+ @BindView(R.id.excludes_domains_text_input_layout_customize_post_filter_activity)
+ TextInputLayout excludesDomainsTextInputLayout;
+ @BindView(R.id.excludes_domains_text_input_edit_text_customize_post_filter_activity)
+ TextInputEditText excludesDomainsTextInputEditText;
@BindView(R.id.min_vote_text_input_layout_customize_post_filter_activity)
TextInputLayout minVoteTextInputLayout;
@BindView(R.id.min_vote_text_input_edit_text_customize_post_filter_activity)
@@ -298,6 +302,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
excludesUsersTextInputEditText.setText(postFilter.excludeUsers);
excludesFlairsTextInputEditText.setText(postFilter.excludeFlairs);
containsFlairsTextInputEditText.setText(postFilter.containFlairs);
+ excludesDomainsTextInputEditText.setText(postFilter.excludeDomains);
minVoteTextInputEditText.setText(Integer.toString(postFilter.minVote));
maxVoteTextInputEditText.setText(Integer.toString(postFilter.maxVote));
minCommentsTextInputEditText.setText(Integer.toString(postFilter.minComments));
@@ -353,6 +358,9 @@ public class CustomizePostFilterActivity extends BaseActivity {
containsFlairsTextInputLayout.setBoxStrokeColor(primaryTextColor);
containsFlairsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
containsFlairsTextInputEditText.setTextColor(primaryTextColor);
+ excludesDomainsTextInputLayout.setBoxStrokeColor(primaryTextColor);
+ excludesDomainsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
+ excludesDomainsTextInputEditText.setTextColor(primaryTextColor);
minVoteTextInputLayout.setBoxStrokeColor(primaryTextColor);
minVoteTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
minVoteTextInputEditText.setTextColor(primaryTextColor);
@@ -490,6 +498,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
postFilter.excludeUsers = excludesUsersTextInputEditText.getText().toString();
postFilter.excludeFlairs = excludesUsersTextInputEditText.getText().toString();
postFilter.containFlairs = containsFlairsTextInputEditText.getText().toString();
+ postFilter.excludeDomains = excludesDomainsTextInputEditText.getText().toString();
postFilter.containTextType = postTypeTextCheckBox.isChecked();
postFilter.containLinkType = postTypeLinkCheckBox.isChecked();
postFilter.containImageType = postTypeImageCheckBox.isChecked();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index 8400985b..161643a5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -1285,7 +1285,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void changeNSFW(boolean nsfw) {
postFilter.allowNSFW = nsfw;
- mPostViewModel.changePostFilter(postFilter);
+ if (mPostViewModel != null) {
+ mPostViewModel.changePostFilter(postFilter);
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java
index 99d40536..f61ecc46 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java
@@ -51,6 +51,8 @@ public class PostFilter implements Parcelable {
public String containFlairs;
@ColumnInfo(name = "exclude_flairs")
public String excludeFlairs;
+ @ColumnInfo(name = "exclude_domains")
+ public String excludeDomains;
@ColumnInfo(name = "contain_text_type")
public boolean containTextType = true;
@ColumnInfo(name = "contain_link_type")
@@ -85,6 +87,7 @@ public class PostFilter implements Parcelable {
excludeUsers = in.readString();
containFlairs = in.readString();
excludeFlairs = in.readString();
+ excludeDomains = in.readString();
containTextType = in.readByte() != 0;
containLinkType = in.readByte() != 0;
containImageType = in.readByte() != 0;
@@ -199,6 +202,14 @@ public class PostFilter implements Parcelable {
}
}
}
+ if (postFilter.excludeDomains != null && !postFilter.excludeDomains.equals("")) {
+ String[] domains = postFilter.excludeDomains.split(",", 0);
+ for (String f : domains) {
+ if (!f.trim().equals("") && post.getUrl().toLowerCase().contains(f.trim().toLowerCase())) {
+ return false;
+ }
+ }
+ }
if (postFilter.containFlairs != null && !postFilter.containFlairs.equals("")) {
String[] flairs = postFilter.containFlairs.split(",", 0);
for (String f : flairs) {
@@ -263,6 +274,12 @@ public class PostFilter implements Parcelable {
postFilter.excludeFlairs = stringBuilder.toString();
}
+ if (p.excludeDomains != null && !p.excludeDomains.equals("")) {
+ stringBuilder = new StringBuilder(postFilter.excludeDomains == null ? "" : postFilter.excludeDomains);
+ stringBuilder.append(",").append(p.excludeDomains);
+ postFilter.excludeDomains = stringBuilder.toString();
+ }
+
postFilter.containTextType = p.containTextType || postFilter.containTextType;
postFilter.containLinkType = p.containLinkType || postFilter.containLinkType;
postFilter.containImageType = p.containImageType || postFilter.containImageType;
@@ -297,6 +314,7 @@ public class PostFilter implements Parcelable {
parcel.writeString(excludeUsers);
parcel.writeString(containFlairs);
parcel.writeString(excludeFlairs);
+ parcel.writeString(excludeDomains);
parcel.writeByte((byte) (containTextType ? 1 : 0));
parcel.writeByte((byte) (containLinkType ? 1 : 0));
parcel.writeByte((byte) (containImageType ? 1 : 0));
diff --git a/app/src/main/res/layout/activity_customize_post_filter.xml b/app/src/main/res/layout/activity_customize_post_filter.xml
index 7768b75c..572d6f94 100644
--- a/app/src/main/res/layout/activity_customize_post_filter.xml
+++ b/app/src/main/res/layout/activity_customize_post_filter.xml
@@ -457,6 +457,26 @@
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
+ android:id="@+id/excludes_domains_text_input_layout_customize_post_filter_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
+
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/excludes_domains_text_input_edit_text_customize_post_filter_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:fontFamily="?attr/font_family"
+ android:textSize="?attr/font_default"
+ android:hint="@string/exclude_domains_hint" />
+
+ </com.google.android.material.textfield.TextInputLayout>
+
+ <com.google.android.material.textfield.TextInputLayout
android:id="@+id/min_vote_text_input_layout_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 254384a7..5a46106f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1015,6 +1015,7 @@
<string name="exclude_users_hint">Exclude users (e.g. Hostilenemy,random)</string>
<string name="exclude_flairs_hint">Exclude flairs (e.g. flair1,flair2)</string>
<string name="contain_flairs_hint">Contain flairs (e.g. flair1,flair2)</string>
+ <string name="exclude_domains_hint">Exclude domains</string>
<string name="min_vote_hint">Min vote (-1: no restriction)</string>
<string name="max_vote_hint">Max vote (-1: no restriction)</string>
<string name="min_comments_hint">Min comments (-1: no restriction)</string>