mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 15:27:55 -04:00
Migrated the copy_move_progress_bar
to Jetpack Compose.
* Improved `AlertDialogShower` to support bottom padding for customView, allowing design customization from the caller side. * Removed unused code from the project. * Refactored the UI, and unit test cases.
This commit is contained in:
parent
99bcb5e836
commit
c9b94f50a8
@ -28,7 +28,6 @@ import androidx.test.espresso.web.sugar.Web
|
|||||||
import androidx.test.espresso.web.webdriver.DriverAtoms
|
import androidx.test.espresso.web.webdriver.DriverAtoms
|
||||||
import androidx.test.espresso.web.webdriver.Locator
|
import androidx.test.espresso.web.webdriver.Locator
|
||||||
import applyWithViewHierarchyPrinting
|
import applyWithViewHierarchyPrinting
|
||||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
|
||||||
import org.kiwix.kiwixmobile.BaseRobot
|
import org.kiwix.kiwixmobile.BaseRobot
|
||||||
import org.kiwix.kiwixmobile.Findable
|
import org.kiwix.kiwixmobile.Findable
|
||||||
import org.kiwix.kiwixmobile.R.id
|
import org.kiwix.kiwixmobile.R.id
|
||||||
@ -39,8 +38,8 @@ import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_MESSAGE_TEXT_TESTING
|
|||||||
import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_NATURAL_BUTTON_TESTING_TAG
|
import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_NATURAL_BUTTON_TESTING_TAG
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.local.NO_FILE_TEXT_TESTING_TAG
|
import org.kiwix.kiwixmobile.nav.destination.library.local.NO_FILE_TEXT_TESTING_TAG
|
||||||
import org.kiwix.kiwixmobile.storage.STORAGE_SELECTION_DIALOG_TITLE_TESTING_TAG
|
import org.kiwix.kiwixmobile.storage.STORAGE_SELECTION_DIALOG_TITLE_TESTING_TAG
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
||||||
|
import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout
|
||||||
import org.kiwix.kiwixmobile.ui.STORAGE_DEVICE_ITEM_TESTING_TAG
|
import org.kiwix.kiwixmobile.ui.STORAGE_DEVICE_ITEM_TESTING_TAG
|
||||||
|
|
||||||
fun copyMoveFileHandler(func: CopyMoveFileHandlerRobot.() -> Unit) =
|
fun copyMoveFileHandler(func: CopyMoveFileHandlerRobot.() -> Unit) =
|
||||||
@ -48,9 +47,8 @@ fun copyMoveFileHandler(func: CopyMoveFileHandlerRobot.() -> Unit) =
|
|||||||
|
|
||||||
class CopyMoveFileHandlerRobot : BaseRobot() {
|
class CopyMoveFileHandlerRobot : BaseRobot() {
|
||||||
fun assertCopyMoveDialogDisplayed(composeTestRule: ComposeContentTestRule) {
|
fun assertCopyMoveDialogDisplayed(composeTestRule: ComposeContentTestRule) {
|
||||||
pauseForBetterTestPerformance()
|
|
||||||
composeTestRule.apply {
|
composeTestRule.apply {
|
||||||
waitForIdle()
|
waitUntilTimeout()
|
||||||
onNodeWithTag(ALERT_DIALOG_MESSAGE_TEXT_TESTING_TAG)
|
onNodeWithTag(ALERT_DIALOG_MESSAGE_TEXT_TESTING_TAG)
|
||||||
.assertTextEquals(context.getString(R.string.copy_move_files_dialog_description))
|
.assertTextEquals(context.getString(R.string.copy_move_files_dialog_description))
|
||||||
}
|
}
|
||||||
@ -59,7 +57,7 @@ class CopyMoveFileHandlerRobot : BaseRobot() {
|
|||||||
fun assertCopyMoveDialogNotDisplayed(composeTestRule: ComposeContentTestRule) {
|
fun assertCopyMoveDialogNotDisplayed(composeTestRule: ComposeContentTestRule) {
|
||||||
testFlakyView({
|
testFlakyView({
|
||||||
composeTestRule.apply {
|
composeTestRule.apply {
|
||||||
waitForIdle()
|
waitUntilTimeout()
|
||||||
onNodeWithTag(ALERT_DIALOG_MESSAGE_TEXT_TESTING_TAG)
|
onNodeWithTag(ALERT_DIALOG_MESSAGE_TEXT_TESTING_TAG)
|
||||||
.assertDoesNotExist()
|
.assertDoesNotExist()
|
||||||
}
|
}
|
||||||
@ -69,7 +67,7 @@ class CopyMoveFileHandlerRobot : BaseRobot() {
|
|||||||
fun assertStorageSelectionDialogDisplayed(composeTestRule: ComposeContentTestRule) {
|
fun assertStorageSelectionDialogDisplayed(composeTestRule: ComposeContentTestRule) {
|
||||||
testFlakyView({
|
testFlakyView({
|
||||||
composeTestRule.apply {
|
composeTestRule.apply {
|
||||||
waitForIdle()
|
waitUntilTimeout()
|
||||||
onNodeWithTag(STORAGE_SELECTION_DIALOG_TITLE_TESTING_TAG)
|
onNodeWithTag(STORAGE_SELECTION_DIALOG_TITLE_TESTING_TAG)
|
||||||
.assertTextEquals(context.getString(R.string.choose_storage_to_copy_move_zim_file))
|
.assertTextEquals(context.getString(R.string.choose_storage_to_copy_move_zim_file))
|
||||||
}
|
}
|
||||||
@ -77,21 +75,18 @@ class CopyMoveFileHandlerRobot : BaseRobot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun clickOnInternalStorage(composeTestRule: ComposeContentTestRule) {
|
fun clickOnInternalStorage(composeTestRule: ComposeContentTestRule) {
|
||||||
pauseForBetterTestPerformance()
|
|
||||||
testFlakyView({
|
testFlakyView({
|
||||||
testFlakyView({
|
composeTestRule.apply {
|
||||||
composeTestRule.apply {
|
waitUntilTimeout()
|
||||||
waitForIdle()
|
onAllNodesWithTag(STORAGE_DEVICE_ITEM_TESTING_TAG)[0].performClick()
|
||||||
onAllNodesWithTag(STORAGE_DEVICE_ITEM_TESTING_TAG)[0].performClick()
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clickOnCopy(composeTestRule: ComposeContentTestRule) {
|
fun clickOnCopy(composeTestRule: ComposeContentTestRule) {
|
||||||
testFlakyView({
|
testFlakyView({
|
||||||
composeTestRule.apply {
|
composeTestRule.apply {
|
||||||
waitForIdle()
|
waitUntilTimeout()
|
||||||
onNodeWithTag(ALERT_DIALOG_CONFIRM_BUTTON_TESTING_TAG)
|
onNodeWithTag(ALERT_DIALOG_CONFIRM_BUTTON_TESTING_TAG)
|
||||||
.assertTextEquals(context.getString(R.string.action_copy).uppercase())
|
.assertTextEquals(context.getString(R.string.action_copy).uppercase())
|
||||||
.performClick()
|
.performClick()
|
||||||
@ -121,8 +116,8 @@ class CopyMoveFileHandlerRobot : BaseRobot() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun assertZimFileCopiedAndShowingIntoTheReader() {
|
fun assertZimFileCopiedAndShowingIntoTheReader(composeTestRule: ComposeContentTestRule) {
|
||||||
pauseForBetterTestPerformance()
|
composeTestRule.waitUntilTimeout()
|
||||||
isVisible(Findable.ViewId(id.readerFragment))
|
isVisible(Findable.ViewId(id.readerFragment))
|
||||||
testFlakyView({
|
testFlakyView({
|
||||||
Web.onWebView()
|
Web.onWebView()
|
||||||
@ -143,8 +138,4 @@ class CopyMoveFileHandlerRobot : BaseRobot() {
|
|||||||
// do nothing zim file is added in the local library
|
// do nothing zim file is added in the local library
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pauseForBetterTestPerformance() {
|
|
||||||
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ import org.kiwix.kiwixmobile.nav.destination.library.CopyMoveFileHandler
|
|||||||
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragment
|
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragment
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
|
import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout
|
||||||
import org.kiwix.kiwixmobile.zimManager.Fat32Checker
|
import org.kiwix.kiwixmobile.zimManager.Fat32Checker
|
||||||
import org.kiwix.kiwixmobile.zimManager.FileWritingFileSystemChecker
|
import org.kiwix.kiwixmobile.zimManager.FileWritingFileSystemChecker
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -116,7 +117,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
|
|||||||
kiwixMainActivity = it
|
kiwixMainActivity = it
|
||||||
kiwixMainActivity.navigate(R.id.libraryFragment)
|
kiwixMainActivity.navigate(R.id.libraryFragment)
|
||||||
}
|
}
|
||||||
copyMoveFileHandler(CopyMoveFileHandlerRobot::pauseForBetterTestPerformance)
|
composeTestRule.waitUntilTimeout()
|
||||||
// test with first launch
|
// test with first launch
|
||||||
sharedPreferenceUtil.shouldShowStorageSelectionDialog = true
|
sharedPreferenceUtil.shouldShowStorageSelectionDialog = true
|
||||||
showMoveFileToPublicDirectoryDialog()
|
showMoveFileToPublicDirectoryDialog()
|
||||||
@ -126,7 +127,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
|
|||||||
clickOnCopy(composeTestRule)
|
clickOnCopy(composeTestRule)
|
||||||
assertStorageSelectionDialogDisplayed(composeTestRule)
|
assertStorageSelectionDialogDisplayed(composeTestRule)
|
||||||
clickOnInternalStorage(composeTestRule)
|
clickOnInternalStorage(composeTestRule)
|
||||||
assertZimFileCopiedAndShowingIntoTheReader()
|
assertZimFileCopiedAndShowingIntoTheReader(composeTestRule)
|
||||||
}
|
}
|
||||||
assertZimFileAddedInTheLocalLibrary()
|
assertZimFileAddedInTheLocalLibrary()
|
||||||
|
|
||||||
@ -138,7 +139,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
|
|||||||
copyMoveFileHandler {
|
copyMoveFileHandler {
|
||||||
assertCopyMoveDialogDisplayed(composeTestRule)
|
assertCopyMoveDialogDisplayed(composeTestRule)
|
||||||
clickOnCopy(composeTestRule)
|
clickOnCopy(composeTestRule)
|
||||||
assertZimFileCopiedAndShowingIntoTheReader()
|
assertZimFileCopiedAndShowingIntoTheReader(composeTestRule)
|
||||||
}
|
}
|
||||||
assertZimFileAddedInTheLocalLibrary()
|
assertZimFileAddedInTheLocalLibrary()
|
||||||
deleteAllFilesInDirectory(parentFile)
|
deleteAllFilesInDirectory(parentFile)
|
||||||
@ -155,7 +156,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
|
|||||||
kiwixMainActivity = it
|
kiwixMainActivity = it
|
||||||
kiwixMainActivity.navigate(R.id.libraryFragment)
|
kiwixMainActivity.navigate(R.id.libraryFragment)
|
||||||
}
|
}
|
||||||
copyMoveFileHandler(CopyMoveFileHandlerRobot::pauseForBetterTestPerformance)
|
composeTestRule.waitUntilTimeout()
|
||||||
// test with first launch
|
// test with first launch
|
||||||
sharedPreferenceUtil.shouldShowStorageSelectionDialog = true
|
sharedPreferenceUtil.shouldShowStorageSelectionDialog = true
|
||||||
showMoveFileToPublicDirectoryDialog()
|
showMoveFileToPublicDirectoryDialog()
|
||||||
@ -165,7 +166,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
|
|||||||
clickOnMove(composeTestRule)
|
clickOnMove(composeTestRule)
|
||||||
assertStorageSelectionDialogDisplayed(composeTestRule)
|
assertStorageSelectionDialogDisplayed(composeTestRule)
|
||||||
clickOnInternalStorage(composeTestRule)
|
clickOnInternalStorage(composeTestRule)
|
||||||
assertZimFileCopiedAndShowingIntoTheReader()
|
assertZimFileCopiedAndShowingIntoTheReader(composeTestRule)
|
||||||
}
|
}
|
||||||
assertZimFileAddedInTheLocalLibrary()
|
assertZimFileAddedInTheLocalLibrary()
|
||||||
// Test with second launch, this time permission dialog should not show.
|
// Test with second launch, this time permission dialog should not show.
|
||||||
@ -177,7 +178,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
|
|||||||
copyMoveFileHandler {
|
copyMoveFileHandler {
|
||||||
assertCopyMoveDialogDisplayed(composeTestRule)
|
assertCopyMoveDialogDisplayed(composeTestRule)
|
||||||
clickOnMove(composeTestRule)
|
clickOnMove(composeTestRule)
|
||||||
assertZimFileCopiedAndShowingIntoTheReader()
|
assertZimFileCopiedAndShowingIntoTheReader(composeTestRule)
|
||||||
}
|
}
|
||||||
assertZimFileAddedInTheLocalLibrary()
|
assertZimFileAddedInTheLocalLibrary()
|
||||||
kiwixMainActivity.lifecycleScope.launch {
|
kiwixMainActivity.lifecycleScope.launch {
|
||||||
@ -312,7 +313,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
|
|||||||
kiwixMainActivity = it
|
kiwixMainActivity = it
|
||||||
kiwixMainActivity.navigate(R.id.libraryFragment)
|
kiwixMainActivity.navigate(R.id.libraryFragment)
|
||||||
}
|
}
|
||||||
copyMoveFileHandler(CopyMoveFileHandlerRobot::pauseForBetterTestPerformance)
|
composeTestRule.waitUntilTimeout()
|
||||||
sharedPreferenceUtil.apply {
|
sharedPreferenceUtil.apply {
|
||||||
shouldShowStorageSelectionDialog = false
|
shouldShowStorageSelectionDialog = false
|
||||||
setIsPlayStoreBuildType(true)
|
setIsPlayStoreBuildType(true)
|
||||||
|
@ -123,7 +123,7 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
|
|||||||
clickOnMove(composeTestRule)
|
clickOnMove(composeTestRule)
|
||||||
assertStorageSelectionDialogDisplayed(composeTestRule)
|
assertStorageSelectionDialogDisplayed(composeTestRule)
|
||||||
clickOnInternalStorage(composeTestRule)
|
clickOnInternalStorage(composeTestRule)
|
||||||
assertZimFileCopiedAndShowingIntoTheReader()
|
assertZimFileCopiedAndShowingIntoTheReader(composeTestRule)
|
||||||
}
|
}
|
||||||
} catch (ignore: Exception) {
|
} catch (ignore: Exception) {
|
||||||
fail("Could not open file from file manager. Original exception = $ignore")
|
fail("Could not open file from file manager. Original exception = $ignore")
|
||||||
@ -153,7 +153,7 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
|
|||||||
clickOnMove(composeTestRule)
|
clickOnMove(composeTestRule)
|
||||||
assertStorageSelectionDialogDisplayed(composeTestRule)
|
assertStorageSelectionDialogDisplayed(composeTestRule)
|
||||||
clickOnInternalStorage(composeTestRule)
|
clickOnInternalStorage(composeTestRule)
|
||||||
assertZimFileCopiedAndShowingIntoTheReader()
|
assertZimFileCopiedAndShowingIntoTheReader(composeTestRule)
|
||||||
}
|
}
|
||||||
} catch (ignore: Exception) {
|
} catch (ignore: Exception) {
|
||||||
fail("Could not open file from file manager. Original exception = $ignore")
|
fail("Could not open file from file manager. Original exception = $ignore")
|
||||||
|
@ -18,34 +18,41 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.nav.destination.library
|
package org.kiwix.kiwixmobile.nav.destination.library
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
import android.widget.ProgressBar
|
import androidx.compose.foundation.layout.Column
|
||||||
import android.widget.TextView
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import org.kiwix.kiwixmobile.storage.STORAGE_SELECT_STORAGE_TITLE_TEXTVIEW_SIZE
|
|
||||||
import eu.mhutti1.utils.storage.StorageDevice
|
import eu.mhutti1.utils.storage.StorageDevice
|
||||||
import org.kiwix.kiwixmobile.storage.StorageSelectDialog
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.kiwix.kiwixmobile.R.id
|
|
||||||
import org.kiwix.kiwixmobile.R.layout
|
|
||||||
import org.kiwix.kiwixmobile.core.R
|
import org.kiwix.kiwixmobile.core.R
|
||||||
|
import org.kiwix.kiwixmobile.core.downloader.downloadManager.ZERO
|
||||||
import org.kiwix.kiwixmobile.core.extensions.deleteFile
|
import org.kiwix.kiwixmobile.core.extensions.deleteFile
|
||||||
import org.kiwix.kiwixmobile.core.extensions.isFileExist
|
import org.kiwix.kiwixmobile.core.extensions.isFileExist
|
||||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
|
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
|
||||||
import org.kiwix.kiwixmobile.core.settings.StorageCalculator
|
import org.kiwix.kiwixmobile.core.settings.StorageCalculator
|
||||||
import org.kiwix.kiwixmobile.core.ui.components.ContentLoadingProgressBar
|
import org.kiwix.kiwixmobile.core.ui.components.ContentLoadingProgressBar
|
||||||
|
import org.kiwix.kiwixmobile.core.ui.components.ProgressBarStyle
|
||||||
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.EIGHT_DP
|
||||||
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.SIXTEEN_DP
|
||||||
import org.kiwix.kiwixmobile.core.utils.EXTERNAL_SELECT_POSITION
|
import org.kiwix.kiwixmobile.core.utils.EXTERNAL_SELECT_POSITION
|
||||||
import org.kiwix.kiwixmobile.core.utils.INTERNAL_SELECT_POSITION
|
import org.kiwix.kiwixmobile.core.utils.INTERNAL_SELECT_POSITION
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
@ -53,6 +60,8 @@ import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
|||||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
|
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
|
||||||
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
|
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
|
import org.kiwix.kiwixmobile.storage.STORAGE_SELECT_STORAGE_TITLE_TEXTVIEW_SIZE
|
||||||
|
import org.kiwix.kiwixmobile.storage.StorageSelectDialog
|
||||||
import org.kiwix.kiwixmobile.zimManager.Fat32Checker
|
import org.kiwix.kiwixmobile.zimManager.Fat32Checker
|
||||||
import org.kiwix.kiwixmobile.zimManager.Fat32Checker.Companion.FOUR_GIGABYTES_IN_KILOBYTES
|
import org.kiwix.kiwixmobile.zimManager.Fat32Checker.Companion.FOUR_GIGABYTES_IN_KILOBYTES
|
||||||
import org.kiwix.kiwixmobile.zimManager.Fat32Checker.FileSystemState.CannotWrite4GbFile
|
import org.kiwix.kiwixmobile.zimManager.Fat32Checker.FileSystemState.CannotWrite4GbFile
|
||||||
@ -73,21 +82,27 @@ class CopyMoveFileHandler @Inject constructor(
|
|||||||
private var fileCopyMoveCallback: FileCopyMoveCallback? = null
|
private var fileCopyMoveCallback: FileCopyMoveCallback? = null
|
||||||
private var selectedFileUri: Uri? = null
|
private var selectedFileUri: Uri? = null
|
||||||
private var selectedFile: DocumentFile? = null
|
private var selectedFile: DocumentFile? = null
|
||||||
private var progressBarDialog: AlertDialog? = null
|
|
||||||
private var lifecycleScope: CoroutineScope? = null
|
private var lifecycleScope: CoroutineScope? = null
|
||||||
private var progressBar: ProgressBar? = null
|
|
||||||
private var progressBarTextView: TextView? = null
|
/**
|
||||||
|
* Holds the state for the copy/move progress bar.
|
||||||
|
*
|
||||||
|
* A [Pair] containing:
|
||||||
|
* - [String]: The message to display below the progress bar.
|
||||||
|
* - [Int]: The current progress value (0 to 100).
|
||||||
|
*/
|
||||||
|
private var progressBarState = mutableStateOf(Pair("", ZERO))
|
||||||
var isMoveOperation = false
|
var isMoveOperation = false
|
||||||
var shouldValidateZimFile: Boolean = false
|
var shouldValidateZimFile: Boolean = false
|
||||||
private var fileSystemDisposable: Disposable? = null
|
private var fileSystemDisposable: Disposable? = null
|
||||||
private lateinit var fragmentManager: FragmentManager
|
private lateinit var fragmentManager: FragmentManager
|
||||||
private lateinit var alertDialogShower: AlertDialogShower
|
private lateinit var alertDialogShower: AlertDialogShower
|
||||||
|
|
||||||
private val copyMoveTitle: String by lazy {
|
private val copyMoveTitle: Int by lazy {
|
||||||
if (isMoveOperation) {
|
if (isMoveOperation) {
|
||||||
activity.getString(R.string.moving_zim_file)
|
R.string.moving_zim_file
|
||||||
} else {
|
} else {
|
||||||
activity.getString(R.string.copying_zim_file)
|
R.string.copying_zim_file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,9 +111,9 @@ class CopyMoveFileHandler @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateProgress(progress: Int) {
|
private fun updateProgress(progress: Int) {
|
||||||
progressBar?.post {
|
synchronized(this) {
|
||||||
progressBarTextView?.text = activity.getString(R.string.percentage, progress)
|
progressBarState.value =
|
||||||
progressBar?.setProgress(progress, true)
|
activity.getString(R.string.percentage, progress) to progress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +403,7 @@ class CopyMoveFileHandler @Inject constructor(
|
|||||||
errorMessage: String?,
|
errorMessage: String?,
|
||||||
destinationFile: File
|
destinationFile: File
|
||||||
) {
|
) {
|
||||||
dismissProgressDialog()
|
dismissCopyMoveProgressDialog()
|
||||||
fileCopyMoveCallback?.onError("$errorMessage").also {
|
fileCopyMoveCallback?.onError("$errorMessage").also {
|
||||||
// Clean up the destination file if an error occurs
|
// Clean up the destination file if an error occurs
|
||||||
lifecycleScope?.launch {
|
lifecycleScope?.launch {
|
||||||
@ -402,7 +417,7 @@ class CopyMoveFileHandler @Inject constructor(
|
|||||||
handleInvalidZimFile(destinationFile, sourceUri)
|
handleInvalidZimFile(destinationFile, sourceUri)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dismissProgressDialog()
|
dismissCopyMoveProgressDialog()
|
||||||
if (isMoveOperation) {
|
if (isMoveOperation) {
|
||||||
deleteSourceFile(sourceUri)
|
deleteSourceFile(sourceUri)
|
||||||
fileCopyMoveCallback?.onFileMoved(destinationFile)
|
fileCopyMoveCallback?.onFileMoved(destinationFile)
|
||||||
@ -425,7 +440,7 @@ class CopyMoveFileHandler @Inject constructor(
|
|||||||
|
|
||||||
if (moveSuccessful) {
|
if (moveSuccessful) {
|
||||||
// If files is moved back using the documentContract then show the error message to user
|
// If files is moved back using the documentContract then show the error message to user
|
||||||
dismissProgressDialog()
|
dismissCopyMoveProgressDialog()
|
||||||
fileCopyMoveCallback?.onError(errorMessage)
|
fileCopyMoveCallback?.onError(errorMessage)
|
||||||
} else {
|
} else {
|
||||||
// Show error message and delete the moved file if move failed.
|
// Show error message and delete the moved file if move failed.
|
||||||
@ -520,32 +535,37 @@ class CopyMoveFileHandler @Inject constructor(
|
|||||||
alertDialogShower.dismiss()
|
alertDialogShower.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
|
||||||
private fun showProgressDialog() {
|
private fun showProgressDialog() {
|
||||||
val dialogView =
|
progressBarState.value =
|
||||||
activity.layoutInflater.inflate(layout.copy_move_progress_bar, null)
|
activity.getString(R.string.percentage, ZERO) to ZERO
|
||||||
progressBar =
|
alertDialogShower.show(
|
||||||
dialogView.findViewById<ProgressBar>(id.progressBar).apply {
|
KiwixDialog.CopyMoveProgressBarDialog(
|
||||||
isIndeterminate = false
|
titleId = copyMoveTitle,
|
||||||
}
|
customViewBottomPadding = ZERO.dp,
|
||||||
progressBarTextView =
|
customGetView = { CopyMoveProgressDialog() }
|
||||||
dialogView.findViewById(id.progressTextView)
|
)
|
||||||
val builder = AlertDialog.Builder(activity).apply {
|
)
|
||||||
setTitle(copyMoveTitle)
|
|
||||||
setView(dialogView)
|
|
||||||
setCancelable(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
progressBarDialog = builder.create()
|
|
||||||
progressBarDialog?.show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dismissProgressDialog() {
|
@Composable
|
||||||
if (progressBarDialog?.isShowing == true) {
|
private fun CopyMoveProgressDialog() {
|
||||||
progressBarDialog?.dismiss()
|
Column(horizontalAlignment = Alignment.End, modifier = Modifier.fillMaxWidth()) {
|
||||||
|
ContentLoadingProgressBar(
|
||||||
|
progress = progressBarState.value.second,
|
||||||
|
progressBarStyle = ProgressBarStyle.HORIZONTAL
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(EIGHT_DP))
|
||||||
|
Text(
|
||||||
|
progressBarState.value.first,
|
||||||
|
modifier = Modifier.padding(end = SIXTEEN_DP, bottom = SIXTEEN_DP)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dismissCopyMoveProgressDialog() {
|
||||||
|
hidePreparingCopyMoveDialog()
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getStorageDeviceList() =
|
suspend fun getStorageDeviceList() =
|
||||||
(activity as KiwixMainActivity).getStorageDeviceList()
|
(activity as KiwixMainActivity).getStorageDeviceList()
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem
|
|||||||
import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem.DividerItem
|
import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem.DividerItem
|
||||||
|
|
||||||
const val ONLINE_LIBRARY_SEARCH_VIEW_TESTING_TAG = "onlineLibrarySearchViewTestingTag"
|
const val ONLINE_LIBRARY_SEARCH_VIEW_TESTING_TAG = "onlineLibrarySearchViewTestingTag"
|
||||||
const val ONLINE_LIBRARY_SEARCH_VIEW_CLOSE_BUTTON_TESTING_TAG = "onlineLibrarySearchViewCloseButtonTestingTag"
|
const val ONLINE_LIBRARY_SEARCH_VIEW_CLOSE_BUTTON_TESTING_TAG =
|
||||||
|
"onlineLibrarySearchViewCloseButtonTestingTag"
|
||||||
const val NO_CONTENT_VIEW_TEXT_TESTING_TAG = "noContentViewTextTestingTag"
|
const val NO_CONTENT_VIEW_TEXT_TESTING_TAG = "noContentViewTextTestingTag"
|
||||||
const val SHOW_FETCHING_LIBRARY_LAYOUT_TESTING_TAG = "showFetchingLibraryLayoutTestingTag"
|
const val SHOW_FETCHING_LIBRARY_LAYOUT_TESTING_TAG = "showFetchingLibraryLayoutTestingTag"
|
||||||
|
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?><!--
|
|
||||||
~ Kiwix Android
|
|
||||||
~ Copyright (c) 2024 Kiwix <android.kiwix.org>
|
|
||||||
~ This program is free software: you can redistribute it and/or modify
|
|
||||||
~ it under the terms of the GNU General Public License as published by
|
|
||||||
~ the Free Software Foundation, either version 3 of the License, or
|
|
||||||
~ (at your option) any later version.
|
|
||||||
~
|
|
||||||
~ This program is distributed in the hope that it will be useful,
|
|
||||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
~ GNU General Public License for more details.
|
|
||||||
~
|
|
||||||
~ You should have received a copy of the GNU General Public License
|
|
||||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
~
|
|
||||||
-->
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/progressTextView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
|
||||||
android:paddingBottom="@dimen/activity_horizontal_margin"
|
|
||||||
android:text="@string/copying_zim_file"
|
|
||||||
android:textSize="12sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/progressBar" />
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/progressBar"
|
|
||||||
style="?android:attr/progressBarStyleHorizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_margin="@dimen/activity_horizontal_margin"
|
|
||||||
android:max="100"
|
|
||||||
android:progress="0"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -318,7 +318,7 @@ class CopyMoveFileHandlerTest {
|
|||||||
fileHandler.notifyFileOperationSuccess(destinationFile, sourceUri)
|
fileHandler.notifyFileOperationSuccess(destinationFile, sourceUri)
|
||||||
|
|
||||||
verify { fileCopyMoveCallback.onFileMoved(destinationFile) }
|
verify { fileCopyMoveCallback.onFileMoved(destinationFile) }
|
||||||
verify { fileHandler.dismissProgressDialog() }
|
verify { fileHandler.dismissCopyMoveProgressDialog() }
|
||||||
coVerify { fileHandler.deleteSourceFile(sourceUri) }
|
coVerify { fileHandler.deleteSourceFile(sourceUri) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ class CopyMoveFileHandlerTest {
|
|||||||
fileHandler.notifyFileOperationSuccess(destinationFile, sourceUri)
|
fileHandler.notifyFileOperationSuccess(destinationFile, sourceUri)
|
||||||
|
|
||||||
verify { fileCopyMoveCallback.onFileCopied(destinationFile) }
|
verify { fileCopyMoveCallback.onFileCopied(destinationFile) }
|
||||||
verify { fileHandler.dismissProgressDialog() }
|
verify { fileHandler.dismissCopyMoveProgressDialog() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -356,7 +356,7 @@ class CopyMoveFileHandlerTest {
|
|||||||
|
|
||||||
fileHandler.handleInvalidZimFile(destinationFile, sourceUri)
|
fileHandler.handleInvalidZimFile(destinationFile, sourceUri)
|
||||||
|
|
||||||
verify { fileHandler.dismissProgressDialog() }
|
verify { fileHandler.dismissCopyMoveProgressDialog() }
|
||||||
verify {
|
verify {
|
||||||
fileCopyMoveCallback.onError(
|
fileCopyMoveCallback.onError(
|
||||||
activity.getString(
|
activity.getString(
|
||||||
|
@ -67,7 +67,6 @@ import org.kiwix.kiwixmobile.core.ui.theme.KiwixDialogTheme
|
|||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_BUTTONS_TEXT_SIZE
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_BUTTONS_TEXT_SIZE
|
||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_BUTTON_ROW_BOTTOM_PADDING
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_BUTTON_ROW_BOTTOM_PADDING
|
||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_BUTTON_TEXT_LETTER_SPACING
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_BUTTON_TEXT_LETTER_SPACING
|
||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_CUSTOM_VIEW_BOTTOM_PADDING
|
|
||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_DEFAULT_PADDING_FOR_CONTENT
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_DEFAULT_PADDING_FOR_CONTENT
|
||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_ICON_END_PADDING
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_ICON_END_PADDING
|
||||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_ICON_SIZE
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_ICON_SIZE
|
||||||
@ -152,7 +151,7 @@ fun ShowCustomComposeView(dialog: KiwixDialog) {
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.wrapContentHeight()
|
.wrapContentHeight()
|
||||||
.padding(bottom = DIALOG_CUSTOM_VIEW_BOTTOM_PADDING),
|
.padding(bottom = dialog.customComposeViewBottomPadding),
|
||||||
contentAlignment = Alignment.TopStart
|
contentAlignment = Alignment.TopStart
|
||||||
) {
|
) {
|
||||||
it.invoke()
|
it.invoke()
|
||||||
|
@ -20,9 +20,11 @@ package org.kiwix.kiwixmobile.core.utils.dialog
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
import org.kiwix.kiwixmobile.core.R
|
import org.kiwix.kiwixmobile.core.R
|
||||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||||
import org.kiwix.kiwixmobile.core.ui.models.IconItem
|
import org.kiwix.kiwixmobile.core.ui.models.IconItem
|
||||||
|
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.DIALOG_CUSTOM_VIEW_BOTTOM_PADDING
|
||||||
|
|
||||||
@Suppress("LongParameterList")
|
@Suppress("LongParameterList")
|
||||||
sealed class KiwixDialog(
|
sealed class KiwixDialog(
|
||||||
@ -33,7 +35,8 @@ sealed class KiwixDialog(
|
|||||||
val cancelable: Boolean = true,
|
val cancelable: Boolean = true,
|
||||||
val iconItem: IconItem? = null,
|
val iconItem: IconItem? = null,
|
||||||
val neutralButtonText: Int? = null,
|
val neutralButtonText: Int? = null,
|
||||||
val customComposeView: (@Composable (() -> Unit))? = null
|
val customComposeView: (@Composable (() -> Unit))? = null,
|
||||||
|
val customComposeViewBottomPadding: Dp = DIALOG_CUSTOM_VIEW_BOTTOM_PADDING
|
||||||
) {
|
) {
|
||||||
data class DeleteZims(override val args: List<Any>) :
|
data class DeleteZims(override val args: List<Any>) :
|
||||||
KiwixDialog(
|
KiwixDialog(
|
||||||
@ -127,6 +130,20 @@ sealed class KiwixDialog(
|
|||||||
cancelable = false
|
cancelable = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class CopyMoveProgressBarDialog(
|
||||||
|
private val titleId: Int,
|
||||||
|
private val customViewBottomPadding: Dp,
|
||||||
|
private val customGetView: @Composable (() -> Unit)?
|
||||||
|
) : KiwixDialog(
|
||||||
|
title = titleId,
|
||||||
|
message = null,
|
||||||
|
cancelable = false,
|
||||||
|
confirmButtonText = R.string.empty_string,
|
||||||
|
dismissButtonText = null,
|
||||||
|
customComposeView = customGetView,
|
||||||
|
customComposeViewBottomPadding = customViewBottomPadding
|
||||||
|
)
|
||||||
|
|
||||||
data object ShowWarningAboutSplittedZimFile : KiwixDialog(
|
data object ShowWarningAboutSplittedZimFile : KiwixDialog(
|
||||||
R.string.verify_zim_chunk_dialog_title,
|
R.string.verify_zim_chunk_dialog_title,
|
||||||
R.string.verify_zim_chunks_dialog_message,
|
R.string.verify_zim_chunks_dialog_message,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user