Andy Scherzinger před 8 roky
rodič
revize
3fc8d999db

+ 1 - 0
AndroidManifest.xml

@@ -79,6 +79,7 @@
                   android:taskAffinity=""
                   android:excludeFromRecents="true"
                   android:theme="@style/Theme.ownCloud.NoActionBar">
+        <activity android:name=".ui.activity.LocalDirectorySelectorActivity" />
             <intent-filter>
                 <action android:name="android.intent.action.SEND" />
 

+ 2 - 3
res/xml/preferences.xml

@@ -18,9 +18,8 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
-
-	<PreferenceCategory android:title="@string/prefs_common">
-		<EditTextPreference
+	<PreferenceCategory android:title="@string/prefs_category_general">
+		<Preference
 			android:title="@string/prefs_storage_path"
 			android:key="storage_path" />
 	</PreferenceCategory>

+ 1 - 2
src/com/owncloud/android/MainApp.java

@@ -89,8 +89,7 @@ public class MainApp extends Application {
             // 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");
         }
 

+ 53 - 0
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 <http://www.gnu.org/licenses/>.
+ *
+ */
+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();
+		}
+	}
+}

+ 35 - 21
src/com/owncloud/android/ui/activity/Preferences.java

@@ -66,6 +66,7 @@ import com.owncloud.android.ui.PreferenceWithLongSummary;
 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 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");
@@ -598,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);
@@ -634,9 +633,24 @@ public class Preferences extends PreferenceActivity {
 
                 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 @@ 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());
     }
 
     /**

+ 31 - 0
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 <http://www.gnu.org/licenses/>.
+ *
+ */
+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";
+}

+ 1 - 1
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";

+ 6 - 7
src/com/owncloud/android/utils/FileStorageUtils.java

@@ -79,7 +79,7 @@ public class FileStorageUtils {
      * 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 class FileStorageUtils {
      * 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 class FileStorageUtils {
      */
     @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 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";
     }
 
     /**