Search in sources :

Example 1 with StoragePoint

use of com.owncloud.android.datastorage.StoragePoint in project android by nextcloud.

the class SystemDefaultStoragePointProvider method getAvailableStoragePoint.

@Override
public Vector<StoragePoint> getAvailableStoragePoint() {
    Vector<StoragePoint> result = new Vector<>();
    final String defaultStringDesc = MainApp.getAppContext().getString(R.string.storage_description_default);
    // Add private internal storage data directory.
    result.add(new StoragePoint(defaultStringDesc, MainApp.getAppContext().getFilesDir().getAbsolutePath(), StoragePoint.StorageType.INTERNAL, StoragePoint.PrivacyType.PRIVATE));
    return result;
}
Also used : StoragePoint(com.owncloud.android.datastorage.StoragePoint) Vector(java.util.Vector)

Example 2 with StoragePoint

use of com.owncloud.android.datastorage.StoragePoint in project android by nextcloud.

the class VDCStoragePointProvider method getPaths.

private Vector<StoragePoint> getPaths(String vdcResources) {
    Vector<StoragePoint> result = new Vector<>();
    for (String line : vdcResources.split("\n")) {
        String[] vdcLine = line.split(" ");
        try {
            int status = Integer.parseInt(vdcLine[0]);
            if (status != sVDCVolumeList) {
                continue;
            }
            final String description = vdcLine[1];
            final String path = vdcLine[2];
            if (canBeAddedToAvailableList(result, path)) {
                result.add(new StoragePoint(description, path, StoragePoint.StorageType.EXTERNAL, StoragePoint.PrivacyType.PRIVATE));
            }
        } catch (NumberFormatException e) {
            Log_OC.e(TAG, "Incorrect VDC output format " + e);
        } catch (Exception e) {
            Log_OC.e(TAG, "Unexpected exception on VDC parsing " + e);
        }
    }
    return result;
}
Also used : StoragePoint(com.owncloud.android.datastorage.StoragePoint) Vector(java.util.Vector) StoragePoint(com.owncloud.android.datastorage.StoragePoint)

Example 3 with StoragePoint

use of com.owncloud.android.datastorage.StoragePoint in project android by nextcloud.

the class Preferences method setupGeneralCategory.

private void setupGeneralCategory(int accentColor) {
    PreferenceCategory preferenceCategoryGeneral = (PreferenceCategory) findPreference("general");
    preferenceCategoryGeneral.setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_general), accentColor));
    mPrefStoragePath = (ListPreference) findPreference(PreferenceKeys.STORAGE_PATH);
    if (mPrefStoragePath != null) {
        StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints();
        String[] entries = new String[storageOptions.length];
        String[] values = new String[storageOptions.length];
        for (int i = 0; i < storageOptions.length; ++i) {
            entries[i] = storageOptions[i].getDescription();
            values[i] = storageOptions[i].getPath();
        }
        mPrefStoragePath.setEntries(entries);
        mPrefStoragePath.setEntryValues(values);
        mPrefStoragePath.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String newPath = (String) newValue;
                if (mStoragePath.equals(newPath)) {
                    return true;
                }
                StorageMigration storageMigration = new StorageMigration(Preferences.this, mStoragePath, newPath);
                storageMigration.setStorageMigrationProgressListener(Preferences.this);
                storageMigration.migrate();
                return false;
            }
        });
    }
    loadStoragePath();
}
Also used : PreferenceCategory(android.preference.PreferenceCategory) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference) StoragePoint(com.owncloud.android.datastorage.StoragePoint) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) StoragePoint(com.owncloud.android.datastorage.StoragePoint)

Example 4 with StoragePoint

use of com.owncloud.android.datastorage.StoragePoint in project android by nextcloud.

the class MainApp method fixStoragePath.

// commit is done on purpose to write immediately
@SuppressLint("ApplySharedPref")
private void fixStoragePath() {
    if (!PreferenceManager.getStoragePathFix(this)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            StoragePoint[] storagePoints = DataStorageProvider.getInstance().getAvailableStoragePoints();
            String storagePath = appPrefs.getString(Preferences.PreferenceKeys.STORAGE_PATH, "");
            if (TextUtils.isEmpty(storagePath)) {
                if (appPrefs.getInt(WhatsNewActivity.KEY_LAST_SEEN_VERSION_CODE, 0) != 0) {
                    // We already used the app, but no storage is set - fix that!
                    appPrefs.edit().putString(Preferences.PreferenceKeys.STORAGE_PATH, Environment.getExternalStorageDirectory().getAbsolutePath()).commit();
                    appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
                } else {
                    // find internal storage path that's indexable
                    boolean set = false;
                    for (StoragePoint storagePoint : storagePoints) {
                        if (storagePoint.getStorageType().equals(StoragePoint.StorageType.INTERNAL) && storagePoint.getPrivacyType().equals(StoragePoint.PrivacyType.PUBLIC)) {
                            appPrefs.edit().putString(Preferences.PreferenceKeys.STORAGE_PATH, storagePoint.getPath()).commit();
                            appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
                            set = true;
                            break;
                        }
                    }
                    if (!set) {
                        for (StoragePoint storagePoint : storagePoints) {
                            if (storagePoint.getPrivacyType().equals(StoragePoint.PrivacyType.PUBLIC)) {
                                appPrefs.edit().putString(Preferences.PreferenceKeys.STORAGE_PATH, storagePoint.getPath()).commit();
                                appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
                                set = true;
                                break;
                            }
                        }
                    }
                }
                PreferenceManager.setStoragePathFix(this, true);
            } else {
                appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
                PreferenceManager.setStoragePathFix(this, true);
            }
        } else {
            if (TextUtils.isEmpty(storagePath)) {
                appPrefs.edit().putString(Preferences.PreferenceKeys.STORAGE_PATH, Environment.getExternalStorageDirectory().getAbsolutePath()).commit();
            }
            appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
            PreferenceManager.setStoragePathFix(this, true);
        }
    }
}
Also used : StoragePoint(com.owncloud.android.datastorage.StoragePoint) SuppressLint(android.annotation.SuppressLint)

Aggregations

StoragePoint (com.owncloud.android.datastorage.StoragePoint)4 Vector (java.util.Vector)2 SuppressLint (android.annotation.SuppressLint)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)1 PreferenceCategory (android.preference.PreferenceCategory)1 SwitchPreference (android.preference.SwitchPreference)1