Extension api only called when bringing up the extensions sheet

This commit is contained in:
Jay 2020-03-21 22:07:35 -04:00
parent 09a8ec6ffa
commit 3e40105232
3 changed files with 17 additions and 2 deletions

View File

@ -160,6 +160,9 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
if (state == BottomSheetBehavior.STATE_COLLAPSED) 1f else 0f
showingExtenions = state == BottomSheetBehavior.STATE_EXPANDED
setTitle()
if (state == BottomSheetBehavior.STATE_EXPANDED)
ext_bottom_sheet.fetchOnlineExtensionsIfNeeded()
else ext_bottom_sheet.shouldCallApi = true
activity?.invalidateOptionsMenu()
}
@ -177,6 +180,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
fun showExtensions() {
ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
ext_bottom_sheet.fetchOnlineExtensionsIfNeeded()
}
fun toggleExtensions() {
@ -184,6 +188,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED
} else {
ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
ext_bottom_sheet.fetchOnlineExtensionsIfNeeded()
}
}

View File

@ -38,7 +38,7 @@ open class ExtensionBottomPresenter(
private var currentDownloads = hashMapOf<String, InstallStep>()
fun onCreate() {
extensionManager.findAvailableExtensions()
// extensionManager.findAvailableExtensions()
bindToExtensionsObservable()
}

View File

@ -31,7 +31,9 @@ ExtensionAdapter.OnButtonClickListener,
ExtensionTrustDialog.Listener {
var sheetBehavior: BottomSheetBehavior<*>? = null
lateinit var autoCheckItem: AutoCheckItem
private lateinit var autoCheckItem: AutoCheckItem
var shouldCallApi = true
/**
* Adapter containing the list of manga from the catalogue.
@ -71,6 +73,7 @@ ExtensionAdapter.OnButtonClickListener,
sheet_layout.setOnClickListener {
if (sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED) {
sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
fetchOnlineExtensionsIfNeeded()
} else {
sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED
}
@ -78,6 +81,13 @@ ExtensionAdapter.OnButtonClickListener,
presenter.getExtensionUpdateCount()
}
fun fetchOnlineExtensionsIfNeeded() {
if (shouldCallApi) {
presenter.findAvailableExtensions()
shouldCallApi = false
}
}
fun updateExtTitle() {
val extCount = presenter.getExtensionUpdateCount()
title_text.text = if (extCount == 0) context.getString(R.string.label_extensions)