Notify about broken source on list screen
This commit is contained in:
@@ -29,7 +29,7 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
|||||||
import org.koitharu.kotatsu.search.domain.SearchKind
|
import org.koitharu.kotatsu.search.domain.SearchKind
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner {
|
class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner, View.OnClickListener {
|
||||||
|
|
||||||
override val viewModel by viewModels<RemoteListViewModel>()
|
override val viewModel by viewModels<RemoteListViewModel>()
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner {
|
|||||||
addMenuProvider(MangaSearchMenuProvider(filterCoordinator, viewModel))
|
addMenuProvider(MangaSearchMenuProvider(filterCoordinator, viewModel))
|
||||||
viewModel.isRandomLoading.observe(viewLifecycleOwner, MenuInvalidator(requireActivity()))
|
viewModel.isRandomLoading.observe(viewLifecycleOwner, MenuInvalidator(requireActivity()))
|
||||||
viewModel.onOpenManga.observeEvent(viewLifecycleOwner) { router.openDetails(it) }
|
viewModel.onOpenManga.observeEvent(viewLifecycleOwner) { router.openDetails(it) }
|
||||||
|
viewModel.onSourceBroken.observeEvent(viewLifecycleOwner) { showSourceBrokenWarning() }
|
||||||
filterCoordinator.observe().distinctUntilChangedBy { it.listFilter.isEmpty() }
|
filterCoordinator.observe().distinctUntilChangedBy { it.listFilter.isEmpty() }
|
||||||
.drop(1)
|
.drop(1)
|
||||||
.observe(viewLifecycleOwner) {
|
.observe(viewLifecycleOwner) {
|
||||||
@@ -87,6 +88,8 @@ class RemoteListFragment : MangaListFragment(), FilterCoordinator.Owner {
|
|||||||
openInBrowser(error.getCauseUrl())
|
openInBrowser(error.getCauseUrl())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onClick(v: View?) = Unit // from Snackbar, do nothing
|
||||||
|
|
||||||
private fun openInBrowser(url: String?) {
|
private fun openInBrowser(url: String?) {
|
||||||
if (url?.isHttpUrl() == true) {
|
if (url?.isHttpUrl() == true) {
|
||||||
router.openBrowser(
|
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 {
|
private inner class RemoteListMenuProvider : MenuProvider {
|
||||||
|
|
||||||
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
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.data.LocalStorageChanges
|
||||||
import org.koitharu.kotatsu.local.domain.model.LocalManga
|
import org.koitharu.kotatsu.local.domain.model.LocalManga
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaParserSource
|
||||||
import org.koitharu.kotatsu.parsers.util.sizeOrZero
|
import org.koitharu.kotatsu.parsers.util.sizeOrZero
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ open class RemoteListViewModel @Inject constructor(
|
|||||||
val source = MangaSource(savedStateHandle[RemoteListFragment.ARG_SOURCE])
|
val source = MangaSource(savedStateHandle[RemoteListFragment.ARG_SOURCE])
|
||||||
val isRandomLoading = MutableStateFlow(false)
|
val isRandomLoading = MutableStateFlow(false)
|
||||||
val onOpenManga = MutableEventFlow<Manga>()
|
val onOpenManga = MutableEventFlow<Manga>()
|
||||||
|
val onSourceBroken = MutableEventFlow<Unit>()
|
||||||
|
|
||||||
protected val repository = mangaRepositoryFactory.create(source)
|
protected val repository = mangaRepositoryFactory.create(source)
|
||||||
private val mangaList = MutableStateFlow<List<Manga>?>(null)
|
private val mangaList = MutableStateFlow<List<Manga>?>(null)
|
||||||
@@ -117,6 +119,11 @@ open class RemoteListViewModel @Inject constructor(
|
|||||||
launchJob(Dispatchers.Default) {
|
launchJob(Dispatchers.Default) {
|
||||||
sourcesRepository.trackUsage(source)
|
sourcesRepository.trackUsage(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (source is MangaParserSource && source.isBroken) {
|
||||||
|
// Just notify one. Will show reason in future
|
||||||
|
onSourceBroken.call(Unit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRefresh() {
|
override fun onRefresh() {
|
||||||
|
|||||||
@@ -899,4 +899,5 @@
|
|||||||
<string name="create_or_restore_backup">Create or restore a backup</string>
|
<string name="create_or_restore_backup">Create or restore a backup</string>
|
||||||
<string name="data_removal">Data removal</string>
|
<string name="data_removal">Data removal</string>
|
||||||
<string name="privacy">Privacy</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>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user