Notify about broken source on list screen

devel
Koitharu 6 months ago
parent 9e5664da3a
commit d0ed1fb85f
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -29,7 +29,7 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
import org.koitharu.kotatsu.search.domain.SearchKind
@AndroidEntryPoint
class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner {
class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner, View.OnClickListener {
override val viewModel by viewModels<RemoteListViewModel>()
@ -42,6 +42,7 @@ class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner {
addMenuProvider(MangaSearchMenuProvider(filterCoordinator, viewModel))
viewModel.isRandomLoading.observe(viewLifecycleOwner, MenuInvalidator(requireActivity()))
viewModel.onOpenManga.observeEvent(viewLifecycleOwner) { router.openDetails(it) }
viewModel.onSourceBroken.observeEvent(viewLifecycleOwner) { showSourceBrokenWarning() }
filterCoordinator.observe().distinctUntilChangedBy { it.listFilter.isEmpty() }
.drop(1)
.observe(viewLifecycleOwner) {
@ -87,6 +88,8 @@ class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner {
openInBrowser(error.getCauseUrl())
}
override fun onClick(v: View?) = Unit // from Snackbar, do nothing
private fun openInBrowser(url: String?) {
if (url?.isHttpUrl() == true) {
router.openBrowser(
@ -100,6 +103,16 @@ class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner {
}
}
private fun showSourceBrokenWarning() {
val snackbar = Snackbar.make(
viewBinding?.recyclerView ?: return,
R.string.source_broken_warning,
Snackbar.LENGTH_INDEFINITE,
)
snackbar.setAction(R.string.got_it, this)
snackbar.show()
}
private inner class RemoteListMenuProvider : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {

@ -44,6 +44,7 @@ import org.koitharu.kotatsu.list.ui.model.toErrorState
import org.koitharu.kotatsu.local.data.LocalStorageChanges
import org.koitharu.kotatsu.local.domain.model.LocalManga
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaParserSource
import org.koitharu.kotatsu.parsers.util.sizeOrZero
import javax.inject.Inject
@ -65,6 +66,7 @@ open class RemoteListViewModel @Inject constructor(
val source = MangaSource(savedStateHandle[RemoteListFragment.ARG_SOURCE])
val isRandomLoading = MutableStateFlow(false)
val onOpenManga = MutableEventFlow<Manga>()
val onSourceBroken = MutableEventFlow<Unit>()
protected val repository = mangaRepositoryFactory.create(source)
private val mangaList = MutableStateFlow<List<Manga>?>(null)
@ -117,6 +119,11 @@ open class RemoteListViewModel @Inject constructor(
launchJob(Dispatchers.Default) {
sourcesRepository.trackUsage(source)
}
if (source is MangaParserSource && source.isBroken) {
// Just notify one. Will show reason in future
onSourceBroken.call(Unit)
}
}
override fun onRefresh() {

@ -899,4 +899,5 @@
<string name="create_or_restore_backup">Create or restore a backup</string>
<string name="data_removal">Data removal</string>
<string name="privacy">Privacy</string>
<string name="source_broken_warning">This manga source has been marked as broken. Some features may not work</string>
</resources>

Loading…
Cancel
Save