Show help action when source fails to load

This commit is contained in:
arkon 2021-02-06 13:09:56 -05:00
parent 5f9ddf9ff5
commit d84b5e8b46
4 changed files with 39 additions and 31 deletions

View file

@ -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.library.ChangeMangaCategoriesDialog
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaController 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.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.system.connectivityManager import eu.kanade.tachiyomi.util.system.connectivityManager
import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.openInBrowser
@ -391,16 +392,16 @@ open class BrowseSourceController(bundle: Bundle) :
} }
if (adapter.isEmpty) { if (adapter.isEmpty) {
val actions = emptyList<EmptyView.Action>().toMutableList() val actions = if (presenter.source is LocalSource) {
listOf(
if (presenter.source is LocalSource) { EmptyView.Action(R.string.local_source_help_guide, R.drawable.ic_help_24dp) { openLocalSourceHelpGuide() }
actions += EmptyView.Action(R.string.local_source_help_guide) { openLocalSourceHelpGuide() } )
} else { } else {
actions += EmptyView.Action(R.string.action_retry, retryAction) 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() },
if (presenter.source is HttpSource) { EmptyView.Action(R.string.label_help, R.drawable.ic_help_24dp) { activity?.openInBrowser(MoreController.URL_HELP) }
actions += EmptyView.Action(R.string.action_open_in_web_view) { openInWebView() } )
} }
binding.emptyView.show(message, actions) binding.emptyView.show(message, actions)

View file

@ -151,6 +151,6 @@ class MoreController :
} }
companion object { companion object {
private const val URL_HELP = "https://tachiyomi.org/help/" const val URL_HELP = "https://tachiyomi.org/help/"
} }
} }

View file

@ -1,24 +1,26 @@
package eu.kanade.tachiyomi.widget package eu.kanade.tachiyomi.widget
import android.content.Context import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.widget.AppCompatButton import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.google.android.material.button.MaterialButton
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.CommonViewEmptyBinding import eu.kanade.tachiyomi.databinding.CommonViewEmptyBinding
import kotlin.random.Random import kotlin.random.Random
class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
RelativeLayout(context, attrs) { RelativeLayout(context, attrs) {
private val binding: CommonViewEmptyBinding private val binding: CommonViewEmptyBinding =
CommonViewEmptyBinding.inflate(LayoutInflater.from(context), this, true)
init {
binding = CommonViewEmptyBinding.inflate(LayoutInflater.from(context), this, true)
}
/** /**
* Hide the information view * Hide the information view
@ -40,20 +42,25 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
binding.textLabel.text = message binding.textLabel.text = message
binding.actionsContainer.removeAllViews() binding.actionsContainer.removeAllViews()
if (!actions.isNullOrEmpty()) { actions?.forEach {
actions.forEach { val button = MaterialButton(ContextThemeWrapper(context, R.style.Theme_Widget_Button_Action)).apply {
val button = AppCompatButton(context).apply { layoutParams = LinearLayout.LayoutParams(
layoutParams = LinearLayout.LayoutParams( 0,
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT 1f / actions.size
) )
setText(it.resId) backgroundTintList = ColorStateList.valueOf(Color.TRANSPARENT)
setOnClickListener(it.listener) stateListAnimator = null
} elevation = 0f
binding.actionsContainer.addView(button) setIconResource(it.iconResId)
setText(it.stringResId)
setOnClickListener(it.listener)
} }
binding.actionsContainer.addView(button)
} }
this.isVisible = true this.isVisible = true
@ -75,7 +82,8 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
} }
data class Action( data class Action(
@StringRes val resId: Int, @StringRes val stringResId: Int,
@DrawableRes val iconResId: Int,
val listener: OnClickListener val listener: OnClickListener
) )
} }

View file

@ -27,9 +27,8 @@
<LinearLayout <LinearLayout
android:id="@+id/actions_container" android:id="@+id/actions_container"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:orientation="horizontal" />
android:orientation="vertical" />
</LinearLayout> </LinearLayout>