From d84b5e8b461bb8c9c0e6c684dc717e27ba40f6c5 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 6 Feb 2021 13:09:56 -0500 Subject: [PATCH] Show help action when source fails to load --- .../source/browse/BrowseSourceController.kt | 19 ++++---- .../tachiyomi/ui/more/MoreController.kt | 2 +- .../eu/kanade/tachiyomi/widget/EmptyView.kt | 44 +++++++++++-------- app/src/main/res/layout/common_view_empty.xml | 5 +-- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index ee44251a10..5c6885c5a4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -39,6 +39,7 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController +import eu.kanade.tachiyomi.ui.more.MoreController import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.system.connectivityManager import eu.kanade.tachiyomi.util.system.openInBrowser @@ -391,16 +392,16 @@ open class BrowseSourceController(bundle: Bundle) : } if (adapter.isEmpty) { - val actions = emptyList().toMutableList() - - if (presenter.source is LocalSource) { - actions += EmptyView.Action(R.string.local_source_help_guide) { openLocalSourceHelpGuide() } + val actions = if (presenter.source is LocalSource) { + listOf( + EmptyView.Action(R.string.local_source_help_guide, R.drawable.ic_help_24dp) { openLocalSourceHelpGuide() } + ) } else { - actions += EmptyView.Action(R.string.action_retry, retryAction) - } - - if (presenter.source is HttpSource) { - actions += EmptyView.Action(R.string.action_open_in_web_view) { openInWebView() } + listOf( + EmptyView.Action(R.string.action_retry, R.drawable.ic_refresh_24dp, retryAction), + EmptyView.Action(R.string.action_open_in_web_view, R.drawable.ic_public_24dp) { openInWebView() }, + EmptyView.Action(R.string.label_help, R.drawable.ic_help_24dp) { activity?.openInBrowser(MoreController.URL_HELP) } + ) } binding.emptyView.show(message, actions) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index 8573a7922d..12172ff321 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -151,6 +151,6 @@ class MoreController : } companion object { - private const val URL_HELP = "https://tachiyomi.org/help/" + const val URL_HELP = "https://tachiyomi.org/help/" } } 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 b211f4303a..78c39c4a63 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt @@ -1,24 +1,26 @@ package eu.kanade.tachiyomi.widget import android.content.Context +import android.content.res.ColorStateList +import android.graphics.Color import android.util.AttributeSet import android.view.LayoutInflater import android.widget.LinearLayout import android.widget.RelativeLayout +import androidx.annotation.DrawableRes import androidx.annotation.StringRes -import androidx.appcompat.widget.AppCompatButton +import androidx.appcompat.view.ContextThemeWrapper import androidx.core.view.isVisible +import com.google.android.material.button.MaterialButton +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.CommonViewEmptyBinding import kotlin.random.Random class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : RelativeLayout(context, attrs) { - private val binding: CommonViewEmptyBinding - - init { - binding = CommonViewEmptyBinding.inflate(LayoutInflater.from(context), this, true) - } + private val binding: CommonViewEmptyBinding = + CommonViewEmptyBinding.inflate(LayoutInflater.from(context), this, true) /** * Hide the information view @@ -40,20 +42,25 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? binding.textLabel.text = message binding.actionsContainer.removeAllViews() - if (!actions.isNullOrEmpty()) { - actions.forEach { - val button = AppCompatButton(context).apply { - layoutParams = LinearLayout.LayoutParams( - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT - ) + actions?.forEach { + val button = MaterialButton(ContextThemeWrapper(context, R.style.Theme_Widget_Button_Action)).apply { + layoutParams = LinearLayout.LayoutParams( + 0, + LinearLayout.LayoutParams.WRAP_CONTENT, + 1f / actions.size + ) - setText(it.resId) - setOnClickListener(it.listener) - } + backgroundTintList = ColorStateList.valueOf(Color.TRANSPARENT) + stateListAnimator = null + elevation = 0f - binding.actionsContainer.addView(button) + setIconResource(it.iconResId) + setText(it.stringResId) + + setOnClickListener(it.listener) } + + binding.actionsContainer.addView(button) } this.isVisible = true @@ -75,7 +82,8 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? } data class Action( - @StringRes val resId: Int, + @StringRes val stringResId: Int, + @DrawableRes val iconResId: 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 5e2ca33b0a..02a68037cd 100644 --- a/app/src/main/res/layout/common_view_empty.xml +++ b/app/src/main/res/layout/common_view_empty.xml @@ -27,9 +27,8 @@ + android:orientation="horizontal" />