enable multiple hashtags in one hashtag tab (#1790)
* enable multiple hashtags in one hashtag tab * add comment explaining the code in TabAdapter * delete unused drawables * add padding to EditText in dialog
This commit is contained in:
parent
2fc7ad13bb
commit
df8dc3a198
39 changed files with 105 additions and 121 deletions
|
@ -19,7 +19,9 @@ import android.view.LayoutInflater
|
|||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.size
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.keylesspalace.tusky.HASHTAG
|
||||
import com.keylesspalace.tusky.LIST
|
||||
import com.keylesspalace.tusky.R
|
||||
|
@ -29,13 +31,13 @@ import com.keylesspalace.tusky.util.hide
|
|||
import com.keylesspalace.tusky.util.show
|
||||
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)
|
||||
fun onChipClicked(tab: TabData, chipPosition: Int)
|
||||
}
|
||||
|
||||
class TabAdapter(private var data: List<TabData>,
|
||||
|
@ -86,9 +88,9 @@ class TabAdapter(private var data: List<TabData>,
|
|||
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.textColorDisabled)
|
||||
holder.itemView.context,
|
||||
holder.itemView.removeButton.drawable,
|
||||
(if (removeButtonEnabled) android.R.attr.textColorTertiary else R.attr.textColorDisabled)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -96,11 +98,38 @@ class TabAdapter(private var data: List<TabData>,
|
|||
|
||||
if (data[position].id == HASHTAG) {
|
||||
holder.itemView.chipGroup.show()
|
||||
holder.itemView.actionChip.text = data[position].arguments[0]
|
||||
|
||||
holder.itemView.actionChip.setChipIconResource(R.drawable.ic_edit_chip)
|
||||
/*
|
||||
* The chip group will always contain the actionChip (it is defined in the xml layout).
|
||||
* The other dynamic chips are inserted in front of the actionChip.
|
||||
* This code tries to reuse already added chips to reduce the number of Views created.
|
||||
*/
|
||||
data[position].arguments.forEachIndexed { i, arg ->
|
||||
|
||||
val chip = holder.itemView.chipGroup.getChildAt(i).takeUnless { it.id == R.id.actionChip } as Chip?
|
||||
?: Chip(context).apply {
|
||||
text = arg
|
||||
holder.itemView.chipGroup.addView(this, holder.itemView.chipGroup.size - 1)
|
||||
}
|
||||
|
||||
chip.text = arg
|
||||
|
||||
if(data[position].arguments.size <= 1) {
|
||||
chip.chipIcon = null
|
||||
chip.setOnClickListener(null)
|
||||
} else {
|
||||
val cancelIcon = ThemeUtils.getTintedDrawable(context, R.drawable.ic_cancel_24dp, android.R.attr.textColorPrimary)
|
||||
chip.chipIcon = cancelIcon
|
||||
chip.setOnClickListener {
|
||||
listener.onChipClicked(data[position], i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while(holder.itemView.chipGroup.size - 1 > data[position].arguments.size) {
|
||||
holder.itemView.chipGroup.removeViewAt(data[position].arguments.size - 1)
|
||||
}
|
||||
|
||||
holder.itemView.actionChip.chipIcon = context.getDrawable(R.drawable.ic_edit_chip)
|
||||
holder.itemView.actionChip.setOnClickListener {
|
||||
listener.onActionChipClicked(data[position])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue