added 'filter unavailable status'

This commit is contained in:
Mariotaku Lee 2016-12-24 22:05:15 +08:00
parent e70056dd13
commit 24e5781b8c
7 changed files with 37 additions and 21 deletions

View File

@ -1193,7 +1193,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
for (final AccountPreferences pref : prefs) { for (final AccountPreferences pref : prefs) {
if (!pref.isHomeTimelineNotificationEnabled()) continue; if (!pref.isHomeTimelineNotificationEnabled()) continue;
final long positionTag = getPositionTag(CustomTabType.HOME_TIMELINE, pref.getAccountKey()); final long positionTag = getPositionTag(CustomTabType.HOME_TIMELINE, pref.getAccountKey());
showTimelineNotification(pref, positionTag); showTimelineNotification(mPreferences, pref, positionTag);
} }
notifyUnreadCountChanged(NOTIFICATION_ID_HOME_TIMELINE); notifyUnreadCountChanged(NOTIFICATION_ID_HOME_TIMELINE);
} }
@ -1241,7 +1241,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
return mReadStateManager.getPosition(tag); return mReadStateManager.getPosition(tag);
} }
private void showTimelineNotification(AccountPreferences pref, long position) { private void showTimelineNotification(SharedPreferences preferences, AccountPreferences pref, long position) {
final UserKey accountKey = pref.getAccountKey(); final UserKey accountKey = pref.getAccountKey();
final Context context = getContext(); final Context context = getContext();
if (context == null) return; if (context == null) return;
@ -1249,8 +1249,8 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
final NotificationManagerWrapper nm = mNotificationManager; final NotificationManagerWrapper nm = mNotificationManager;
final Expression selection = Expression.and(Expression.equalsArgs(Statuses.ACCOUNT_KEY), final Expression selection = Expression.and(Expression.equalsArgs(Statuses.ACCOUNT_KEY),
Expression.greaterThan(Statuses.POSITION_KEY, position)); Expression.greaterThan(Statuses.POSITION_KEY, position));
final String filteredSelection = DataStoreUtils.buildStatusFilterWhereClause(Statuses.TABLE_NAME, final String filteredSelection = DataStoreUtils.buildStatusFilterWhereClause(preferences,
selection).getSQL(); Statuses.TABLE_NAME, selection).getSQL();
final String[] selectionArgs = {accountKey.toString()}; final String[] selectionArgs = {accountKey.toString()};
final String[] userProjection = {Statuses.USER_KEY, Statuses.USER_NAME, Statuses.USER_SCREEN_NAME}; final String[] userProjection = {Statuses.USER_KEY, Statuses.USER_NAME, Statuses.USER_SCREEN_NAME};
final String[] statusProjection = {Statuses.STATUS_ID}; final String[] statusProjection = {Statuses.STATUS_ID};

View File

@ -24,6 +24,7 @@ import android.accounts.AccountManager;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.UriMatcher; import android.content.UriMatcher;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
@ -41,6 +42,7 @@ import com.bluelinelabs.logansquare.LoganSquare;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.mariotaku.kpreferences.SharedPreferencesExtensionsKt;
import org.mariotaku.microblog.library.twitter.model.Activity; import org.mariotaku.microblog.library.twitter.model.Activity;
import org.mariotaku.sqliteqb.library.ArgsArray; import org.mariotaku.sqliteqb.library.ArgsArray;
import org.mariotaku.sqliteqb.library.Columns; import org.mariotaku.sqliteqb.library.Columns;
@ -54,6 +56,7 @@ import org.mariotaku.sqliteqb.library.Tables;
import org.mariotaku.sqliteqb.library.query.SQLSelectQuery; import org.mariotaku.sqliteqb.library.query.SQLSelectQuery;
import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.TwidereConstants; import org.mariotaku.twidere.TwidereConstants;
import org.mariotaku.twidere.constant.PreferenceKeysKt;
import org.mariotaku.twidere.extension.AccountExtensionsKt; import org.mariotaku.twidere.extension.AccountExtensionsKt;
import org.mariotaku.twidere.model.FiltersData; import org.mariotaku.twidere.model.FiltersData;
import org.mariotaku.twidere.model.FiltersData$BaseItemValuesCreator; import org.mariotaku.twidere.model.FiltersData$BaseItemValuesCreator;
@ -323,7 +326,9 @@ public class DataStoreUtils implements Constants {
} }
@NonNull @NonNull
public static Expression buildStatusFilterWhereClause(@NonNull final String table, final Expression extraSelection) { public static Expression buildStatusFilterWhereClause(@NonNull final SharedPreferences preferences,
@NonNull final String table,
@Nullable final Expression extraSelection) {
final SQLSelectQuery filteredUsersQuery = SQLQueryBuilder final SQLSelectQuery filteredUsersQuery = SQLQueryBuilder
.select(new Column(new Table(Filters.Users.TABLE_NAME), Filters.Users.USER_KEY)) .select(new Column(new Table(Filters.Users.TABLE_NAME), Filters.Users.USER_KEY))
.from(new Tables(Filters.Users.TABLE_NAME)) .from(new Tables(Filters.Users.TABLE_NAME))
@ -364,8 +369,16 @@ public class DataStoreUtils implements Constants {
Expression.likeRaw(new Column(new Table(table), Statuses.QUOTED_SPANS), Expression.likeRaw(new Column(new Table(table), Statuses.QUOTED_SPANS),
"'%'||" + Filters.Links.TABLE_NAME + "." + Filters.Links.VALUE + "||'%'") "'%'||" + Filters.Links.TABLE_NAME + "." + Filters.Links.VALUE + "||'%'")
)); ));
int filterFlags = 0;
if (SharedPreferencesExtensionsKt.get(preferences, PreferenceKeysKt.getFilterUnavailableQuoteStatusesKey())) {
filterFlags |= ParcelableStatus.FilterFlags.QUOTE_NOT_AVAILABLE;
}
final Expression filterExpression = Expression.or( final Expression filterExpression = Expression.or(
Expression.notIn(new Column(new Table(table), Statuses._ID), filteredIdsQueryBuilder.build()), Expression.and(
new Expression("(" + Statuses.FILTER_FLAGS + " & " + filterFlags + ") == 0"),
Expression.notIn(new Column(new Table(table), Statuses._ID), filteredIdsQueryBuilder.build())
),
Expression.equals(new Column(new Table(table), Statuses.IS_GAP), 1) Expression.equals(new Column(new Table(table), Statuses.IS_GAP), 1)
); );
if (extraSelection != null) { if (extraSelection != null) {
@ -420,7 +433,9 @@ public class DataStoreUtils implements Constants {
return keys.toArray(new UserKey[keys.size()]); return keys.toArray(new UserKey[keys.size()]);
} }
public static int getStatusesCount(@NonNull final Context context, final Uri uri, public static int getStatusesCount(@NonNull final Context context,
@NonNull final SharedPreferences preferences,
final Uri uri,
@Nullable final Bundle extraArgs, final long compare, @Nullable final Bundle extraArgs, final long compare,
String compareColumn, boolean greaterThan, String compareColumn, boolean greaterThan,
@Nullable UserKey[] accountKeys) { @Nullable UserKey[] accountKeys) {
@ -443,7 +458,7 @@ public class DataStoreUtils implements Constants {
} }
expressionArgs.add(String.valueOf(compare)); expressionArgs.add(String.valueOf(compare));
expressions.add(buildStatusFilterWhereClause(getTableNameByUri(uri), null)); expressions.add(buildStatusFilterWhereClause(preferences, getTableNameByUri(uri), null));
if (extraArgs != null) { if (extraArgs != null) {
Parcelable extras = extraArgs.getParcelable(EXTRA_EXTRAS); Parcelable extras = extraArgs.getParcelable(EXTRA_EXTRAS);

View File

@ -28,6 +28,7 @@ import android.app.SearchManager
import android.content.Context import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Rect import android.graphics.Rect
@ -515,7 +516,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
fun updateUnreadCount() { fun updateUnreadCount() {
if (mainTabs == null || updateUnreadCountTask != null && updateUnreadCountTask!!.status == AsyncTask.Status.RUNNING) if (mainTabs == null || updateUnreadCountTask != null && updateUnreadCountTask!!.status == AsyncTask.Status.RUNNING)
return return
updateUnreadCountTask = UpdateUnreadCountTask(this, readStateManager, mainTabs, updateUnreadCountTask = UpdateUnreadCountTask(this, preferences, readStateManager, mainTabs,
pagerAdapter.tabs.toTypedArray()) pagerAdapter.tabs.toTypedArray())
AsyncTaskUtils.executeTask<UpdateUnreadCountTask, Any>(updateUnreadCountTask) AsyncTaskUtils.executeTask<UpdateUnreadCountTask, Any>(updateUnreadCountTask)
mainTabs.setDisplayBadge(preferences.getBoolean(SharedPreferenceConstants.KEY_UNREAD_COUNT, true)) mainTabs.setDisplayBadge(preferences.getBoolean(SharedPreferenceConstants.KEY_UNREAD_COUNT, true))
@ -885,6 +886,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
private class UpdateUnreadCountTask internal constructor( private class UpdateUnreadCountTask internal constructor(
private val context: Context, private val context: Context,
private val preferences: SharedPreferences,
private val readStateManager: ReadStateManager, private val readStateManager: ReadStateManager,
private val indicator: TabPagerIndicator, private val indicator: TabPagerIndicator,
private val tabs: Array<SupportTabSpec>) : AsyncTask<Any, UpdateUnreadCountTask.TabBadge, SparseIntArray>() { private val tabs: Array<SupportTabSpec>) : AsyncTask<Any, UpdateUnreadCountTask.TabBadge, SparseIntArray>() {
@ -904,8 +906,9 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
val tag = Utils.getReadPositionTagWithAccount(ReadPositionTag.HOME_TIMELINE, it) val tag = Utils.getReadPositionTagWithAccount(ReadPositionTag.HOME_TIMELINE, it)
readStateManager.getPosition(tag) readStateManager.getPosition(tag)
}.fold(0L, Math::max) }.fold(0L, Math::max)
val count = DataStoreUtils.getStatusesCount(context, Statuses.CONTENT_URI, val count = DataStoreUtils.getStatusesCount(context, preferences,
spec.args, position, Statuses.STATUS_TIMESTAMP, true, accountKeys) Statuses.CONTENT_URI, spec.args, position, Statuses.STATUS_TIMESTAMP,
true, accountKeys)
result.put(i, count) result.put(i, count)
publishProgress(TabBadge(i, count)) publishProgress(TabBadge(i, count))
} }

View File

@ -51,6 +51,7 @@ val drawerToggleKey = KBooleanKey(KEY_DRAWER_TOGGLE, false)
val fabVisibleKey = KBooleanKey(KEY_FAB_VISIBLE, true) val fabVisibleKey = KBooleanKey(KEY_FAB_VISIBLE, true)
val themeKey = KStringKey(KEY_THEME, VALUE_THEME_NAME_LIGHT) val themeKey = KStringKey(KEY_THEME, VALUE_THEME_NAME_LIGHT)
val themeColorKey = KIntKey(KEY_THEME_COLOR, 0) val themeColorKey = KIntKey(KEY_THEME_COLOR, 0)
val filterUnavailableQuoteStatusesKey = KBooleanKey("filter_unavailable_quote_statuses", false)
object refreshIntervalKey : KSimpleKey<Long>(KEY_REFRESH_INTERVAL, 15) { object refreshIntervalKey : KSimpleKey<Long>(KEY_REFRESH_INTERVAL, 15) {
override fun read(preferences: SharedPreferences): Long { override fun read(preferences: SharedPreferences): Long {

View File

@ -45,8 +45,6 @@ import org.mariotaku.twidere.model.message.*
import org.mariotaku.twidere.provider.TwidereDataStore.Filters import org.mariotaku.twidere.provider.TwidereDataStore.Filters
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
import org.mariotaku.twidere.util.DataStoreUtils import org.mariotaku.twidere.util.DataStoreUtils
import org.mariotaku.twidere.util.DataStoreUtils.buildStatusFilterWhereClause
import org.mariotaku.twidere.util.DataStoreUtils.getTableNameByUri
import org.mariotaku.twidere.util.ErrorInfoStore import org.mariotaku.twidere.util.ErrorInfoStore
import org.mariotaku.twidere.util.Utils import org.mariotaku.twidere.util.Utils
@ -78,7 +76,7 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
override fun onCreateStatusesLoader(context: Context, args: Bundle, fromUser: Boolean): Loader<List<ParcelableStatus>?> { override fun onCreateStatusesLoader(context: Context, args: Bundle, fromUser: Boolean): Loader<List<ParcelableStatus>?> {
val uri = contentUri val uri = contentUri
val table = getTableNameByUri(uri) val table = DataStoreUtils.getTableNameByUri(uri)
val sortOrder = Statuses.DEFAULT_SORT_ORDER val sortOrder = Statuses.DEFAULT_SORT_ORDER
val accountKeys = this.accountKeys val accountKeys = this.accountKeys
val accountWhere = Expression.`in`(Column(Statuses.ACCOUNT_KEY), val accountWhere = Expression.`in`(Column(Statuses.ACCOUNT_KEY),
@ -224,7 +222,7 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
protected fun getFiltersWhere(table: String): Expression? { protected fun getFiltersWhere(table: String): Expression? {
if (!isFilterEnabled) return null if (!isFilterEnabled) return null
return buildStatusFilterWhereClause(table, null) return DataStoreUtils.buildStatusFilterWhereClause(preferences, table, null)
} }
protected fun getNewestStatusIds(accountKeys: Array<UserKey>): Array<String?>? { protected fun getNewestStatusIds(accountKeys: Array<UserKey>): Array<String?>? {

View File

@ -7,7 +7,6 @@ import org.mariotaku.microblog.library.twitter.model.Status
import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM
import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.ParcelableStatus.FilterFlags import org.mariotaku.twidere.model.ParcelableStatus.FilterFlags
import org.mariotaku.twidere.task.twitter.GetStatusesTask
import org.mariotaku.twidere.util.HtmlSpanBuilder import org.mariotaku.twidere.util.HtmlSpanBuilder
import org.mariotaku.twidere.util.InternalTwitterContentUtils import org.mariotaku.twidere.util.InternalTwitterContentUtils
import org.mariotaku.twidere.util.TwitterContentUtils import org.mariotaku.twidere.util.TwitterContentUtils
@ -105,7 +104,7 @@ object ParcelableStatusUtils {
result.quoted_user_profile_image = TwitterContentUtils.getProfileImageUrl(quotedUser) result.quoted_user_profile_image = TwitterContentUtils.getProfileImageUrl(quotedUser)
result.quoted_user_is_protected = quotedUser.isProtected result.quoted_user_is_protected = quotedUser.isProtected
result.quoted_user_is_verified = quotedUser.isVerified result.quoted_user_is_verified = quotedUser.isVerified
} else { } else if (status.isQuoteStatus) {
result.filter_flags = result.filter_flags or FilterFlags.QUOTE_NOT_AVAILABLE result.filter_flags = result.filter_flags or FilterFlags.QUOTE_NOT_AVAILABLE
} }

View File

@ -12,7 +12,7 @@ import org.apache.commons.lang3.ArrayUtils
import org.apache.commons.lang3.math.NumberUtils import org.apache.commons.lang3.math.NumberUtils
import org.mariotaku.abstask.library.AbstractTask import org.mariotaku.abstask.library.AbstractTask
import org.mariotaku.abstask.library.TaskStarter import org.mariotaku.abstask.library.TaskStarter
import org.mariotaku.kpreferences.KPreferences import org.mariotaku.kpreferences.get
import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlog
import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.Paging
@ -48,7 +48,7 @@ abstract class GetStatusesTask(
protected val context: Context protected val context: Context
) : AbstractTask<RefreshTaskParam, List<TwitterWrapper.StatusListResponse>, () -> Unit>() { ) : AbstractTask<RefreshTaskParam, List<TwitterWrapper.StatusListResponse>, () -> Unit>() {
@Inject @Inject
lateinit var preferences: KPreferences lateinit var preferences: SharedPreferencesWrapper
@Inject @Inject
lateinit var bus: Bus lateinit var bus: Bus
@Inject @Inject
@ -200,8 +200,8 @@ abstract class GetStatusesTask(
val deleteWhereArgs = arrayOf(accountKey.toString(), *statusIds) val deleteWhereArgs = arrayOf(accountKey.toString(), *statusIds)
var olderCount = -1 var olderCount = -1
if (minPositionKey > 0) { if (minPositionKey > 0) {
olderCount = DataStoreUtils.getStatusesCount(context, uri, null, minPositionKey, olderCount = DataStoreUtils.getStatusesCount(context, preferences, uri, null,
Statuses.POSITION_KEY, false, arrayOf(accountKey)) minPositionKey, Statuses.POSITION_KEY, false, arrayOf(accountKey))
} }
val rowsDeleted = resolver.delete(writeUri, deleteWhere, deleteWhereArgs) val rowsDeleted = resolver.delete(writeUri, deleteWhere, deleteWhereArgs)