mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Fixed: testOpeningFileWithFilePicker
test intermittently fails on API level 34.
* Fixed: Memory leaks in `OnlineLibraryFragment` that appeared after upgrading LeakCanary. * Fixed: Memory leaks in `LocalFileTransferFragment` that appeared after upgrading LeakCanary. * Fixed: A memory leak in `ZimManageViewModel` caused by `addNetworkInterceptor` holding a reference to progressListener.
This commit is contained in:
parent
6aa0980e4d
commit
4205fc41b7
@ -117,7 +117,7 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
|
||||
sharedPreferenceUtil.shouldShowStorageSelectionDialog = true
|
||||
// open file picker to select a file to test the real scenario.
|
||||
composeTestRule.onNodeWithTag(SELECT_FILE_BUTTON_TESTING_TAG).performClick()
|
||||
uiDevice.findObject(By.textContains(fileName)).click()
|
||||
TestUtils.testFlakyView(uiDevice.findObject(By.textContains(fileName))::click, 10)
|
||||
|
||||
copyMoveFileHandler {
|
||||
assertCopyMoveDialogDisplayed()
|
||||
|
@ -533,6 +533,7 @@ class LocalFileTransferFragment :
|
||||
override fun onDestroyView() {
|
||||
wifiDirectManager.stopWifiDirectManager()
|
||||
wifiDirectManager.callbacks = null
|
||||
fragmentLocalFileTransferBinding?.root?.removeAllViews()
|
||||
fragmentLocalFileTransferBinding = null
|
||||
searchIconView = null
|
||||
materialShowCaseSequence = null
|
||||
|
@ -227,13 +227,13 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
|
||||
setupMenu()
|
||||
|
||||
// hides keyboard when scrolled
|
||||
fragmentDestinationDownloadBinding?.libraryList?.addOnScrollListener(
|
||||
SimpleRecyclerViewScrollListener { _, newState ->
|
||||
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
||||
fragmentDestinationDownloadBinding?.libraryList?.closeKeyboard()
|
||||
}
|
||||
}
|
||||
)
|
||||
fragmentDestinationDownloadBinding?.libraryList?.addOnScrollListener(simpleScrollListener)
|
||||
}
|
||||
|
||||
private var simpleScrollListener = SimpleRecyclerViewScrollListener { _, newState ->
|
||||
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
||||
fragmentDestinationDownloadBinding?.libraryList?.closeKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupMenu() {
|
||||
@ -373,7 +373,12 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
fragmentDestinationDownloadBinding?.libraryList?.adapter = null
|
||||
fragmentDestinationDownloadBinding?.apply {
|
||||
librarySwipeRefresh.setOnRefreshListener(null)
|
||||
libraryList.removeOnScrollListener(simpleScrollListener)
|
||||
libraryList.adapter = null
|
||||
root.removeAllViews()
|
||||
}
|
||||
fragmentDestinationDownloadBinding = null
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ class ZimManageViewModel @Inject constructor(
|
||||
.body(
|
||||
ProgressResponseBody(
|
||||
responseBody,
|
||||
AppProgressListenerProvider(this),
|
||||
appProgressListener,
|
||||
contentLength
|
||||
)
|
||||
)
|
||||
@ -195,6 +195,8 @@ class ZimManageViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private var appProgressListener: AppProgressListenerProvider? = AppProgressListenerProvider(this)
|
||||
|
||||
private fun getContentLengthOfLibraryXmlFile(): Long {
|
||||
val headRequest =
|
||||
Request.Builder()
|
||||
@ -218,7 +220,7 @@ class ZimManageViewModel @Inject constructor(
|
||||
?: DEFAULT_INT_VALUE.toLong()
|
||||
}
|
||||
}
|
||||
} catch (ignore: Exception) {
|
||||
} catch (_: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
return DEFAULT_INT_VALUE.toLong()
|
||||
@ -237,6 +239,7 @@ class ZimManageViewModel @Inject constructor(
|
||||
fileSelectActions.onComplete()
|
||||
requestDownloadLibrary.onComplete()
|
||||
compositeDisposable = null
|
||||
appProgressListener = null
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ import org.kiwix.kiwixmobile.core.downloader.downloadManager.ZERO
|
||||
|
||||
class ProgressResponseBody(
|
||||
private val responseBody: ResponseBody,
|
||||
private val progressListener: OnlineLibraryProgressListener,
|
||||
private val progressListener: OnlineLibraryProgressListener?,
|
||||
private val contentLength: Long
|
||||
) : ResponseBody() {
|
||||
private lateinit var bufferedSource: BufferedSource
|
||||
@ -51,7 +51,7 @@ class ProgressResponseBody(
|
||||
override fun read(sink: Buffer, byteCount: Long): Long {
|
||||
val bytesRead = super.read(sink, byteCount)
|
||||
totalBytesRead += if (bytesRead != DEFAULT_INT_VALUE.toLong()) bytesRead else ZERO.toLong()
|
||||
progressListener.onProgress(totalBytesRead, contentLength)
|
||||
progressListener?.onProgress(totalBytesRead, contentLength)
|
||||
return bytesRead
|
||||
}
|
||||
}
|
||||
|
@ -189,7 +189,10 @@ abstract class PageFragment : OnItemClickListener, BaseFragment(), FragmentActiv
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
compositeDisposable.clear()
|
||||
fragmentPageBinding?.recyclerView?.adapter = null
|
||||
fragmentPageBinding?.apply {
|
||||
recyclerView.adapter = null
|
||||
root.removeAllViews()
|
||||
}
|
||||
fragmentPageBinding = null
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user