Improve tablet navigation
parent
12f1ffd019
commit
d3d7912bb8
@ -0,0 +1,97 @@
|
||||
package org.koitharu.kotatsu.core.ui.widgets
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.os.Parcelable.Creator
|
||||
import android.util.AttributeSet
|
||||
import android.widget.Checkable
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.appcompat.widget.AppCompatImageButton
|
||||
import androidx.core.os.ParcelCompat
|
||||
import androidx.customview.view.AbsSavedState
|
||||
|
||||
class CheckableImageButton @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
@AttrRes defStyleAttr: Int = 0,
|
||||
) : AppCompatImageButton(context, attrs, defStyleAttr), Checkable {
|
||||
|
||||
private var isCheckedInternal = false
|
||||
private var isBroadcasting = false
|
||||
|
||||
var onCheckedChangeListener: OnCheckedChangeListener? = null
|
||||
|
||||
override fun isChecked() = isCheckedInternal
|
||||
|
||||
override fun toggle() {
|
||||
isChecked = !isCheckedInternal
|
||||
}
|
||||
|
||||
override fun setChecked(checked: Boolean) {
|
||||
if (checked != isCheckedInternal) {
|
||||
isCheckedInternal = checked
|
||||
refreshDrawableState()
|
||||
if (!isBroadcasting) {
|
||||
isBroadcasting = true
|
||||
onCheckedChangeListener?.onCheckedChanged(this, checked)
|
||||
isBroadcasting = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateDrawableState(extraSpace: Int): IntArray {
|
||||
val state = super.onCreateDrawableState(extraSpace + 1)
|
||||
if (isCheckedInternal) {
|
||||
mergeDrawableStates(state, intArrayOf(android.R.attr.state_checked))
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(): Parcelable? {
|
||||
val superState = super.onSaveInstanceState() ?: return null
|
||||
return SavedState(superState, isChecked)
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(state: Parcelable?) {
|
||||
if (state is SavedState) {
|
||||
super.onRestoreInstanceState(state.superState)
|
||||
isChecked = state.isChecked
|
||||
} else {
|
||||
super.onRestoreInstanceState(state)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface OnCheckedChangeListener {
|
||||
|
||||
fun onCheckedChanged(view: CheckableImageButton, isChecked: Boolean)
|
||||
}
|
||||
|
||||
private class SavedState : AbsSavedState {
|
||||
|
||||
val isChecked: Boolean
|
||||
|
||||
constructor(superState: Parcelable, checked: Boolean) : super(superState) {
|
||||
isChecked = checked
|
||||
}
|
||||
|
||||
constructor(source: Parcel, classLoader: ClassLoader?) : super(source, classLoader) {
|
||||
isChecked = ParcelCompat.readBoolean(source)
|
||||
}
|
||||
|
||||
override fun writeToParcel(out: Parcel, flags: Int) {
|
||||
super.writeToParcel(out, flags)
|
||||
ParcelCompat.writeBoolean(out, isChecked)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Suppress("unused")
|
||||
@JvmField
|
||||
val CREATOR: Creator<SavedState> = object : Creator<SavedState> {
|
||||
override fun createFromParcel(`in`: Parcel) = SavedState(`in`, SavedState::class.java.classLoader)
|
||||
|
||||
override fun newArray(size: Int): Array<SavedState?> = arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z" />
|
||||
</vector>
|
||||
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:autoMirrored="true"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M120,720v-80L640,640v80L120,720ZM784,680L584,480L784,280l56,56L696,480L840,624l-56,56ZM120,520v-80L520,440v80L120,520ZM120,320v-80L640,240v80L120,320Z" />
|
||||
</vector>
|
||||
@ -1,9 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/railFab"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/cat_navigation_rail_efab_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/_continue"
|
||||
app:srcCompat="@drawable/ic_read" />
|
||||
android:layout_gravity="top|start"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/button_expand"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/expand"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_drawer_menu" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/railFab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/_continue"
|
||||
app:icon="@drawable/ic_read" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Loading…
Reference in New Issue