Show empty catalogue error view with actions
This commit is contained in:
parent
ed277357cf
commit
bb43e2aa03
4 changed files with 104 additions and 38 deletions
|
@ -41,8 +41,10 @@ import eu.kanade.tachiyomi.util.view.inflate
|
|||
import eu.kanade.tachiyomi.util.view.snack
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
import eu.kanade.tachiyomi.widget.EmptyView
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlinx.android.synthetic.main.catalogue_controller.catalogue_view
|
||||
import kotlinx.android.synthetic.main.catalogue_controller.empty_view
|
||||
import kotlinx.android.synthetic.main.catalogue_controller.progress
|
||||
import kotlinx.android.synthetic.main.main_activity.drawer
|
||||
import rx.Observable
|
||||
|
@ -352,16 +354,32 @@ open class BrowseCatalogueController(bundle: Bundle) :
|
|||
snack?.dismiss()
|
||||
|
||||
if (catalogue_view != null) {
|
||||
snack = catalogue_view.snack(getErrorMessage(error), Snackbar.LENGTH_INDEFINITE) {
|
||||
setAction(R.string.action_retry) {
|
||||
// If not the first page, show bottom progress bar.
|
||||
if (adapter.mainItemCount > 0) {
|
||||
val item = progressItem ?: return@setAction
|
||||
adapter.addScrollableFooterWithDelay(item, 0, true)
|
||||
} else {
|
||||
showProgressBar()
|
||||
}
|
||||
presenter.requestNext()
|
||||
val message = getErrorMessage(error)
|
||||
val retryAction = View.OnClickListener {
|
||||
empty_view.hide()
|
||||
|
||||
// If not the first page, show bottom progress bar.
|
||||
if (adapter.mainItemCount > 0 && progressItem != null) {
|
||||
adapter.addScrollableFooterWithDelay(progressItem!!, 0, true)
|
||||
} else {
|
||||
showProgressBar()
|
||||
}
|
||||
presenter.requestNext()
|
||||
}
|
||||
val openInWebViewAction = View.OnClickListener {
|
||||
openInWebView()
|
||||
}
|
||||
|
||||
if (adapter.isEmpty) {
|
||||
empty_view.show(message, listOf(
|
||||
EmptyView.Action(R.string.action_retry, retryAction),
|
||||
EmptyView.Action(R.string.action_open_in_web_view, openInWebViewAction)
|
||||
))
|
||||
} else {
|
||||
empty_view.hide()
|
||||
|
||||
snack = catalogue_view.snack(message, Snackbar.LENGTH_INDEFINITE) {
|
||||
setAction(R.string.action_retry, retryAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,16 @@ package eu.kanade.tachiyomi.widget
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.annotation.StringRes
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import kotlin.random.Random
|
||||
import kotlinx.android.synthetic.main.common_view_empty.view.actions_container
|
||||
import kotlinx.android.synthetic.main.common_view_empty.view.text_face
|
||||
import kotlinx.android.synthetic.main.common_view_empty.view.text_label
|
||||
|
||||
|
@ -29,24 +33,50 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
|
|||
* Show the information view
|
||||
* @param textResource text of information view
|
||||
*/
|
||||
fun show(@StringRes textResource: Int) {
|
||||
fun show(@StringRes textResource: Int, actions: List<Action>? = null) {
|
||||
show(context.getString(textResource), actions)
|
||||
}
|
||||
|
||||
fun show(message: String, actions: List<Action>? = null) {
|
||||
text_face.text = getRandomErrorFace()
|
||||
text_label.text = context.getString(textResource)
|
||||
text_label.text = message
|
||||
|
||||
actions_container.removeAllViews()
|
||||
if (!actions.isNullOrEmpty()) {
|
||||
actions.forEach {
|
||||
val button = Button(context).apply {
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT)
|
||||
|
||||
setText(it.resId)
|
||||
setOnClickListener(it.listener)
|
||||
}
|
||||
|
||||
actions_container.addView(button)
|
||||
}
|
||||
}
|
||||
|
||||
this.visible()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val ERROR_FACES = listOf(
|
||||
"(・o・;)",
|
||||
"Σ(ಠ_ಠ)",
|
||||
"ಥ_ಥ",
|
||||
"(˘・_・˘)",
|
||||
"(; ̄Д ̄)",
|
||||
"(・Д・。"
|
||||
"(・o・;)",
|
||||
"Σ(ಠ_ಠ)",
|
||||
"ಥ_ಥ",
|
||||
"(˘・_・˘)",
|
||||
"(; ̄Д ̄)",
|
||||
"(・Д・。"
|
||||
)
|
||||
|
||||
fun getRandomErrorFace(): String {
|
||||
return ERROR_FACES[Random.nextInt(ERROR_FACES.size)]
|
||||
}
|
||||
}
|
||||
|
||||
data class Action(
|
||||
@StringRes val resId: Int,
|
||||
val listener: View.OnClickListener
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,22 +4,35 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/catalogue_view"
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical"
|
||||
tools:context="eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCatalogueController">
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:id="@+id/catalogue_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:orientation="vertical"
|
||||
tools:context="eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCatalogueController">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<eu.kanade.tachiyomi.widget.EmptyView
|
||||
android:id="@+id/empty_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_gravity="center">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_face"
|
||||
style="@style/TextAppearance.Medium.Body2.Hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="center"
|
||||
android:textSize="48sp"
|
||||
tools:text="-_-" />
|
||||
|
@ -21,10 +21,15 @@
|
|||
style="@style/TextAppearance.Medium.Body2.Hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/text_face"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="center"
|
||||
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>
|
||||
|
|
Reference in a new issue