mirror of https://github.com/tasks/tasks
parent
e6e275834a
commit
4b892a0eb1
@ -1,70 +0,0 @@
|
|||||||
package org.tasks.tags
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.view.View
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import org.tasks.R
|
|
||||||
import org.tasks.data.TagData
|
|
||||||
import org.tasks.databinding.RowTagPickerBinding
|
|
||||||
import org.tasks.themes.DrawableUtil
|
|
||||||
|
|
||||||
class TagPickerViewHolder internal constructor(
|
|
||||||
private val context: Context,
|
|
||||||
binding: RowTagPickerBinding,
|
|
||||||
private val callback: (TagData, TagPickerViewHolder) -> Unit
|
|
||||||
) : RecyclerView.ViewHolder(binding.root) {
|
|
||||||
|
|
||||||
val isChecked: Boolean
|
|
||||||
get() = checkBox.isChecked
|
|
||||||
|
|
||||||
private val text: TextView = binding.text
|
|
||||||
private val checkBox: CheckBoxTriStates = binding.checkbox.apply {
|
|
||||||
setOnCheckedChangeListener { _, _ -> onCheckedChanged() }
|
|
||||||
}
|
|
||||||
private var tagData: TagData? = null
|
|
||||||
|
|
||||||
private fun onClickRow() {
|
|
||||||
if (tagData!!.id == null) {
|
|
||||||
callback(tagData!!, this)
|
|
||||||
} else {
|
|
||||||
checkBox.toggle()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onCheckedChanged() {
|
|
||||||
callback(tagData!!, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bind(
|
|
||||||
tagData: TagData, color: Int, icon: Int?, state: CheckBoxTriStates.State) {
|
|
||||||
var icon = icon
|
|
||||||
this.tagData = tagData
|
|
||||||
if (tagData.id == null) {
|
|
||||||
text.text = context.getString(R.string.create_new_tag, tagData.name)
|
|
||||||
icon = R.drawable.ic_outline_add_24px
|
|
||||||
checkBox.visibility = View.GONE
|
|
||||||
} else {
|
|
||||||
text.text = tagData.name
|
|
||||||
if (state == CheckBoxTriStates.State.CHECKED) {
|
|
||||||
checkBox.isChecked = true
|
|
||||||
} else {
|
|
||||||
updateCheckbox(state)
|
|
||||||
}
|
|
||||||
if (icon == null) {
|
|
||||||
icon = R.drawable.ic_outline_label_24px
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DrawableUtil.setLeftDrawable(context, text, icon)
|
|
||||||
DrawableUtil.setTint(DrawableUtil.getLeftDrawable(text), color)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateCheckbox(state: CheckBoxTriStates.State) {
|
|
||||||
checkBox.setState(state, false)
|
|
||||||
checkBox.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
binding.tagRow.setOnClickListener { onClickRow() }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:descendantFocusability="beforeDescendants"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
|
||||||
android:id="@+id/toolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?attr/actionBarSize"
|
|
||||||
android:elevation="@dimen/elevation_toolbar"
|
|
||||||
android:theme="@style/ToolbarTheme"
|
|
||||||
android:background="@color/content_background"
|
|
||||||
app:popupTheme="@style/popup_overlay"
|
|
||||||
app:titleTextColor="@color/text_primary"
|
|
||||||
tools:ignore="UnusedAttribute">
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/search_input"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="@null"
|
|
||||||
android:hint="@string/enter_tag_name"
|
|
||||||
android:imeOptions="flagNoExtractUi"
|
|
||||||
android:inputType="textCapSentences|textAutoCorrect"
|
|
||||||
android:lines="1"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:scrollbars="vertical"
|
|
||||||
android:textColor="@color/text_primary"
|
|
||||||
android:textColorHint="@color/text_secondary" />
|
|
||||||
|
|
||||||
</androidx.appcompat.widget.Toolbar>
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/recycler_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@ -1,32 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/tag_row"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="56dp"
|
|
||||||
android:background="?android:attr/selectableItemBackground"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true">
|
|
||||||
|
|
||||||
<org.tasks.tags.CheckBoxTriStates
|
|
||||||
android:id="@+id/checkbox"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:padding="12dp" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_toStartOf="@id/checkbox"
|
|
||||||
android:drawablePadding="@dimen/keyline_second"
|
|
||||||
android:textColor="@color/text_primary"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:paddingStart="@dimen/keyline_first"
|
|
||||||
android:paddingEnd="@dimen/keyline_first"
|
|
||||||
android:textSize="@dimen/task_edit_text_size" />
|
|
||||||
</RelativeLayout>
|
|
Loading…
Reference in New Issue