From 5066f3650626f7695046cbbd93c2a341eaeff28d Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Thu, 14 Sep 2017 23:38:31 +0800 Subject: [PATCH] supported filters for description --- build.gradle | 1 - .../twidere/annotation/FilterScope.java | 8 +- .../twidere/model/ParcelableStatus.java | 3 + .../twidere/provider/TwidereDataStore.java | 1 + twidere/build.gradle | 1 - twidere/src/.google.commit-id | 2 +- .../java/org/mariotaku/twidere/Constants.java | 2 +- .../extension/ContentResolverExtensions.kt | 31 +++- .../model/ParcelableActivityExtensions.kt | 26 ++- .../model/ParcelableStatusExtensions.kt | 4 +- .../extension/model/api/StatusExtensions.kt | 54 +++--- .../api/mastodon/NotificationExtensions.kt | 3 + .../model/api/mastodon/StatusExtensions.kt | 15 ++ .../model/api/microblog/ActivityExtensions.kt | 4 +- .../fragment/CursorActivitiesFragment.kt | 4 +- .../fragment/CursorStatusesFragment.kt | 3 +- .../fragment/filter/AddEditItemFragment.kt | 50 +++-- .../fragment/filter/BaseFiltersFragment.kt | 3 +- .../twidere/provider/TwidereDataProvider.kt | 3 +- .../mariotaku/twidere/util/DataStoreUtils.kt | 5 + .../res/layout/dialog_filter_rule_editor.xml | 173 ++++++++++++------ twidere/src/main/res/values/strings.xml | 2 + 22 files changed, 277 insertions(+), 121 deletions(-) diff --git a/build.gradle b/build.gradle index ed237ae24..46b7100bf 100644 --- a/build.gradle +++ b/build.gradle @@ -79,7 +79,6 @@ subprojects { ACRA : '4.9.2', AbstractTask : '0.9.5', Dagger : '2.11', - ExpandableLayout : '1.6.0', ] } diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/FilterScope.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/FilterScope.java index c637b5582..fc0168c20 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/FilterScope.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/FilterScope.java @@ -26,8 +26,9 @@ 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.ALL, - FilterScope.FLAG_MATCH_NAME, FilterScope.FLAG_MATCH_TEXT, FilterScope.UGC_TIMELINE}, flag = true) + FilterScope.USER_TIMELINE, FilterScope.PUBLIC_TIMELINE, FilterScope.UGC_TIMELINE, + FilterScope.FLAG_MATCH_NAME, FilterScope.FLAG_MATCH_TEXT, FilterScope.FLAG_MATCH_DESCRIPTION, + FilterScope.ALL, FilterScope.DEFAULT}, flag = true) @Retention(RetentionPolicy.SOURCE) public @interface FilterScope { int HOME = 0x1; @@ -43,6 +44,7 @@ public @interface FilterScope { int FLAG_MATCH_NAME = 0x80000000; int FLAG_MATCH_TEXT = 0x40000000; + int FLAG_MATCH_DESCRIPTION = 0x20000000; int MASK_FLAG = 0xFF000000; int MASK_SCOPE = 0x00FFFFFF; @@ -54,4 +56,6 @@ public @interface FilterScope { // Contains all flags int ALL = 0xFFFFFFFF; + @SuppressWarnings("PointlessBitwiseExpression") + int DEFAULT = ALL & ~FLAG_MATCH_NAME; } diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java index f4655a483..11d2c2dd7 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java @@ -345,6 +345,9 @@ public class ParcelableStatus implements Parcelable, Comparable? = null, + selection: String? = null, selectionArgs: Array? = null, sortOrder: String? = null, + limit: String? = null): Cursor { + return if (limit != null) { + query(uri.buildUpon().appendQueryParameter(QUERY_PARAM_LIMIT, limit.toString()).build(), + projection, selection, selectionArgs, sortOrder) + } else { + query(uri, projection, selection, selectionArgs, sortOrder) + } +} + fun ContentResolver.queryReference(uri: Uri, projection: Array? = null, - selection: String? = null, selectionArgs: Array? = null, sortOrder: String? = null) = - CursorReference(query(uri, projection, selection, selectionArgs, sortOrder)) + selection: String? = null, selectionArgs: Array? = null, sortOrder: String? = null, + limit: String? = null): CursorReference { + return CursorReference(query(uri, projection, selection, selectionArgs, sortOrder, limit)) +} @SuppressLint("Recycle") fun ContentResolver.rawQuery(sql: String, selectionArgs: Array?, notifyUri: Uri? = null): Cursor? { @@ -41,9 +55,10 @@ fun ContentResolver.rawQuery(sql: String, selectionArgs: Array?, notifyU return query(rawUri, null, null, selectionArgs, null) } + fun ContentResolver.queryOne(uri: Uri, projection: Array?, selection: String?, selectionArgs: Array?, sortOrder: String? = null, cls: Class): T? { - return queryReference(uri, projection, selection, selectionArgs, sortOrder).use { (cur) -> + return queryReference(uri, projection, selection, selectionArgs, sortOrder, "1").use { (cur) -> if (!cur.moveToFirst()) return@use null val indices = ObjectCursor.indicesFrom(cur, cls) return@use indices.newObject(cur) @@ -67,6 +82,16 @@ fun ContentResolver.queryCount(uri: Uri, selection: String?, selectionArgs: Arra } } +fun ContentResolver.queryLong(uri: Uri, field: String, selection: String?, selectionArgs: Array?, def: Long = -1): Long { + val projection = arrayOf(field) + return queryReference(uri, projection, selection, selectionArgs, null, "1").use { (cur) -> + if (cur.moveToFirst()) { + return@use cur.getLong(0) + } + return@use def + } +} + fun ContentResolver.insert(uri: Uri, obj: T, cls: Class = obj.javaClass): Uri? { return this.insert(uri, ObjectCursor.valuesCreatorFrom(cls).create(obj)) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableActivityExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableActivityExtensions.kt index 1eddace20..588c38c4c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableActivityExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableActivityExtensions.kt @@ -30,10 +30,11 @@ val ParcelableActivity.activityStatus: ParcelableActivity? else -> null } -val ParcelableActivity.reachedCountLimit: Boolean get() { - return sources.reachedCountLimit() || targets.reachedCountLimit() || - target_objects.reachedCountLimit() -} +val ParcelableActivity.reachedCountLimit: Boolean + get() { + return sources.reachedCountLimit() || targets.reachedCountLimit() || + target_objects.reachedCountLimit() + } fun ParcelableActivity.isSameSources(another: ParcelableActivity): Boolean { return Arrays.equals(sources, another.sources) @@ -66,13 +67,20 @@ fun ParcelableActivity.prependTargetObjects(from: ParcelableActivity) { .prepend(from.target_objects) } -inline val ParcelableActivity.RelatedObject.size get() = when { - statuses != null -> statuses.size - users != null -> users.size - user_lists != null -> user_lists.size - else -> 0 +fun ParcelableActivity.updateActivityFilterInfo() { + updateFilterInfo(sources?.flatMap { + listOf(it.description_unescaped, it.location) + }?.toTypedArray()) } +inline val ParcelableActivity.RelatedObject.size + get() = when { + statuses != null -> statuses.size + users != null -> users.size + user_lists != null -> user_lists.size + else -> 0 + } + fun ParcelableActivity.RelatedObject?.isNullOrEmpty(): Boolean { if (this == null) return true return size == 0 diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableStatusExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableStatusExtensions.kt index 185c917ac..13857f69b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableStatusExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableStatusExtensions.kt @@ -127,7 +127,7 @@ fun ParcelableStatus.addFilterFlag(@ParcelableStatus.FilterFlags flags: Long) { filter_flags = filter_flags or flags } -fun ParcelableStatus.updateFilterInfo() { +fun ParcelableStatus.updateFilterInfo(descriptions: Array?) { val links = mutableSetOf() spans?.mapNotNullTo(links) { span -> if (span.type != SpanItem.SpanType.LINK) return@mapNotNullTo null @@ -166,6 +166,8 @@ fun ParcelableStatus.updateFilterInfo() { item.alt_text?.appendNewLineTo(texts) } filter_texts = texts.toString() + + filter_descriptions = descriptions?.filterNotNull()?.joinToString("\n") } fun ParcelableStatus.updateExtraInformation(details: AccountDetails) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/StatusExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/StatusExtensions.kt index 6b38da753..49dde4a36 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/StatusExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/StatusExtensions.kt @@ -42,6 +42,7 @@ import org.mariotaku.twidere.text.AcctMentionSpan import org.mariotaku.twidere.text.HashtagSpan import org.mariotaku.twidere.util.HtmlBuilder import org.mariotaku.twidere.util.HtmlSpanBuilder +import org.mariotaku.twidere.util.InternalTwitterContentUtils import org.mariotaku.twidere.util.InternalTwitterContentUtils.getMediaUrl import org.mariotaku.twidere.util.InternalTwitterContentUtils.getStartEndForEntity @@ -200,7 +201,9 @@ fun Status.applyTo(accountKey: UserKey, accountType: String, profileImageSize: S result.addFilterFlag(ParcelableStatus.FilterFlags.HAS_MEDIA) } - result.updateFilterInfo() + result.updateFilterInfo(arrayOf(userDescriptionUnescaped, retweetedStatus?.userDescriptionUnescaped, + quotedStatus?.userDescriptionUnescaped, this.user.location, retweetedStatus?.user?.location, + quotedStatus?.user?.location)) } @@ -268,6 +271,9 @@ private fun String.twitterUnescaped(): String { return twitterRawTextTranslator.translate(this) } +private val Status.userDescriptionUnescaped: String? + get() = user?.let { InternalTwitterContentUtils.formatUserDescription(it)?.first } + /** * @param spans Ordered spans * * @@ -279,35 +285,39 @@ internal fun findByOrigRange(spans: Array, start: Int, end: Int): List return spans.filter { it.orig_start >= start && it.orig_end <= end } } -internal inline val CharSequence.spanItems get() = (this as? Spanned)?.let { text -> - text.getSpans(0, length, URLSpan::class.java).mapToArray { - val item = it.toSpanItem(text) - when (it) { - is AcctMentionSpan -> item.type = SpanItem.SpanType.ACCT_MENTION - is HashtagSpan -> item.type = SpanItem.SpanType.HASHTAG +internal inline val CharSequence.spanItems + get() = (this as? Spanned)?.let { text -> + text.getSpans(0, length, URLSpan::class.java).mapToArray { + val item = it.toSpanItem(text) + when (it) { + is AcctMentionSpan -> item.type = SpanItem.SpanType.ACCT_MENTION + is HashtagSpan -> item.type = SpanItem.SpanType.HASHTAG + } + return@mapToArray item } - return@mapToArray item } -} internal inline val String.isHtml get() = contains('<') && contains('>') -private inline val Status.inReplyToName get() = userMentionEntities?.firstOrNull { - inReplyToUserId == it.id -}?.name ?: attentions?.firstOrNull { - inReplyToUserId == it.id -}?.fullName ?: inReplyToScreenName +private inline val Status.inReplyToName + get() = userMentionEntities?.firstOrNull { + inReplyToUserId == it.id + }?.name ?: attentions?.firstOrNull { + inReplyToUserId == it.id + }?.fullName ?: inReplyToScreenName -private inline val Status.placeFullName get() = place?.fullName ?: location?.takeIf { - ParcelableLocation.valueOf(location) == null -} - -private inline val Status.inferredExternalUrl get() = externalUrl ?: uri?.let { uri -> - noticeUriRegex.matchEntire(uri)?.let { result: MatchResult -> - "https://${result.groups[1]?.value}/notice/${result.groups[3]?.value}" +private inline val Status.placeFullName + get() = place?.fullName ?: location?.takeIf { + ParcelableLocation.valueOf(location) == null + } + +private inline val Status.inferredExternalUrl + get() = externalUrl ?: uri?.let { uri -> + noticeUriRegex.matchEntire(uri)?.let { result: MatchResult -> + "https://${result.groups[1]?.value}/notice/${result.groups[3]?.value}" + } } -} private val Status.parcelableLocation: ParcelableLocation? get() { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/NotificationExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/NotificationExtensions.kt index e7ca61f9e..2aabd9cad 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/NotificationExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/NotificationExtensions.kt @@ -25,6 +25,7 @@ import org.mariotaku.microblog.library.mastodon.model.Relationship import org.mariotaku.microblog.library.twitter.model.Activity import org.mariotaku.twidere.extension.model.toLite import org.mariotaku.twidere.extension.model.toSummaryLine +import org.mariotaku.twidere.extension.model.updateActivityFilterInfo import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableActivity import org.mariotaku.twidere.model.ParcelableUser @@ -92,6 +93,8 @@ fun Notification.toParcelable(accountKey: UserKey, relationships: Map?, media: Array?): IntArray? { @@ -130,6 +135,16 @@ private fun calculateDisplayTextRange(text: String, spans: Array?, med return intArrayOf(0, lastMatch.start) } +private val Status.accountDescriptionUnescaped: String? + get() { + val note = account?.note ?: return null + return if (note.isHtml) { + HtmlSpanBuilder.fromHtml(note, note, MastodonSpanProcessor).toString() + } else { + HtmlEscapeHelper.unescape(note) + } + } + object MastodonSpanProcessor : HtmlSpanBuilder.SpanProcessor { override fun appendText(text: Editable, buffer: CharArray, start: Int, len: Int, diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/ActivityExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/ActivityExtensions.kt index 92c9ab169..37447c895 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/ActivityExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/ActivityExtensions.kt @@ -27,7 +27,7 @@ import org.mariotaku.twidere.extension.model.api.applyTo import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.toLite import org.mariotaku.twidere.extension.model.toSummaryLine -import org.mariotaku.twidere.extension.model.updateFilterInfo +import org.mariotaku.twidere.extension.model.updateActivityFilterInfo import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableActivity import org.mariotaku.twidere.model.ParcelableUserList @@ -152,7 +152,7 @@ fun Activity.toParcelable(accountKey: UserKey, accountType: String, isGap: Boole } ?: false result.is_gap = isGap - result.updateFilterInfo() + result.updateActivityFilterInfo() return result } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorActivitiesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorActivitiesFragment.kt index d995ceddb..951fcade0 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorActivitiesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorActivitiesFragment.kt @@ -44,6 +44,7 @@ import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.event.* import org.mariotaku.twidere.model.pagination.SinceMaxPagination +import org.mariotaku.twidere.provider.TwidereDataStore import org.mariotaku.twidere.provider.TwidereDataStore.Activities import org.mariotaku.twidere.provider.TwidereDataStore.Filters import org.mariotaku.twidere.task.twitter.GetStatusesTask @@ -354,7 +355,8 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() { val activityColumnsLite = Activities.COLUMNS - arrayOf(Activities.SOURCES, Activities.TARGETS, Activities.TARGET_OBJECTS, Activities.MENTIONS_JSON, Activities.CARD, Activities.FILTER_FLAGS, Activities.FILTER_USERS, Activities.FILTER_LINKS, - Activities.FILTER_SOURCES, Activities.FILTER_NAMES, Activities.FILTER_TEXTS) + Activities.FILTER_SOURCES, Activities.FILTER_NAMES, Activities.FILTER_TEXTS, + Activities.FILTER_DESCRIPTIONS) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt index ed5584154..da3a7e750 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt @@ -319,6 +319,7 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() { companion object { private val statusColumnsLite = Statuses.COLUMNS - arrayOf(Statuses.MENTIONS_JSON, Statuses.CARD, Statuses.FILTER_FLAGS, Statuses.FILTER_USERS, Statuses.FILTER_LINKS, - Statuses.FILTER_SOURCES, Statuses.FILTER_NAMES, Statuses.FILTER_TEXTS) + Statuses.FILTER_SOURCES, Statuses.FILTER_NAMES, Statuses.FILTER_TEXTS, + Statuses.FILTER_DESCRIPTIONS) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/AddEditItemFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/AddEditItemFragment.kt index 889757fd3..fcd0d1e42 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/AddEditItemFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/AddEditItemFragment.kt @@ -28,6 +28,7 @@ import android.os.Parcel import android.os.Parcelable import android.support.v7.app.AlertDialog import android.view.View +import android.view.WindowManager import android.widget.CheckBox import android.widget.Toast import kotlinx.android.synthetic.main.dialog_filter_rule_editor.* @@ -43,7 +44,8 @@ import org.mariotaku.twidere.annotation.FilterScope import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.extension.applyOnShow import org.mariotaku.twidere.extension.applyTheme -import org.mariotaku.twidere.extension.queryCount +import org.mariotaku.twidere.extension.queryLong +import org.mariotaku.twidere.extension.setVisible import org.mariotaku.twidere.fragment.BaseDialogFragment import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.provider.TwidereDataStore.Filters @@ -60,7 +62,7 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene get() = arguments.getString(EXTRA_VALUE) private val defaultScope: FilterScopes - get() = FilterScopes(filterMasks, arguments.getInt(EXTRA_SCOPE, filterMasks)) + get() = FilterScopes(filterMasks, arguments.getInt(EXTRA_SCOPE, FilterScope.DEFAULT)) private val filterMasks: Int get() = when (contentUri) { @@ -78,11 +80,18 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene } private var Dialog.scope: FilterScopes? - get() = defaultScope.also { applyScopes(it) } + get() = defaultScope.also { saveScopes(it) } set(value) { loadScopes(value ?: defaultScope) } + private var Dialog.advancedExpanded: Boolean + get() = advancedContainer.visibility == View.VISIBLE + set(value) { + advancedContainer.setVisible(value) + advancedCollapseIndicator.rotation = if (value) 90f else 0f + } + override fun onClick(dialog: DialogInterface, which: Int) { dialog as AlertDialog when (which) { @@ -100,12 +109,14 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene if (id >= 0) { val valueWhere = Expression.equalsArgs(Filters.VALUE).sql val valueWhereArgs = arrayOf(value) - if (resolver.queryCount(uri, valueWhere, valueWhereArgs) == 0) { - val idWhere = Expression.equals(Filters._ID, id).sql - resolver.update(uri, values, idWhere, null) - } else { + val matchedId = resolver.queryLong(uri, Filters._ID, valueWhere, valueWhereArgs, + -1) + if (matchedId != -1L && matchedId != id) { Toast.makeText(context, R.string.message_toast_duplicate_filter_rule, Toast.LENGTH_SHORT).show() + } else { + val idWhere = Expression.equals(Filters._ID, id).sql + resolver.update(uri, values, idWhere, null) } } else { resolver.insert(uri, values) @@ -129,6 +140,7 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene val dialog = builder.create() dialog.applyOnShow { applyTheme() + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) editText.setAdapter(when (contentUri) { Filters.Sources.CONTENT_URI -> SourceAutoCompleteAdapter(activity) Filters.Users.CONTENT_URI -> ComposeAutoCompleteAdapter(activity, requestManager).apply { @@ -138,6 +150,10 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene else -> null }) editText.threshold = 1 + advancedToggle.setOnClickListener { + advancedExpanded = !advancedExpanded + } + advancedExpanded = false if (savedInstanceState == null) { value = defaultValue @@ -156,19 +172,21 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene outState.putParcelable(EXTRA_SCOPE, dialog.scope) } - private fun Dialog.applyScopes(scopes: FilterScopes) { - targetText.applyScope(scopes, FilterScope.FLAG_MATCH_TEXT) - targetName.applyScope(scopes, FilterScope.FLAG_MATCH_NAME) - scopeHome.applyScope(scopes, FilterScope.HOME) - scopeInteractions.applyScope(scopes, FilterScope.INTERACTIONS) - scopeMessages.applyScope(scopes, FilterScope.MESSAGES) - scopeSearchResults.applyScope(scopes, FilterScope.SEARCH_RESULTS) - scopeOther.applyScope(scopes, FilterScope.UGC_TIMELINE) + 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) + scopeHome.saveScope(scopes, FilterScope.HOME) + scopeInteractions.saveScope(scopes, FilterScope.INTERACTIONS) + scopeMessages.saveScope(scopes, FilterScope.MESSAGES) + scopeSearchResults.saveScope(scopes, FilterScope.SEARCH_RESULTS) + scopeOther.saveScope(scopes, FilterScope.UGC_TIMELINE) } 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) scopeHome.loadScope(scopes, FilterScope.HOME) scopeInteractions.loadScope(scopes, FilterScope.INTERACTIONS) scopeMessages.loadScope(scopes, FilterScope.MESSAGES) @@ -176,7 +194,7 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene scopeOther.loadScope(scopes, FilterScope.UGC_TIMELINE) } - private fun CheckBox.applyScope(scopes: FilterScopes, scope: Int) { + private fun CheckBox.saveScope(scopes: FilterScopes, scope: Int) { if (!isEnabled || visibility != View.VISIBLE) return scopes[scope] = isChecked } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/BaseFiltersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/BaseFiltersFragment.kt index 99290604d..5647a5521 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/BaseFiltersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/BaseFiltersFragment.kt @@ -47,6 +47,7 @@ import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.* import org.mariotaku.twidere.activity.iface.IControlBarActivity +import org.mariotaku.twidere.annotation.FilterScope import org.mariotaku.twidere.extension.invertSelection import org.mariotaku.twidere.extension.selectAll import org.mariotaku.twidere.extension.selectNone @@ -222,7 +223,7 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment. --> - - + android:layout_height="wrap_content"> - + android:orientation="vertical" + android:padding="8dp"> - + - + - + - + + - + - + - + - + - - \ No newline at end of file + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index a917cc18d..90cc90c71 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -500,6 +500,7 @@ Account Account type + Advanced Auth type Background operation service Buffer accounts @@ -523,6 +524,7 @@ Messages Other Search results + Description Name Text Subscription