2017-01-02 06:09:23 -05:00
|
|
|
package eu.kanade.tachiyomi.widget
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2020-02-26 18:12:44 -05:00
|
|
|
import android.widget.CheckBox
|
|
|
|
import android.widget.CheckedTextView
|
|
|
|
import android.widget.EditText
|
|
|
|
import android.widget.RadioButton
|
|
|
|
import android.widget.Spinner
|
|
|
|
import android.widget.TextView
|
2020-01-07 19:20:08 -05:00
|
|
|
import androidx.appcompat.widget.TintTypedArray
|
|
|
|
import androidx.core.view.ViewCompat
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import com.google.android.material.R
|
2020-01-05 11:29:27 -05:00
|
|
|
import com.google.android.material.internal.ScrimInsetsFrameLayout
|
2020-01-07 19:20:08 -05:00
|
|
|
import com.google.android.material.textfield.TextInputLayout
|
2020-02-26 18:03:34 -05:00
|
|
|
import eu.kanade.tachiyomi.R as TR
|
2020-02-02 22:22:54 -05:00
|
|
|
import eu.kanade.tachiyomi.util.view.inflate
|
2017-01-02 06:09:23 -05:00
|
|
|
|
|
|
|
@Suppress("LeakingThis")
|
2020-01-05 11:29:27 -05:00
|
|
|
@SuppressLint("PrivateResource", "RestrictedApi")
|
2017-01-02 06:09:23 -05:00
|
|
|
open class SimpleNavigationView @JvmOverloads constructor(
|
2020-02-26 18:03:34 -05:00
|
|
|
context: Context,
|
|
|
|
attrs: AttributeSet? = null,
|
|
|
|
defStyleAttr: Int = 0
|
2020-03-28 17:17:21 -04:00
|
|
|
) : ScrimInsetsFrameLayout(context, attrs, defStyleAttr) {
|
2017-01-02 06:09:23 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Recycler view containing all the items.
|
|
|
|
*/
|
|
|
|
protected val recycler = RecyclerView(context)
|
|
|
|
|
|
|
|
init {
|
|
|
|
// Custom attributes
|
|
|
|
val a = TintTypedArray.obtainStyledAttributes(context, attrs,
|
|
|
|
R.styleable.NavigationView, defStyleAttr,
|
|
|
|
R.style.Widget_Design_NavigationView)
|
|
|
|
|
|
|
|
ViewCompat.setBackground(
|
|
|
|
this, a.getDrawable(R.styleable.NavigationView_android_background))
|
|
|
|
|
|
|
|
if (a.hasValue(R.styleable.NavigationView_elevation)) {
|
|
|
|
ViewCompat.setElevation(this, a.getDimensionPixelSize(
|
|
|
|
R.styleable.NavigationView_elevation, 0).toFloat())
|
|
|
|
}
|
|
|
|
|
|
|
|
a.recycle()
|
|
|
|
|
|
|
|
recycler.layoutManager = LinearLayoutManager(context)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base view holder.
|
|
|
|
*/
|
|
|
|
abstract class Holder(view: View) : RecyclerView.ViewHolder(view)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Separator view holder.
|
|
|
|
*/
|
2020-02-26 18:03:34 -05:00
|
|
|
class SeparatorHolder(parent: ViewGroup) :
|
|
|
|
Holder(parent.inflate(R.layout.design_navigation_item_separator))
|
2017-01-02 06:09:23 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Header view holder.
|
|
|
|
*/
|
2020-02-26 18:03:34 -05:00
|
|
|
class HeaderHolder(parent: ViewGroup) :
|
|
|
|
Holder(parent.inflate(TR.layout.navigation_view_group)) {
|
2018-02-16 09:23:15 -05:00
|
|
|
|
|
|
|
val title: TextView = itemView.findViewById(TR.id.title)
|
|
|
|
}
|
|
|
|
|
2017-01-02 06:09:23 -05:00
|
|
|
/**
|
|
|
|
* Clickable view holder.
|
|
|
|
*/
|
2020-04-18 14:47:22 -04:00
|
|
|
abstract class ClickableHolder(view: View, listener: OnClickListener?) : Holder(view) {
|
2017-01-02 06:09:23 -05:00
|
|
|
init {
|
|
|
|
itemView.setOnClickListener(listener)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Radio view holder.
|
|
|
|
*/
|
2020-04-18 14:47:22 -04:00
|
|
|
class RadioHolder(parent: ViewGroup, listener: OnClickListener?) :
|
2020-02-26 18:03:34 -05:00
|
|
|
ClickableHolder(parent.inflate(TR.layout.navigation_view_radio), listener) {
|
2017-01-02 06:09:23 -05:00
|
|
|
|
2017-09-23 11:14:04 -04:00
|
|
|
val radio: RadioButton = itemView.findViewById(TR.id.nav_view_item)
|
2017-01-02 06:09:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checkbox view holder.
|
|
|
|
*/
|
2020-04-18 14:47:22 -04:00
|
|
|
class CheckboxHolder(parent: ViewGroup, listener: OnClickListener?) :
|
2020-02-26 18:03:34 -05:00
|
|
|
ClickableHolder(parent.inflate(TR.layout.navigation_view_checkbox), listener) {
|
2017-01-02 06:09:23 -05:00
|
|
|
|
2017-09-23 11:14:04 -04:00
|
|
|
val check: CheckBox = itemView.findViewById(TR.id.nav_view_item)
|
2017-01-02 06:09:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multi state view holder.
|
|
|
|
*/
|
2020-04-18 14:47:22 -04:00
|
|
|
class MultiStateHolder(parent: ViewGroup, listener: OnClickListener?) :
|
2020-02-26 18:03:34 -05:00
|
|
|
ClickableHolder(parent.inflate(TR.layout.navigation_view_checkedtext), listener) {
|
2017-01-02 06:09:23 -05:00
|
|
|
|
2017-09-23 11:14:04 -04:00
|
|
|
val text: CheckedTextView = itemView.findViewById(TR.id.nav_view_item)
|
2017-01-02 06:09:23 -05:00
|
|
|
}
|
|
|
|
|
2020-02-26 18:03:34 -05:00
|
|
|
class SpinnerHolder(parent: ViewGroup, listener: OnClickListener? = null) :
|
|
|
|
ClickableHolder(parent.inflate(TR.layout.navigation_view_spinner), listener) {
|
2017-01-02 06:09:23 -05:00
|
|
|
|
2017-09-23 11:14:04 -04:00
|
|
|
val text: TextView = itemView.findViewById(TR.id.nav_view_item_text)
|
|
|
|
val spinner: Spinner = itemView.findViewById(TR.id.nav_view_item)
|
2017-01-02 06:09:23 -05:00
|
|
|
}
|
|
|
|
|
2020-02-26 18:03:34 -05:00
|
|
|
class EditTextHolder(parent: ViewGroup) :
|
|
|
|
Holder(parent.inflate(TR.layout.navigation_view_text)) {
|
2017-01-02 06:09:23 -05:00
|
|
|
|
2017-09-23 11:14:04 -04:00
|
|
|
val wrapper: TextInputLayout = itemView.findViewById(TR.id.nav_view_item_wrapper)
|
|
|
|
val edit: EditText = itemView.findViewById(TR.id.nav_view_item)
|
2017-01-02 06:09:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
protected companion object {
|
|
|
|
const val VIEW_TYPE_HEADER = 100
|
|
|
|
const val VIEW_TYPE_SEPARATOR = 101
|
|
|
|
const val VIEW_TYPE_RADIO = 102
|
|
|
|
const val VIEW_TYPE_CHECKBOX = 103
|
|
|
|
const val VIEW_TYPE_MULTISTATE = 104
|
|
|
|
const val VIEW_TYPE_TEXT = 105
|
|
|
|
const val VIEW_TYPE_LIST = 106
|
|
|
|
}
|
2020-01-05 11:29:27 -05:00
|
|
|
}
|