mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 04:33:54 -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() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
unRegisterHotspotService()
|
unRegisterHotspotService()
|
||||||
presenter.detachView()
|
presenter.detachView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun unRegisterHotspotService() {
|
private fun unRegisterHotspotService() {
|
||||||
|
@ -30,11 +30,9 @@ import javax.inject.Inject
|
|||||||
@ActivityScope
|
@ActivityScope
|
||||||
class ZimHostPresenter @Inject internal constructor(
|
class ZimHostPresenter @Inject internal constructor(
|
||||||
private val dataSource: DataSource
|
private val dataSource: DataSource
|
||||||
) : BasePresenter<View>(),
|
) : BasePresenter<View>(), Presenter {
|
||||||
Presenter {
|
|
||||||
@Suppress("TooGenericExceptionCaught")
|
|
||||||
override suspend fun loadBooks(previouslyHostedBooks: Set<String>) {
|
override suspend fun loadBooks(previouslyHostedBooks: Set<String>) {
|
||||||
try {
|
runCatching {
|
||||||
val books = dataSource.getLanguageCategorizedBooks().first()
|
val books = dataSource.getLanguageCategorizedBooks().first()
|
||||||
books.forEach { item ->
|
books.forEach { item ->
|
||||||
if (item is BooksOnDiskListItem.BookOnDisk) {
|
if (item is BooksOnDiskListItem.BookOnDisk) {
|
||||||
@ -43,8 +41,8 @@ class ZimHostPresenter @Inject internal constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
view?.addBooks(books)
|
view?.addBooks(books)
|
||||||
} catch (e: Exception) {
|
}.onFailure {
|
||||||
Log.e(TAG, "Unable to load books", e)
|
Log.e(TAG, "Unable to load books", it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,9 @@ class BaseContract {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Drops the reference to the view when destroyed
|
* 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
|
this.view = view
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun detachView() {
|
override fun detachView(view: T) {
|
||||||
view = null
|
// 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