diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index c1ab87a69..60b9324b6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -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); diff --git a/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt b/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt index fe8783acd..f7b38055b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt @@ -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) { diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/TabAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/TabAdapter.kt index a16898198..bc252ab98 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/TabAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/TabAdapter.kt @@ -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, - private val small: Boolean = false, - private val listener: ItemInteractionListener? = null) : RecyclerView.Adapter() { + private val small: Boolean, + private val listener: ItemInteractionListener, + private var removeButtonEnabled: Boolean = false) : RecyclerView.Adapter() { fun updateData(newData: List) { this.data = newData @@ -67,17 +69,28 @@ class TabAdapter(private var data: List, 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, 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, return data.size } + fun setRemoveButtonVisible(enabled: Boolean) { + if (removeButtonEnabled != enabled) { + removeButtonEnabled = enabled + notifyDataSetChanged() + } + } + class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) } diff --git a/app/src/main/res/layout/item_tab_preference.xml b/app/src/main/res/layout/item_tab_preference.xml index e76c23999..deebdb907 100644 --- a/app/src/main/res/layout/item_tab_preference.xml +++ b/app/src/main/res/layout/item_tab_preference.xml @@ -7,7 +7,7 @@ android:background="?android:colorBackground" android:orientation="horizontal" android:paddingStart="16dp" - android:paddingTop="16dp" + android:paddingTop="8dp" android:paddingEnd="16dp"> @@ -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" /> + + - diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index 643a42066..90e692c49 100644 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -47,7 +47,7 @@ @color/account_toolbar_icon_collapsed_dark @color/toolbar_icon_dark - @color/compose_media_button_disabled_dark + @color/image_button_disabled_dark @drawable/border_background_dark @color/compose_reply_content_background_dark diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 46395bb91..2be804853 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -30,7 +30,7 @@ - + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 92770f4cf..35a972cd2 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -26,7 +26,7 @@ #2f3441 #1a1c23 #ffffff - #586173 + #586173 #313543 #373c4b #424a5b @@ -54,7 +54,7 @@ #cfcfcf #cfcfcf #DE000000 - #a3a5ab + #a3a5ab #EFEFEF #ffffff #e0e1e6 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5eb6c78b0..8251dfd63 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -105,7 +105,7 @@ @color/toolbar_icon_light - @color/compose_media_button_disabled_light + @color/image_button_disabled_light @drawable/border_background_light