Search in sources :

Example 6 with QuranSettings

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();
    }
}
Also used : Context(android.content.Context) HashMap(java.util.HashMap) StorageUtils(com.quran.labs.androidquran.util.StorageUtils) QuranSettings(com.quran.labs.androidquran.util.QuranSettings)

Example 7 with QuranSettings

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);
}
Also used : StorageUtils(com.quran.labs.androidquran.util.StorageUtils) QuranSettings(com.quran.labs.androidquran.util.QuranSettings)

Example 8 with QuranSettings

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();
}
Also used : Context(android.content.Context) OkHttpClient(okhttp3.OkHttpClient) MockWebServer(okhttp3.mockwebserver.MockWebServer) TranslationList(com.quran.labs.androidquran.dao.translation.TranslationList) QuranSettings(com.quran.labs.androidquran.util.QuranSettings) Before(org.junit.Before)

Aggregations

QuranSettings (com.quran.labs.androidquran.util.QuranSettings)8 Activity (android.app.Activity)2 Context (android.content.Context)2 TranslationItem (com.quran.labs.androidquran.dao.translation.TranslationItem)2 QuranActivity (com.quran.labs.androidquran.ui.QuranActivity)2 StorageUtils (com.quran.labs.androidquran.util.StorageUtils)2 DisposableSingleObserver (io.reactivex.observers.DisposableSingleObserver)2 File (java.io.File)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 Snackbar (android.support.design.widget.Snackbar)1 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 ActionBar (android.support.v7.app.ActionBar)1 AlertDialog (android.support.v7.app.AlertDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SparseIntArray (android.util.SparseIntArray)1 MenuItem (android.view.MenuItem)1