From 62ca1ecff59a4f29c49e63b11af7eb2490db19b7 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sun, 11 Dec 2016 15:38:33 +0800 Subject: [PATCH] use simple ui on mutes/blocks list --- .../twidere/constant/IntentConstants.java | 1 + .../twidere/util/AsyncTwitterWrapper.java | 4 +- .../twidere/activity/LinkHandlerActivity.kt | 4 + .../twidere/adapter/DummyItemAdapter.kt | 1 + .../twidere/adapter/ParcelableUsersAdapter.kt | 4 +- .../twidere/adapter/iface/IUsersAdapter.kt | 2 + .../AbsUserMuteBlockDialogFragment.kt | 70 +++++++++++++ .../fragment/AddUserFilterDialogFragment.kt | 58 +++-------- .../twidere/fragment/BaseDialogFragment.kt | 3 + .../fragment/CreateUserBlockDialogFragment.kt | 50 +++------- .../fragment/CreateUserMuteDialogFragment.kt | 46 +++------ .../fragment/MutesUsersListFragment.kt | 10 ++ .../fragment/ParcelableUsersFragment.kt | 5 + .../twidere/task/CreateUserMuteTask.kt | 8 +- .../twidere/view/holder/UserViewHolder.kt | 99 ++++++++++++------- ...dialog_block_mute_filter_user_confirm.xml} | 0 .../res/layout/dialog_block_user_confirm.xml | 45 --------- .../src/main/res/layout/list_item_user.xml | 4 +- .../src/main/res/menu/menu_user_profile.xml | 1 + 19 files changed, 215 insertions(+), 200 deletions(-) create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsUserMuteBlockDialogFragment.kt rename twidere/src/main/res/layout/{dialog_filter_user_confirm.xml => dialog_block_mute_filter_user_confirm.xml} (100%) delete mode 100644 twidere/src/main/res/layout/dialog_block_user_confirm.xml diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java index 8abb0693b..f58f5f9d8 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java @@ -219,4 +219,5 @@ public interface IntentConstants { String EXTRA_START_INTENT = "start_intent"; String EXTRA_SELECT_ONLY_ITEM = "select_only_item"; String EXTRA_OBJECT = "object"; + String EXTRA_SIMPLE_LAYOUT = "simple_layout"; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java b/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java index 76968d455..08ab597dd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java @@ -233,8 +233,8 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return asyncTaskManager.add(task, true); } - public void createMuteAsync(final UserKey accountKey, final UserKey userKey) { - final CreateUserMuteTask task = new CreateUserMuteTask(context); + public void createMuteAsync(final UserKey accountKey, final UserKey userKey, boolean filterEverywhere) { + final CreateUserMuteTask task = new CreateUserMuteTask(context, filterEverywhere); task.setup(accountKey, userKey); TaskStarter.execute(task); } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt index 36260f03e..ac49bc6dd 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt @@ -34,12 +34,14 @@ import android.view.KeyEvent import android.view.MenuItem import android.view.Window import org.mariotaku.ktextension.convert +import org.mariotaku.ktextension.set import org.mariotaku.ktextension.toDoubleOrNull import org.mariotaku.twidere.Constants.* import org.mariotaku.twidere.R import org.mariotaku.twidere.activity.iface.IControlBarActivity import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarShowHideHelper import org.mariotaku.twidere.constant.CompatibilityConstants +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_SIMPLE_LAYOUT import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER_KEY import org.mariotaku.twidere.constant.KeyboardShortcutConstants import org.mariotaku.twidere.constant.SharedPreferenceConstants @@ -553,9 +555,11 @@ class LinkHandlerActivity : BaseActivity(), SystemWindowsInsetsCallback, IContro } LINK_ID_USER_BLOCKS -> { fragment = UserBlocksListFragment() + args[EXTRA_SIMPLE_LAYOUT] = true } LINK_ID_MUTES_USERS -> { fragment = MutesUsersListFragment() + args[EXTRA_SIMPLE_LAYOUT] = true } LINK_ID_DIRECT_MESSAGES_CONVERSATION -> { fragment = MessagesConversationFragment() diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DummyItemAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DummyItemAdapter.kt index b6171f4a2..479ca535b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DummyItemAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DummyItemAdapter.kt @@ -50,6 +50,7 @@ class DummyItemAdapter @JvmOverloads constructor( override var userClickListener: IUsersAdapter.UserClickListener? = null override var showAccountsColor: Boolean = false override var useStarsForLikes: Boolean = false + override var simpleLayout: Boolean = false private var showCardActions: Boolean = false private var showingActionCardPosition = RecyclerView.NO_POSITION diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableUsersAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableUsersAdapter.kt index eeb1b1225..2cd69bcca 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableUsersAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableUsersAdapter.kt @@ -47,7 +47,7 @@ class ParcelableUsersAdapter(context: Context) : LoadMoreSupportAdapter, inflater: LayoutInflater, parent: ViewGroup): UserViewHolder { val view = inflater.inflate(R.layout.list_item_user, parent, false) - val holder = UserViewHolder(adapter, view) + val holder = UserViewHolder(view, adapter, adapter.simpleLayout) holder.setOnClickListeners() holder.setupViewOptions() return holder diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/iface/IUsersAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/iface/IUsersAdapter.kt index f670e39f6..684d06d2f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/iface/IUsersAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/iface/IUsersAdapter.kt @@ -37,6 +37,8 @@ interface IUsersAdapter : IContentCardAdapter { val showAccountsColor: Boolean + val simpleLayout: Boolean + fun setData(data: Data?): Boolean fun getUser(position: Int): ParcelableUser? diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsUserMuteBlockDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsUserMuteBlockDialogFragment.kt new file mode 100644 index 000000000..67b0c59d7 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsUserMuteBlockDialogFragment.kt @@ -0,0 +1,70 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.fragment + +import android.app.Dialog +import android.content.DialogInterface +import android.os.Bundle +import android.support.v7.app.AlertDialog +import android.widget.CheckBox +import android.widget.TextView +import org.mariotaku.twidere.R +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER +import org.mariotaku.twidere.model.ParcelableUser + +abstract class AbsUserMuteBlockDialogFragment : BaseDialogFragment(), DialogInterface.OnClickListener { + + private val user: ParcelableUser by lazy { arguments.getParcelable(EXTRA_USER) } + + override fun onClick(dialog: DialogInterface, which: Int) { + when (which) { + DialogInterface.BUTTON_POSITIVE -> { + val filterEverywhere = ((dialog as Dialog).findViewById(R.id.filterEverywhereToggle) as CheckBox).isChecked + performUserAction(user, filterEverywhere) + } + else -> { + } + } + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val builder = AlertDialog.Builder(context) + builder.setTitle(getTitle(user)) + builder.setView(R.layout.dialog_block_mute_filter_user_confirm) + builder.setPositiveButton(android.R.string.ok, this) + builder.setNegativeButton(android.R.string.cancel, null) + val dialog = builder.create() + dialog.setOnShowListener { + val confirmMessageView = dialog.findViewById(R.id.confirmMessage) as TextView + val filterEverywhereHelp = dialog.findViewById(R.id.filterEverywhereHelp)!! + filterEverywhereHelp.setOnClickListener { + MessageDialogFragment.show(childFragmentManager, title = getString(R.string.filter_everywhere), + message = getString(R.string.filter_everywhere_description), tag = "filter_everywhere_help") + } + confirmMessageView.text = getMessage(user) + } + return dialog + } + + abstract fun performUserAction(user: ParcelableUser, filterEverywhere: Boolean) + + abstract fun getTitle(user: ParcelableUser): String + abstract fun getMessage(user: ParcelableUser): String +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddUserFilterDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddUserFilterDialogFragment.kt index 1837fd5fc..b486aa749 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddUserFilterDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddUserFilterDialogFragment.kt @@ -19,60 +19,32 @@ package org.mariotaku.twidere.fragment -import android.app.Dialog -import android.content.DialogInterface import android.os.Bundle import android.support.v4.app.FragmentManager -import android.support.v7.app.AlertDialog -import android.widget.CheckBox -import android.widget.TextView import android.widget.Toast import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST +import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.message.FriendshipTaskEvent import org.mariotaku.twidere.util.DataStoreUtils -class AddUserFilterDialogFragment : BaseDialogFragment(), DialogInterface.OnClickListener { - - private val user: ParcelableUser by lazy { arguments.getParcelable(EXTRA_USER) } - - override fun onClick(dialog: DialogInterface, which: Int) { - when (which) { - DialogInterface.BUTTON_POSITIVE -> { - val filterEverywhere = ((dialog as Dialog).findViewById(R.id.filterEverywhereToggle) as CheckBox).isChecked - DataStoreUtils.addToFilter(context, user, filterEverywhere) - bus.post(FriendshipTaskEvent(FriendshipTaskEvent.Action.FILTER, user.account_key, user.key).apply { - isFinished = true - isSucceeded = true - }) - Toast.makeText(context, R.string.message_toast_added_to_filter, Toast.LENGTH_SHORT).show() - } - else -> { - } - } +class AddUserFilterDialogFragment : AbsUserMuteBlockDialogFragment() { + override fun getMessage(user: ParcelableUser): String { + return getString(R.string.filter_user_confirm_message, userColorNameManager.getDisplayName(user, kPreferences[nameFirstKey])) } - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val builder = AlertDialog.Builder(context) - val nameFirst = preferences.getBoolean(KEY_NAME_FIRST) - val displayName = userColorNameManager.getDisplayName(user, nameFirst) - builder.setTitle(R.string.add_to_filter) - builder.setView(R.layout.dialog_filter_user_confirm) - builder.setPositiveButton(android.R.string.ok, this) - builder.setNegativeButton(android.R.string.cancel, null) - val dialog = builder.create() - dialog.setOnShowListener { - val confirmMessageView = dialog.findViewById(R.id.confirmMessage) as TextView - val filterEverywhereHelp = dialog.findViewById(R.id.filterEverywhereHelp)!! - filterEverywhereHelp.setOnClickListener { - MessageDialogFragment.show(childFragmentManager, title = getString(R.string.filter_everywhere), - message = getString(R.string.filter_everywhere_description), tag = "filter_everywhere_help") - } - confirmMessageView.text = getString(R.string.filter_user_confirm_message, displayName) - } - return dialog + override fun getTitle(user: ParcelableUser): String { + return getString(R.string.add_to_filter) + } + + override fun performUserAction(user: ParcelableUser, filterEverywhere: Boolean) { + DataStoreUtils.addToFilter(context, user, filterEverywhere) + bus.post(FriendshipTaskEvent(FriendshipTaskEvent.Action.FILTER, user.account_key, user.key).apply { + isFinished = true + isSucceeded = true + }) + Toast.makeText(context, R.string.message_toast_added_to_filter, Toast.LENGTH_SHORT).show() } companion object { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseDialogFragment.kt index 3113e3472..29493bf1e 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseDialogFragment.kt @@ -22,6 +22,7 @@ package org.mariotaku.twidere.fragment import android.content.Context import android.support.v4.app.DialogFragment import com.squareup.otto.Bus +import org.mariotaku.kpreferences.KPreferences import org.mariotaku.twidere.Constants import org.mariotaku.twidere.util.* import org.mariotaku.twidere.util.dagger.GeneralComponentHelper @@ -36,6 +37,8 @@ open class BaseDialogFragment : DialogFragment(), Constants { @Inject lateinit var preferences: SharedPreferencesWrapper @Inject + lateinit var kPreferences: KPreferences + @Inject lateinit var validator: TwidereValidator @Inject lateinit var keyboardShortcutsHandler: KeyboardShortcutsHandler diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CreateUserBlockDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CreateUserBlockDialogFragment.kt index 00dc6ec29..038d50b91 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CreateUserBlockDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CreateUserBlockDialogFragment.kt @@ -19,52 +19,26 @@ package org.mariotaku.twidere.fragment -import android.app.Dialog -import android.content.DialogInterface import android.os.Bundle import android.support.v4.app.FragmentManager -import android.support.v7.app.AlertDialog -import android.widget.CheckBox -import android.widget.TextView import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST +import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.model.ParcelableUser -class CreateUserBlockDialogFragment : BaseDialogFragment(), DialogInterface.OnClickListener { - - private val user: ParcelableUser by lazy { arguments.getParcelable(EXTRA_USER) } - - override fun onClick(dialog: DialogInterface, which: Int) { - when (which) { - DialogInterface.BUTTON_POSITIVE -> { - val filterEverywhere = ((dialog as Dialog).findViewById(R.id.filterEverywhereToggle) as CheckBox).isChecked - twitterWrapper.createBlockAsync(user.account_key, user.key, filterEverywhere) - } - else -> { - } - } +class CreateUserBlockDialogFragment : AbsUserMuteBlockDialogFragment() { + override fun getMessage(user: ParcelableUser): String { + val displayName = userColorNameManager.getDisplayName(user, kPreferences[nameFirstKey]) + return getString(R.string.block_user_confirm_message, displayName) } - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val builder = AlertDialog.Builder(context) - val nameFirst = preferences.getBoolean(KEY_NAME_FIRST) - val displayName = userColorNameManager.getDisplayName(user, nameFirst) - builder.setTitle(getString(R.string.block_user, displayName)) - builder.setView(R.layout.dialog_block_user_confirm) - builder.setPositiveButton(android.R.string.ok, this) - builder.setNegativeButton(android.R.string.cancel, null) - val dialog = builder.create() - dialog.setOnShowListener { - val confirmMessageView = dialog.findViewById(R.id.confirmMessage) as TextView - val filterEverywhereHelp = dialog.findViewById(R.id.filterEverywhereHelp)!! - filterEverywhereHelp.setOnClickListener { - MessageDialogFragment.show(childFragmentManager, title = getString(R.string.filter_everywhere), - message = getString(R.string.filter_everywhere_description), tag = "filter_everywhere_help") - } - confirmMessageView.text = getString(R.string.block_user_confirm_message, displayName) - } - return dialog + override fun getTitle(user: ParcelableUser): String { + val displayName = userColorNameManager.getDisplayName(user, kPreferences[nameFirstKey]) + return getString(R.string.block_user, displayName) + } + + override fun performUserAction(user: ParcelableUser, filterEverywhere: Boolean) { + twitterWrapper.createBlockAsync(user.account_key, user.key, filterEverywhere) } companion object { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CreateUserMuteDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CreateUserMuteDialogFragment.kt index 358372733..d339b9ab1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CreateUserMuteDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CreateUserMuteDialogFragment.kt @@ -19,52 +19,28 @@ package org.mariotaku.twidere.fragment -import android.app.Dialog -import android.content.DialogInterface import android.os.Bundle import android.support.v4.app.FragmentManager -import android.support.v7.app.AlertDialog import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST +import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.model.ParcelableUser -class CreateUserMuteDialogFragment : BaseDialogFragment(), DialogInterface.OnClickListener { +class CreateUserMuteDialogFragment : AbsUserMuteBlockDialogFragment() { - override fun onClick(dialog: DialogInterface, which: Int) { - when (which) { - DialogInterface.BUTTON_POSITIVE -> { - val user = user - val twitter = twitterWrapper - if (user == null) return - twitter.createMuteAsync(user.account_key, user.key) - } - else -> { - } - } + override fun getMessage(user: ParcelableUser): String { + val displayName = userColorNameManager.getDisplayName(user, kPreferences[nameFirstKey]) + return getString(R.string.mute_user_confirm_message, displayName) } - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val context = context - val builder = AlertDialog.Builder(context) - val user = user - if (user != null) { - val nameFirst = preferences.getBoolean(KEY_NAME_FIRST) - val displayName = userColorNameManager.getDisplayName(user, nameFirst) - builder.setTitle(getString(R.string.mute_user, displayName)) - builder.setMessage(getString(R.string.mute_user_confirm_message, displayName)) - } - builder.setPositiveButton(android.R.string.ok, this) - builder.setNegativeButton(android.R.string.cancel, null) - return builder.create() + override fun getTitle(user: ParcelableUser): String { + val displayName = userColorNameManager.getDisplayName(user, kPreferences[nameFirstKey]) + return getString(R.string.mute_user, displayName) } - private val user: ParcelableUser? - get() { - val args = arguments - if (!args.containsKey(EXTRA_USER)) return null - return args.getParcelable(EXTRA_USER) - } + override fun performUserAction(user: ParcelableUser, filterEverywhere: Boolean) { + twitterWrapper.createMuteAsync(user.account_key, user.key, filterEverywhere) + } companion object { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MutesUsersListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MutesUsersListFragment.kt index e59a957c3..1b054a048 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MutesUsersListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MutesUsersListFragment.kt @@ -25,6 +25,7 @@ import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY import org.mariotaku.twidere.loader.CursorSupportUsersLoader import org.mariotaku.twidere.loader.MutesUsersLoader import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.message.FriendshipTaskEvent class MutesUsersListFragment : CursorSupportUsersListFragment() { @@ -38,4 +39,13 @@ class MutesUsersListFragment : CursorSupportUsersListFragment() { return loader } + override fun shouldRemoveUser(position: Int, event: FriendshipTaskEvent): Boolean { + if (!event.isSucceeded) return false + when (event.action) { + FriendshipTaskEvent.Action.UNMUTE -> { + return true + } + } + return false + } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt index 8e214e6ef..afe0f3934 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt @@ -38,6 +38,7 @@ import org.mariotaku.twidere.adapter.iface.IUsersAdapter import org.mariotaku.twidere.adapter.iface.IUsersAdapter.UserClickListener import org.mariotaku.twidere.annotation.Referral import org.mariotaku.twidere.constant.IntentConstants +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_SIMPLE_LAYOUT import org.mariotaku.twidere.constant.SharedPreferenceConstants import org.mariotaku.twidere.loader.iface.IExtendedLoader import org.mariotaku.twidere.model.ParcelableUser @@ -93,6 +94,7 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment, - itemView: View + private val simple: Boolean = false ) : ViewHolder(itemView), OnClickListener, OnLongClickListener { private val itemContent: IColorLabelView @@ -64,31 +63,55 @@ class UserViewHolder( private val actionsProgressContainer: View private val actionsContainer: View private val processingRequestProgress: View + private val countsContainer: LinearLayout private var userClickListener: UserClickListener? = null private var requestClickListener: RequestClickListener? = null + private var friendshipClickListener: FriendshipClickListener? = null init { - itemContent = itemView.findViewById(R.id.itemContent) as IColorLabelView - profileImageView = itemView.findViewById(R.id.profileImage) as ImageView - profileTypeView = itemView.findViewById(R.id.profileType) as ImageView - nameView = itemView.findViewById(R.id.name) as NameView - externalIndicator = itemView.findViewById(R.id.externalIndicator) as TextView - descriptionView = itemView.findViewById(R.id.description) as TextView - locationView = itemView.findViewById(R.id.location) as TextView - urlView = itemView.findViewById(R.id.url) as TextView - statusesCountView = itemView.findViewById(R.id.statusesCount) as TextView - followersCountView = itemView.findViewById(R.id.followersCount) as TextView - friendsCountView = itemView.findViewById(R.id.friendsCount) as TextView - actionsProgressContainer = itemView.findViewById(R.id.actionsProgressContainer) - actionsContainer = itemView.findViewById(R.id.actionsContainer) + itemContent = itemView.itemContent + profileImageView = itemView.profileImage + profileTypeView = itemView.profileType + nameView = itemView.name + externalIndicator = itemView.externalIndicator + descriptionView = itemView.description + locationView = itemView.location + urlView = itemView.url + statusesCountView = itemView.statusesCount + followersCountView = itemView.followersCount + friendsCountView = itemView.friendsCount + actionsProgressContainer = itemView.actionsProgressContainer + actionsContainer = itemView.actionsContainer acceptRequestButton = itemView.acceptRequest denyRequestButton = itemView.denyRequest unblockButton = itemView.unblock unmuteButton = itemView.unmute followButton = itemView.follow + countsContainer = itemView.countsContainer processingRequestProgress = itemView.findViewById(R.id.processingRequest) + + if (simple) { + externalIndicator.visibility = View.GONE + descriptionView.visibility = View.GONE + locationView.visibility = View.GONE + urlView.visibility = View.GONE + countsContainer.visibility = View.GONE + + itemView.profileImageContainer.layoutParams.apply { + (this as RelativeLayout.LayoutParams).clearVerticalRules() + this.addRule(RelativeLayout.CENTER_VERTICAL) + } + nameView.layoutParams.apply { + (this as RelativeLayout.LayoutParams).clearVerticalRules() + this.addRule(RelativeLayout.CENTER_VERTICAL) + } + actionsProgressContainer.layoutParams.apply { + (this as RelativeLayout.LayoutParams).clearVerticalRules() + this.addRule(RelativeLayout.CENTER_VERTICAL) + } + } } fun displayUser(user: ParcelableUser) { @@ -98,7 +121,6 @@ class UserViewHolder( val manager = adapter.userColorNameManager val twitter = adapter.twitterWrapper - itemContent.drawStart(manager.getUserColor(user.key)) val userTypeRes = getUserTypeIconRes(user.is_verified, user.is_protected) @@ -110,16 +132,7 @@ class UserViewHolder( nameView.setName(manager.getUserNickname(user.key, user.name)) nameView.setScreenName("@${user.screen_name}") nameView.updateText(adapter.bidiFormatter) - descriptionView.visibility = if (TextUtils.isEmpty(user.description_unescaped)) View.GONE else View.VISIBLE - descriptionView.text = user.description_unescaped - locationView.visibility = if (TextUtils.isEmpty(user.location)) View.GONE else View.VISIBLE - locationView.text = user.location - urlView.visibility = if (TextUtils.isEmpty(user.url_expanded)) View.GONE else View.VISIBLE - urlView.text = user.url_expanded - val locale = Locale.getDefault() - statusesCountView.text = getLocalizedNumber(locale, user.statuses_count) - followersCountView.text = getLocalizedNumber(locale, user.followers_count) - friendsCountView.text = getLocalizedNumber(locale, user.friends_count) + if (adapter.profileImageEnabled) { profileImageView.visibility = View.VISIBLE loader.displayProfileImage(profileImageView, user) @@ -142,10 +155,7 @@ class UserViewHolder( externalIndicator.text = context.getString(R.string.external_user_host_format, user.key.host) } - followButton.setImageResource(if (user.is_following) - R.drawable.ic_action_confirm - else - R.drawable.ic_action_add) + followButton.setImageResource(if (user.is_following) R.drawable.ic_action_confirm else R.drawable.ic_action_add) followButton.isActivated = user.is_following val isMySelf = user.account_key == user.key @@ -171,6 +181,19 @@ class UserViewHolder( unblockButton.visibility = View.GONE unmuteButton.visibility = View.GONE } + + if (!simple) { + descriptionView.visibility = if (TextUtils.isEmpty(user.description_unescaped)) View.GONE else View.VISIBLE + descriptionView.text = user.description_unescaped + locationView.visibility = if (TextUtils.isEmpty(user.location)) View.GONE else View.VISIBLE + locationView.text = user.location + urlView.visibility = if (TextUtils.isEmpty(user.url_expanded)) View.GONE else View.VISIBLE + urlView.text = user.url_expanded + val locale = Locale.getDefault() + statusesCountView.text = Utils.getLocalizedNumber(locale, user.statuses_count) + followersCountView.text = Utils.getLocalizedNumber(locale, user.followers_count) + friendsCountView.text = Utils.getLocalizedNumber(locale, user.friends_count) + } } override fun onClick(v: View) { @@ -190,6 +213,9 @@ class UserViewHolder( R.id.unblock -> { friendshipClickListener?.onUnblockClicked(this, layoutPosition) } + R.id.unmute -> { + friendshipClickListener?.onUnmuteClicked(this, layoutPosition) + } } } @@ -249,3 +275,10 @@ class UserViewHolder( } } + +private fun RelativeLayout.LayoutParams.clearVerticalRules() { + intArrayOf(RelativeLayout.ABOVE, RelativeLayout.BELOW, RelativeLayout.ALIGN_BASELINE, + RelativeLayout.ALIGN_TOP, RelativeLayout.ALIGN_BOTTOM).forEach { verb -> + removeRule(verb) + } +} diff --git a/twidere/src/main/res/layout/dialog_filter_user_confirm.xml b/twidere/src/main/res/layout/dialog_block_mute_filter_user_confirm.xml similarity index 100% rename from twidere/src/main/res/layout/dialog_filter_user_confirm.xml rename to twidere/src/main/res/layout/dialog_block_mute_filter_user_confirm.xml diff --git a/twidere/src/main/res/layout/dialog_block_user_confirm.xml b/twidere/src/main/res/layout/dialog_block_user_confirm.xml deleted file mode 100644 index 76fa7ab2d..000000000 --- a/twidere/src/main/res/layout/dialog_block_user_confirm.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/twidere/src/main/res/layout/list_item_user.xml b/twidere/src/main/res/layout/list_item_user.xml index d4eab830b..4c1c6e281 100644 --- a/twidere/src/main/res/layout/list_item_user.xml +++ b/twidere/src/main/res/layout/list_item_user.xml @@ -26,6 +26,7 @@ android:layout_height="wrap_content" android:background="?selectableItemBackground" android:clipChildren="false" + android:clipToPadding="false" android:padding="@dimen/element_spacing_normal" app:ignorePadding="true" tools:context=".adapter.ParcelableUsersAdapter"> @@ -41,6 +42,7 @@ android:layout_marginEnd="@dimen/element_spacing_normal" android:layout_marginRight="@dimen/element_spacing_normal" android:clipChildren="false" + android:clipToPadding="false" tools:visibility="visible"> -