From 00f79df953b5de2611b26685eeef83387c279df4 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 24 Mar 2025 19:48:49 +0530 Subject: [PATCH] Improved the selection and deselection of ZIM files for deletion. * Fixed: A memory leak in `HelpFragment` which is showing after migrating the localLibrary fragment to compose. --- .../java/org/kiwix/kiwixmobile/download/DownloadTest.kt | 5 ++++- .../org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt | 5 ++++- .../nav/destination/library/local/LocalLibraryFragment.kt | 2 ++ .../java/eu/mhutti1/utils/storage/StorageSelectDialog.kt | 1 + .../java/org/kiwix/kiwixmobile/core/help/HelpFragment.kt | 1 + .../kiwixmobile/custom/download/CustomDownloadFragment.kt | 1 + 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt index be3ff0106..4d6d365c3 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt @@ -17,6 +17,7 @@ */ package org.kiwix.kiwixmobile.download +import android.os.Build import android.util.Log import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit @@ -158,7 +159,9 @@ class DownloadTest : BaseActivityTest() { "Couldn't find downloaded file\n Original Exception: ${e.message}" ) } - LeakAssertions.assertNoLeaks() + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { + LeakAssertions.assertNoLeaks() + } } private fun getOnlineLibraryList(): List { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt index 87c9d9595..73b4aaa64 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt @@ -17,6 +17,7 @@ */ package org.kiwix.kiwixmobile.main +import android.os.Build import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit import androidx.lifecycle.Lifecycle @@ -131,6 +132,8 @@ class TopLevelDestinationTest : BaseActivityTest() { clickSupportKiwixOnSideNav() pressBack() } - LeakAssertions.assertNoLeaks() + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { + LeakAssertions.assertNoLeaks() + } } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt index acffc6465..41fba2f37 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt @@ -563,6 +563,8 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal // Force recomposition by first setting an empty list before assigning the updated list. // This is necessary because modifying an object's property doesn't trigger recomposition, // as Compose still considers the list unchanged. + updateLibraryScreenState(fileSelectListState = FileSelectListState(emptyList())) + // Update the real state for UI. updateLibraryScreenState( fileSelectListState = state, noFilesViewItem = Triple( diff --git a/core/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt b/core/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt index 47928ce0a..4758ded63 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt @@ -133,6 +133,7 @@ class StorageSelectDialog : DialogFragment() { override fun onDestroyView() { super.onDestroyView() + storageSelectDialogViewBinding?.root?.removeAllViews() storageSelectDialogViewBinding = null } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpFragment.kt index b49871172..8a059b9dd 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpFragment.kt @@ -95,6 +95,7 @@ abstract class HelpFragment : BaseFragment() { override fun onDestroyView() { super.onDestroyView() + fragmentHelpBinding?.root?.removeAllViews() fragmentHelpBinding = null } } diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt index cc2068d0e..d87e86d96 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt @@ -159,6 +159,7 @@ class CustomDownloadFragment : BaseFragment(), FragmentActivityExtensions { override fun onDestroyView() { super.onDestroyView() + fragmentCustomDownloadBinding?.root?.removeAllViews() fragmentCustomDownloadBinding = null } }