mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-17 11:25:34 -04:00
#2256 External device mgmt is not robust and gives contradictory information - don't depend on isEmulated
This commit is contained in:
parent
ce527d3b00
commit
c4e03f3183
@ -19,8 +19,9 @@
|
||||
package org.kiwix.kiwixmobile.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.preference.Preference
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil.PREF_STORAGE
|
||||
@ -33,13 +34,13 @@ class KiwixPrefsFragment : CorePrefsFragment() {
|
||||
}
|
||||
|
||||
override fun setStorage() {
|
||||
if (Environment.isExternalStorageEmulated()) {
|
||||
findPreference<Preference>(PREF_STORAGE)?.title =
|
||||
sharedPreferenceUtil.getPrefStorageTitle("Internal")
|
||||
} else {
|
||||
findPreference<Preference>(PREF_STORAGE)?.title =
|
||||
sharedPreferenceUtil.getPrefStorageTitle("External")
|
||||
}
|
||||
findPreference<Preference>(PREF_STORAGE)?.title = getString(
|
||||
if (sharedPreferenceUtil.prefStorage == internalStorage()) R.string.internal_storage
|
||||
else R.string.external_storage
|
||||
)
|
||||
findPreference<Preference>(PREF_STORAGE)?.summary = storageCalculator.calculateAvailableSpace()
|
||||
}
|
||||
|
||||
private fun internalStorage(): String? =
|
||||
ContextCompat.getExternalFilesDirs(requireContext(), null).firstOrNull()?.path
|
||||
}
|
||||
|
@ -177,12 +177,6 @@ open class LibraryFragment : BaseFragment() {
|
||||
|
||||
private fun storeDeviceInPreferences(storageDevice: StorageDevice) {
|
||||
sharedPreferenceUtil.putPrefStorage(storageDevice.name)
|
||||
sharedPreferenceUtil.putPrefStorageTitle(
|
||||
getString(
|
||||
if (storageDevice.isInternal) R.string.internal_storage
|
||||
else R.string.external_storage
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun onBookItemClick(item: BookItem) {
|
||||
|
@ -268,7 +268,7 @@ public abstract class CorePrefsFragment extends PreferenceFragmentCompat impleme
|
||||
public void openFolderSelect() {
|
||||
StorageSelectDialog dialogFragment = new StorageSelectDialog();
|
||||
dialogFragment.setOnSelectAction(this::onStorageDeviceSelected);
|
||||
dialogFragment.show(((AppCompatActivity) getActivity()).getSupportFragmentManager(),
|
||||
dialogFragment.show(getActivity().getSupportFragmentManager(),
|
||||
getResources().getString(R.string.pref_storage));
|
||||
}
|
||||
|
||||
@ -278,13 +278,9 @@ public abstract class CorePrefsFragment extends PreferenceFragmentCompat impleme
|
||||
);
|
||||
sharedPreferenceUtil.putPrefStorage(storageDevice.getName());
|
||||
if (storageDevice.isInternal()) {
|
||||
findPreference(PREF_STORAGE).setTitle(getResources().getString(R.string.internal_storage));
|
||||
sharedPreferenceUtil.putPrefStorageTitle(
|
||||
getResources().getString(R.string.internal_storage));
|
||||
findPreference(PREF_STORAGE).setTitle(getString(R.string.internal_storage));
|
||||
} else {
|
||||
findPreference(PREF_STORAGE).setTitle(getResources().getString(R.string.external_storage));
|
||||
sharedPreferenceUtil.putPrefStorageTitle(
|
||||
getResources().getString(R.string.external_storage));
|
||||
findPreference(PREF_STORAGE).setTitle(getString(R.string.external_storage));
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ public class SharedPreferenceUtil {
|
||||
private static final String PREF_BACK_TO_TOP = "pref_backtotop";
|
||||
private static final String PREF_FULLSCREEN = "pref_fullscreen";
|
||||
private static final String PREF_NEW_TAB_BACKGROUND = "pref_newtab_background";
|
||||
private static final String PREF_STORAGE_TITLE = "pref_selected_title";
|
||||
private static final String PREF_EXTERNAL_LINK_POPUP = "pref_external_link_popup";
|
||||
private static final String PREF_IS_FIRST_RUN = "isFirstRun";
|
||||
private static final String PREF_SHOW_BOOKMARKS_ALL_BOOKS = "show_bookmarks_current_book";
|
||||
@ -115,10 +114,6 @@ public class SharedPreferenceUtil {
|
||||
: CoreApp.getInstance().getFilesDir().getPath(); // workaround for emulators
|
||||
}
|
||||
|
||||
public String getPrefStorageTitle(String defaultTitle) {
|
||||
return sharedPreferences.getString(PREF_STORAGE_TITLE, defaultTitle);
|
||||
}
|
||||
|
||||
public void putPrefLanguage(String language) {
|
||||
sharedPreferences.edit().putString(PREF_LANG, language).apply();
|
||||
}
|
||||
@ -131,10 +126,6 @@ public class SharedPreferenceUtil {
|
||||
sharedPreferences.edit().putBoolean(PREF_WIFI_ONLY, wifiOnly).apply();
|
||||
}
|
||||
|
||||
public void putPrefStorageTitle(String storageTitle) {
|
||||
sharedPreferences.edit().putString(PREF_STORAGE_TITLE, storageTitle).apply();
|
||||
}
|
||||
|
||||
public void putPrefStorage(String storage) {
|
||||
sharedPreferences.edit().putString(PREF_STORAGE, storage).apply();
|
||||
prefStorages.onNext(storage);
|
||||
|
Loading…
x
Reference in New Issue
Block a user