use of com.quran.labs.androidquran.util.QuranSettings in project quran_android by quran.
the class QuranAdvancedSettingsFragment method loadStorageOptions.
private void loadStorageOptions(Context context) {
try {
if (appSize == -1) {
// sdcard is not mounted...
hideStorageListPref();
return;
}
listStoragePref.setLabelsAndSummaries(context, appSize, storageList);
final HashMap<String, StorageUtils.Storage> storageMap = new HashMap<>(storageList.size());
for (StorageUtils.Storage storage : storageList) {
storageMap.put(storage.getMountPoint(), storage);
}
listStoragePref.setOnPreferenceChangeListener((preference, newValue) -> {
final Context context1 = getActivity();
final QuranSettings settings = QuranSettings.getInstance(context1);
if (TextUtils.isEmpty(settings.getAppCustomLocation()) && Environment.getExternalStorageDirectory().equals(newValue)) {
// the default sdcard setting, which are the same, but write it.
return false;
}
// this is called right before the preference is saved
String newLocation = (String) newValue;
StorageUtils.Storage destStorage = storageMap.get(newLocation);
String current = settings.getAppCustomLocation();
if (appSize < destStorage.getFreeSpace()) {
if (current == null || !current.equals(newLocation)) {
if (destStorage.doesRequirePermission()) {
if (!PermissionUtil.haveWriteExternalStoragePermission(context1)) {
requestExternalStoragePermission(newLocation);
return false;
}
// we have the permission, so fall through and handle the move
}
handleMove(newLocation);
}
} else {
Toast.makeText(context1, getString(R.string.prefs_no_enough_space_to_move_files), Toast.LENGTH_LONG).show();
}
// this says, "don't write the preference"
return false;
});
listStoragePref.setEnabled(true);
} catch (Exception e) {
Timber.e(e, "error loading storage options");
hideStorageListPref();
}
}
use of com.quran.labs.androidquran.util.QuranSettings in project quran_android by quran.
the class DataListPreference method setLabelsAndSummaries.
public void setLabelsAndSummaries(Context context, int appSize, List<StorageUtils.Storage> storageList) {
String summary = context.getString(R.string.prefs_app_location_summary) + "\n" + context.getString(R.string.prefs_app_size) + " " + context.getString(R.string.prefs_megabytes_int, appSize);
setSummary(summary);
CharSequence[] values = new CharSequence[storageList.size()];
CharSequence[] displayNames = new CharSequence[storageList.size()];
mDescriptions = new CharSequence[storageList.size()];
StorageUtils.Storage storage;
for (int i = 0; i < storageList.size(); i++) {
storage = storageList.get(i);
values[i] = storage.getMountPoint();
displayNames[i] = storage.getLabel();
mDescriptions[i] = storage.getMountPoint() + " " + context.getString(R.string.prefs_megabytes_int, storage.getFreeSpace());
}
setEntries(displayNames);
setEntryValues(values);
final QuranSettings settings = QuranSettings.getInstance(context);
String current = settings.getAppCustomLocation();
if (TextUtils.isEmpty(current)) {
current = values[0].toString();
}
setValue(current);
}
use of com.quran.labs.androidquran.util.QuranSettings in project quran_android by quran.
the class TranslationManagerPresenterTest method setup.
@Before
public void setup() {
Context mockAppContext = mock(Context.class);
QuranSettings mockSettings = mock(QuranSettings.class);
OkHttpClient mockOkHttp = new OkHttpClient.Builder().build();
mockWebServer = new MockWebServer();
translationManager = new TranslationManagerPresenter(mockAppContext, mockOkHttp, mockSettings, null, mock(QuranFileUtils.class)) {
@Override
void writeTranslationList(TranslationList list) {
// no op
}
};
translationManager.host = mockWebServer.url("").toString();
}
Aggregations