diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/FiltersData.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/FiltersData.java index d626f64c1..883cecd36 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/FiltersData.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/FiltersData.java @@ -163,6 +163,10 @@ public class FiltersData { @JsonField(name = "source") long source = -1; + public long getId() { + return _id; + } + public String getValue() { return value; } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MessagesConversationFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MessagesConversationFragment.kt index 20eb081e5..f993d6b01 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MessagesConversationFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MessagesConversationFragment.kt @@ -217,8 +217,8 @@ class MessagesConversationFragment : BaseFragment(), LoaderCallbacks, O addImage.setOnClickListener(this) sendMessage.isEnabled = false if (savedInstanceState != null) { - val account: AccountDetails = savedInstanceState.getParcelable(EXTRA_ACCOUNT) - val recipient: ParcelableUser = savedInstanceState.getParcelable(EXTRA_USER) + val account: AccountDetails? = savedInstanceState.getParcelable(EXTRA_ACCOUNT) + val recipient: ParcelableUser? = savedInstanceState.getParcelable(EXTRA_USER) showConversation(account, recipient) editText.setText(savedInstanceState.getString(EXTRA_TEXT)) imageUri = savedInstanceState.getString(EXTRA_IMAGE_URI) @@ -289,12 +289,12 @@ class MessagesConversationFragment : BaseFragment(), LoaderCallbacks, O updateAddImageButton() } - override fun onSaveInstanceState(outState: Bundle?) { + override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) if (editText != null) { - outState!!.putCharSequence(EXTRA_TEXT, editText.text) + outState.putCharSequence(EXTRA_TEXT, editText.text) } - outState!!.putParcelable(EXTRA_ACCOUNT, account) + outState.putParcelable(EXTRA_ACCOUNT, account) outState.putParcelable(EXTRA_USER, recipient) outState.putString(EXTRA_IMAGE_URI, imageUri) } 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 ad8f69f4e..a07e49640 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 @@ -39,16 +39,14 @@ import android.text.SpannableStringBuilder import android.text.Spanned import android.text.TextUtils import android.view.* -import android.widget.AbsListView +import android.widget.* import android.widget.AbsListView.MultiChoiceModeListener -import android.widget.AutoCompleteTextView -import android.widget.ListView -import android.widget.TextView import kotlinx.android.synthetic.main.fragment_content_listview.* import org.mariotaku.ktextension.setGroupAvailability import org.mariotaku.sqliteqb.library.Columns import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.twidere.R +import org.mariotaku.twidere.TwidereConstants.EXTRA_ID import org.mariotaku.twidere.TwidereConstants.EXTRA_URI import org.mariotaku.twidere.activity.iface.IControlBarActivity import org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter @@ -59,9 +57,11 @@ import org.mariotaku.twidere.extension.selectNone import org.mariotaku.twidere.extension.updateSelectionItems import org.mariotaku.twidere.fragment.AbsContentListViewFragment import org.mariotaku.twidere.fragment.BaseDialogFragment +import org.mariotaku.twidere.model.FiltersData import org.mariotaku.twidere.model.`FiltersData$BaseItemCursorIndices` import org.mariotaku.twidere.provider.TwidereDataStore.Filters import org.mariotaku.twidere.text.style.EmojiSpan +import org.mariotaku.twidere.util.DataStoreUtils import org.mariotaku.twidere.util.ParseUtils import org.mariotaku.twidere.util.ThemeUtils import org.mariotaku.twidere.util.Utils @@ -81,11 +81,23 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment protected open val sortOrder: String? = "${Filters.SOURCE} >= 0" + protected open val autoCompleteType: Int = 0 + protected open val supportsEdit: Boolean = true + + private val isQuickReturnEnabled: Boolean + get() = actionMode == null override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setHasOptionsMenu(true) listView.choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL + listView.setOnItemClickListener { view, child, pos, id -> + if (!supportsEdit) return@setOnItemClickListener + val adapter = this.adapter as FilterListAdapter + val item = adapter.getFilterItem(pos) ?: return@setOnItemClickListener + if (item.source >= 0) return@setOnItemClickListener + addOrEditItem(item.id, item.value) + } listView.setMultiChoiceModeListener(this) loaderManager.initLoader(0, null, this) setRefreshEnabled(false) @@ -103,9 +115,6 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment { - val args = Bundle() - args.putParcelable(EXTRA_URI, contentUri) - val dialog = AddItemFragment() - dialog.arguments = args - dialog.show(fragmentManager, "add_rule") + addOrEditItem() return true } } return super.onOptionsItemSelected(item) } - override fun onCreateAdapter(context: Context): SimpleCursorAdapter { return FilterListAdapter(context) } + protected open fun performDeletion() { val ids = listView.checkedItemIds val where = Expression.inArgs(Columns.Column(Filters._ID), ids.size) context.contentResolver.delete(contentUri, where.sql, Array(ids.size) { ids[it].toString() }) } + protected open fun addOrEditItem(id: Long = -1, value: String? = null) { + val args = Bundle() + args.putParcelable(EXTRA_URI, contentUri) + args.putInt(EXTRA_AUTO_COMPLETE_TYPE, autoCompleteType) + args.putLong(EXTRA_ID, id) + args.putString(EXTRA_VALUE, value) + val dialog = AddEditItemFragment() + dialog.arguments = args + dialog.show(fragmentManager, "add_rule") + } + private fun updateTitle(mode: ActionMode?) { if (listView == null || mode == null || activity == null) return @@ -231,7 +246,7 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment= 0) { + val where = Expression.equalsArgs(Filters._ID).sql + val whereArgs = arrayOf(id.toString()) + if (DataStoreUtils.queryCount(context, uri, where, whereArgs) == 0) { + resolver.update(uri, values, where, whereArgs) + } else { + Toast.makeText(context, R.string.message_toast_duplicate_filter_rule, + Toast.LENGTH_SHORT).show() + } + } else { + resolver.insert(uri, values) + } } } @@ -253,16 +281,21 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment= 0) { + builder.setTitle(R.string.action_edit_filter_rule) + } else { + builder.setTitle(R.string.action_add_filter_rule) + } builder.setPositiveButton(android.R.string.ok, this) builder.setNegativeButton(android.R.string.cancel, this) val dialog = builder.create() dialog.setOnShowListener { dialog -> val alertDialog = dialog as AlertDialog val editText = (alertDialog.findViewById(R.id.edit_text) as AutoCompleteTextView?)!! - val args = arguments - val autoCompleteType: Int - autoCompleteType = args.getInt(EXTRA_AUTO_COMPLETE_TYPE, 0) + if (savedInstanceState == null) { + editText.setText(arguments.getString(EXTRA_VALUE)) + } + val autoCompleteType = arguments.getInt(EXTRA_AUTO_COMPLETE_TYPE, 0) if (autoCompleteType != 0) { val userAutoCompleteAdapter: SimpleCursorAdapter if (autoCompleteType == AUTO_COMPLETE_TYPE_SOURCES) { @@ -334,11 +367,20 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment - get() = TwidereDataStore.Filters.Sources.COLUMNS + override val contentColumns: Array = Filters.Sources.COLUMNS - override val contentUri: Uri - get() = TwidereDataStore.Filters.Sources.CONTENT_URI + override val contentUri: Uri = Filters.Sources.CONTENT_URI - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.add -> { - val args = Bundle() - args.putInt(EXTRA_AUTO_COMPLETE_TYPE, AUTO_COMPLETE_TYPE_SOURCES) - args.putParcelable(EXTRA_URI, contentUri) - val dialog = AddItemFragment() - dialog.arguments = args - dialog.show(fragmentManager, "add_rule") - return true - } - } - return super.onOptionsItemSelected(item) - } + override val autoCompleteType: Int = AUTO_COMPLETE_TYPE_SOURCES } \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FilteredUsersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FilteredUsersFragment.kt index 9c701347b..a2c9ef092 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FilteredUsersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FilteredUsersFragment.kt @@ -33,7 +33,10 @@ import org.mariotaku.twidere.model.`FiltersData$UserItemCursorIndices` 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.* +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.dagger.GeneralComponentHelper import org.mariotaku.twidere.util.premium.ExtraFeaturesService import javax.inject.Inject @@ -43,6 +46,7 @@ class FilteredUsersFragment : BaseFiltersFragment() { override val contentUri: Uri = Filters.Users.CONTENT_URI override val contentColumns: Array = Filters.Users.COLUMNS override val sortOrder: String? = "${Filters.Users.SOURCE} >= 0" + override val supportsEdit: Boolean = false override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) @@ -128,6 +132,10 @@ class FilteredUsersFragment : BaseFiltersFragment() { return FilterUsersListAdapter(context) } + override fun addOrEditItem(id: Long, value: String?) { + // No-op + } + class FilterUsersListAdapter( context: Context ) : SimpleCursorAdapter(context, R.layout.list_item_two_line, null, diff --git a/twidere/src/main/res/layout-sw600dp/activity_link_handler.xml b/twidere/src/main/res/layout-sw600dp/activity_link_handler.xml index 4fde6b528..34a0786c0 100644 --- a/twidere/src/main/res/layout-sw600dp/activity_link_handler.xml +++ b/twidere/src/main/res/layout-sw600dp/activity_link_handler.xml @@ -14,7 +14,6 @@ android:layout_alignParentTop="true" android:background="?colorToolbar" android:elevation="@dimen/toolbar_elevation" - android:tag="ate_ignore" app:popupTheme="?actionBarPopupTheme" tools:elevation="0dp"/> diff --git a/twidere/src/main/res/layout/activity_compose.xml b/twidere/src/main/res/layout/activity_compose.xml index dcad6bc1c..594541901 100644 --- a/twidere/src/main/res/layout/activity_compose.xml +++ b/twidere/src/main/res/layout/activity_compose.xml @@ -124,7 +124,6 @@ android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_centerVertical="true" - android:tag="mvs_tint|accent_color" tools:max="3" tools:position="2"/> diff --git a/twidere/src/main/res/layout/activity_home_content.xml b/twidere/src/main/res/layout/activity_home_content.xml index 8fc23c1b1..570afa02e 100644 --- a/twidere/src/main/res/layout/activity_home_content.xml +++ b/twidere/src/main/res/layout/activity_home_content.xml @@ -55,8 +55,7 @@ android:layout_height="?actionBarSize" android:layout_weight="0" android:background="?actionBarItemBackground" - android:contentDescription="@string/open_accounts_dashboard" - android:tag="tint|primary_color_dependent"/> + android:contentDescription="@string/open_accounts_dashboard"/> - + android:maxLines="1" + app:backgroundTint="?colorAccent"/> \ No newline at end of file diff --git a/twidere/src/main/res/layout/fragment_user.xml b/twidere/src/main/res/layout/fragment_user.xml index 28e983062..5ec7a9b1a 100644 --- a/twidere/src/main/res/layout/fragment_user.xml +++ b/twidere/src/main/res/layout/fragment_user.xml @@ -78,7 +78,6 @@ android:layout_height="?actionBarSize" android:layout_alignParentTop="true" android:elevation="@dimen/toolbar_elevation" - android:tag="ate_ignore" app:popupTheme="?actionBarPopupTheme" tools:elevation="0dp"/> diff --git a/twidere/src/main/res/layout/header_drawer_account_selector.xml b/twidere/src/main/res/layout/header_drawer_account_selector.xml index 4f1dd4e3c..0b1fc6148 100644 --- a/twidere/src/main/res/layout/header_drawer_account_selector.xml +++ b/twidere/src/main/res/layout/header_drawer_account_selector.xml @@ -168,8 +168,7 @@ android:id="@+id/accountDashboardMenu" android:layout_width="match_parent" android:layout_height="match_parent" - android:focusable="true" - android:tag="ate_ignore"/> + android:focusable="true"/> diff --git a/twidere/src/main/res/layout/header_status_common.xml b/twidere/src/main/res/layout/header_status_common.xml index 3ce454c9a..2d45f69c0 100644 --- a/twidere/src/main/res/layout/header_status_common.xml +++ b/twidere/src/main/res/layout/header_status_common.xml @@ -41,7 +41,6 @@ android:maxLines="1" android:minHeight="@dimen/element_size_small" android:padding="@dimen/element_spacing_normal" - android:tag="font_family|user" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="?android:textColorSecondary" tools:text="Retweeted by Mariotaku" /> @@ -104,7 +103,6 @@ android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" - android:tag="font_family|user" app:nv_primaryTextColor="?android:textColorPrimary" app:nv_secondaryTextColor="?android:textColorSecondary" app:nv_twoLine="false" /> @@ -115,7 +113,6 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/element_spacing_small" android:gravity="center_vertical" - android:tag="font_family|user" android:textAppearance="?android:attr/textAppearanceSmall" tools:text="Jan 1 2015 0:00 ยท Twidere" /> @@ -160,7 +157,6 @@ android:layout_marginTop="@dimen/element_spacing_small" android:paddingLeft="@dimen/element_spacing_normal" android:paddingRight="@dimen/element_spacing_normal" - android:tag="font_family|user" android:textAppearance="?android:textAppearanceMedium" android:textColor="?android:textColorPrimary" android:visibility="visible" @@ -186,7 +182,6 @@ android:gravity="center_vertical" android:maxLines="1" android:padding="@dimen/element_spacing_normal" - android:tag="font_family|user" android:text="@string/unknown_language" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="?android:textColorSecondary" /> @@ -196,7 +191,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/element_spacing_normal" - android:tag="font_family|user" android:textColor="?android:textColorPrimary" android:visibility="gone" tools:text="@string/sample_status_text" /> @@ -242,7 +236,6 @@ android:drawableLeft="@drawable/ic_action_gallery" android:drawableStart="@drawable/ic_action_gallery" android:gravity="center_vertical" - android:tag="font_family|user" android:text="@string/load_media" android:textAppearance="?android:attr/textAppearanceMedium" android:textStyle="bold" /> @@ -275,7 +268,6 @@ android:orientation="horizontal" android:paddingLeft="@dimen/element_spacing_normal" android:paddingRight="@dimen/element_spacing_normal" - android:tag="font_family|user" android:visibility="gone" app:nv_primaryTextColor="?android:textColorPrimary" app:nv_secondaryTextColor="?android:textColorSecondary" @@ -289,7 +281,6 @@ android:layout_margin="@dimen/element_spacing_normal" android:ellipsize="end" android:maxLines="4" - android:tag="font_family|user" android:textAppearance="?android:textAppearanceMedium" android:textColor="?android:textColorPrimary" android:visibility="gone" @@ -355,7 +346,6 @@ android:gravity="center_vertical" android:maxLines="1" android:padding="@dimen/element_spacing_normal" - android:tag="font_family|user" android:text="@string/action_view_map" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="?android:textColorSecondary" /> diff --git a/twidere/src/main/res/layout/layout_actionbar_message_user_picker.xml b/twidere/src/main/res/layout/layout_actionbar_message_user_picker.xml index cc6a292bf..5365eb954 100644 --- a/twidere/src/main/res/layout/layout_actionbar_message_user_picker.xml +++ b/twidere/src/main/res/layout/layout_actionbar_message_user_picker.xml @@ -63,7 +63,6 @@ android:contentDescription="@string/search" android:scaleType="centerInside" android:src="@drawable/ic_action_search" - android:tag="tint|primary_color_dependent" app:backgroundTintMode="src_atop"/> diff --git a/twidere/src/main/res/layout/list_item_custom_tab.xml b/twidere/src/main/res/layout/list_item_custom_tab.xml index e5592b2d2..9ec9f1475 100644 --- a/twidere/src/main/res/layout/list_item_custom_tab.xml +++ b/twidere/src/main/res/layout/list_item_custom_tab.xml @@ -28,7 +28,6 @@ android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight" android:orientation="horizontal" - android:tag="tint_background|accent_color" app:backgroundTint="?colorControlActivated"> diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index 449a37f49..f4467bcc7 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -33,6 +33,7 @@ denying follow request Edit + Edit rule Favorite favoriting Import from blocked users @@ -688,6 +689,7 @@ You have already logged in Can\'t get your location Permission required to delete taken photo/video + Rule duplicated An error occurred, please try again Enhanced features not purchased