Skip to content

Commit

Permalink
Better handling of showing OPDS catalogs
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenzeck committed Jul 27, 2023
1 parent 9408caa commit 1f4c3f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,8 @@ class CatalogFragment : Fragment() {

(activity as MainActivity).supportActionBar?.title = catalog.title

// FIXME opening a catalog, then opening a different catalog does not transition well
catalogViewModel.parseCatalog(catalog)
catalogViewModel.parseData.observe(viewLifecycleOwner) { result ->

facets = result.feed?.facets ?: mutableListOf()

if (facets.size > 0) {
showFacetMenu = true
}
requireActivity().invalidateOptionsMenu()

navigationAdapter.submitList(result.feed!!.navigation)
publicationAdapter.submitList(result.feed!!.publications)
groupAdapter.submitList(result.feed!!.groups)

binding.catalogProgressBar.visibility = View.GONE
}
binding.catalogProgressBar.visibility = View.VISIBLE

val menuHost: MenuHost = requireActivity()

Expand Down Expand Up @@ -145,15 +130,28 @@ class CatalogFragment : Fragment() {
}

private fun handleEvent(event: CatalogViewModel.Event.FeedEvent) {
val message =
when (event) {
is CatalogViewModel.Event.FeedEvent.CatalogParseFailed -> getString(R.string.failed_parsing_catalog)
when (event) {
is CatalogViewModel.Event.FeedEvent.CatalogParseFailed -> {
Snackbar.make(
requireView(),
getString(R.string.failed_parsing_catalog),
Snackbar.LENGTH_LONG
).show()
}

is CatalogViewModel.Event.FeedEvent.CatalogParseSuccess -> {
facets = event.result.feed?.facets ?: mutableListOf()

if (facets.size > 0) {
showFacetMenu = true
}
requireActivity().invalidateOptionsMenu()

navigationAdapter.submitList(event.result.feed!!.navigation)
publicationAdapter.submitList(event.result.feed!!.publications)
groupAdapter.submitList(event.result.feed!!.groups)
}
}
binding.catalogProgressBar.visibility = View.GONE
Snackbar.make(
requireView(),
message,
Snackbar.LENGTH_LONG
).show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class CatalogViewModel(application: Application) : AndroidViewModel(application)

val detailChannel = EventChannel(Channel<Event.DetailEvent>(Channel.BUFFERED), viewModelScope)
val eventChannel = EventChannel(Channel<Event.FeedEvent>(Channel.BUFFERED), viewModelScope)
val parseData = MutableLiveData<ParseData>()
lateinit var publication: Publication

fun parseCatalog(catalog: Catalog) = viewModelScope.launch {
Expand All @@ -55,7 +54,7 @@ class CatalogViewModel(application: Application) : AndroidViewModel(application)
}
}
parseRequest?.onSuccess {
parseData.postValue(it)
eventChannel.send(Event.FeedEvent.CatalogParseSuccess(it))
}
parseRequest?.onFailure {
Timber.e(it)
Expand Down Expand Up @@ -96,6 +95,8 @@ class CatalogViewModel(application: Application) : AndroidViewModel(application)
sealed class FeedEvent : Event() {

object CatalogParseFailed : FeedEvent()

class CatalogParseSuccess(val result: ParseData): FeedEvent()
}

sealed class DetailEvent : Event() {
Expand Down

0 comments on commit 1f4c3f1

Please sign in to comment.