added 'filter everywhere' dialog to filtered users list

fixed filter import checked duplicate
This commit is contained in:
Mariotaku Lee 2017-02-13 22:53:38 +08:00
parent daa0618f26
commit e0be6af513
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
7 changed files with 70 additions and 26 deletions

View File

@ -21,6 +21,8 @@
package org.mariotaku.twidere.model;
import android.support.annotation.Nullable;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
@ -146,9 +148,11 @@ public class FiltersData {
@Override
public String toString() {
return "UserItem{" +
"userKey='" + userKey + '\'' +
"_id=" + _id +
", userKey=" + userKey +
", name='" + name + '\'' +
", screenName='" + screenName + '\'' +
", source=" + source +
'}';
}
@ -180,9 +184,16 @@ public class FiltersData {
/**
* Used for filter list subscription
*/
@CursorField(value = Filters.Users.SOURCE, type = "INTEGER DEFAULT -1")
@CursorField(value = Filters.SOURCE, type = "INTEGER DEFAULT -1")
@JsonField(name = "source")
long source = -1;
/**
* Used for "filter everywhere"
*/
@CursorField(value = Filters.USER_KEY, converter = UserKeyCursorFieldConverter.class, type = TwidereDataStore.TYPE_TEXT)
@JsonField(name = "user_key", typeConverter = UserKeyConverter.class)
@Nullable
UserKey userKey = null;
public long getId() {
return _id;
@ -204,10 +215,22 @@ public class FiltersData {
this.source = source;
}
@Nullable
public UserKey getUserKey() {
return userKey;
}
public void setUserKey(@Nullable final UserKey userKey) {
this.userKey = userKey;
}
@Override
public String toString() {
return "BaseItem{" +
"value='" + value + '\'' +
"_id=" + _id +
", value='" + value + '\'' +
", source=" + source +
", userKey=" + userKey +
'}';
}

View File

@ -603,6 +603,8 @@ public interface TwidereDataStore {
String SOURCE = "source";
String USER_KEY = "user_key";
String ENABLE_IN_HOME_TIMELINE = "enable_in_home_timeline";
String ENABLE_IN_MENTIONS = "enable_in_mentions";

View File

@ -34,7 +34,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING;
public interface Constants extends TwidereConstants {
String DATABASES_NAME = "twidere.sqlite";
int DATABASES_VERSION = 173;
int DATABASES_VERSION = 175;
int EXTRA_FEATURES_NOTICE_VERSION = 0;

View File

@ -218,7 +218,6 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
return FilterListAdapter(context)
}
protected open fun performDeletion() {
val ids = listView.checkedItemIds
val where = Expression.inArgs(Columns.Column(Filters._ID), ids.size)

View File

@ -188,7 +188,12 @@ abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment<Ba
private fun performImport(filterEverywhere: Boolean) {
val selectedUsers = rangeOfSize(adapter.userStartIndex, adapter.userCount - 1)
.filter { adapter.isItemChecked(it) }
.map { adapter.getUser(it)!! }
.mapNotNull {
val user = adapter.getUser(it) ?: return@mapNotNull null
// Skip if already filtered
if (user.is_filtered) return@mapNotNull null
return@mapNotNull user
}
selectedUsers.forEach { it.is_filtered = true }
val weakDf = WeakReference(ProgressDialogFragment.show(childFragmentManager, "import_progress"))
val weakThis = WeakReference(this)

View File

@ -17,6 +17,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import kotlinx.android.synthetic.main.fragment_content_listview.*
import org.mariotaku.kpreferences.KPreferences
import org.mariotaku.ktextension.setItemAvailability
import org.mariotaku.twidere.R
@ -26,6 +27,7 @@ import org.mariotaku.twidere.activity.LinkHandlerActivity
import org.mariotaku.twidere.activity.UserSelectorActivity
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_HOST
import org.mariotaku.twidere.constant.nameFirstKey
import org.mariotaku.twidere.fragment.AddUserFilterDialogFragment
import org.mariotaku.twidere.fragment.ExtraFeaturesIntroductionDialogFragment
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.UserKey
@ -34,9 +36,9 @@ import org.mariotaku.twidere.model.analyzer.PurchaseFinished
import org.mariotaku.twidere.provider.TwidereDataStore.Filters
import org.mariotaku.twidere.text.style.EmojiSpan
import org.mariotaku.twidere.util.Analyzer
import org.mariotaku.twidere.util.DataStoreUtils
import org.mariotaku.twidere.util.ThemeUtils
import org.mariotaku.twidere.util.UserColorNameManager
import org.mariotaku.twidere.util.content.ContentResolverUtils
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
import javax.inject.Inject
@ -57,7 +59,9 @@ class FilteredUsersFragment : BaseFiltersFragment() {
REQUEST_SELECT_USER -> {
if (resultCode != FragmentActivity.RESULT_OK || data == null) return
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER)
DataStoreUtils.addToFilter(context, listOf(user), false)
executeAfterFragmentResumed { fragment ->
AddUserFilterDialogFragment.show(fragment.childFragmentManager, user)
}
}
REQUEST_IMPORT_BLOCKS_SELECT_ACCOUNT -> {
if (resultCode != FragmentActivity.RESULT_OK || data == null) return
@ -136,6 +140,19 @@ class FilteredUsersFragment : BaseFiltersFragment() {
// No-op
}
override fun performDeletion() {
val positions = listView.checkedItemPositions
val keys = (0 until positions.size()).mapNotNull {
if (!positions.valueAt(it)) return@mapNotNull null
return@mapNotNull (adapter as FilterUsersListAdapter).getUserKeyString(positions.keyAt(it))
}
super.performDeletion()
ContentResolverUtils.bulkDelete(context.contentResolver, Filters.Keywords.CONTENT_URI,
Filters.USER_KEY, false, keys, null, null)
ContentResolverUtils.bulkDelete(context.contentResolver, Filters.Links.CONTENT_URI,
Filters.USER_KEY, false, keys, null, null)
}
class FilterUsersListAdapter(
context: Context
) : SimpleCursorAdapter(context, R.layout.list_item_two_line, null,
@ -200,6 +217,14 @@ class FilteredUsersFragment : BaseFiltersFragment() {
}
return false
}
fun getUserKeyString(position: Int): String? {
val cursor = this.cursor ?: return null
if (cursor.moveToPosition(position)) {
return cursor.getString(indices!!.userKey)
}
return null
}
}
}

View File

@ -839,6 +839,7 @@ object DataStoreUtils {
val keywordItem = FiltersData.BaseItem()
keywordItem.value = "@" + user.screen_name
keywordItem.userKey = user.key
keywordValues.add(`FiltersData$BaseItemValuesCreator`.create(keywordItem))
// Insert user link (without scheme) to links
@ -846,6 +847,7 @@ object DataStoreUtils {
val userLink = LinkCreator.getUserWebLink(user)
val linkWithoutScheme = userLink.toString().substringAfter("://")
linkItem.value = linkWithoutScheme
linkItem.userKey = user.key
linkValues.add(`FiltersData$BaseItemValuesCreator`.create(linkItem))
}
@ -863,27 +865,15 @@ object DataStoreUtils {
}
fun removeFromFilter(context: Context, users: Collection<ParcelableUser>) {
val userKeyValues = ArrayList<String>()
val linkValues = ArrayList<String>()
val keywordValues = ArrayList<String>()
val cr = context.contentResolver
for (user in users) {
// Delete from filtered users
userKeyValues.add(user.key.toString())
// Delete user mention from keywords
keywordValues.add("@" + user.screen_name)
// Delete user link (without scheme) from links
val userLink = LinkCreator.getUserWebLink(user)
val linkWithoutScheme = userLink.toString().substringAfter("://")
linkValues.add(linkWithoutScheme)
}
// Delete from filtered users
val userKeyValues = users.map { it.key.toString() }
ContentResolverUtils.bulkDelete(cr, Filters.Users.CONTENT_URI, Filters.Users.USER_KEY,
false, userKeyValues, null, null)
ContentResolverUtils.bulkDelete(cr, Filters.Keywords.CONTENT_URI, Filters.Keywords.VALUE,
false, keywordValues, null, null)
ContentResolverUtils.bulkDelete(cr, Filters.Links.CONTENT_URI, Filters.Links.VALUE, false,
linkValues, null, null)
ContentResolverUtils.bulkDelete(cr, Filters.Keywords.CONTENT_URI, Filters.Keywords.USER_KEY,
false, userKeyValues, null, null)
ContentResolverUtils.bulkDelete(cr, Filters.Links.CONTENT_URI, Filters.Links.USER_KEY,
false, userKeyValues, null, null)
}
@WorkerThread