Change filters dialog with a drawer
This commit is contained in:
@@ -1,88 +1,27 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.support.annotation.CallSuper
|
||||
import android.support.design.R
|
||||
import android.support.design.internal.ScrimInsetsFrameLayout
|
||||
import android.support.graphics.drawable.VectorDrawableCompat
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.view.ViewCompat
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.support.v7.widget.TintTypedArray
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CheckBox
|
||||
import android.widget.CheckedTextView
|
||||
import android.widget.RadioButton
|
||||
import android.widget.TextView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.inflate
|
||||
import eu.kanade.tachiyomi.R as TR
|
||||
|
||||
/**
|
||||
* An alternative implementation of [android.support.design.widget.NavigationView], without menu
|
||||
* inflation and allowing customizable items (multiple selections, custom views, etc).
|
||||
*/
|
||||
@Suppress("LeakingThis")
|
||||
@SuppressLint("PrivateResource")
|
||||
open class ExtendedNavigationView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0)
|
||||
: ScrimInsetsFrameLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
/**
|
||||
* Max width of the navigation view.
|
||||
*/
|
||||
private var maxWidth: Int
|
||||
|
||||
/**
|
||||
* 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())
|
||||
}
|
||||
|
||||
ViewCompat.setFitsSystemWindows(this,
|
||||
a.getBoolean(R.styleable.NavigationView_android_fitsSystemWindows, false))
|
||||
|
||||
maxWidth = a.getDimensionPixelSize(R.styleable.NavigationView_android_maxWidth, 0)
|
||||
|
||||
a.recycle()
|
||||
|
||||
recycler.layoutManager = LinearLayoutManager(context)
|
||||
addView(recycler)
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden to measure the width of the navigation view.
|
||||
*/
|
||||
override fun onMeasure(widthSpec: Int, heightSpec: Int) {
|
||||
val width = when (MeasureSpec.getMode(widthSpec)) {
|
||||
MeasureSpec.AT_MOST -> MeasureSpec.makeMeasureSpec(
|
||||
Math.min(MeasureSpec.getSize(widthSpec), maxWidth), MeasureSpec.EXACTLY)
|
||||
MeasureSpec.UNSPECIFIED -> MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.EXACTLY)
|
||||
else -> widthSpec
|
||||
}
|
||||
// Let super sort out the height
|
||||
super.onMeasure(width, heightSpec)
|
||||
}
|
||||
: SimpleNavigationView(context, attrs, defStyleAttr) {
|
||||
|
||||
/**
|
||||
* Every item of the nav view. Generic items must belong to this list, custom items could be
|
||||
@@ -136,7 +75,7 @@ open class ExtendedNavigationView @JvmOverloads constructor(
|
||||
*/
|
||||
fun tintVector(context: Context, resId: Int): Drawable {
|
||||
return VectorDrawableCompat.create(context.resources, resId, context.theme)!!.apply {
|
||||
setTint(context.theme.getResourceColor(TR.attr.colorAccent))
|
||||
setTint(context.theme.getResourceColor(R.attr.colorAccent))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,9 +100,9 @@ open class ExtendedNavigationView @JvmOverloads constructor(
|
||||
|
||||
override fun getStateDrawable(context: Context): Drawable? {
|
||||
return when (state) {
|
||||
SORT_ASC -> tintVector(context, TR.drawable.ic_keyboard_arrow_up_black_32dp)
|
||||
SORT_DESC -> tintVector(context, TR.drawable.ic_keyboard_arrow_down_black_32dp)
|
||||
SORT_NONE -> ContextCompat.getDrawable(context, TR.drawable.empty_drawable_32dp)
|
||||
SORT_ASC -> tintVector(context, R.drawable.ic_keyboard_arrow_up_black_32dp)
|
||||
SORT_DESC -> tintVector(context, R.drawable.ic_keyboard_arrow_down_black_32dp)
|
||||
SORT_NONE -> ContextCompat.getDrawable(context, R.drawable.empty_drawable_32dp)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -218,59 +157,6 @@ open class ExtendedNavigationView @JvmOverloads constructor(
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Base view holder.
|
||||
*/
|
||||
abstract class Holder(view: View) : RecyclerView.ViewHolder(view)
|
||||
|
||||
/**
|
||||
* Separator view holder.
|
||||
*/
|
||||
class SeparatorHolder(parent: ViewGroup)
|
||||
: Holder(parent.inflate(R.layout.design_navigation_item_separator))
|
||||
|
||||
/**
|
||||
* Header view holder.
|
||||
*/
|
||||
class HeaderHolder(parent: ViewGroup)
|
||||
: Holder(parent.inflate(R.layout.design_navigation_item_subheader))
|
||||
|
||||
/**
|
||||
* Clickable view holder.
|
||||
*/
|
||||
abstract class ClickableHolder(view: View, listener: View.OnClickListener?) : Holder(view) {
|
||||
init {
|
||||
itemView.setOnClickListener(listener)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Radio view holder.
|
||||
*/
|
||||
class RadioHolder(parent: ViewGroup, listener: View.OnClickListener?)
|
||||
: ClickableHolder(parent.inflate(TR.layout.navigation_view_radio), listener) {
|
||||
|
||||
val radio = itemView.findViewById(TR.id.nav_view_item) as RadioButton
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox view holder.
|
||||
*/
|
||||
class CheckboxHolder(parent: ViewGroup, listener: View.OnClickListener?)
|
||||
: ClickableHolder(parent.inflate(TR.layout.navigation_view_checkbox), listener) {
|
||||
|
||||
val check = itemView.findViewById(TR.id.nav_view_item) as CheckBox
|
||||
}
|
||||
|
||||
/**
|
||||
* Multi state view holder.
|
||||
*/
|
||||
class MultiStateHolder(parent: ViewGroup, listener: View.OnClickListener?)
|
||||
: ClickableHolder(parent.inflate(TR.layout.navigation_view_checkedtext), listener) {
|
||||
|
||||
val text = itemView.findViewById(TR.id.nav_view_item) as CheckedTextView
|
||||
}
|
||||
|
||||
/**
|
||||
* Base adapter for the navigation view. It knows how to create and render every subclass of
|
||||
* [Item].
|
||||
@@ -352,12 +238,4 @@ open class ExtendedNavigationView @JvmOverloads constructor(
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val VIEW_TYPE_HEADER = 100
|
||||
private const val VIEW_TYPE_SEPARATOR = 101
|
||||
private const val VIEW_TYPE_RADIO = 102
|
||||
private const val VIEW_TYPE_CHECKBOX = 103
|
||||
private const val VIEW_TYPE_MULTISTATE = 104
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user