diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt index 23e75cae9f..7527eaf080 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt @@ -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? = 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? = 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 + ) } diff --git a/app/src/main/res/layout/common_view_empty.xml b/app/src/main/res/layout/common_view_empty.xml index 8973f40132..fa8ccf9557 100644 --- a/app/src/main/res/layout/common_view_empty.xml +++ b/app/src/main/res/layout/common_view_empty.xml @@ -1,24 +1,32 @@ - + android:gravity="center" + android:orientation="vertical" + android:padding="16dp"> + tools:src="@drawable/ic_file_download_white_24dp"/> + tools:text="Label" /> - + + + diff --git a/app/src/main/res/layout/material_text_button.xml b/app/src/main/res/layout/material_text_button.xml new file mode 100644 index 0000000000..edb4b351d7 --- /dev/null +++ b/app/src/main/res/layout/material_text_button.xml @@ -0,0 +1,6 @@ + + \ No newline at end of file