From d572af4fcdbc146143732b2d6d347d7c0ca082ba Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 7 Nov 2024 10:44:43 +0530 Subject: [PATCH 1/6] Removed the usesCleartextTraffic from our manifest --- app/src/androidTest/AndroidManifest.xml | 3 +-- core/src/main/AndroidManifest.xml | 1 - custom/src/androidTest/AndroidManifest.xml | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/src/androidTest/AndroidManifest.xml b/app/src/androidTest/AndroidManifest.xml index 9a891e6916..f633d37a3c 100644 --- a/app/src/androidTest/AndroidManifest.xml +++ b/app/src/androidTest/AndroidManifest.xml @@ -6,7 +6,6 @@ see more information here https://github.com/kiwix/kiwix-android/issues/3172 --> + android:forceQueryable="true" /> diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml index 2301c6491c..ab9593b5d8 100644 --- a/core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -58,7 +58,6 @@ android:resizeableActivity="true" android:supportsRtl="true" android:theme="@style/KiwixTheme" - android:usesCleartextTraffic="true" tools:targetApi="tiramisu"> diff --git a/custom/src/androidTest/AndroidManifest.xml b/custom/src/androidTest/AndroidManifest.xml index d24c7492a3..e704e117bc 100644 --- a/custom/src/androidTest/AndroidManifest.xml +++ b/custom/src/androidTest/AndroidManifest.xml @@ -23,7 +23,6 @@ see more information here https://github.com/kiwix/kiwix-android/issues/3172 --> + android:forceQueryable="true" /> From 071dc96c9a12c731adf00676aa4474aed9871945 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 7 Nov 2024 10:39:01 +0530 Subject: [PATCH 2/6] Fixed: Kiwix now opens in the Samsung file navigator. --- app/src/main/AndroidManifest.xml | 2 +- .../org/kiwix/kiwixmobile/main/KiwixMainActivity.kt | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 06787e9cfa..db386c9afb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,7 +28,7 @@ android:configChanges="orientation|keyboardHidden|screenSize" android:exported="true" android:label="@string/app_name" - android:launchMode="singleTop" + android:launchMode="singleInstance" android:theme="@style/KiwixTheme.Launcher" android:windowSoftInputMode="adjustPan"> diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt index ff49bf4fc4..758fea7155 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt @@ -117,9 +117,6 @@ class KiwixMainActivity : CoreMainActivity() { super.onCreate(savedInstanceState) activityKiwixMainBinding = ActivityKiwixMainBinding.inflate(layoutInflater) setContentView(activityKiwixMainBinding.root) - if (intent.action == "GET_CONTENT") { - navigate(R.id.downloadsFragment) - } navController.addOnDestinationChangedListener(finishActionModeOnDestinationChange) activityKiwixMainBinding.drawerNavView.setupWithNavController(navController) @@ -130,6 +127,7 @@ class KiwixMainActivity : CoreMainActivity() { activityKiwixMainBinding.bottomNavView.setupWithNavController(navController) migrateInternalToPublicAppDirectory() handleZimFileIntent(intent) + handleGetContentIntent(intent) } private fun migrateInternalToPublicAppDirectory() { @@ -220,11 +218,18 @@ class KiwixMainActivity : CoreMainActivity() { super.onNewIntent(intent) handleNotificationIntent(intent) handleZimFileIntent(intent) + handleGetContentIntent(intent) supportFragmentManager.fragments.filterIsInstance().forEach { it.onNewIntent(intent, this) } } + private fun handleGetContentIntent(intent: Intent?) { + if (intent?.action == ACTION_GET_CONTENT) { + navigate(R.id.downloadsFragment) + } + } + private fun handleZimFileIntent(intent: Intent?) { intent?.data?.let { when (it.scheme) { From 47c0abc48276937cc28e5a9d69a0986d3b8c4bd6 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 4 Nov 2024 22:25:59 +0530 Subject: [PATCH 3/6] Fixed: Still displaying old storage configurator (at first download). --- .../initial/download/InitialDownloadRobot.kt | 14 +++- .../initial/download/InitialDownloadTest.kt | 2 +- .../library/OnlineLibraryFragment.kt | 21 ++--- .../settings/KiwixPrefsFragment.kt | 69 +++------------- .../utils/storage/StorageSelectDialog.kt | 37 ++++++++- .../utils/storage/adapter/StorageDelegate.kt | 4 +- .../storage/adapter/StorageViewHolder.kt | 80 ++++++++++++++----- .../extensions/StorageDeviceExtensions.kt | 73 +++++++++++++++++ .../core/utils/dialog/KiwixDialog.kt | 8 -- .../res/drawable/ic_baseline_storage_24.xml | 10 --- core/src/main/res/layout/device_item.xml | 38 --------- .../res/layout/item_storage_preference.xml | 12 ++- core/src/main/res/values-ar/strings.xml | 4 +- core/src/main/res/values-bn/strings.xml | 2 - core/src/main/res/values-br/strings.xml | 2 - core/src/main/res/values-cs/strings.xml | 2 - core/src/main/res/values-dag/strings.xml | 2 - core/src/main/res/values-de/strings.xml | 2 - core/src/main/res/values-es/strings.xml | 2 - core/src/main/res/values-eu/strings.xml | 2 - core/src/main/res/values-fr/strings.xml | 2 - core/src/main/res/values-gpe/strings.xml | 1 - core/src/main/res/values-ha/strings.xml | 2 - core/src/main/res/values-hi/strings.xml | 2 - core/src/main/res/values-ia/strings.xml | 2 - core/src/main/res/values-ig/strings.xml | 2 - core/src/main/res/values-in/strings.xml | 2 - core/src/main/res/values-it/strings.xml | 2 - core/src/main/res/values-iw/strings.xml | 2 - core/src/main/res/values-ja/strings.xml | 2 - core/src/main/res/values-ko/strings.xml | 2 - core/src/main/res/values-ku/strings.xml | 2 - core/src/main/res/values-lb/strings.xml | 1 - core/src/main/res/values-mk/strings.xml | 2 - core/src/main/res/values-nl/strings.xml | 2 - core/src/main/res/values-nqo/strings.xml | 2 - core/src/main/res/values-or/strings.xml | 2 - core/src/main/res/values-pl/strings.xml | 2 - core/src/main/res/values-pt-rBR/strings.xml | 2 - core/src/main/res/values-qq/strings.xml | 2 - core/src/main/res/values-ru/strings.xml | 2 - core/src/main/res/values-sc/strings.xml | 2 - core/src/main/res/values-skr/strings.xml | 1 - core/src/main/res/values-sl/strings.xml | 2 - core/src/main/res/values-sq/strings.xml | 2 - core/src/main/res/values-sv/strings.xml | 2 - core/src/main/res/values-sw/strings.xml | 2 - core/src/main/res/values-ta/strings.xml | 2 - core/src/main/res/values-te/strings.xml | 2 - core/src/main/res/values-tn/strings.xml | 2 - core/src/main/res/values-tr/strings.xml | 2 - core/src/main/res/values-uk/strings.xml | 1 - core/src/main/res/values-xal/strings.xml | 2 - core/src/main/res/values-yo/strings.xml | 2 - core/src/main/res/values-zh-rTW/strings.xml | 2 - core/src/main/res/values-zh/strings.xml | 2 - core/src/main/res/values/strings.xml | 3 +- 57 files changed, 215 insertions(+), 242 deletions(-) create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/extensions/StorageDeviceExtensions.kt delete mode 100644 core/src/main/res/drawable/ic_baseline_storage_24.xml delete mode 100644 core/src/main/res/layout/device_item.xml diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadRobot.kt index d75465dbb1..f375bdd8d1 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadRobot.kt @@ -34,6 +34,7 @@ import org.kiwix.kiwixmobile.Findable.Text import org.kiwix.kiwixmobile.Findable.ViewId import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.R.string +import org.kiwix.kiwixmobile.core.R.id import org.kiwix.kiwixmobile.core.utils.files.Log import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView @@ -98,7 +99,7 @@ class InitialDownloadRobot : BaseRobot() { } fun assertStorageConfigureDialogDisplayed() { - testFlakyView({ isVisible(Text("Download book to internal storage?")) }) + testFlakyView({ onView(withText(string.choose_storage_to_download_book)) }) } fun assertStopDownloadDialogDisplayed() { @@ -109,6 +110,17 @@ class InitialDownloadRobot : BaseRobot() { testFlakyView({ onView(withText("YES")).perform(click()) }) } + fun clickOnInternalStorage() { + pauseForBetterTestPerformance() + testFlakyView({ + onView( + RecyclerViewMatcher(id.device_list).atPosition( + 0 + ) + ).perform(click()) + }) + } + fun assertDownloadStart() { testFlakyView({ isVisible(ViewId(R.id.stop)) }, 10) } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt index c486bbd0c7..3b3b7c6a74 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt @@ -122,7 +122,7 @@ class InitialDownloadTest : BaseActivityTest() { stopDownloadIfAlreadyStarted() downloadZimFile() assertStorageConfigureDialogDisplayed() - clickOnYesToConfirm() + clickOnInternalStorage() assertDownloadStart() stopDownload() assertStopDownloadDialogDisplayed() diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt index 66e1ed33c6..c1991575d1 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt @@ -49,6 +49,7 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import eu.mhutti1.utils.storage.STORAGE_SELECT_STORAGE_TITLE_TEXTVIEW_SIZE import eu.mhutti1.utils.storage.StorageDevice import eu.mhutti1.utils.storage.StorageSelectDialog import org.kiwix.kiwixmobile.R @@ -419,6 +420,7 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { private fun storeDeviceInPreferences( storageDevice: StorageDevice ) { + sharedPreferenceUtil.showStorageOption = false sharedPreferenceUtil.putPrefStorage( sharedPreferenceUtil.getPublicDirectoryPath(storageDevice.name) ) @@ -528,7 +530,7 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { } else -> if (sharedPreferenceUtil.showStorageOption) { - showStorageConfigureDialog() + showStorageSelectDialog() } else if (!requireActivity().isManageExternalStoragePermissionGranted( sharedPreferenceUtil ) @@ -561,22 +563,9 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { private fun showStorageSelectDialog() = StorageSelectDialog() .apply { onSelectAction = ::storeDeviceInPreferences + titleSize = STORAGE_SELECT_STORAGE_TITLE_TEXTVIEW_SIZE } - .show(parentFragmentManager, getString(string.pref_storage)) - - private fun showStorageConfigureDialog() { - alertDialogShower.show( - KiwixDialog.StorageConfigure, - { - showStorageSelectDialog() - sharedPreferenceUtil.showStorageOption = false - }, - { - sharedPreferenceUtil.showStorageOption = false - clickOnBookItem() - } - ) - } + .show(parentFragmentManager, getString(string.choose_storage_to_download_book)) private fun clickOnBookItem() { if (!requireActivity().isManageExternalStoragePermissionGranted(sharedPreferenceUtil)) { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/settings/KiwixPrefsFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/settings/KiwixPrefsFragment.kt index 8b8aff5077..8e40ca4c7d 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/settings/KiwixPrefsFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/settings/KiwixPrefsFragment.kt @@ -31,6 +31,10 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import org.kiwix.kiwixmobile.core.R +import org.kiwix.kiwixmobile.core.extensions.getFreeSpace +import org.kiwix.kiwixmobile.core.extensions.getUsedSpace +import org.kiwix.kiwixmobile.core.extensions.storagePathAndTitle +import org.kiwix.kiwixmobile.core.extensions.usedPercentage import org.kiwix.kiwixmobile.core.navigateToSettings import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment import org.kiwix.kiwixmobile.core.settings.StorageRadioButtonPreference @@ -80,69 +84,18 @@ class KiwixPrefsFragment : CorePrefsFragment() { onStorageDeviceSelected(storageDevice) true } - setPathAndTitleForStorage( - buildStoragePathAndTitle( - storageDevice, - index, - selectedStoragePosition, - sharedPreferenceUtil + storageCalculator?.let { + setPathAndTitleForStorage( + storageDevice.storagePathAndTitle(context, index, sharedPreferenceUtil, it) ) - ) - setFreeSpace(getFreeSpaceText(storageDevice)) - setUsedSpace(getUsedSpaceText(storageDevice)) - setProgress(calculateUsedPercentage(storageDevice)) + setFreeSpace(storageDevice.getFreeSpace(context, it)) + setUsedSpace(storageDevice.getUsedSpace(context, it)) + setProgress(storageDevice.usedPercentage(it)) + } } } } - private fun getFreeSpaceText(storageDevice: StorageDevice): String { - val freeSpace = storageCalculator?.calculateAvailableSpace(storageDevice.file) - return getString(R.string.pref_free_storage, freeSpace) - } - - private fun getUsedSpaceText(storageDevice: StorageDevice): String { - val usedSpace = storageCalculator?.calculateUsedSpace(storageDevice.file) - return getString(R.string.pref_storage_used, usedSpace) - } - - private fun buildStoragePathAndTitle( - storageDevice: StorageDevice, - index: Int, - selectedStoragePosition: Int, - sharedPreferenceUtil: SharedPreferenceUtil - ): String { - val storageName = if (storageDevice.isInternal) { - getString(R.string.internal_storage) - } else { - getString(R.string.external_storage) - } - val storagePath = if (index == selectedStoragePosition) { - sharedPreferenceUtil.prefStorage - } else { - getStoragePathForNonSelectedStorage(storageDevice, sharedPreferenceUtil) - } - val totalSpace = storageCalculator?.calculateTotalSpace(storageDevice.file) - return "$storageName - $totalSpace\n$storagePath/Kiwix" - } - - private fun getStoragePathForNonSelectedStorage( - storageDevice: StorageDevice, - sharedPreferenceUtil: SharedPreferenceUtil - ): String = - if (storageDevice.isInternal) { - sharedPreferenceUtil.getPublicDirectoryPath(storageDevice.name) - } else { - storageDevice.name - } - - @Suppress("MagicNumber") - private fun calculateUsedPercentage(storageDevice: StorageDevice): Int { - val totalSpace = storageCalculator?.totalBytes(storageDevice.file) ?: 1 - val availableSpace = storageCalculator?.availableBytes(storageDevice.file) ?: 0 - val usedSpace = totalSpace - availableSpace - return (usedSpace.toDouble() / totalSpace * 100).toInt() - } - private fun showExternalPreferenceIfAvailable() { findPreference(PREF_EXTERNAL_STORAGE)?.isVisible = storageDeviceList.size > 1 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 368ae14636..bfe47f064e 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt @@ -18,6 +18,7 @@ package eu.mhutti1.utils.storage +import android.content.res.Configuration import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -33,13 +34,19 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import org.kiwix.kiwixmobile.core.CoreApp +import org.kiwix.kiwixmobile.core.R.dimen import org.kiwix.kiwixmobile.core.databinding.StorageSelectDialogBinding +import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isLandScapeMode import org.kiwix.kiwixmobile.core.settings.StorageCalculator +import org.kiwix.kiwixmobile.core.utils.DimenUtils.getWindowWidth import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import javax.inject.Inject +const val STORAGE_SELECT_STORAGE_TITLE_TEXTVIEW_SIZE = 16F + class StorageSelectDialog : DialogFragment() { var onSelectAction: ((StorageDevice) -> Unit)? = null + var titleSize: Float? = null @Inject lateinit var storageCalculator: StorageCalculator @Inject lateinit var sharedPreferenceUtil: SharedPreferenceUtil @@ -68,7 +75,10 @@ class StorageSelectDialog : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) CoreApp.coreComponent.inject(this) - storageSelectDialogViewBinding?.title?.text = aTitle + storageSelectDialogViewBinding?.title?.apply { + text = aTitle + titleSize?.let(::setTextSize) + } storageSelectDialogViewBinding?.deviceList?.run { adapter = storageAdapter layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false) @@ -90,6 +100,31 @@ class StorageSelectDialog : DialogFragment() { super.show(fm, text) } + override fun onStart() { + super.onStart() + setStorageSelectDialogWidth() + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + setStorageSelectDialogWidth() + } + + @Suppress("MagicNumber") + private fun setStorageSelectDialogWidth() { + val windowWidth = requireActivity().getWindowWidth() + val maximumStorageSelectDialogWidth = + requireActivity().resources.getDimensionPixelSize(dimen.maximum_donation_popup_width) + + val width = + if (windowWidth > maximumStorageSelectDialogWidth || requireActivity().isLandScapeMode()) { + maximumStorageSelectDialogWidth + } else { + (windowWidth * 0.9).toInt() + } + dialog?.window?.setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT) + } + override fun onDestroyView() { super.onDestroyView() storageDisposable?.dispose() diff --git a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageDelegate.kt b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageDelegate.kt index 0eaecd338b..29ec303ff5 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageDelegate.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageDelegate.kt @@ -22,7 +22,7 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView.ViewHolder import eu.mhutti1.utils.storage.StorageDevice import org.kiwix.kiwixmobile.core.base.adapter.AdapterDelegate -import org.kiwix.kiwixmobile.core.databinding.DeviceItemBinding +import org.kiwix.kiwixmobile.core.databinding.ItemStoragePreferenceBinding import org.kiwix.kiwixmobile.core.extensions.ViewGroupExtensions.viewBinding import org.kiwix.kiwixmobile.core.settings.StorageCalculator import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil @@ -34,7 +34,7 @@ class StorageDelegate( ) : AdapterDelegate { override fun createViewHolder(parent: ViewGroup): ViewHolder { return StorageViewHolder( - parent.viewBinding(DeviceItemBinding::inflate, false), + parent.viewBinding(ItemStoragePreferenceBinding::inflate, false), storageCalculator, sharedPreferenceUtil, onClickAction diff --git a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt index ae3a4d2070..7f1c0bd3e9 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt @@ -19,42 +19,84 @@ package eu.mhutti1.utils.storage.adapter import android.annotation.SuppressLint +import android.text.Spannable +import android.text.SpannableStringBuilder +import android.text.style.AbsoluteSizeSpan +import android.view.View.VISIBLE import eu.mhutti1.utils.storage.StorageDevice import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.base.adapter.BaseViewHolder -import org.kiwix.kiwixmobile.core.databinding.DeviceItemBinding +import org.kiwix.kiwixmobile.core.databinding.ItemStoragePreferenceBinding +import org.kiwix.kiwixmobile.core.downloader.downloadManager.ZERO +import org.kiwix.kiwixmobile.core.extensions.getFreeSpace +import org.kiwix.kiwixmobile.core.extensions.getUsedSpace import org.kiwix.kiwixmobile.core.extensions.setToolTipWithContentDescription +import org.kiwix.kiwixmobile.core.extensions.storagePathAndTitle +import org.kiwix.kiwixmobile.core.extensions.usedPercentage import org.kiwix.kiwixmobile.core.settings.StorageCalculator import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil +const val FREE_SPACE_TEXTVIEW_SIZE = 12F +const val STORAGE_TITLE_TEXTVIEW_SIZE = 15 + @SuppressLint("SetTextI18n") internal class StorageViewHolder( - private val deviceItemBinding: DeviceItemBinding, + private val itemStoragePreferenceBinding: ItemStoragePreferenceBinding, private val storageCalculator: StorageCalculator, private val sharedPreferenceUtil: SharedPreferenceUtil, private val onClickAction: (StorageDevice) -> Unit -) : BaseViewHolder(deviceItemBinding.root) { +) : BaseViewHolder(itemStoragePreferenceBinding.root) { override fun bind(item: StorageDevice) { - deviceItemBinding.fileName.setText( - if (item.isInternal) R.string.internal_storage - else R.string.external_storage - ) + with(itemStoragePreferenceBinding) { + storagePathAndTitle.text = + resizeStoragePathAndTitle( + item.storagePathAndTitle( + root.context, + adapterPosition, + sharedPreferenceUtil, + storageCalculator + ) + ) - if (adapterPosition == sharedPreferenceUtil.storagePosition) { - deviceItemBinding.fileName.isChecked = true - } - deviceItemBinding.fileSize.text = storageCalculator.calculateAvailableSpace(item.file) + " / " + - storageCalculator.calculateTotalSpace(item.file) + " " - deviceItemBinding.clickOverlay.apply { - setToolTipWithContentDescription( - deviceItemBinding.root.context.getString( - R.string.storage_selection_dialog_accessibility_description + radioButton.isChecked = + adapterPosition == sharedPreferenceUtil.storagePosition + freeSpace.apply { + text = item.getFreeSpace(root.context, storageCalculator) + textSize = FREE_SPACE_TEXTVIEW_SIZE + } + usedSpace.apply { + text = item.getUsedSpace(root.context, storageCalculator) + textSize = FREE_SPACE_TEXTVIEW_SIZE + } + storageProgressBar.progress = item.usedPercentage(storageCalculator) + clickOverlay.apply { + visibility = VISIBLE + setToolTipWithContentDescription( + root.context.getString( + R.string.storage_selection_dialog_accessibility_description + ) ) - ) - setOnClickListener { - onClickAction.invoke(item) + setOnClickListener { + onClickAction.invoke(item) + } } } } + + private fun resizeStoragePathAndTitle(storagePathAndTitle: String): CharSequence = + SpannableStringBuilder(storagePathAndTitle).apply { + setSpan( + AbsoluteSizeSpan(STORAGE_TITLE_TEXTVIEW_SIZE, true), + ZERO, + storagePathAndTitle.indexOf('\n'), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ) + setSpan( + AbsoluteSizeSpan(FREE_SPACE_TEXTVIEW_SIZE.toInt(), true), + storagePathAndTitle.indexOf('\n') + 1, + storagePathAndTitle.length, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ) + } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/StorageDeviceExtensions.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/StorageDeviceExtensions.kt new file mode 100644 index 0000000000..edc62ba8f1 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/StorageDeviceExtensions.kt @@ -0,0 +1,73 @@ +/* + * Kiwix Android + * Copyright (c) 2024 Kiwix + * 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 . + * + */ + +package org.kiwix.kiwixmobile.core.extensions + +import android.content.Context +import eu.mhutti1.utils.storage.StorageDevice +import org.kiwix.kiwixmobile.core.R +import org.kiwix.kiwixmobile.core.settings.StorageCalculator +import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil + +fun StorageDevice.getFreeSpace(context: Context, storageCalculator: StorageCalculator): String { + val freeSpace = storageCalculator.calculateAvailableSpace(file) + return context.getString(R.string.pref_free_storage, freeSpace) +} + +fun StorageDevice.getUsedSpace(context: Context, storageCalculator: StorageCalculator): String { + val usedSpace = storageCalculator.calculateUsedSpace(file) + return context.getString(R.string.pref_storage_used, usedSpace) +} + +@Suppress("MagicNumber") +fun StorageDevice.usedPercentage(storageCalculator: StorageCalculator): Int { + val totalSpace = storageCalculator.totalBytes(file) + val availableSpace = storageCalculator.availableBytes(file) + val usedSpace = totalSpace - availableSpace + return (usedSpace.toDouble() / totalSpace * 100).toInt() +} + +fun StorageDevice.storagePathAndTitle( + context: Context, + index: Int, + sharedPreferenceUtil: SharedPreferenceUtil, + storageCalculator: StorageCalculator +): String { + val storageName = if (isInternal) { + context.getString(R.string.internal_storage) + } else { + context.getString(R.string.external_storage) + } + val storagePath = if (index == sharedPreferenceUtil.storagePosition) { + sharedPreferenceUtil.prefStorage + } else { + getStoragePathForNonSelectedStorage(this, sharedPreferenceUtil) + } + val totalSpace = storageCalculator.calculateTotalSpace(file) + return "$storageName - $totalSpace\n$storagePath/Kiwix" +} + +private fun getStoragePathForNonSelectedStorage( + storageDevice: StorageDevice, + sharedPreferenceUtil: SharedPreferenceUtil +): String = + if (storageDevice.isInternal) { + sharedPreferenceUtil.getPublicDirectoryPath(storageDevice.name) + } else { + storageDevice.name + } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt index ce7d2247dd..8f2aa2b323 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt @@ -292,14 +292,6 @@ sealed class KiwixDialog( ) } - object StorageConfigure : KiwixDialog( - R.string.configure_storage_option, - null, - positiveMessage = R.string.configure, - negativeMessage = R.string.yes, - icon = R.drawable.ic_baseline_storage_24 - ) - object ImportBookmarks : KiwixDialog( R.string.import_bookmarks_dialog_title, message = null, diff --git a/core/src/main/res/drawable/ic_baseline_storage_24.xml b/core/src/main/res/drawable/ic_baseline_storage_24.xml deleted file mode 100644 index 5ca45e33ef..0000000000 --- a/core/src/main/res/drawable/ic_baseline_storage_24.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/core/src/main/res/layout/device_item.xml b/core/src/main/res/layout/device_item.xml deleted file mode 100644 index d6730aaa40..0000000000 --- a/core/src/main/res/layout/device_item.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - diff --git a/core/src/main/res/layout/item_storage_preference.xml b/core/src/main/res/layout/item_storage_preference.xml index e45f9b2f2c..7b3b9544a2 100644 --- a/core/src/main/res/layout/item_storage_preference.xml +++ b/core/src/main/res/layout/item_storage_preference.xml @@ -18,7 +18,7 @@ + diff --git a/core/src/main/res/values-ar/strings.xml b/core/src/main/res/values-ar/strings.xml index 8fad37d05f..b839ffd8aa 100644 --- a/core/src/main/res/values-ar/strings.xml +++ b/core/src/main/res/values-ar/strings.xml @@ -87,7 +87,7 @@ الإحالات لغة هذه الصفحة غير مدعومة، أو لم تُثبت البيانات المناسبة للغة. قد لا تتم قراءة المقالة بشكل صحيح. تعذر العثور على تطبيق مثبت لهذا النوع من الملفات - الرجاء تثبيت موفر خدمة البريد الإلكتروني أو مراسلتنا عبر البريد الإلكتروني على %1s + الرجاء تثبيت موفر خدمة البريد الإلكتروني أو مراسلتنا عبر البريد الإلكتروني على لا يوجد تطبيق لتحديد ملف علامة مرجعية لم يتم العثور على عناوين محتوى للوصول إلى المحتوى بلا اتصال، نحتاج إلى الوصول إلى وحدة التخزين @@ -161,10 +161,8 @@ إيقاف مؤقت استئناف إيقاف - هل تريد تنزيل الكتاب إلى وحدة التخزين الداخلية؟ داخلي خارجي - اضبط الإعدادات نعم لا إيقاف التنزيل؟ diff --git a/core/src/main/res/values-bn/strings.xml b/core/src/main/res/values-bn/strings.xml index 0616038154..b470585161 100644 --- a/core/src/main/res/values-bn/strings.xml +++ b/core/src/main/res/values-bn/strings.xml @@ -113,10 +113,8 @@ বিরতি পুনরায় শুরু করুন বন্ধ - অভ্যন্তরীণ স্টোরেজে বই ডাউনলোড করবেন? অভ্যন্তরীণ বহিঃস্থ - কনফিগার করুন হ্যাঁ না ডাউনলোড বন্ধ করবেন? diff --git a/core/src/main/res/values-br/strings.xml b/core/src/main/res/values-br/strings.xml index b58cf36199..4b6da30656 100644 --- a/core/src/main/res/values-br/strings.xml +++ b/core/src/main/res/values-br/strings.xml @@ -122,10 +122,8 @@ ehanañ adkemer paouez - Pellgargañ al levr er stokañ diabarzh? Diabarzh Diavaez - Kefluniañ Ya Ket Paouez ar pellgargadur ? diff --git a/core/src/main/res/values-cs/strings.xml b/core/src/main/res/values-cs/strings.xml index da2581be55..32315ccc98 100644 --- a/core/src/main/res/values-cs/strings.xml +++ b/core/src/main/res/values-cs/strings.xml @@ -144,10 +144,8 @@ Pozastavit Obnovit stop - Stáhnout knihu do interního úložiště? Interní Externí - Konfigurovat Ano Ne Zastavit stahování? diff --git a/core/src/main/res/values-dag/strings.xml b/core/src/main/res/values-dag/strings.xml index 634a72889a..5ca657a96f 100644 --- a/core/src/main/res/values-dag/strings.xml +++ b/core/src/main/res/values-dag/strings.xml @@ -149,10 +149,8 @@ Zanima Tuɣi zanima - A bɔri ni a vooi la buku maa n zaŋ niŋ a maŋmaŋ kpanjɔɣu ni? Puuni Kpaŋa - Sanidi ii Aayi A bɔri ni a chɛla voobu bee? diff --git a/core/src/main/res/values-de/strings.xml b/core/src/main/res/values-de/strings.xml index 71c7c3b6e1..dfd60bad4c 100644 --- a/core/src/main/res/values-de/strings.xml +++ b/core/src/main/res/values-de/strings.xml @@ -169,10 +169,8 @@ pausieren fortfahren abbrechen - Buch in den internen Speicher herunterladen? Intern Extern - Konfigurieren Ja Nein Herunterladen beenden? diff --git a/core/src/main/res/values-es/strings.xml b/core/src/main/res/values-es/strings.xml index 3744573a09..c60d59f98e 100644 --- a/core/src/main/res/values-es/strings.xml +++ b/core/src/main/res/values-es/strings.xml @@ -160,10 +160,8 @@ pausa continuar detener - ¿Descargar el libro al almacenamiento interno? Interno Externo - Configurar. No ¿Detener descarga? diff --git a/core/src/main/res/values-eu/strings.xml b/core/src/main/res/values-eu/strings.xml index c7db6755b2..2bbe3b371b 100644 --- a/core/src/main/res/values-eu/strings.xml +++ b/core/src/main/res/values-eu/strings.xml @@ -157,10 +157,8 @@ pausatua jarraitu Gelditu - Liburua barneko biltegiratzera deskargatu nahi duzu? Barneko Kanpokoa - Konfiguratu Bai Ez Deskarga geldiarazi? diff --git a/core/src/main/res/values-fr/strings.xml b/core/src/main/res/values-fr/strings.xml index a202f13284..e3ffd29b5c 100644 --- a/core/src/main/res/values-fr/strings.xml +++ b/core/src/main/res/values-fr/strings.xml @@ -176,10 +176,8 @@ pause reprendre arrêter - Télécharger le livre vers la mémoire interne ? Interne Externe - Configurer Oui Non Arrêter le téléchargement ? diff --git a/core/src/main/res/values-gpe/strings.xml b/core/src/main/res/values-gpe/strings.xml index e0a48d9caa..dd346595c1 100644 --- a/core/src/main/res/values-gpe/strings.xml +++ b/core/src/main/res/values-gpe/strings.xml @@ -139,7 +139,6 @@ pause resume stop - Download book go internal storage? Internal External diff --git a/core/src/main/res/values-ha/strings.xml b/core/src/main/res/values-ha/strings.xml index 1547088ce9..22cfdbb283 100644 --- a/core/src/main/res/values-ha/strings.xml +++ b/core/src/main/res/values-ha/strings.xml @@ -142,10 +142,8 @@ dan dakata ci gaba Dakata - Download littafin zuwa ciki ajiya Ciki Waje - Sanya Ee A’a A daina saukewa? diff --git a/core/src/main/res/values-hi/strings.xml b/core/src/main/res/values-hi/strings.xml index a0999d8006..fe9540307a 100644 --- a/core/src/main/res/values-hi/strings.xml +++ b/core/src/main/res/values-hi/strings.xml @@ -145,10 +145,8 @@ रुका फिर से शुरू करना रोकें - आंतरिक भंडारण में पुस्तक डाउनलोड करें? अन्दरूनी बाहरी - कॉन्फ़िगर करें हाँ नहीं डाउनलोड रोकें? diff --git a/core/src/main/res/values-ia/strings.xml b/core/src/main/res/values-ia/strings.xml index 24fc056f21..34239fa17c 100644 --- a/core/src/main/res/values-ia/strings.xml +++ b/core/src/main/res/values-ia/strings.xml @@ -152,10 +152,8 @@ pausar reprender stoppar - Discargar le libro al immagazinage interne? Interne Externe - Configurar Si No Stoppar le discargamento? diff --git a/core/src/main/res/values-ig/strings.xml b/core/src/main/res/values-ig/strings.xml index c5967435cc..8ad5dfbf76 100644 --- a/core/src/main/res/values-ig/strings.xml +++ b/core/src/main/res/values-ig/strings.xml @@ -149,10 +149,8 @@ kwụsịtụ maliteghachi ịkwụsị - Budata akwụkwọ na nchekwa ime? Ime Mpụga - Hazie Ee Mba Kwụsị nbudata? diff --git a/core/src/main/res/values-in/strings.xml b/core/src/main/res/values-in/strings.xml index 954b67ca59..01469acecb 100644 --- a/core/src/main/res/values-in/strings.xml +++ b/core/src/main/res/values-in/strings.xml @@ -130,10 +130,8 @@ jeda lanjut berhenti - Unduh buku ke penyimpanan internal? Internal Eksternal - Konfigurasikan Ya Tidak Hentikan unduhan? diff --git a/core/src/main/res/values-it/strings.xml b/core/src/main/res/values-it/strings.xml index 31ed8476c6..8db1512fc7 100644 --- a/core/src/main/res/values-it/strings.xml +++ b/core/src/main/res/values-it/strings.xml @@ -146,10 +146,8 @@ pausa riprendi interrompi - Scaricare il libro nella memoria interna? Interno Esterno - Configura No Vuoi interrompere il download? diff --git a/core/src/main/res/values-iw/strings.xml b/core/src/main/res/values-iw/strings.xml index 791c9edd46..d42b0a9c51 100644 --- a/core/src/main/res/values-iw/strings.xml +++ b/core/src/main/res/values-iw/strings.xml @@ -157,10 +157,8 @@ השהיה המשך עצירה - להוריד את הספר לאחסון פנימי? פנימי חיצוני - הגדרות כן לא לעצור הורדה? diff --git a/core/src/main/res/values-ja/strings.xml b/core/src/main/res/values-ja/strings.xml index 671f30874f..cd705b2551 100644 --- a/core/src/main/res/values-ja/strings.xml +++ b/core/src/main/res/values-ja/strings.xml @@ -146,10 +146,8 @@ 一時停止 再開 停止 - 本を内部ストレージにダウンロードしますか? 内部ストレージ 外部ストレージ - 設定 はい いいえ ダウンロードを停止しますか? diff --git a/core/src/main/res/values-ko/strings.xml b/core/src/main/res/values-ko/strings.xml index a87398a1b9..5d3fd756ce 100644 --- a/core/src/main/res/values-ko/strings.xml +++ b/core/src/main/res/values-ko/strings.xml @@ -165,10 +165,8 @@ 일시 정지 계속하기 정지 - 책을 내부 저장소에 다운로드하시겠습니까? 내부 장치 외부 장치 - 구성 아니오 다운로드를 중단하겠습니까? diff --git a/core/src/main/res/values-ku/strings.xml b/core/src/main/res/values-ku/strings.xml index 69ea3e3370..bcd021a81d 100644 --- a/core/src/main/res/values-ku/strings.xml +++ b/core/src/main/res/values-ku/strings.xml @@ -137,10 +137,8 @@ rawestîne dewam bike rawestîne - Bila kitêbê daxîne depoya daxilî? Daxilî Derveyî - Eyar bike Erê Na Daxistinê rabiwestîne? diff --git a/core/src/main/res/values-lb/strings.xml b/core/src/main/res/values-lb/strings.xml index 8a04bd8cb9..05c926f8d3 100644 --- a/core/src/main/res/values-lb/strings.xml +++ b/core/src/main/res/values-lb/strings.xml @@ -117,7 +117,6 @@ stopp Intern Extern - Configuréieren Jo Neen Erofluede stoppen? diff --git a/core/src/main/res/values-mk/strings.xml b/core/src/main/res/values-mk/strings.xml index 244e14d504..924c21d8f6 100644 --- a/core/src/main/res/values-mk/strings.xml +++ b/core/src/main/res/values-mk/strings.xml @@ -149,10 +149,8 @@ паузирај продолжи запри - Да ја преземам книгата во внатрешен склад? Внатрешен Надворешен - Нагоди Да Не Да го прекинам преземањето? diff --git a/core/src/main/res/values-nl/strings.xml b/core/src/main/res/values-nl/strings.xml index 7b183ad8d1..c9cfb482c0 100644 --- a/core/src/main/res/values-nl/strings.xml +++ b/core/src/main/res/values-nl/strings.xml @@ -154,10 +154,8 @@ pauzeren hervatten stoppen - Boek naar interne opslag downloaden? Intern Extern - Instellen Ja Nee Download stoppen? diff --git a/core/src/main/res/values-nqo/strings.xml b/core/src/main/res/values-nqo/strings.xml index 87acfa5e2c..7b7b28fa44 100644 --- a/core/src/main/res/values-nqo/strings.xml +++ b/core/src/main/res/values-nqo/strings.xml @@ -137,10 +137,8 @@ ߊ߬ ߟߊߟߐ߬ ߊ߬ ߘߊߡߌ߬ߣߊ߬ ߌ ߟߐ߬ - ߞߊ߬ ߞߊ߬ߝߊ ߡߊߞߍ߫ ߞߣߐߟߊ ߟߊ߬ߡߙߊ߬ߦߙߐ ߘߐ߫؟ ߞߣߐߟߊ ߞߐߞߊ߲ߠߊ - ߊ߬ ߢߊߓߐ߫ ߊ߬ߥߐ߫ ߍ߲߬ߍ߲߫ ߥߎߟߊߟߊߖߛߐߟߌ ߟߊߟߐ߬؟ diff --git a/core/src/main/res/values-or/strings.xml b/core/src/main/res/values-or/strings.xml index f5d8d09137..d6f67e35c5 100644 --- a/core/src/main/res/values-or/strings.xml +++ b/core/src/main/res/values-or/strings.xml @@ -137,10 +137,8 @@ ବିରାମ ପୁନଃ ଆରମ୍ଭ କରନ୍ତୁ ଅଟକି ଯାଆନ୍ତୁ - ଆଭ୍ୟନ୍ତରୀଣ ଭଣ୍ଡାରକୁ ବହି ଡାଉନଲୋଡ୍ କରନ୍ତୁ? ମଧ୍ୟାନ୍ତର ବାହ୍ୟ - ସଜଡ଼ାନ୍ତୁ ହଁ ନାହିଁ ଡାଉନଲୋଡ୍ ବନ୍ଦ କରନ୍ତୁ? diff --git a/core/src/main/res/values-pl/strings.xml b/core/src/main/res/values-pl/strings.xml index 604e660e43..f857d2c7cf 100644 --- a/core/src/main/res/values-pl/strings.xml +++ b/core/src/main/res/values-pl/strings.xml @@ -151,10 +151,8 @@ pauza Podsumuj stop - Pobrać książkę do pamięci wewnętrznej? Wewnętrzny Zewnętrzny - Konfiguruj Tak Nie Zatrzymać pobieranie? diff --git a/core/src/main/res/values-pt-rBR/strings.xml b/core/src/main/res/values-pt-rBR/strings.xml index 7910e32f3b..4a0aed2a12 100644 --- a/core/src/main/res/values-pt-rBR/strings.xml +++ b/core/src/main/res/values-pt-rBR/strings.xml @@ -167,10 +167,8 @@ pausar continuar parar - Transferir livro para armazenamento interno? Interna Externo - Configurar Sim Não Parar o download? diff --git a/core/src/main/res/values-qq/strings.xml b/core/src/main/res/values-qq/strings.xml index 21fbe19d75..e9ff93d39c 100644 --- a/core/src/main/res/values-qq/strings.xml +++ b/core/src/main/res/values-qq/strings.xml @@ -147,10 +147,8 @@ {{identical|pause}} {{identical|resume}} {{Identical|Stop}} - This message appears in the \"Android Dialog\" as an information message. It takes confirmation from the user if he wants to download books in internal storage. {{Identical|Internal}} {{Identical|External}} - {{Identical|Configure}} {{Identical|Yes}} {{Identical|No}} This message appears in the \"Android Dialog\" as a confirmation title message. When the user wants to stop the current running download. diff --git a/core/src/main/res/values-ru/strings.xml b/core/src/main/res/values-ru/strings.xml index b80d13da6f..36f5c331df 100644 --- a/core/src/main/res/values-ru/strings.xml +++ b/core/src/main/res/values-ru/strings.xml @@ -178,10 +178,8 @@ пауза продолжить остановить - Загрузить книгу во внутреннюю память? Внутренний Внешний - Настроить Да Нет Остановить загрузку? diff --git a/core/src/main/res/values-sc/strings.xml b/core/src/main/res/values-sc/strings.xml index aeba1073f0..4c2664f034 100644 --- a/core/src/main/res/values-sc/strings.xml +++ b/core/src/main/res/values-sc/strings.xml @@ -137,10 +137,8 @@ pàusa sighi firma - Iscarrigare su libru in sa memòria interna? Interna Esterna - Cunfigura Eja Nono Firmare s’iscarrigamentu? diff --git a/core/src/main/res/values-skr/strings.xml b/core/src/main/res/values-skr/strings.xml index b81ff5c061..951176d652 100644 --- a/core/src/main/res/values-skr/strings.xml +++ b/core/src/main/res/values-skr/strings.xml @@ -63,7 +63,6 @@ اختتام اندرونی ٻاہر آلا - کنفیگر جیا کو ڈاؤن لوڈ روکوں؟ diff --git a/core/src/main/res/values-sl/strings.xml b/core/src/main/res/values-sl/strings.xml index 53b85eb99f..66782d19d0 100644 --- a/core/src/main/res/values-sl/strings.xml +++ b/core/src/main/res/values-sl/strings.xml @@ -145,10 +145,8 @@ premor nadaljuj ustavi - Prenesem knjigo v notranji pomnilnik? Notranji Zunanji - Konfiguriraj Da Ne Ustavim prenos? diff --git a/core/src/main/res/values-sq/strings.xml b/core/src/main/res/values-sq/strings.xml index 00df257f2e..16748c2e85 100644 --- a/core/src/main/res/values-sq/strings.xml +++ b/core/src/main/res/values-sq/strings.xml @@ -134,10 +134,8 @@ ndalesë rimerre ndale - Të shkarkohet libri te depozita e brendshme? I brendshëm I jashtëm - Formësojeni Po Jo Të ndalet shkarkim? diff --git a/core/src/main/res/values-sv/strings.xml b/core/src/main/res/values-sv/strings.xml index ff22534a49..1d46b15342 100644 --- a/core/src/main/res/values-sv/strings.xml +++ b/core/src/main/res/values-sv/strings.xml @@ -157,10 +157,8 @@ pausa återuppta stoppa - Ladda ned bok till intern lagring? Internt Extern - Konfigurera Ja Nej Stoppa nedladdning? diff --git a/core/src/main/res/values-sw/strings.xml b/core/src/main/res/values-sw/strings.xml index 299b4a2dda..a9c680dd6f 100644 --- a/core/src/main/res/values-sw/strings.xml +++ b/core/src/main/res/values-sw/strings.xml @@ -149,10 +149,8 @@ kupumzika rejea acha - Ungependa kupakua kitabu hadi hifadhi ya ndani? Ndani Nje - Sanidi Ndiyo Hapana Acha kupakua? diff --git a/core/src/main/res/values-ta/strings.xml b/core/src/main/res/values-ta/strings.xml index 39b468a27d..f67e5d3397 100644 --- a/core/src/main/res/values-ta/strings.xml +++ b/core/src/main/res/values-ta/strings.xml @@ -137,10 +137,8 @@ இடைநிறுத்து தொடர்க நிறுத்து - புத்தகத்தை உள் சேமிப்பகத்தில் பதிவிறக்கவா? உள்ளே வெளியிலுள்ள - கட்டமைக்கவும் ஆம் இல்லை பதிவிறக்குவதை நிறுத்தவா? diff --git a/core/src/main/res/values-te/strings.xml b/core/src/main/res/values-te/strings.xml index 8fae7b9fbd..b9c9174b23 100644 --- a/core/src/main/res/values-te/strings.xml +++ b/core/src/main/res/values-te/strings.xml @@ -142,10 +142,8 @@ విరామం పునఃప్రారంభం ఆపండి - పుస్తకాన్ని అంతర్గత నిల్వకు డౌన్‌లోడ్ చేయాలా? అంతర్గత అంతర్గత - కాన్ఫిగర్ చేయండి సరే వద్దు డౌన్‌లోడ్ ఆపివేయాలా? diff --git a/core/src/main/res/values-tn/strings.xml b/core/src/main/res/values-tn/strings.xml index 5799b85ecd..84b7f61899 100644 --- a/core/src/main/res/values-tn/strings.xml +++ b/core/src/main/res/values-tn/strings.xml @@ -138,10 +138,8 @@ Kgama Tsweledisa Ema - A o kopa buka go e baya mo mabolokelong a a moteng? Mo teng Ka fa ntle - Sekaseka Ee Nnyaa A o emisa go e itseela? diff --git a/core/src/main/res/values-tr/strings.xml b/core/src/main/res/values-tr/strings.xml index 60161b1cd5..1b68d2c9bc 100644 --- a/core/src/main/res/values-tr/strings.xml +++ b/core/src/main/res/values-tr/strings.xml @@ -154,10 +154,8 @@ duraklat devam et durdur - Kitap, dahili depolama birimine indirilsin mi? Dahili Harici - Yapılandır Evet Hayır İndirme durdurulsun mu? diff --git a/core/src/main/res/values-uk/strings.xml b/core/src/main/res/values-uk/strings.xml index ed071a1430..c6d8a8bbea 100644 --- a/core/src/main/res/values-uk/strings.xml +++ b/core/src/main/res/values-uk/strings.xml @@ -145,7 +145,6 @@ зупинити Внутрішнє Зовнішні - Налаштувати Так Ні Зупинити завантаження? diff --git a/core/src/main/res/values-xal/strings.xml b/core/src/main/res/values-xal/strings.xml index 2a076e7050..ec0665c5d4 100644 --- a/core/src/main/res/values-xal/strings.xml +++ b/core/src/main/res/values-xal/strings.xml @@ -71,10 +71,8 @@ завсрлһ үрглҗлүлх зогсах - Дегтриг дотад багтамҗур татҗ авхий? Дотад Һазад - Тохрулх Тиим Уга Ацалхиг зогсахий? diff --git a/core/src/main/res/values-yo/strings.xml b/core/src/main/res/values-yo/strings.xml index 27fb973fab..3d204ae6d4 100644 --- a/core/src/main/res/values-yo/strings.xml +++ b/core/src/main/res/values-yo/strings.xml @@ -142,10 +142,8 @@ da duro bẹrẹ pada dúró - Ṣe igbasilẹ iwe si ibi ipamọ inu? Àárín Ita - Ṣiṣeto Bẹ́ẹ̀ni Bẹ́ẹ̀kọ́ Duro gbigba lati ayelujara? diff --git a/core/src/main/res/values-zh-rTW/strings.xml b/core/src/main/res/values-zh-rTW/strings.xml index 81dd6cb106..0ca7385b7a 100644 --- a/core/src/main/res/values-zh-rTW/strings.xml +++ b/core/src/main/res/values-zh-rTW/strings.xml @@ -160,10 +160,8 @@ 暫停 繼續 停止 - 將書籍下載至內部儲存空間? 內部 外部 - 配置 停止下載? diff --git a/core/src/main/res/values-zh/strings.xml b/core/src/main/res/values-zh/strings.xml index 1f3d36b370..f39b1de5f4 100644 --- a/core/src/main/res/values-zh/strings.xml +++ b/core/src/main/res/values-zh/strings.xml @@ -177,10 +177,8 @@ 暂停 恢复 停止 - 将书籍下载至内部存储空间? 内部 外部 - 配置 停止下载? diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 7ef66a40a2..da50489435 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -142,14 +142,13 @@ Current Folder %s used %s free + Choose storage to download the book Sorry we were unable to delete some files. You should try using a file manager instead. pause resume stop - Download book to internal storage? Internal External - Configure Yes No Stop download? From ff87fddece76b20f9d83ae027839b3e8d2196bb1 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Tue, 5 Nov 2024 11:29:58 +0530 Subject: [PATCH 4/6] Displaying the storage selection dialog for configuration if an SD card is available at first download. If only internal storage is available, proceed directly with the ZIM file download, as showing the configuration dialog is unnecessary in this case. --- .../nav/destination/library/OnlineLibraryFragment.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt index c1991575d1..a619d4f2f1 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt @@ -51,6 +51,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import eu.mhutti1.utils.storage.STORAGE_SELECT_STORAGE_TITLE_TEXTVIEW_SIZE import eu.mhutti1.utils.storage.StorageDevice +import eu.mhutti1.utils.storage.StorageDeviceUtils import eu.mhutti1.utils.storage.StorageSelectDialog import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.cachedComponent @@ -530,7 +531,15 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { } else -> if (sharedPreferenceUtil.showStorageOption) { - showStorageSelectDialog() + // Show the storage selection dialog for configuration if there is an SD card available. + if (StorageDeviceUtils.getWritableStorage(requireActivity()).size > 1) { + showStorageSelectDialog() + } else { + // If only internal storage is available, proceed with the ZIM file download directly. + // Displaying a configuration dialog is unnecessary in this case. + sharedPreferenceUtil.showStorageOption = false + onBookItemClick(item) + } } else if (!requireActivity().isManageExternalStoragePermissionGranted( sharedPreferenceUtil ) From 13c5cb5278445ae3e98d15b59fa820f912121220 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 6 Nov 2024 12:17:05 +0530 Subject: [PATCH 5/6] Improved the showing of storage list in dialog --- .../library/LocalLibraryFragment.kt | 5 ++++ .../library/OnlineLibraryFragment.kt | 6 +++- .../utils/storage/StorageSelectDialog.kt | 28 ++++++++----------- .../utils/storage/adapter/StorageDelegate.kt | 2 ++ .../storage/adapter/StorageViewHolder.kt | 4 ++- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt index 0345ad39d3..87fb27811e 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt @@ -58,6 +58,7 @@ import androidx.recyclerview.widget.RecyclerView import com.google.android.material.bottomnavigation.BottomNavigationView import eu.mhutti1.utils.storage.Bytes import eu.mhutti1.utils.storage.StorageDevice +import eu.mhutti1.utils.storage.StorageDeviceUtils import eu.mhutti1.utils.storage.StorageSelectDialog import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable @@ -133,6 +134,9 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal private val zimManageViewModel by lazy { requireActivity().viewModel(viewModelFactory) } + private val storageDeviceList by lazy { + StorageDeviceUtils.getWritableStorage(requireActivity()) + } private var storagePermissionLauncher: ActivityResultLauncher>? = registerForActivityResult( @@ -664,6 +668,7 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal private fun showStorageSelectDialog() = StorageSelectDialog() .apply { onSelectAction = ::storeDeviceInPreferences + setStorageDeviceList(storageDeviceList) } .show(parentFragmentManager, getString(string.pref_storage)) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt index a619d4f2f1..e2297e571e 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt @@ -113,6 +113,9 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { private val zimManageViewModel by lazy { requireActivity().viewModel(viewModelFactory) } + private val storageDeviceList by lazy { + StorageDeviceUtils.getWritableStorage(requireActivity()) + } @VisibleForTesting fun getOnlineLibraryList() = libraryAdapter.items @@ -532,7 +535,7 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { else -> if (sharedPreferenceUtil.showStorageOption) { // Show the storage selection dialog for configuration if there is an SD card available. - if (StorageDeviceUtils.getWritableStorage(requireActivity()).size > 1) { + if (storageDeviceList.size > 1) { showStorageSelectDialog() } else { // If only internal storage is available, proceed with the ZIM file download directly. @@ -573,6 +576,7 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { .apply { onSelectAction = ::storeDeviceInPreferences titleSize = STORAGE_SELECT_STORAGE_TITLE_TEXTVIEW_SIZE + setStorageDeviceList(storageDeviceList) } .show(parentFragmentManager, getString(string.choose_storage_to_download_book)) 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 bfe47f064e..3e562fa9c8 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt @@ -29,11 +29,8 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import eu.mhutti1.utils.storage.adapter.StorageAdapter import eu.mhutti1.utils.storage.adapter.StorageDelegate -import io.reactivex.Flowable -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.Disposable -import io.reactivex.schedulers.Schedulers import org.kiwix.kiwixmobile.core.CoreApp +import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R.dimen import org.kiwix.kiwixmobile.core.databinding.StorageSelectDialogBinding import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isLandScapeMode @@ -52,17 +49,25 @@ class StorageSelectDialog : DialogFragment() { @Inject lateinit var sharedPreferenceUtil: SharedPreferenceUtil private var aTitle: String? = null private var storageSelectDialogViewBinding: StorageSelectDialogBinding? = null - private var storageDisposable: Disposable? = null + private val storageDeviceList = arrayListOf() private val storageAdapter: StorageAdapter by lazy { StorageAdapter( - StorageDelegate(storageCalculator, sharedPreferenceUtil) { + StorageDelegate( + storageCalculator, + sharedPreferenceUtil, + aTitle == getString(R.string.choose_storage_to_download_book) + ) { onSelectAction?.invoke(it) dismiss() } ) } + fun setStorageDeviceList(storageDeviceList: List) { + this.storageDeviceList.addAll(storageDeviceList) + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -84,15 +89,7 @@ class StorageSelectDialog : DialogFragment() { layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false) setHasFixedSize(true) } - - storageDisposable = - Flowable.fromCallable { StorageDeviceUtils.getWritableStorage(requireActivity()) } - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe( - { storageAdapter.items = it }, - Throwable::printStackTrace - ) + storageAdapter.items = storageDeviceList } override fun show(fm: FragmentManager, text: String?) { @@ -127,7 +124,6 @@ class StorageSelectDialog : DialogFragment() { override fun onDestroyView() { super.onDestroyView() - storageDisposable?.dispose() storageSelectDialogViewBinding = null } } diff --git a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageDelegate.kt b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageDelegate.kt index 29ec303ff5..bd8a07ea8c 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageDelegate.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageDelegate.kt @@ -30,6 +30,7 @@ import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil class StorageDelegate( private val storageCalculator: StorageCalculator, private val sharedPreferenceUtil: SharedPreferenceUtil, + private val isShowingStorageOptionForFirstDownload: Boolean, private val onClickAction: (StorageDevice) -> Unit ) : AdapterDelegate { override fun createViewHolder(parent: ViewGroup): ViewHolder { @@ -37,6 +38,7 @@ class StorageDelegate( parent.viewBinding(ItemStoragePreferenceBinding::inflate, false), storageCalculator, sharedPreferenceUtil, + isShowingStorageOptionForFirstDownload, onClickAction ) } diff --git a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt index 7f1c0bd3e9..5371a6d95a 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt @@ -44,6 +44,7 @@ internal class StorageViewHolder( private val itemStoragePreferenceBinding: ItemStoragePreferenceBinding, private val storageCalculator: StorageCalculator, private val sharedPreferenceUtil: SharedPreferenceUtil, + private val isShowingStorageOptionForFirstDownload: Boolean, private val onClickAction: (StorageDevice) -> Unit ) : BaseViewHolder(itemStoragePreferenceBinding.root) { @@ -60,7 +61,8 @@ internal class StorageViewHolder( ) radioButton.isChecked = - adapterPosition == sharedPreferenceUtil.storagePosition + !isShowingStorageOptionForFirstDownload && + adapterPosition == sharedPreferenceUtil.storagePosition freeSpace.apply { text = item.getFreeSpace(root.context, storageCalculator) textSize = FREE_SPACE_TEXTVIEW_SIZE From ac3b63560fe4f343f06e675a3d785a718c682c0f Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 6 Nov 2024 12:24:14 +0530 Subject: [PATCH 6/6] Fixed code formatting issue --- .../eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt index 5371a6d95a..ad686e5ba3 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/adapter/StorageViewHolder.kt @@ -60,9 +60,8 @@ internal class StorageViewHolder( ) ) - radioButton.isChecked = - !isShowingStorageOptionForFirstDownload && - adapterPosition == sharedPreferenceUtil.storagePosition + radioButton.isChecked = !isShowingStorageOptionForFirstDownload && + adapterPosition == sharedPreferenceUtil.storagePosition freeSpace.apply { text = item.getFreeSpace(root.context, storageCalculator) textSize = FREE_SPACE_TEXTVIEW_SIZE