Show help action when source fails to load
This commit is contained in:
parent
5f9ddf9ff5
commit
d84b5e8b46
@ -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<EmptyView.Action>().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)
|
||||
|
@ -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/"
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
|
@ -27,9 +27,8 @@
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/actions_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical" />
|
||||
android:orientation="horizontal" />
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user