mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
Fixed: UI was displaying storage options prematurely while storage information was still being fetched in the background.
* To resolve this, storage options are initially hidden, and a progress bar with a title is shown to inform users that storage information is being fetched.
This commit is contained in:
parent
e309dde0c5
commit
d94fb5cb3a
@ -33,6 +33,7 @@ import androidx.core.os.ConfigurationCompat
|
|||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.drawerlayout.widget.DrawerLayout
|
import androidx.drawerlayout.widget.DrawerLayout
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavDestination
|
import androidx.navigation.NavDestination
|
||||||
import androidx.navigation.fragment.NavHostFragment
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
@ -40,6 +41,7 @@ import androidx.navigation.ui.NavigationUI
|
|||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
import com.google.android.material.navigation.NavigationView
|
import com.google.android.material.navigation.NavigationView
|
||||||
import eu.mhutti1.utils.storage.StorageDeviceUtils
|
import eu.mhutti1.utils.storage.StorageDeviceUtils
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.kiwix.kiwixmobile.BuildConfig
|
import org.kiwix.kiwixmobile.BuildConfig
|
||||||
import org.kiwix.kiwixmobile.R
|
import org.kiwix.kiwixmobile.R
|
||||||
import org.kiwix.kiwixmobile.core.R.id
|
import org.kiwix.kiwixmobile.core.R.id
|
||||||
@ -126,13 +128,15 @@ class KiwixMainActivity : CoreMainActivity() {
|
|||||||
onNavigationItemSelected(item)
|
onNavigationItemSelected(item)
|
||||||
}
|
}
|
||||||
activityKiwixMainBinding.bottomNavView.setupWithNavController(navController)
|
activityKiwixMainBinding.bottomNavView.setupWithNavController(navController)
|
||||||
migrateInternalToPublicAppDirectory()
|
lifecycleScope.launch {
|
||||||
|
migrateInternalToPublicAppDirectory()
|
||||||
|
}
|
||||||
handleZimFileIntent(intent)
|
handleZimFileIntent(intent)
|
||||||
handleNotificationIntent(intent)
|
handleNotificationIntent(intent)
|
||||||
handleGetContentIntent(intent)
|
handleGetContentIntent(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun migrateInternalToPublicAppDirectory() {
|
private suspend fun migrateInternalToPublicAppDirectory() {
|
||||||
if (!sharedPreferenceUtil.prefIsAppDirectoryMigrated) {
|
if (!sharedPreferenceUtil.prefIsAppDirectoryMigrated) {
|
||||||
val storagePath = StorageDeviceUtils.getWritableStorage(this)
|
val storagePath = StorageDeviceUtils.getWritableStorage(this)
|
||||||
.getOrNull(sharedPreferenceUtil.storagePosition)
|
.getOrNull(sharedPreferenceUtil.storagePosition)
|
||||||
|
@ -501,7 +501,7 @@ class CopyMoveFileHandler @Inject constructor(
|
|||||||
@SuppressLint("InflateParams") fun showPreparingCopyMoveDialog() {
|
@SuppressLint("InflateParams") fun showPreparingCopyMoveDialog() {
|
||||||
if (copyMovePreparingDialog == null) {
|
if (copyMovePreparingDialog == null) {
|
||||||
val dialogView: View =
|
val dialogView: View =
|
||||||
activity.layoutInflater.inflate(layout.item_custom_spinner, null)
|
activity.layoutInflater.inflate(R.layout.item_custom_spinner, null)
|
||||||
copyMovePreparingDialog =
|
copyMovePreparingDialog =
|
||||||
alertDialogShower.create(KiwixDialog.PreparingCopyingFilesDialog { dialogView })
|
alertDialogShower.create(KiwixDialog.PreparingCopyingFilesDialog { dialogView })
|
||||||
}
|
}
|
||||||
|
@ -39,11 +39,14 @@ import org.kiwix.kiwixmobile.core.extensions.storagePathAndTitle
|
|||||||
import org.kiwix.kiwixmobile.core.extensions.usedPercentage
|
import org.kiwix.kiwixmobile.core.extensions.usedPercentage
|
||||||
import org.kiwix.kiwixmobile.core.navigateToSettings
|
import org.kiwix.kiwixmobile.core.navigateToSettings
|
||||||
import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment
|
import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment
|
||||||
|
import org.kiwix.kiwixmobile.core.settings.StorageLoadingPreference
|
||||||
import org.kiwix.kiwixmobile.core.settings.StorageRadioButtonPreference
|
import org.kiwix.kiwixmobile.core.settings.StorageRadioButtonPreference
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil.Companion.PREF_EXTERNAL_STORAGE
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil.Companion.PREF_EXTERNAL_STORAGE
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil.Companion.PREF_INTERNAL_STORAGE
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil.Companion.PREF_INTERNAL_STORAGE
|
||||||
|
|
||||||
|
const val PREF_STORAGE_PROGRESSBAR = "storage_progressbar"
|
||||||
|
|
||||||
class KiwixPrefsFragment : CorePrefsFragment() {
|
class KiwixPrefsFragment : CorePrefsFragment() {
|
||||||
private var storageDisposable: Disposable? = null
|
private var storageDisposable: Disposable? = null
|
||||||
private var storageDeviceList: List<StorageDevice> = listOf()
|
private var storageDeviceList: List<StorageDevice> = listOf()
|
||||||
@ -56,10 +59,12 @@ class KiwixPrefsFragment : CorePrefsFragment() {
|
|||||||
|
|
||||||
override suspend fun setStorage() {
|
override suspend fun setStorage() {
|
||||||
sharedPreferenceUtil?.let {
|
sharedPreferenceUtil?.let {
|
||||||
if (storageDisposable?.isDisposed == false) {
|
if (storageDeviceList.isNotEmpty()) {
|
||||||
// update the storage when user switch to other storage.
|
// update the storage when user switch to other storage.
|
||||||
setUpStoragePreference(it)
|
setUpStoragePreference(it)
|
||||||
|
return@setStorage
|
||||||
}
|
}
|
||||||
|
showHideProgressBarWhileFetchingStorageInfo(true)
|
||||||
storageDisposable =
|
storageDisposable =
|
||||||
Flowable.fromCallable { StorageDeviceUtils.getWritableStorage(requireActivity()) }
|
Flowable.fromCallable { StorageDeviceUtils.getWritableStorage(requireActivity()) }
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
@ -67,6 +72,8 @@ class KiwixPrefsFragment : CorePrefsFragment() {
|
|||||||
.subscribe(
|
.subscribe(
|
||||||
{ storageList ->
|
{ storageList ->
|
||||||
storageDeviceList = storageList
|
storageDeviceList = storageList
|
||||||
|
showHideProgressBarWhileFetchingStorageInfo(false)
|
||||||
|
showInternalStoragePreferece()
|
||||||
showExternalPreferenceIfAvailable()
|
showExternalPreferenceIfAvailable()
|
||||||
setUpStoragePreference(it)
|
setUpStoragePreference(it)
|
||||||
},
|
},
|
||||||
@ -75,6 +82,20 @@ class KiwixPrefsFragment : CorePrefsFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows or hides the progress bar while the application is fetching
|
||||||
|
* storage information in the background. The progress bar is displayed
|
||||||
|
* with a title indicating that the storage information is being retrieved.
|
||||||
|
*
|
||||||
|
* @param show If true, the progress bar will be displayed; otherwise, it will be hidden.
|
||||||
|
*/
|
||||||
|
private fun showHideProgressBarWhileFetchingStorageInfo(show: Boolean) {
|
||||||
|
findPreference<StorageLoadingPreference>(PREF_STORAGE_PROGRESSBAR)?.apply {
|
||||||
|
isVisible = show
|
||||||
|
setTitle(getString(R.string.fetching_storage_info))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setUpStoragePreference(sharedPreferenceUtil: SharedPreferenceUtil) {
|
private fun setUpStoragePreference(sharedPreferenceUtil: SharedPreferenceUtil) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
storageDeviceList.forEachIndexed { index, storageDevice ->
|
storageDeviceList.forEachIndexed { index, storageDevice ->
|
||||||
@ -100,6 +121,10 @@ class KiwixPrefsFragment : CorePrefsFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showInternalStoragePreferece() {
|
||||||
|
findPreference<StorageRadioButtonPreference>(PREF_INTERNAL_STORAGE)?.isVisible = true
|
||||||
|
}
|
||||||
|
|
||||||
private fun showExternalPreferenceIfAvailable() {
|
private fun showExternalPreferenceIfAvailable() {
|
||||||
findPreference<StorageRadioButtonPreference>(PREF_EXTERNAL_STORAGE)?.isVisible =
|
findPreference<StorageRadioButtonPreference>(PREF_EXTERNAL_STORAGE)?.isVisible =
|
||||||
storageDeviceList.size > 1
|
storageDeviceList.size > 1
|
||||||
|
@ -276,7 +276,7 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
|
|||||||
private fun startKiwixHotspot() {
|
private fun startKiwixHotspot() {
|
||||||
if (dialog == null) {
|
if (dialog == null) {
|
||||||
val dialogView: View =
|
val dialogView: View =
|
||||||
layoutInflater.inflate(layout.item_custom_spinner, null)
|
layoutInflater.inflate(R.layout.item_custom_spinner, null)
|
||||||
dialog = alertDialogShower.create(StartServer { dialogView })
|
dialog = alertDialogShower.create(StartServer { dialogView })
|
||||||
}
|
}
|
||||||
dialog?.show()
|
dialog?.show()
|
||||||
|
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Kiwix Android
|
||||||
|
* Copyright (c) 2O24 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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.kiwix.kiwixmobile.core.settings
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View.VISIBLE
|
||||||
|
import android.widget.ProgressBar
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
import androidx.constraintlayout.widget.ConstraintSet
|
||||||
|
import androidx.preference.Preference
|
||||||
|
import androidx.preference.PreferenceViewHolder
|
||||||
|
import org.kiwix.kiwixmobile.core.R
|
||||||
|
import org.kiwix.kiwixmobile.core.downloader.downloadManager.ZERO
|
||||||
|
|
||||||
|
const val MARGIN_TOP = 8
|
||||||
|
|
||||||
|
class StorageLoadingPreference @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
defStyleAttr: Int = ZERO
|
||||||
|
) : Preference(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
private var customProgressTitle: TextView? = null
|
||||||
|
private var progressBarTitleText: String? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
widgetLayoutResource = R.layout.item_custom_spinner
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||||
|
super.onBindViewHolder(holder)
|
||||||
|
val progressBar = holder.findViewById(R.id.custom_progressbar) as? ProgressBar
|
||||||
|
customProgressTitle = holder.findViewById(R.id.custom_progress_title) as TextView
|
||||||
|
progressBarTitleText?.let(::setProgressBarTitle)
|
||||||
|
|
||||||
|
val constraintLayout = holder.itemView as ConstraintLayout
|
||||||
|
val constraintSet = ConstraintSet()
|
||||||
|
constraintSet.clone(constraintLayout)
|
||||||
|
|
||||||
|
constraintSet.connect(
|
||||||
|
progressBar?.id ?: ZERO,
|
||||||
|
ConstraintSet.START,
|
||||||
|
ConstraintSet.PARENT_ID,
|
||||||
|
ConstraintSet.START,
|
||||||
|
ZERO
|
||||||
|
)
|
||||||
|
constraintSet.connect(
|
||||||
|
progressBar?.id ?: ZERO,
|
||||||
|
ConstraintSet.END,
|
||||||
|
ConstraintSet.PARENT_ID,
|
||||||
|
ConstraintSet.END,
|
||||||
|
ZERO
|
||||||
|
)
|
||||||
|
constraintSet.connect(
|
||||||
|
progressBar?.id ?: ZERO,
|
||||||
|
ConstraintSet.TOP,
|
||||||
|
ConstraintSet.PARENT_ID,
|
||||||
|
ConstraintSet.TOP,
|
||||||
|
ZERO
|
||||||
|
)
|
||||||
|
|
||||||
|
constraintSet.connect(
|
||||||
|
customProgressTitle?.id ?: ZERO,
|
||||||
|
ConstraintSet.START,
|
||||||
|
ConstraintSet.PARENT_ID,
|
||||||
|
ConstraintSet.START,
|
||||||
|
ZERO
|
||||||
|
)
|
||||||
|
constraintSet.connect(
|
||||||
|
customProgressTitle?.id ?: ZERO,
|
||||||
|
ConstraintSet.END,
|
||||||
|
ConstraintSet.PARENT_ID,
|
||||||
|
ConstraintSet.END,
|
||||||
|
ZERO
|
||||||
|
)
|
||||||
|
constraintSet.connect(
|
||||||
|
customProgressTitle?.id ?: ZERO,
|
||||||
|
ConstraintSet.TOP,
|
||||||
|
progressBar?.id ?: ZERO,
|
||||||
|
ConstraintSet.BOTTOM,
|
||||||
|
MARGIN_TOP
|
||||||
|
)
|
||||||
|
constraintSet.connect(
|
||||||
|
customProgressTitle?.id ?: ZERO,
|
||||||
|
ConstraintSet.BOTTOM,
|
||||||
|
ConstraintSet.PARENT_ID,
|
||||||
|
ConstraintSet.BOTTOM,
|
||||||
|
ZERO
|
||||||
|
)
|
||||||
|
constraintSet.applyTo(constraintLayout)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setTitle(title: String) {
|
||||||
|
progressBarTitleText = title
|
||||||
|
setProgressBarTitle(title)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setProgressBarTitle(title: String) {
|
||||||
|
customProgressTitle?.apply {
|
||||||
|
text = title
|
||||||
|
visibility = VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,9 +20,10 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="16dp">
|
android:padding="@dimen/activity_horizontal_margin">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
|
android:id="@+id/custom_progressbar"
|
||||||
style="?android:attr/progressBarStyleLarge"
|
style="?android:attr/progressBarStyleLarge"
|
||||||
android:layout_width="50dp"
|
android:layout_width="50dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
@ -31,4 +32,14 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/custom_progress_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/card_margin"
|
||||||
|
android:layout_marginBottom="@dimen/activity_horizontal_margin"
|
||||||
|
android:gravity="center"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/custom_progressbar" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -138,6 +138,7 @@
|
|||||||
<string name="help_9">• Other contents like Wikileaks or Wikisource are also available</string>
|
<string name="help_9">• Other contents like Wikileaks or Wikisource are also available</string>
|
||||||
<string name="help_10">You can either download your chosen ZIM files in-app or carefully select the one(s) you want and download from a Desktop computer before transferring the ZIM files to your SD card.</string>
|
<string name="help_10">You can either download your chosen ZIM files in-app or carefully select the one(s) you want and download from a Desktop computer before transferring the ZIM files to your SD card.</string>
|
||||||
<string name="help_11">ZIM files download in-app are located in the external storage directory in a folder entitled Kiwix.</string>
|
<string name="help_11">ZIM files download in-app are located in the external storage directory in a folder entitled Kiwix.</string>
|
||||||
|
<string name="fetching_storage_info">Fetching storage details…</string>
|
||||||
<string name="pref_storage">Storage</string>
|
<string name="pref_storage">Storage</string>
|
||||||
<string name="pref_current_folder">Current Folder</string>
|
<string name="pref_current_folder">Current Folder</string>
|
||||||
<string name="pref_storage_used">%s used</string>
|
<string name="pref_storage_used">%s used</string>
|
||||||
|
@ -65,15 +65,23 @@
|
|||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:title="@string/pref_storage">
|
app:title="@string/pref_storage">
|
||||||
|
|
||||||
|
<org.kiwix.kiwixmobile.core.settings.StorageLoadingPreference
|
||||||
|
android:key="storage_progressbar"
|
||||||
|
android:layout="@layout/item_custom_spinner"
|
||||||
|
app:iconSpaceReserved="false"
|
||||||
|
app:isPreferenceVisible="false" />
|
||||||
|
|
||||||
<org.kiwix.kiwixmobile.core.settings.StorageRadioButtonPreference
|
<org.kiwix.kiwixmobile.core.settings.StorageRadioButtonPreference
|
||||||
android:key="pref_internal_storage"
|
android:key="pref_internal_storage"
|
||||||
android:layout="@layout/item_storage_preference"
|
android:layout="@layout/item_storage_preference"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false"
|
||||||
|
app:isPreferenceVisible="false" />
|
||||||
|
|
||||||
<org.kiwix.kiwixmobile.core.settings.StorageRadioButtonPreference
|
<org.kiwix.kiwixmobile.core.settings.StorageRadioButtonPreference
|
||||||
android:key="pref_external_storage"
|
android:key="pref_external_storage"
|
||||||
android:layout="@layout/item_storage_preference"
|
android:layout="@layout/item_storage_preference"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false"
|
||||||
|
app:isPreferenceVisible="false" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user