Remove USER_TYPE in CommentFilterUsage. Add exclude users in comment filter.

This commit is contained in:
Docile-Alligator
2023-10-21 10:15:56 -04:00
parent bfec1912bd
commit 3d4bb32cbf
8 changed files with 19 additions and 36 deletions

View File

@ -405,7 +405,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE comment_filter " +
"(name TEXT NOT NULL PRIMARY KEY, max_vote INTEGER NOT NULL, min_vote INTEGER NOT NULL, exclude_strings TEXT)");
"(name TEXT NOT NULL PRIMARY KEY, max_vote INTEGER NOT NULL, min_vote INTEGER NOT NULL, exclude_strings TEXT, exclude_users TEXT)");
database.execSQL("CREATE TABLE comment_filter_usage (name TEXT NOT NULL, usage INTEGER NOT NULL, " +
"name_of_usage TEXT NOT NULL, PRIMARY KEY(name, usage, name_of_usage), FOREIGN KEY(name) REFERENCES comment_filter(name) ON DELETE CASCADE)");
}

View File

@ -94,7 +94,6 @@ public class CommentFilterUsageListingActivity extends BaseActivity {
public void newCommentFilterUsage(int type) {
switch (type) {
case CommentFilterUsage.SUBREDDIT_TYPE:
case CommentFilterUsage.USER_TYPE:
editAndCommentFilterUsageNameOfUsage(type, null);
break;
}
@ -119,10 +118,6 @@ public class CommentFilterUsageListingActivity extends BaseActivity {
case CommentFilterUsage.SUBREDDIT_TYPE:
textInputEditText.setHint(R.string.settings_tab_subreddit_name);
break;
case CommentFilterUsage.USER_TYPE:
textInputEditText.setHint(R.string.settings_tab_username);
titleStringId = R.string.user;
break;
}
Utils.showKeyboard(this, new Handler(), textInputEditText);

View File

@ -41,9 +41,6 @@ public class CommentFilterUsageEmbeddedRecyclerViewAdapter extends RecyclerView.
case CommentFilterUsage.SUBREDDIT_TYPE:
holder.textView.setText("r/" + commentFilterUsage.nameOfUsage);
break;
case CommentFilterUsage.USER_TYPE:
holder.textView.setText("u/" + commentFilterUsage.nameOfUsage);
break;
}
}
}

View File

@ -45,9 +45,6 @@ public class CommentFilterUsageRecyclerViewAdapter extends RecyclerView.Adapter<
case CommentFilterUsage.SUBREDDIT_TYPE:
((CommentFilterUsageRecyclerViewAdapter.CommentFilterUsageViewHolder) holder).usageTextView.setText(activity.getString(R.string.post_filter_usage_subreddit, commentFilterUsage.nameOfUsage));
break;
case CommentFilterUsage.USER_TYPE:
((CommentFilterUsageRecyclerViewAdapter.CommentFilterUsageViewHolder) holder).usageTextView.setText(activity.getString(R.string.post_filter_usage_user, commentFilterUsage.nameOfUsage));
break;
}
}

View File

@ -32,11 +32,6 @@ public class NewCommentFilterUsageBottomSheetFragment extends LandscapeExpandedR
dismiss();
});
binding.userTextViewNewCommentFilterUsageBottomSheetFragment.setOnClickListener(view -> {
activity.newCommentFilterUsage(CommentFilterUsage.USER_TYPE);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
}

View File

@ -23,6 +23,8 @@ public class CommentFilter implements Parcelable {
public int minVote = -1;
@ColumnInfo(name = "exclude_strings")
public String excludeStrings;
@ColumnInfo(name = "exclude_users")
public String excludeUsers;
public CommentFilter() {
@ -33,6 +35,7 @@ public class CommentFilter implements Parcelable {
maxVote = in.readInt();
minVote = in.readInt();
excludeStrings = in.readString();
excludeUsers = in.readString();
}
public static final Creator<CommentFilter> CREATOR = new Creator<CommentFilter>() {
@ -62,6 +65,14 @@ public class CommentFilter implements Parcelable {
}
}
}
if (commentFilter.excludeUsers != null && !commentFilter.excludeUsers.equals("")) {
String[] users = commentFilter.excludeUsers.split(",", 0);
for (String u : users) {
if (!u.trim().equals("") && comment.getAuthor().equalsIgnoreCase(u.trim())) {
return false;
}
}
}
return true;
}
@ -83,6 +94,12 @@ public class CommentFilter implements Parcelable {
stringBuilder.append(",").append(c.excludeStrings);
commentFilter.excludeStrings = stringBuilder.toString();
}
if (c.excludeUsers != null && !c.excludeUsers.equals("")) {
stringBuilder = new StringBuilder(commentFilter.excludeUsers == null ? "" : commentFilter.excludeUsers);
stringBuilder.append(",").append(c.excludeUsers);
commentFilter.excludeUsers = stringBuilder.toString();
}
}
return commentFilter;
@ -99,5 +116,6 @@ public class CommentFilter implements Parcelable {
dest.writeInt(maxVote);
dest.writeInt(minVote);
dest.writeString(excludeStrings);
dest.writeString(excludeUsers);
}
}

View File

@ -13,7 +13,6 @@ import androidx.room.ForeignKey;
childColumns = "name", onDelete = ForeignKey.CASCADE))
public class CommentFilterUsage implements Parcelable {
public static final int SUBREDDIT_TYPE = 1;
public static final int USER_TYPE = 2;
@NonNull
@ColumnInfo(name = "name")

View File

@ -29,24 +29,6 @@
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/user_text_view_new_comment_filter_usage_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/user"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
app:drawableStartCompat="@drawable/ic_user_24dp"
android:drawablePadding="48dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>