mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-13 00:55:08 +01:00
Added actionable items to empty view
This commit is contained in:
parent
ad2e14bf1a
commit
0ea6764671
@ -2,11 +2,15 @@ package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
import eu.kanade.tachiyomi.util.view.setVectorCompat
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import kotlinx.android.synthetic.main.common_view_empty.view.*
|
||||
|
||||
class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
@ -20,17 +24,46 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
|
||||
* Hide the information view
|
||||
*/
|
||||
fun hide() {
|
||||
this.visibility = View.GONE
|
||||
this.gone()
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the information view
|
||||
* @param textResource text of information view
|
||||
*/
|
||||
fun show(@DrawableRes drawable: Int, @StringRes textResource: Int, actions: List<Action>? = null) {
|
||||
show(drawable, context.getString(textResource), actions)
|
||||
}
|
||||
/**
|
||||
* Show the information view
|
||||
* @param drawable icon of information view
|
||||
* @param textResource text of information view
|
||||
*/
|
||||
fun show(drawable: Int, textResource: Int) {
|
||||
fun show(@DrawableRes drawable: Int, message: String, actions: List<Action>? = null) {
|
||||
image_view.setVectorCompat(drawable, context.getResourceColor(android.R.attr.textColorHint))
|
||||
text_label.text = context.getString(textResource)
|
||||
this.visibility = View.VISIBLE
|
||||
text_label.text = message
|
||||
|
||||
actions_container.removeAllViews()
|
||||
if (!actions.isNullOrEmpty()) {
|
||||
actions.forEach {
|
||||
val button = (inflate(
|
||||
context,
|
||||
R.layout.material_text_button,
|
||||
null
|
||||
) as MaterialButton).apply {
|
||||
setText(it.resId)
|
||||
setOnClickListener(it.listener)
|
||||
}
|
||||
|
||||
actions_container.addView(button)
|
||||
}
|
||||
}
|
||||
|
||||
this.visible()
|
||||
}
|
||||
|
||||
data class Action(
|
||||
@StringRes val resId: Int,
|
||||
val listener: OnClickListener
|
||||
)
|
||||
}
|
||||
|
@ -1,24 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/image_view"
|
||||
android:layout_width="128dp"
|
||||
android:layout_height="128dp"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
tools:src="@drawable/ic_file_download_white_24dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_label"
|
||||
android:layout_margin="16dp"
|
||||
style="@style/TextAppearance.Medium.Body2.Hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/image_view"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="center"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
tools:text="Label" />
|
||||
|
||||
</RelativeLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/actions_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
|
6
app/src/main/res/layout/material_text_button.xml
Normal file
6
app/src/main/res/layout/material_text_button.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.button.MaterialButton style="@style/Theme.Widget.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/set_as_default_for_all"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" />
|
Loading…
Reference in New Issue
Block a user