This commit is contained in:
Mariotaku Lee 2017-01-31 22:28:26 +08:00
parent cd91700c75
commit 4d13123caa
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
16 changed files with 93 additions and 73 deletions

View File

@ -163,6 +163,10 @@ public class FiltersData {
@JsonField(name = "source")
long source = -1;
public long getId() {
return _id;
}
public String getValue() {
return value;
}

View File

@ -217,8 +217,8 @@ class MessagesConversationFragment : BaseFragment(), LoaderCallbacks<Cursor?>, 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<Cursor?>, 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)
}

View File

@ -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<SimpleCursorAdap
protected abstract val contentUri: Uri
protected abstract val contentColumns: Array<String>
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<SimpleCursorAdap
super.setControlVisible(visible || !isQuickReturnEnabled)
}
private val isQuickReturnEnabled: Boolean
get() = actionMode == null
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
actionMode = mode
setControlVisible(true)
@ -146,8 +155,7 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
actionMode = null
}
override fun onItemCheckedStateChanged(mode: ActionMode, position: Int, id: Long,
checked: Boolean) {
override fun onItemCheckedStateChanged(mode: ActionMode, position: Int, id: Long, checked: Boolean) {
val adapter = this.adapter
if (adapter is SelectableItemAdapter) {
if (!adapter.isSelectable(position) && checked) {
@ -202,28 +210,35 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.add -> {
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<SimpleCursorAdap
mode.title = resources.getQuantityString(R.plurals.Nitems_selected, count, count)
}
class AddItemFragment : BaseDialogFragment(), OnClickListener {
class AddEditItemFragment : BaseDialogFragment(), OnClickListener {
override fun onClick(dialog: DialogInterface, which: Int) {
when (which) {
@ -241,7 +256,20 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
val values = ContentValues()
values.put(Filters.VALUE, text)
val uri: Uri = arguments.getParcelable(EXTRA_URI)
context.contentResolver.insert(uri, values)
val id = arguments.getLong(EXTRA_ID, -1)
val resolver = context.contentResolver
if (id >= 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<SimpleCursorAdap
val builder = AlertDialog.Builder(context)
builder.setView(R.layout.dialog_auto_complete_textview)
builder.setTitle(R.string.action_add_filter_rule)
if (arguments.getLong(EXTRA_ID, -1) >= 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<SimpleCursorAdap
}
return false
}
fun getFilterItem(position: Int): FiltersData.BaseItem? {
val cursor = this.cursor ?: return null
if (cursor.moveToPosition(position)) {
return indices!!.newObject(cursor)
}
return null
}
}
companion object {
internal const val EXTRA_AUTO_COMPLETE_TYPE = "auto_complete_type"
internal const val EXTRA_VALUE = "value"
internal const val AUTO_COMPLETE_TYPE_SOURCES = 2
internal const val REQUEST_ADD_USER_SELECT_ACCOUNT = 201
internal const val REQUEST_IMPORT_BLOCKS_SELECT_ACCOUNT = 202

View File

@ -1,34 +1,14 @@
package org.mariotaku.twidere.fragment.filter
import android.net.Uri
import android.os.Bundle
import android.view.MenuItem
import org.mariotaku.twidere.R
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_URI
import org.mariotaku.twidere.fragment.filter.BaseFiltersFragment
import org.mariotaku.twidere.provider.TwidereDataStore
import org.mariotaku.twidere.provider.TwidereDataStore.Filters
class FilteredSourcesFragment : BaseFiltersFragment() {
override val contentColumns: Array<String>
get() = TwidereDataStore.Filters.Sources.COLUMNS
override val contentColumns: Array<String> = 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
}

View File

@ -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<String> = 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,

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>
<org.mariotaku.twidere.view.TabPagerIndicator
android:id="@+id/mainTabs"

View File

@ -20,15 +20,17 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<AutoCompleteTextView
<android.support.v7.widget.AppCompatAutoCompleteTextView
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:maxLines="1"/>
android:maxLines="1"
app:backgroundTint="?colorAccent"/>
</FrameLayout>

View File

@ -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"/>

View File

@ -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"/>
</FrameLayout>
</LinearLayout>

View File

@ -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" />

View File

@ -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"/>
</FrameLayout>

View File

@ -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">
<View

View File

@ -28,7 +28,6 @@
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
android:padding="@dimen/element_spacing_normal"
android:tag="tint_background|accent_color"
app:backgroundTint="?colorControlActivated"
app:ignorePadding="true"
tools:context=".adapter.DraftsAdapter">

View File

@ -33,6 +33,7 @@
<string name="action_denying_follow_request">denying follow request</string>
<!-- [verb] Edit image/settings etc. -->
<string name="action_edit">Edit</string>
<string name="action_edit_filter_rule">Edit rule</string>
<string name="action_favorite">Favorite</string>
<string name="action_favoriting">favoriting</string>
<string name="action_filter_import_from_blocked_users">Import from blocked users</string>
@ -688,6 +689,7 @@
<string name="message_toast_already_logged_in">You have already logged in</string>
<string name="message_toast_cannot_get_location">Can\'t get your location</string>
<string name="message_toast_compose_write_storage_no_permission">Permission required to delete taken photo/video</string>
<string name="message_toast_duplicate_filter_rule">Rule duplicated</string>
<string name="message_toast_error_occurred">An error occurred, please try again</string>
<!-- Toast message for enhanced (paid) features not purchased while trying to restore purchase -->
<string name="message_toast_extra_features_not_purchased">Enhanced features not purchased</string>