From: Bartosz Przybylski Date: Sat, 7 Nov 2015 19:57:12 +0000 (+0100) Subject: Add unfinished local directories browser for storage target. Add migration activity... X-Git-Tag: beta-20151128~5^2~8 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/8aa10abb181ee596ffaa751b6dfcb0da10a51d9e?ds=inline;hp=--cc Add unfinished local directories browser for storage target. Add migration activity stub. Adjust some parts of app to prepare it for storage migration --- 8aa10abb181ee596ffaa751b6dfcb0da10a51d9e diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 805e9ce7..d97abbee 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -59,6 +59,7 @@ + diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 18ab5b08..4f3d577f 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -18,8 +18,8 @@ along with this program. If not, see . --> - - + diff --git a/src/com/owncloud/android/MainApp.java b/src/com/owncloud/android/MainApp.java index 4f0ee624..1cac7e53 100644 --- a/src/com/owncloud/android/MainApp.java +++ b/src/com/owncloud/android/MainApp.java @@ -92,7 +92,7 @@ public class MainApp extends Application { // Set folder for store logs Log_OC.setLogDataFolder(dataFolder); - Log_OC.startLogging(); + Log_OC.startLogging(MainApp.storagePath); Log_OC.d("Debug", "start logging"); } diff --git a/src/com/owncloud/android/ui/activity/LocalDirectorySelectorActivity.java b/src/com/owncloud/android/ui/activity/LocalDirectorySelectorActivity.java new file mode 100644 index 00000000..83b44c59 --- /dev/null +++ b/src/com/owncloud/android/ui/activity/LocalDirectorySelectorActivity.java @@ -0,0 +1,53 @@ +/** + * ownCloud Android client application + * + * @author Bartosz Przybylski + * Copyright (C) 2015 ownCloud Inc. + * Copyright (C) 2015 Bartosz Przybylski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.owncloud.android.ui.activity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; + +import com.owncloud.android.R; + +/** + * Created by Bartosz Przybylski on 07.11.2015. + */ +public class LocalDirectorySelectorActivity extends UploadFilesActivity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mUploadBtn.setText(R.string.folder_picker_choose_button_text); + } + + @Override + public void onClick(View v) { + if (v.getId() == R.id.upload_files_btn_cancel) { + setResult(RESULT_CANCELED); + finish(); + + } else if (v.getId() == R.id.upload_files_btn_upload) { + Intent resultIntent = new Intent(); + resultIntent.putExtra(EXTRA_CHOSEN_FILES, getInitialDirectory().getAbsolutePath()); + setResult(RESULT_OK, resultIntent); + finish(); + } + } +} diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index 6310532f..915e4844 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -81,6 +81,8 @@ import com.owncloud.android.ui.PreferenceWithLongSummary; import com.owncloud.android.ui.RadioButtonPreference; import com.owncloud.android.utils.DisplayUtils; +import java.io.File; + /** * An Activity that allows the user to change the application's settings. @@ -95,6 +97,8 @@ public class Preferences extends PreferenceActivity 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; @@ -367,30 +371,26 @@ public class Preferences extends PreferenceActivity } } - mPrefStoragePath = (PreferenceWithLongSummary)findPreference("storage_path"); - if (mPrefStoragePath != null){ + mPrefStoragePath = findPreference("storage_path"); + if (mPrefStoragePath != null) { - mPrefStoragePath.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + 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; } }); - -// mPrefStoragePath.setOnPreferenceClickListener(new OnPreferenceClickListener() { -// @Override -// public boolean onPreferenceClick(Preference preference) { -// -//// if (!mUploadPath.endsWith(OCFile.PATH_SEPARATOR)) { -//// mUploadPath += OCFile.PATH_SEPARATOR; -//// } -//// Intent intent = new Intent(Preferences.this, UploadPathActivity.class); -//// intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadPath); -//// startActivityForResult(intent, ACTION_SELECT_UPLOAD_PATH); -//// return true; -// } -// }); } mPrefInstantUploadPath = findPreference("instant_upload_path"); @@ -597,7 +597,7 @@ public class Preferences extends PreferenceActivity 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); @@ -610,6 +610,22 @@ public class Preferences extends PreferenceActivity 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, + currentStorageDir.getAbsolutePath()); + startActivityForResult(migrationIntent, ACTION_PERFORM_MIGRATION); + } + } else if (requestCode == ACTION_PERFORM_MIGRATION && resultCode == RESULT_OK) { + String resultStorageDir = data.getStringExtra(StorageMigrationActivity.KEY_MIGRATION_TARGET_DIR); + mStoragePath = resultStorageDir; + mPrefStoragePath.setSummary(mStoragePath); } } @@ -826,7 +842,7 @@ public class Preferences extends PreferenceActivity PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mStoragePath = appPrefs.getString("storage_path", Environment.getExternalStorageDirectory() .getAbsolutePath()); - mPrefStoragePath.setSummary(mStoragePath); + mPrefStoragePath.setSummary(mStoragePath + File.separator + MainApp.getDataFolder()); } /** diff --git a/src/com/owncloud/android/ui/activity/StorageMigrationActivity.java b/src/com/owncloud/android/ui/activity/StorageMigrationActivity.java new file mode 100644 index 00000000..c5dc59ba --- /dev/null +++ b/src/com/owncloud/android/ui/activity/StorageMigrationActivity.java @@ -0,0 +1,31 @@ +/** + * ownCloud Android client application + * + * @author Bartosz Przybylski + * Copyright (C) 2015 ownCloud Inc. + * Copyright (C) 2015 Bartosz Przybylski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.owncloud.android.ui.activity; + +import android.support.v7.app.AppCompatActivity; + +/** + * Created by Bartosz Przybylski on 07.11.2015. + */ +public class StorageMigrationActivity extends AppCompatActivity { + public static final String KEY_MIGRATION_TARGET_DIR = "MIGRATION_TARGET"; + public static final String KEY_MIGRATION_SOURCE_DIR = "MIGRATION_SOURCE"; +} diff --git a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java b/src/com/owncloud/android/ui/activity/UploadFilesActivity.java index 9a3ce178..bf1a204d 100644 --- a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java +++ b/src/com/owncloud/android/ui/activity/UploadFilesActivity.java @@ -57,18 +57,18 @@ public class UploadFilesActivity extends FileActivity implements private ArrayAdapter mDirectories; private File mCurrentDir = null; - private LocalFileListFragment mFileListFragment; - private Button mCancelBtn; - private Button mUploadBtn; - private Account mAccountOnCreation; - private DialogFragment mCurrentDialog; + protected LocalFileListFragment mFileListFragment; + protected Button mCancelBtn; + protected Button mUploadBtn; + protected Account mAccountOnCreation; + protected DialogFragment mCurrentDialog; public static final String EXTRA_CHOSEN_FILES = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES"; public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER; - private static final String KEY_DIRECTORY_PATH = + public static final String KEY_DIRECTORY_PATH = UploadFilesActivity.class.getCanonicalName() + ".KEY_DIRECTORY_PATH"; private static final String TAG = "UploadFilesActivity"; private static final String WAIT_DIALOG_TAG = "WAIT"; @@ -81,8 +81,9 @@ public class UploadFilesActivity extends FileActivity implements super.onCreate(savedInstanceState); if(savedInstanceState != null) { - mCurrentDir = new File(savedInstanceState.getString( - UploadFilesActivity.KEY_DIRECTORY_PATH)); + mCurrentDir = new File(savedInstanceState.getString(KEY_DIRECTORY_PATH)); + } else if (getIntent() != null && getIntent().hasExtra(KEY_DIRECTORY_PATH)) { + mCurrentDir = new File(getIntent().getStringExtra(KEY_DIRECTORY_PATH)); } else { mCurrentDir = Environment.getExternalStorageDirectory(); } diff --git a/src/com/owncloud/android/utils/FileStorageUtils.java b/src/com/owncloud/android/utils/FileStorageUtils.java index 6fcf285a..999d490a 100644 --- a/src/com/owncloud/android/utils/FileStorageUtils.java +++ b/src/com/owncloud/android/utils/FileStorageUtils.java @@ -57,7 +57,7 @@ public class FileStorageUtils { public static final String getSavePath(String accountName) { // File sdCard = Environment.getExternalStorageDirectory(); - return MainApp.getStoragePath() + "/" + MainApp.getDataFolder() + "/" + Uri.encode(accountName, "@"); + return MainApp.getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator + Uri.encode(accountName, "@"); // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B } @@ -66,14 +66,13 @@ public class FileStorageUtils { } public static final String getTemporalPath(String accountName) { - File sdCard = Environment.getExternalStorageDirectory(); - return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/tmp/" + Uri.encode(accountName, "@"); + return MainApp.getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator + "tmp" + File.separator + Uri.encode(accountName, "@"); // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B } @SuppressLint("NewApi") public static final long getUsableSpace(String accountName) { - File savePath = Environment.getExternalStorageDirectory(); + File savePath = new File(MainApp.getStoragePath()); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) { return savePath.getUsableSpace(); @@ -85,7 +84,7 @@ public class FileStorageUtils { } public static final String getLogPath() { - return Environment.getExternalStorageDirectory() + File.separator + MainApp.getDataFolder() + File.separator + "log"; + return MainApp.getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator + "log"; } public static String getInstantUploadFilePath(Context context, String fileName) {