improved import filter

This commit is contained in:
Mariotaku Lee 2016-12-28 13:17:24 +08:00
parent edc1ccce56
commit e826276d53
4 changed files with 28 additions and 17 deletions

View File

@ -1065,24 +1065,29 @@ public class DataStoreUtils implements Constants {
}
}
public static void removeFromFilter(Context context, ParcelableUser user) {
public static void removeFromFilter(Context context, Collection<ParcelableUser> users) {
List<String> userKeyValues = new ArrayList<>();
List<String> linkValues = new ArrayList<>();
List<String> keywordValues = new ArrayList<>();
final ContentResolver cr = context.getContentResolver();
// Delete from filtered users
cr.delete(Filters.Users.CONTENT_URI, Expression.equalsArgs(Filters.Users.USER_KEY).getSQL(),
new String[]{user.key.toString()});
// Delete user mention from keywords
cr.delete(Filters.Keywords.CONTENT_URI, Expression.equalsArgs(Filters.Keywords.VALUE).getSQL(),
new String[]{"@" + user.screen_name});
for (ParcelableUser user : 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
Uri userLink = LinkCreator.getUserWebLink(user);
String linkWithoutScheme = userLink.toString();
int idx;
if ((idx = linkWithoutScheme.indexOf("://")) >= 0) {
linkWithoutScheme = linkWithoutScheme.substring(idx + 3);
// Delete user link (without scheme) from links
Uri userLink = LinkCreator.getUserWebLink(user);
String linkWithoutScheme = userLink.toString();
int idx;
if ((idx = linkWithoutScheme.indexOf("://")) >= 0) {
linkWithoutScheme = linkWithoutScheme.substring(idx + 3);
}
linkValues.add(linkWithoutScheme);
}
cr.delete(Filters.Links.CONTENT_URI, Expression.equalsArgs(Filters.Links.VALUE).getSQL(),
new String[]{linkWithoutScheme});
ContentResolverUtils.bulkDelete(cr, Filters.Users.CONTENT_URI, Filters.Users.USER_KEY, userKeyValues, null);
ContentResolverUtils.bulkDelete(cr, Filters.Keywords.CONTENT_URI, Filters.Keywords.VALUE, keywordValues, null);
ContentResolverUtils.bulkDelete(cr, Filters.Links.CONTENT_URI, Filters.Links.VALUE, linkValues, null);
}
public interface UpdateActivityAction {

View File

@ -856,7 +856,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
R.id.add_to_filter -> {
if (userRelationship == null) return true
if (userRelationship.filtering) {
DataStoreUtils.removeFromFilter(context, user)
DataStoreUtils.removeFromFilter(context, listOf(user))
Utils.showInfoMessage(activity, R.string.message_user_unmuted, false)
getFriendship()
} else {

View File

@ -188,6 +188,7 @@ abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment<Ba
val selectedUsers = rangeOfSize(adapter.userStartIndex, adapter.userCount - 1)
.filter { adapter.isItemChecked(it) }
.map { adapter.getUser(it)!! }
selectedUsers.forEach { it.is_filtered = true }
ProgressDialogFragment.show(childFragmentManager, "import_progress")
task {
DataStoreUtils.addToFilter(context, selectedUsers, filterEverywhere)
@ -195,6 +196,7 @@ abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment<Ba
executeAfterFragmentResumed {
(childFragmentManager.findFragmentByTag("import_progress") as? DialogFragment)?.dismiss()
}
adapter.notifyDataSetChanged()
}
}
@ -369,7 +371,7 @@ abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment<Ba
}
val checkedCount: Int get() {
return itemStates.count { it.value }
return data?.count { !it.is_filtered && itemStates[it.key] ?: false } ?: 0
}
fun setItemChecked(position: Int, value: Boolean) {
@ -409,6 +411,8 @@ abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment<Ba
checkBox.setOnCheckedChangeListener(null)
checkBox.isChecked = (adapter as SelectableUsersAdapter).isItemChecked(layoutPosition)
checkBox.setOnCheckedChangeListener(checkChangedListener)
itemView.isEnabled = !user.is_filtered
checkBox.isEnabled = !user.is_filtered
}
}

View File

@ -53,6 +53,7 @@
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
@ -63,6 +64,7 @@
android:id="@+id/screenName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceSmall"