import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.preference.CheckBoxPreference;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.services.OperationsService;
+import com.owncloud.android.ui.PreferenceWithLongSummary;
import com.owncloud.android.ui.RadioButtonPreference;
import com.owncloud.android.utils.DisplayUtils;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.ExecutionException;
+import java.io.File;
/**
private static final int ACTION_SELECT_UPLOAD_PATH = 1;
private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH = 2;
+ private static final int ACTION_SELECT_STORAGE_PATH = 3;
+ private static final int ACTION_PERFORM_MIGRATION = 4;
private DbHandler mDbHandler;
private CheckBoxPreference pCode;
protected FileDownloader.FileDownloaderBinder mDownloaderBinder = null;
protected FileUploader.FileUploaderBinder mUploaderBinder = null;
private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null;
+ private PreferenceWithLongSummary mPrefStoragePath;
+ private String mStoragePath;
@SuppressWarnings("deprecation")
@Override
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
- Preference pHelp = findPreference("help");
+ Preference pHelp = findPreference("help");
if (pHelp != null ){
if (helpEnabled) {
pHelp.setOnPreferenceClickListener(new OnPreferenceClickListener() {
}
if (BuildConfig.DEBUG) {
- Preference pLog = findPreference("log");
+ Preference pLog = findPreference("log");
if (pLog != null ){
pLog.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
intent.putExtra(Intent.EXTRA_TEXT, recommendText);
startActivity(intent);
- return(true);
+ return true;
}
});
pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
- String feedbackMail =(String) getText(R.string.mail_feedback);
- String feedback =(String) getText(R.string.prefs_feedback) + " - android v" + appVersion;
- Intent intent = new Intent(Intent.ACTION_SENDTO);
+ String feedbackMail = (String) getText(R.string.mail_feedback);
+ String feedback = String.format("%s - android v%s", getText(R.string.prefs_feedback), appVersion);
+ Intent intent = new Intent(Intent.ACTION_SENDTO);
+
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, feedback);
}
}
- mPrefInstantUploadPath = findPreference("instant_upload_path");
+ mPrefStoragePath = (PreferenceWithLongSummary)findPreference("storage_path");
+ if (mPrefStoragePath != null) {
+
+ mPrefStoragePath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ Intent intent = new Intent(Preferences.this, LocalDirectorySelectorActivity.class);
+ intent.putExtra(UploadFilesActivity.KEY_DIRECTORY_PATH, mStoragePath);
+ startActivityForResult(intent, ACTION_SELECT_STORAGE_PATH);
+ return true;
+ }
+ });
+
+ mPrefStoragePath.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ MainApp.setStoragePath((String) newValue);
+ return true;
+ }
+ });
+ }
+
+ mPrefInstantUploadPath = (PreferenceWithLongSummary)findPreference("instant_upload_path");
if (mPrefInstantUploadPath != null){
mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
mPrefInstantUploadCategory =
(PreferenceCategory) findPreference("instant_uploading_category");
- mPrefInstantUploadPathWiFi = findPreference("instant_upload_on_wifi");
+ mPrefInstantUploadPathWiFi = findPreference("instant_upload_on_wifi");
mPrefInstantUpload = findPreference("instant_uploading");
toggleInstantPictureOptions(((CheckBoxPreference) mPrefInstantUpload).isChecked());
});
/* About App */
- pAboutApp = (Preference) findPreference("about_app");
+ pAboutApp = findPreference("about_app");
if (pAboutApp != null) {
pAboutApp.setTitle(String.format(getString(R.string.about_android),
getString(R.string.app_name)));
}
loadInstantUploadPath();
+ loadStoragePath();
loadInstantUploadVideoPath();
/* ComponentsGetter */
if (requestCode == ACTION_SELECT_UPLOAD_PATH && resultCode == RESULT_OK){
- OCFile folderToUpload =
- (OCFile) data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
+ OCFile folderToUpload = data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
mUploadPath = folderToUpload.getRemotePath();
saveInstantUploadPathOnPreferences();
- } else if (requestCode == ACTION_SELECT_UPLOAD_VIDEO_PATH && resultCode == RESULT_OK){
+ } else if (requestCode == ACTION_SELECT_UPLOAD_VIDEO_PATH && resultCode == RESULT_OK) {
- OCFile folderToUploadVideo =
- (OCFile) data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
+ OCFile folderToUploadVideo = data.getParcelableExtra(UploadPathActivity.EXTRA_FOLDER);
mUploadVideoPath = folderToUploadVideo.getRemotePath();
mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
saveInstantUploadVideoPathOnPreferences();
+ } else if (requestCode == ACTION_SELECT_STORAGE_PATH && resultCode == RESULT_OK) {
+ File currentStorageDir = new File(mStoragePath);
+ File upcomingStorageDir = new File(data.getStringExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES));
+
+ if (currentStorageDir != upcomingStorageDir) {
+ Intent migrationIntent = new Intent(this, StorageMigrationActivity.class);
+ migrationIntent.putExtra(StorageMigrationActivity.KEY_MIGRATION_SOURCE_DIR,
+ currentStorageDir.getAbsolutePath());
+ migrationIntent.putExtra(StorageMigrationActivity.KEY_MIGRATION_TARGET_DIR,
+ upcomingStorageDir.getAbsolutePath());
+ startActivityForResult(migrationIntent, ACTION_PERFORM_MIGRATION);
+ }
+ } else if (requestCode == ACTION_PERFORM_MIGRATION && resultCode == RESULT_OK) {
+ String resultStorageDir = data.getStringExtra(StorageMigrationActivity.KEY_MIGRATION_TARGET_DIR);
+ saveStoragePath(resultStorageDir);
}
}
}
/**
+ * Save storage path
+ */
+ private void saveStoragePath(String newStoragePath) {
+ SharedPreferences appPrefs =
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ mStoragePath = newStoragePath;
+ MainApp.setStoragePath(mStoragePath);
+ SharedPreferences.Editor editor = appPrefs.edit();
+ editor.putString("storage_path", mStoragePath);
+ editor.commit();
+ mPrefStoragePath.setSummary(mStoragePath);
+ }
+
+ /**
+ * Load storage path set on preferences
+ */
+ private void loadStoragePath() {
+ SharedPreferences appPrefs =
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ mStoragePath = appPrefs.getString("storage_path", Environment.getExternalStorageDirectory()
+ .getAbsolutePath());
+ mPrefStoragePath.setSummary(mStoragePath);
+ }
+
+ /**
* Save the "Instant Upload Path" on preferences
*/
private void saveInstantUploadPathOnPreferences() {
* Load upload video path set on preferences
*/
private void loadInstantUploadVideoPath() {
- SharedPreferences appPrefs =
- PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
- mUploadVideoPath = appPrefs.getString("instant_video_upload_path", getString(R.string.instant_upload_path));
- mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
+ mPrefInstantVideoUploadPath.setSummary(MainApp.getStoragePath());
}
/**
editor.commit();
}
- // Methods for ComponetsGetter
+ // Methods for ComponentsGetter
@Override
public FileDownloader.FileDownloaderBinder getFileDownloaderBinder() {
return mDownloaderBinder;
if (component.equals(new ComponentName(Preferences.this, FileDownloader.class))) {
mDownloaderBinder = (FileDownloader.FileDownloaderBinder) service;
-
} else if (component.equals(new ComponentName(Preferences.this, FileUploader.class))) {
Log_OC.d(TAG, "Upload service connected");
mUploaderBinder = (FileUploader.FileUploaderBinder) service;
- } else {
- return;
}
-
}
@Override