mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-16 19:50:53 +01:00
fixed activity name filter
This commit is contained in:
parent
c5c7b9f992
commit
f8a7e22063
@ -27,7 +27,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
@IntDef(value = {FilterScope.HOME, FilterScope.INTERACTIONS, FilterScope.MESSAGES,
|
||||
FilterScope.SEARCH_RESULTS, FilterScope.LIST_GROUP_TIMELINE, FilterScope.FAVORITES,
|
||||
FilterScope.USER_TIMELINE, FilterScope.PUBLIC_TIMELINE, FilterScope.UGC_TIMELINE,
|
||||
FilterScope.FLAG_MATCH_NAME, FilterScope.FLAG_MATCH_TEXT, FilterScope.FLAG_MATCH_DESCRIPTION,
|
||||
FilterScope.TARGET_NAME, FilterScope.TARGET_TEXT, FilterScope.TARGET_DESCRIPTION,
|
||||
FilterScope.ALL, FilterScope.DEFAULT}, flag = true)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface FilterScope {
|
||||
@ -42,20 +42,20 @@ public @interface FilterScope {
|
||||
|
||||
int UGC_TIMELINE = LIST_GROUP_TIMELINE | FAVORITES | USER_TIMELINE | PUBLIC_TIMELINE;
|
||||
|
||||
int FLAG_MATCH_NAME = 0x80000000;
|
||||
int FLAG_MATCH_TEXT = 0x40000000;
|
||||
int FLAG_MATCH_DESCRIPTION = 0x20000000;
|
||||
int TARGET_NAME = 0x80000000;
|
||||
int TARGET_TEXT = 0x40000000;
|
||||
int TARGET_DESCRIPTION = 0x20000000;
|
||||
|
||||
int MASK_FLAG = 0xFF000000;
|
||||
int MASK_TARGET = 0xFF000000;
|
||||
int MASK_SCOPE = 0x00FFFFFF;
|
||||
|
||||
int VALID_MASKS_USERS = MASK_SCOPE;
|
||||
int VALID_MASKS_KEYWORDS = MASK_SCOPE | MASK_FLAG;
|
||||
int VALID_MASKS_KEYWORDS = MASK_SCOPE | MASK_TARGET;
|
||||
int VALID_MASKS_SOURCES = MASK_SCOPE & ~MESSAGES;
|
||||
int VALID_MASKS_LINKS = MASK_SCOPE;
|
||||
|
||||
// Contains all flags
|
||||
int ALL = 0xFFFFFFFF;
|
||||
@SuppressWarnings("PointlessBitwiseExpression")
|
||||
int DEFAULT = ALL & ~(FLAG_MATCH_NAME | FLAG_MATCH_DESCRIPTION);
|
||||
int DEFAULT = ALL & ~(TARGET_NAME | TARGET_DESCRIPTION);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ import org.mariotaku.twidere.model.util.UserKeysConverter;
|
||||
import org.mariotaku.twidere.model.util.UserKeysCursorFieldConverter;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ParcelablePlease
|
||||
@JsonObject
|
||||
@CursorObject(valuesCreator = true, tableInfo = true)
|
||||
@ -136,6 +138,94 @@ public class ParcelableActivity extends ParcelableStatus implements Parcelable {
|
||||
ParcelableActivityParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ParcelableActivity{" +
|
||||
"action='" + action + '\'' +
|
||||
", max_sort_position=" + max_sort_position +
|
||||
", min_sort_position=" + min_sort_position +
|
||||
", max_position='" + max_position + '\'' +
|
||||
", min_position='" + min_position + '\'' +
|
||||
", source_keys=" + Arrays.toString(source_keys) +
|
||||
", _id=" + _id +
|
||||
", sources=" + Arrays.toString(sources) +
|
||||
", id='" + id + '\'' +
|
||||
", targets=" + targets +
|
||||
", account_key=" + account_key +
|
||||
", target_objects=" + target_objects +
|
||||
", sort_id=" + sort_id +
|
||||
", position_key=" + position_key +
|
||||
", sources_lite=" + Arrays.toString(sources_lite) +
|
||||
", timestamp=" + timestamp +
|
||||
", summary_line=" + Arrays.toString(summary_line) +
|
||||
", has_following_source=" + has_following_source +
|
||||
", user_key=" + user_key +
|
||||
", after_filtered_sources=" + Arrays.toString(after_filtered_sources) +
|
||||
", retweet_id='" + retweet_id + '\'' +
|
||||
", retweeted_by_user_key=" + retweeted_by_user_key +
|
||||
", retweet_timestamp=" + retweet_timestamp +
|
||||
", retweet_count=" + retweet_count +
|
||||
", favorite_count=" + favorite_count +
|
||||
", reply_count=" + reply_count +
|
||||
", in_reply_to_status_id='" + in_reply_to_status_id + '\'' +
|
||||
", in_reply_to_user_key=" + in_reply_to_user_key +
|
||||
", my_retweet_id='" + my_retweet_id + '\'' +
|
||||
", quoted_id='" + quoted_id + '\'' +
|
||||
", quoted_timestamp=" + quoted_timestamp +
|
||||
", quoted_user_key=" + quoted_user_key +
|
||||
", is_gap=" + is_gap +
|
||||
", is_retweet=" + is_retweet +
|
||||
", retweeted=" + retweeted +
|
||||
", is_favorite=" + is_favorite +
|
||||
", is_possibly_sensitive=" + is_possibly_sensitive +
|
||||
", user_is_following=" + user_is_following +
|
||||
", user_is_protected=" + user_is_protected +
|
||||
", user_is_verified=" + user_is_verified +
|
||||
", is_quote=" + is_quote +
|
||||
", quoted_user_is_protected=" + quoted_user_is_protected +
|
||||
", quoted_user_is_verified=" + quoted_user_is_verified +
|
||||
", retweeted_by_user_name='" + retweeted_by_user_name + '\'' +
|
||||
", retweeted_by_user_screen_name='" + retweeted_by_user_screen_name + '\'' +
|
||||
", retweeted_by_user_profile_image='" + retweeted_by_user_profile_image + '\'' +
|
||||
", text_plain='" + text_plain + '\'' +
|
||||
", lang='" + lang + '\'' +
|
||||
", user_name='" + user_name + '\'' +
|
||||
", user_screen_name='" + user_screen_name + '\'' +
|
||||
", in_reply_to_name='" + in_reply_to_name + '\'' +
|
||||
", in_reply_to_screen_name='" + in_reply_to_screen_name + '\'' +
|
||||
", source='" + source + '\'' +
|
||||
", user_profile_image_url='" + user_profile_image_url + '\'' +
|
||||
", text_unescaped='" + text_unescaped + '\'' +
|
||||
", card_name='" + card_name + '\'' +
|
||||
", quoted_text_plain='" + quoted_text_plain + '\'' +
|
||||
", quoted_text_unescaped='" + quoted_text_unescaped + '\'' +
|
||||
", quoted_source='" + quoted_source + '\'' +
|
||||
", quoted_user_name='" + quoted_user_name + '\'' +
|
||||
", quoted_user_screen_name='" + quoted_user_screen_name + '\'' +
|
||||
", quoted_user_profile_image='" + quoted_user_profile_image + '\'' +
|
||||
", location=" + location +
|
||||
", place_full_name='" + place_full_name + '\'' +
|
||||
", mentions=" + Arrays.toString(mentions) +
|
||||
", media=" + Arrays.toString(media) +
|
||||
", quoted_media=" + Arrays.toString(quoted_media) +
|
||||
", card=" + card +
|
||||
", extras=" + extras +
|
||||
", spans=" + Arrays.toString(spans) +
|
||||
", quoted_spans=" + Arrays.toString(quoted_spans) +
|
||||
", account_color=" + account_color +
|
||||
", inserted_date=" + inserted_date +
|
||||
", filter_flags=" + filter_flags +
|
||||
", filter_users=" + Arrays.toString(filter_users) +
|
||||
", filter_sources=" + Arrays.toString(filter_sources) +
|
||||
", filter_links=" + Arrays.toString(filter_links) +
|
||||
", filter_names=" + Arrays.toString(filter_names) +
|
||||
", filter_texts='" + filter_texts + '\'' +
|
||||
", filter_descriptions='" + filter_descriptions + '\'' +
|
||||
", is_pinned_status=" + is_pinned_status +
|
||||
", is_filtered=" + is_filtered +
|
||||
'}';
|
||||
}
|
||||
|
||||
@ParcelablePlease
|
||||
@JsonObject
|
||||
public static class SummaryLine implements Parcelable {
|
||||
|
@ -449,11 +449,17 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
|
||||
", extras=" + extras +
|
||||
", spans=" + Arrays.toString(spans) +
|
||||
", quoted_spans=" + Arrays.toString(quoted_spans) +
|
||||
", is_filtered=" + is_filtered +
|
||||
", account_color=" + account_color +
|
||||
", inserted_date=" + inserted_date +
|
||||
", is_pinned_status=" + is_pinned_status +
|
||||
", filter_flags=" + filter_flags +
|
||||
", filter_users=" + Arrays.toString(filter_users) +
|
||||
", filter_sources=" + Arrays.toString(filter_sources) +
|
||||
", filter_links=" + Arrays.toString(filter_links) +
|
||||
", filter_names=" + Arrays.toString(filter_names) +
|
||||
", filter_texts='" + filter_texts + '\'' +
|
||||
", filter_descriptions='" + filter_descriptions + '\'' +
|
||||
", is_pinned_status=" + is_pinned_status +
|
||||
", is_filtered=" + is_filtered +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -68,9 +68,9 @@ fun ParcelableActivity.prependTargetObjects(from: ParcelableActivity) {
|
||||
}
|
||||
|
||||
fun ParcelableActivity.updateActivityFilterInfo() {
|
||||
updateFilterInfo(sources?.flatMap {
|
||||
listOf(it.description_unescaped, it.location)
|
||||
}?.toTypedArray())
|
||||
updateFilterInfo(sources?.singleOrNull()?.let {
|
||||
listOf(it.description_unescaped, it.location, it.url_expanded)
|
||||
})
|
||||
}
|
||||
|
||||
inline val ParcelableActivity.RelatedObject.size
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.mariotaku.twidere.extension.model
|
||||
|
||||
import org.mariotaku.ktextension.addAllTo
|
||||
import org.mariotaku.ktextension.addTo
|
||||
import org.mariotaku.microblog.library.mastodon.annotation.StatusVisibility
|
||||
import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM
|
||||
import org.mariotaku.twidere.model.*
|
||||
@ -127,7 +126,7 @@ fun ParcelableStatus.addFilterFlag(@ParcelableStatus.FilterFlags flags: Long) {
|
||||
filter_flags = filter_flags or flags
|
||||
}
|
||||
|
||||
fun ParcelableStatus.updateFilterInfo(descriptions: Array<String?>?) {
|
||||
fun ParcelableStatus.updateFilterInfo(descriptions: Collection<String?>?) {
|
||||
val links = mutableSetOf<String>()
|
||||
spans?.mapNotNullTo(links) { span ->
|
||||
if (span.type != SpanItem.SpanType.LINK) return@mapNotNullTo null
|
||||
@ -139,31 +138,20 @@ fun ParcelableStatus.updateFilterInfo(descriptions: Array<String?>?) {
|
||||
}
|
||||
filter_links = links.toTypedArray()
|
||||
|
||||
val sources = mutableSetOf<String>()
|
||||
source?.let(HtmlEscapeHelper::toPlainText)?.addTo(sources)
|
||||
quoted_source?.let(HtmlEscapeHelper::toPlainText)?.addTo(sources)
|
||||
filter_sources = sources.toTypedArray()
|
||||
filter_sources = setOf(source?.plainText, quoted_source?.plainText).filterNotNull().toTypedArray()
|
||||
|
||||
val users = mutableSetOf<UserKey>()
|
||||
user_key.addTo(users)
|
||||
quoted_user_key?.addTo(users)
|
||||
retweeted_by_user_key?.addTo(users)
|
||||
filter_users = users.toTypedArray()
|
||||
filter_users = setOf(user_key, quoted_user_key, retweeted_by_user_key).filterNotNull().toTypedArray()
|
||||
|
||||
val names = mutableSetOf<String>()
|
||||
user_name.addTo(names)
|
||||
quoted_user_name?.addTo(names)
|
||||
retweeted_by_user_name?.addTo(names)
|
||||
filter_names = names.toTypedArray()
|
||||
filter_names = setOf(user_name, quoted_user_name, retweeted_by_user_name).filterNotNull().toTypedArray()
|
||||
|
||||
val texts = StringBuilder()
|
||||
text_unescaped?.appendNewLineTo(texts)
|
||||
quoted_text_unescaped?.appendNewLineTo(texts)
|
||||
texts.appendNonEmptyLine(text_unescaped)
|
||||
texts.appendNonEmptyLine(quoted_text_unescaped)
|
||||
media?.forEach { item ->
|
||||
item.alt_text?.appendNewLineTo(texts)
|
||||
texts.appendNonEmptyLine(item.alt_text)
|
||||
}
|
||||
quoted_media?.forEach { item ->
|
||||
item.alt_text?.appendNewLineTo(texts)
|
||||
texts.appendNonEmptyLine(item.alt_text)
|
||||
}
|
||||
filter_texts = texts.toString()
|
||||
|
||||
@ -200,7 +188,10 @@ private fun parcelableUserMention(key: UserKey, name: String, screenName: String
|
||||
it.screen_name = screenName
|
||||
}
|
||||
|
||||
private fun CharSequence.appendNewLineTo(sb: StringBuilder) {
|
||||
sb.append(this)
|
||||
sb.append('\n')
|
||||
}
|
||||
private fun StringBuilder.appendNonEmptyLine(line: CharSequence?) {
|
||||
if (line.isNullOrEmpty()) return
|
||||
append(line)
|
||||
append('\n')
|
||||
}
|
||||
|
||||
private val String.plainText: String get() = HtmlEscapeHelper.toPlainText(this)
|
@ -201,9 +201,10 @@ fun Status.applyTo(accountKey: UserKey, accountType: String, profileImageSize: S
|
||||
result.addFilterFlag(ParcelableStatus.FilterFlags.HAS_MEDIA)
|
||||
}
|
||||
|
||||
result.updateFilterInfo(arrayOf(userDescriptionUnescaped, retweetedStatus?.userDescriptionUnescaped,
|
||||
result.updateFilterInfo(setOf(userDescriptionUnescaped, retweetedStatus?.userDescriptionUnescaped,
|
||||
quotedStatus?.userDescriptionUnescaped, this.user.location, retweetedStatus?.user?.location,
|
||||
quotedStatus?.user?.location))
|
||||
quotedStatus?.user?.location, userUrlExpanded, retweetedStatus?.userUrlExpanded,
|
||||
quotedStatus?.userUrlExpanded))
|
||||
}
|
||||
|
||||
|
||||
@ -274,6 +275,9 @@ private fun String.twitterUnescaped(): String {
|
||||
private val Status.userDescriptionUnescaped: String?
|
||||
get() = user?.let { InternalTwitterContentUtils.formatUserDescription(it)?.first }
|
||||
|
||||
private val Status.userUrlExpanded: String?
|
||||
get() = user?.urlEntities?.firstOrNull()?.expandedUrl
|
||||
|
||||
/**
|
||||
* @param spans Ordered spans
|
||||
* *
|
||||
|
@ -125,7 +125,8 @@ fun Status.applyTo(accountKey: UserKey, result: ParcelableStatus) {
|
||||
|
||||
result.extras = extras
|
||||
|
||||
result.updateFilterInfo(arrayOf(accountDescriptionUnescaped, reblog?.accountDescriptionUnescaped))
|
||||
result.updateFilterInfo(setOf(accountDescriptionUnescaped, reblog?.accountDescriptionUnescaped,
|
||||
accountUrl, reblog?.accountUrl))
|
||||
}
|
||||
|
||||
private fun calculateDisplayTextRange(text: String, spans: Array<SpanItem>?, media: Array<ParcelableMedia>?): IntArray? {
|
||||
@ -145,6 +146,9 @@ private val Status.accountDescriptionUnescaped: String?
|
||||
}
|
||||
}
|
||||
|
||||
private val Status.accountUrl: String?
|
||||
get() = account?.url
|
||||
|
||||
object MastodonSpanProcessor : HtmlSpanBuilder.SpanProcessor {
|
||||
|
||||
override fun appendText(text: Editable, buffer: CharArray, start: Int, len: Int,
|
||||
|
@ -138,7 +138,10 @@ fun Activity.toParcelable(accountKey: UserKey, accountType: String, isGap: Boole
|
||||
}
|
||||
}
|
||||
}
|
||||
result.user_key = result.sources?.singleOrNull()?.key ?: UserKey("multiple", null)
|
||||
val singleSource = result.sources?.singleOrNull()
|
||||
result.user_key = singleSource?.key ?: UserKey("multiple", null)
|
||||
result.user_name = singleSource?.name
|
||||
result.user_screen_name = singleSource?.screen_name
|
||||
} else {
|
||||
status.applyTo(accountKey, accountType, profileImageSize, result)
|
||||
result.summary_line = arrayOf(result.toSummaryLine())
|
||||
|
@ -190,9 +190,9 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene
|
||||
}
|
||||
|
||||
private fun Dialog.saveScopes(scopes: FilterScopes) {
|
||||
targetText.saveScope(scopes, FilterScope.FLAG_MATCH_TEXT)
|
||||
targetName.saveScope(scopes, FilterScope.FLAG_MATCH_NAME)
|
||||
targetDescription.saveScope(scopes, FilterScope.FLAG_MATCH_DESCRIPTION)
|
||||
targetText.saveScope(scopes, FilterScope.TARGET_TEXT)
|
||||
targetName.saveScope(scopes, FilterScope.TARGET_NAME)
|
||||
targetDescription.saveScope(scopes, FilterScope.TARGET_DESCRIPTION)
|
||||
scopeHome.saveScope(scopes, FilterScope.HOME)
|
||||
scopeInteractions.saveScope(scopes, FilterScope.INTERACTIONS)
|
||||
scopeMessages.saveScope(scopes, FilterScope.MESSAGES)
|
||||
@ -201,9 +201,12 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene
|
||||
}
|
||||
|
||||
private fun Dialog.loadScopes(scopes: FilterScopes) {
|
||||
targetText.loadScope(scopes, FilterScope.FLAG_MATCH_TEXT)
|
||||
targetName.loadScope(scopes, FilterScope.FLAG_MATCH_NAME)
|
||||
targetDescription.loadScope(scopes, FilterScope.FLAG_MATCH_DESCRIPTION)
|
||||
labelTarget.setVisible(scopes.hasMask(FilterScope.MASK_TARGET))
|
||||
targetText.loadScope(scopes, FilterScope.TARGET_TEXT)
|
||||
targetName.loadScope(scopes, FilterScope.TARGET_NAME)
|
||||
targetDescription.loadScope(scopes, FilterScope.TARGET_DESCRIPTION)
|
||||
|
||||
labelScope.setVisible(scopes.hasMask(FilterScope.MASK_SCOPE))
|
||||
scopeHome.loadScope(scopes, FilterScope.HOME)
|
||||
scopeInteractions.loadScope(scopes, FilterScope.INTERACTIONS)
|
||||
scopeMessages.loadScope(scopes, FilterScope.MESSAGES)
|
||||
@ -267,6 +270,8 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene
|
||||
return 0
|
||||
}
|
||||
|
||||
fun hasMask(mask: Int): Boolean = masks and mask != 0
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<FilterScopes> {
|
||||
override fun createFromParcel(parcel: Parcel): FilterScopes {
|
||||
return FilterScopes(parcel)
|
||||
|
@ -486,19 +486,19 @@ object DataStoreUtils {
|
||||
val filteredTextKeywordsWhere = Expression.or(
|
||||
Expression.and(
|
||||
Expression.or(
|
||||
Expression.equals("${Filters.Keywords.TABLE_NAME}.${Filters.Keywords.SCOPE} & ${FilterScope.MASK_FLAG}", 0),
|
||||
Expression.notEquals("${Filters.Keywords.TABLE_NAME}.${Filters.Keywords.SCOPE} & ${FilterScope.FLAG_MATCH_TEXT}", 0)
|
||||
Expression.equals("${Filters.Keywords.TABLE_NAME}.${Filters.Keywords.SCOPE} & ${FilterScope.MASK_TARGET}", 0),
|
||||
Expression.notEquals("${Filters.Keywords.TABLE_NAME}.${Filters.Keywords.SCOPE} & ${FilterScope.TARGET_TEXT}", 0)
|
||||
),
|
||||
ScopeMatchesExpression(Filters.Keywords.TABLE_NAME, Filters.Keywords.SCOPE),
|
||||
ContainsExpression(Statuses.FILTER_TEXTS, Filters.Keywords.TABLE_NAME, Filters.Keywords.VALUE)
|
||||
),
|
||||
Expression.and(
|
||||
Expression.notEquals("${Filters.Keywords.TABLE_NAME}.${Filters.Keywords.SCOPE} & ${FilterScope.FLAG_MATCH_NAME}", 0),
|
||||
Expression.notEquals("${Filters.Keywords.TABLE_NAME}.${Filters.Keywords.SCOPE} & ${FilterScope.TARGET_NAME}", 0),
|
||||
ScopeMatchesExpression(Filters.Keywords.TABLE_NAME, Filters.Keywords.SCOPE),
|
||||
ContainsExpression(Statuses.FILTER_NAMES, Filters.Keywords.TABLE_NAME, Filters.Keywords.VALUE)
|
||||
),
|
||||
Expression.and(
|
||||
Expression.notEquals("${Filters.Keywords.TABLE_NAME}.${Filters.Keywords.SCOPE} & ${FilterScope.FLAG_MATCH_DESCRIPTION}", 0),
|
||||
Expression.notEquals("${Filters.Keywords.TABLE_NAME}.${Filters.Keywords.SCOPE} & ${FilterScope.TARGET_DESCRIPTION}", 0),
|
||||
ScopeMatchesExpression(Filters.Keywords.TABLE_NAME, Filters.Keywords.SCOPE),
|
||||
ContainsExpression(Statuses.FILTER_DESCRIPTIONS, Filters.Keywords.TABLE_NAME, Filters.Keywords.VALUE)
|
||||
)
|
||||
|
@ -72,6 +72,7 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/labelTarget"
|
||||
style="?android:listSeparatorTextViewStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -102,6 +103,7 @@
|
||||
android:text="@string/label_filter_target_description"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/labelScope"
|
||||
style="?android:listSeparatorTextViewStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
Loading…
x
Reference in New Issue
Block a user