mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Fixed: Hotspot list of books appearing empty(when reopening the ZimHostScreen).
* The issue occurred when reopening the `ZimHostScreen`. The presenter was detaching the view of the previous `ZimHostScreen`, but since the presenter is a singleton, it also cleared the reference to the view attached to the new `ZimHostScreen`. As a result, the `ZimHostPresenter` could not post books because the view reference was null. * Updated `BasePresenter` so that it only detaches the view if it matches the one currently attached, preventing accidental clearing of the new screen’s view.
This commit is contained in:
parent
796ff4ccc0
commit
76a70bed09
@ -404,7 +404,7 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
unRegisterHotspotService()
|
||||
presenter.detachView()
|
||||
presenter.detachView(this)
|
||||
}
|
||||
|
||||
private fun unRegisterHotspotService() {
|
||||
|
@ -30,11 +30,9 @@ import javax.inject.Inject
|
||||
@ActivityScope
|
||||
class ZimHostPresenter @Inject internal constructor(
|
||||
private val dataSource: DataSource
|
||||
) : BasePresenter<View>(),
|
||||
Presenter {
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
) : BasePresenter<View>(), Presenter {
|
||||
override suspend fun loadBooks(previouslyHostedBooks: Set<String>) {
|
||||
try {
|
||||
runCatching {
|
||||
val books = dataSource.getLanguageCategorizedBooks().first()
|
||||
books.forEach { item ->
|
||||
if (item is BooksOnDiskListItem.BookOnDisk) {
|
||||
@ -43,8 +41,8 @@ class ZimHostPresenter @Inject internal constructor(
|
||||
}
|
||||
}
|
||||
view?.addBooks(books)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to load books", e)
|
||||
}.onFailure {
|
||||
Log.e(TAG, "Unable to load books", it)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,9 @@ class BaseContract {
|
||||
|
||||
/**
|
||||
* Drops the reference to the view when destroyed
|
||||
*
|
||||
* @param view the view instance to be detached
|
||||
*/
|
||||
fun detachView()
|
||||
fun detachView(view: T)
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,11 @@ abstract class BasePresenter<T : View<*>?> : Presenter<T> {
|
||||
this.view = view
|
||||
}
|
||||
|
||||
override fun detachView() {
|
||||
view = null
|
||||
override fun detachView(view: T) {
|
||||
// Detach the view only if it matches the one currently attached.
|
||||
// Bug Fix #4409
|
||||
if (this.view == view) {
|
||||
this.view = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user