From b1963aed50b5dbe67b8b3eb347e6af1dcd257680 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 9 Oct 2015 17:20:47 +0200 Subject: [PATCH 01/25] Prepare preferences and project to use user defined storage path --- res/values/strings.xml | 2 + res/xml/preferences.xml | 9 ++++ src/com/owncloud/android/MainApp.java | 19 ++++++- .../android/ui/activity/Preferences.java | 52 +++++++++++++++++-- .../android/utils/FileStorageUtils.java | 3 +- 5 files changed, 78 insertions(+), 7 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index eb98378fa249..4e45a83f34d6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -422,6 +422,8 @@ kept in original folder moved to app folder deleted + Storage path + Common Sharing Share %1$s diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 67b089dca4f7..c441435cf664 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -19,6 +19,15 @@ --> + + + + + + + Date: Mon, 15 Aug 2016 16:06:24 +0200 Subject: [PATCH 02/25] rebase --- AndroidManifest.xml | 1 + res/xml/preferences.xml | 5 +- src/com/owncloud/android/MainApp.java | 3 +- .../LocalDirectorySelectorActivity.java | 53 ++++++++++++++++++ .../android/ui/activity/Preferences.java | 56 ++++++++++++------- .../ui/activity/StorageMigrationActivity.java | 31 ++++++++++ .../ui/activity/UploadFilesActivity.java | 2 +- .../android/utils/FileStorageUtils.java | 13 ++--- 8 files changed, 130 insertions(+), 34 deletions(-) create mode 100644 src/com/owncloud/android/ui/activity/LocalDirectorySelectorActivity.java create mode 100644 src/com/owncloud/android/ui/activity/StorageMigrationActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f0cc9ff7c33b..ba80e0dad94d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -79,6 +79,7 @@ android:taskAffinity="" android:excludeFromRecents="true" android:theme="@style/Theme.ownCloud.NoActionBar"> + diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index c441435cf664..10d227bf5e39 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -18,9 +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 13d70367519b..9639ebf3b670 100644 --- a/src/com/owncloud/android/MainApp.java +++ b/src/com/owncloud/android/MainApp.java @@ -89,8 +89,7 @@ public void onCreate(){ // Set folder for store logs Log_OC.setLogDataFolder(dataFolder); - //TODO: to be changed/fixed whenever SD card support gets merged. - Log_OC.startLogging(Environment.getExternalStorageDirectory().getAbsolutePath()); + 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 000000000000..83b44c594012 --- /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 3cf7076b3cb2..a1805e53a500 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -66,6 +66,7 @@ import com.owncloud.android.ui.RadioButtonPreference; import com.owncloud.android.utils.DisplayUtils; +import java.io.File; import java.io.IOException; @@ -81,6 +82,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 static final int ACTION_REQUEST_PASSCODE = 5; private static final int ACTION_CONFIRM_PASSCODE = 6; @@ -336,30 +339,26 @@ public boolean onPreferenceClick(Preference preference) { } } - 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"); @@ -598,7 +597,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { 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); @@ -634,9 +633,24 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { Toast.makeText(this, R.string.pass_code_removed, Toast.LENGTH_LONG).show(); } + } 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); } else if (requestCode == ACTION_REQUEST_CODE_DAVDROID_SETUP && resultCode == RESULT_OK) { - Toast.makeText(this, R.string.prefs_calendar_contacts_sync_setup_successful, Toast.LENGTH_LONG).show(); - } + Toast.makeText(this, R.string.prefs_calendar_contacts_sync_setup_successful, Toast.LENGTH_LONG).show(); } } public ActionBar getSupportActionBar() { @@ -735,7 +749,7 @@ private void loadStoragePath() { 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 000000000000..c5dc59ba22fa --- /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 9cae55a6f9f4..598397202eb2 100644 --- a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java +++ b/src/com/owncloud/android/ui/activity/UploadFilesActivity.java @@ -81,7 +81,7 @@ public class UploadFilesActivity extends FileActivity implements public static final int RESULT_OK_AND_DO_NOTHING = 2; public static final int RESULT_OK_AND_DELETE = 3; - private static final String KEY_DIRECTORY_PATH = + public static final String KEY_DIRECTORY_PATH = UploadFilesActivity.class.getCanonicalName() + ".KEY_DIRECTORY_PATH"; private static final String KEY_ALL_SELECTED = UploadFilesActivity.class.getCanonicalName() + ".KEY_ALL_SELECTED"; diff --git a/src/com/owncloud/android/utils/FileStorageUtils.java b/src/com/owncloud/android/utils/FileStorageUtils.java index 9e8f047c18b7..731e3ba9f7c4 100644 --- a/src/com/owncloud/android/utils/FileStorageUtils.java +++ b/src/com/owncloud/android/utils/FileStorageUtils.java @@ -79,7 +79,7 @@ public static final String removeDataFolderPath(String fullPath) { * Get local owncloud storage path for accountName. */ public static final String getSavePath(String accountName) { - 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 } @@ -97,10 +97,9 @@ public static final String getDefaultSavePathFor(String accountName, OCFile file * Get absolute path to tmp folder inside datafolder in sd-card for given accountName. */ public static final String getTemporalPath(String accountName) { - File sdCard = Environment.getExternalStorageDirectory(); - return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/tmp/" + 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 + 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 } /** @@ -110,7 +109,7 @@ public static final String getTemporalPath(String accountName) { */ @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(); @@ -122,7 +121,7 @@ public static final long getUsableSpace(String accountName) { } 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"; } /** From b38b3276e2c9d5cf8a605344098aefaf27450c1b Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sun, 8 Nov 2015 22:42:53 +0100 Subject: [PATCH 03/25] Add more migration stuff. cleanup step is still missing --- AndroidManifest.xml | 1 + res/layout/migration_layout.xml | 32 ++ res/values/strings.xml | 17 ++ .../datamodel/FileDataStorageManager.java | 64 ++++ .../android/ui/activity/Preferences.java | 20 +- .../ui/activity/StorageMigrationActivity.java | 278 ++++++++++++++++++ 6 files changed, 408 insertions(+), 4 deletions(-) create mode 100644 res/layout/migration_layout.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ba80e0dad94d..26d9b61dd938 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -80,6 +80,7 @@ android:excludeFromRecents="true" android:theme="@style/Theme.ownCloud.NoActionBar"> + diff --git a/res/layout/migration_layout.xml b/res/layout/migration_layout.xml new file mode 100644 index 000000000000..84b5c2207b23 --- /dev/null +++ b/res/layout/migration_layout.xml @@ -0,0 +1,32 @@ + + + + + + + +