Add close icon to tabs in Tabs account preferences page (#1588)

* Add close icon to tabs in Tabs account preferences page

* Improve code according to code review
This commit is contained in:
Mélanie Chauvel (ariasuni) 2019-12-19 18:35:55 +01:00 committed by Konrad Pozniak
parent bac3003182
commit 54b3d1f8cd
8 changed files with 62 additions and 21 deletions

View File

@ -1289,7 +1289,7 @@ public final class ComposeActivity
private void enableButton(ImageButton button, boolean clickable, boolean colorActive) {
button.setEnabled(clickable);
ThemeUtils.setDrawableTint(this, button.getDrawable(),
colorActive ? android.R.attr.textColorTertiary : R.attr.compose_media_button_disabled_tint);
colorActive ? android.R.attr.textColorTertiary : R.attr.image_button_disabled_tint);
}
private void enablePollButton(boolean enable) {
@ -1298,7 +1298,7 @@ public final class ComposeActivity
if(enable) {
textColor = ThemeUtils.getColor(this, android.R.attr.textColorTertiary);
} else {
textColor = ThemeUtils.getColor(this, R.attr.compose_media_button_disabled_tint);
textColor = ThemeUtils.getColor(this, R.attr.image_button_disabled_tint);
}
actionAddPoll.setTextColor(textColor);
actionAddPoll.getCompoundDrawablesRelative()[0].setColorFilter(textColor, PorterDuff.Mode.SRC_IN);

View File

@ -41,6 +41,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_tab_preference.*
import kotlinx.android.synthetic.main.toolbar_basic.*
import kotlinx.android.synthetic.main.item_tab_preference.view.removeButton
import java.util.regex.Pattern
import javax.inject.Inject
@ -76,7 +77,7 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene
}
currentTabs = (accountManager.activeAccount?.tabPreferences ?: emptyList()).toMutableList()
currentTabsAdapter = TabAdapter(currentTabs, false, this)
currentTabsAdapter = TabAdapter(currentTabs, false, this, currentTabs.size <= MIN_TAB_COUNT)
currentTabsRecyclerView.adapter = currentTabsAdapter
currentTabsRecyclerView.layoutManager = LinearLayoutManager(this)
currentTabsRecyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayoutManager.VERTICAL))
@ -109,10 +110,7 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
currentTabs.removeAt(viewHolder.adapterPosition)
currentTabsAdapter.notifyItemRemoved(viewHolder.adapterPosition)
updateAvailableTabs()
saveTabs()
onTabRemoved(viewHolder.adapterPosition)
}
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
@ -168,6 +166,13 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene
saveTabs()
}
override fun onTabRemoved(position: Int) {
currentTabs.removeAt(position)
currentTabsAdapter.notifyItemRemoved(position)
updateAvailableTabs()
saveTabs()
}
override fun onActionChipClicked(tab: TabData) {
showEditHashtagDialog(tab)
}
@ -273,7 +278,7 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene
addTabAdapter.updateData(addableTabs)
maxTabsInfo.visible(addableTabs.size == 0 || currentTabs.size >= MAX_TAB_COUNT)
currentTabsAdapter.setRemoveButtonVisible(currentTabs.size > MIN_TAB_COUNT);
}
override fun onStartDelete(viewHolder: RecyclerView.ViewHolder) {

View File

@ -32,14 +32,16 @@ import kotlinx.android.synthetic.main.item_tab_preference.view.*
interface ItemInteractionListener {
fun onTabAdded(tab: TabData)
fun onTabRemoved(position: Int)
fun onStartDelete(viewHolder: RecyclerView.ViewHolder)
fun onStartDrag(viewHolder: RecyclerView.ViewHolder)
fun onActionChipClicked(tab: TabData)
}
class TabAdapter(private var data: List<TabData>,
private val small: Boolean = false,
private val listener: ItemInteractionListener? = null) : RecyclerView.Adapter<TabAdapter.ViewHolder>() {
private val small: Boolean,
private val listener: ItemInteractionListener,
private var removeButtonEnabled: Boolean = false) : RecyclerView.Adapter<TabAdapter.ViewHolder>() {
fun updateData(newData: List<TabData>) {
this.data = newData
@ -67,17 +69,28 @@ class TabAdapter(private var data: List<TabData>,
holder.itemView.textView.setCompoundDrawablesRelativeWithIntrinsicBounds(iconDrawable, null, null, null)
if (small) {
holder.itemView.textView.setOnClickListener {
listener?.onTabAdded(data[position])
listener.onTabAdded(data[position])
}
}
holder.itemView.imageView?.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
listener?.onStartDrag(holder)
listener.onStartDrag(holder)
true
} else {
false
}
}
holder.itemView.removeButton?.setOnClickListener {
listener.onTabRemoved(holder.adapterPosition)
}
if (holder.itemView.removeButton != null) {
holder.itemView.removeButton.isEnabled = removeButtonEnabled
ThemeUtils.setDrawableTint(
holder.itemView.context,
holder.itemView.removeButton.drawable,
(if (removeButtonEnabled) android.R.attr.textColorTertiary else R.attr.image_button_disabled_tint)
)
}
if (!small) {
@ -89,7 +102,7 @@ class TabAdapter(private var data: List<TabData>,
holder.itemView.actionChip.chipIcon = context.getDrawable(R.drawable.ic_edit_chip)
holder.itemView.actionChip.setOnClickListener {
listener?.onActionChipClicked(data[position])
listener.onActionChipClicked(data[position])
}
} else {
@ -102,5 +115,12 @@ class TabAdapter(private var data: List<TabData>,
return data.size
}
fun setRemoveButtonVisible(enabled: Boolean) {
if (removeButtonEnabled != enabled) {
removeButtonEnabled = enabled
notifyDataSetChanged()
}
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}

View File

@ -7,7 +7,7 @@
android:background="?android:colorBackground"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp">
<ImageView
@ -15,6 +15,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_drag_indicator_24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -24,6 +26,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_weight="1"
android:drawablePadding="12dp"
android:textColor="?android:attr/textColorSecondary"
@ -32,10 +36,23 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/imageView"
app:layout_constraintTop_toTopOf="parent"
app:layout_goneMarginBottom="16dp"
app:layout_goneMarginBottom="8dp"
tools:drawableStart="@drawable/ic_home_24dp"
tools:text="Home" />
<ImageButton
android:id="@+id/removeButton"
style="?attr/image_button_style"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="end"
android:layout_marginTop="4dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/action_delete"
android:src="@drawable/ic_clear_24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="match_parent"
@ -56,4 +73,3 @@
</com.google.android.material.chip.ChipGroup>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -47,7 +47,7 @@
<item name="account_toolbar_icon_tint_collapsed">@color/account_toolbar_icon_collapsed_dark</item>
<item name="compose_close_button_tint">@color/toolbar_icon_dark</item>
<item name="compose_media_button_disabled_tint">@color/compose_media_button_disabled_dark</item>
<item name="image_button_disabled_tint">@color/image_button_disabled_dark</item>
<item name="compose_content_warning_bar_background">@drawable/border_background_dark</item>
<item name="compose_reply_content_background">@color/compose_reply_content_background_dark</item>

View File

@ -30,7 +30,7 @@
<attr name="account_toolbar_icon_tint_uncollapsed" format="reference|color" />
<attr name="account_toolbar_icon_tint_collapsed" format="reference|color" />
<attr name="compose_close_button_tint" format="reference|color" />
<attr name="compose_media_button_disabled_tint" format="reference|color" />
<attr name="image_button_disabled_tint" format="reference|color" />
<attr name="compose_content_warning_bar_background" format="reference" />
<attr name="compose_reply_content_background" format="reference|color" />
<attr name="report_status_background_color" format="reference|color" />

View File

@ -26,7 +26,7 @@
<color name="status_divider_dark">#2f3441</color>
<color name="tab_page_margin_dark">#1a1c23</color>
<color name="account_toolbar_icon_collapsed_dark">#ffffff</color>
<color name="compose_media_button_disabled_dark">#586173</color>
<color name="image_button_disabled_dark">#586173</color>
<color name="custom_tab_toolbar_dark">#313543</color>
<color name="compose_reply_content_background_dark">#373c4b</color>
<color name="autocomplete_divider_dark">#424a5b</color>
@ -54,7 +54,7 @@
<color name="status_divider_light">#cfcfcf</color>
<color name="tab_page_margin_light">#cfcfcf</color>
<color name="account_toolbar_icon_collapsed_light">#DE000000</color>
<color name="compose_media_button_disabled_light">#a3a5ab</color>
<color name="image_button_disabled_light">#a3a5ab</color>
<color name="report_status_background_light">#EFEFEF</color>
<color name="custom_tab_toolbar_light">#ffffff</color>
<color name="compose_reply_content_background_light">#e0e1e6</color>

View File

@ -105,7 +105,7 @@
</item>
<item name="compose_close_button_tint">@color/toolbar_icon_light</item>
<item name="compose_media_button_disabled_tint">@color/compose_media_button_disabled_light
<item name="image_button_disabled_tint">@color/image_button_disabled_light
</item>
<item name="compose_content_warning_bar_background">@drawable/border_background_light</item>
<item name="compose_reply_content_background">