From: tobiasKaminsky Date: Wed, 2 Dec 2015 19:28:56 +0000 (+0100) Subject: Merge remote-tracking branch 'remotes/upstream/avoidDuplicateFiles' into beta X-Git-Tag: beta-20151202~2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/deb1e48fc01a9750cc55429ff290e6f6ac025bf4?hp=-c Merge remote-tracking branch 'remotes/upstream/avoidDuplicateFiles' into beta --- deb1e48fc01a9750cc55429ff290e6f6ac025bf4 diff --combined res/values/strings.xml index 68597bfb,aea93b72..1df3a152 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -23,7 -23,8 +23,7 @@@ All files - + On device Settings Logs Close @@@ -61,7 -62,7 +61,7 @@@ Connect Upload New folder - Choose upload folder: + Choose upload folder No account found There are no %1$s accounts on your device. Please setup an account first. Setup @@@ -84,7 -85,9 +84,7 @@@ Synchronize File was renamed to %1$s during upload List Layout - Share link - Unshare link - Share with users + Share Yes No OK @@@ -203,11 -206,11 +203,11 @@@ Unfavorite Rename Remove - "Do you really want to remove %1$s?" + "Do you really want to remove %1$s?" "Do you really want to remove %1$s and its contents?" Local only Local only - From server + From server Remote & local "Removal succeeded" "Removal failed" @@@ -263,11 -266,9 +263,11 @@@ 389 KB 2012/05/18 12:23 PM 12:23:45 - - Upload pictures via WiFi only - Upload videos via WiFi only + + Upload pictures via wifi only + Upload when charging only + Upload videos via wifi only + Upload when charging only /InstantUpload File conflict Which files do you want to keep? If you select both versions, the local file will have a number added to its name. @@@ -279,7 -280,7 +279,7 @@@ This image cannot be shown %1$s could not be copied to %2$s local folder - Upload Path + Upload path Sorry, sharing is not enabled on your server. Please contact your administrator. @@@ -287,8 -288,6 +287,8 @@@ An error occurred while trying to share this file or folder Unable to unshare. Please check whether the file exists An error occurred while trying to unshare this file or folder + Unable to update. Please check whether the file exists + An error occurred while trying to update the shared link Enter a password You must enter a password @@@ -310,28 -309,10 +310,28 @@@ to delete this file to share this file to unshare this file + to update this shared link to create the file to upload in this folder The file is no longer available on the server + Finish + Preparing for migration... + Checking destination... + Saving accounts configuration... + Waiting for unfinished synchronizations... + Moving data... + Updating index... + Cleaning... + Restoring accounts configuration... + Finished + ERROR: Not enough space + ERROR: File is not writable + ERROR: File is not readable + ERROR: owncloud directory already exists + ERROR: While migrating + ERROR: While updating index + Accounts Add account Secure connection is redirected through an unsecured route. @@@ -364,8 -345,7 +364,8 @@@ Instant Uploads Security - Upload Video Path + Upload video path + Download of %1$s folder could not be completed Synchronization of %1$s folder could not be completed shared @@@ -388,42 -368,18 +388,46 @@@ %1$d files %1$d files, 1 folder %1$d files, %2$d folders + Switch to grid view + Switch to list view + Common + Cache size + Upload file to server and ... + Behaviour + Original file will be... + Original file will be... Copy file Move file + Storage path + Common + do nothing + copy file to OC folder + move file to OC folder + delete origin file + Do you really want to remove selected items? + Do you really want to remove a folder and its content? + selected items + Exit + Send Log + Error Log + Stream file with external player + Do you want to stream this file with an external app?\n\nCAUTION: This may expose your password! + Set picture as + Set As + kept in original folder + moved to ownCloud folder Sharing - Share with Users and Groups + Share with users and groups No data shared with users yet Add User or Group + Share link + Set expiration date + Password protect + Secured + Get link + Search Search users and groups @@@ -431,6 -387,5 +435,6 @@@ Sorry, your server version does not allow share with users within clients. \nPlease contact your administrator + https://github.com/owncloud/android/raw/beta/CHANGELOG.md diff --combined res/xml/preferences.xml index 3972e9e3,eb95bcdb..e1876e94 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@@ -3,7 -3,7 +3,7 @@@ ownCloud Android client application Copyright (C) 2012 Bartek Przybylski - Copyright (C) 2015 ownCloud Inc. + Copyright (C) 2012-2013 ownCloud Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2, @@@ -18,28 -18,14 +18,19 @@@ along with this program. If not, see . --> + + + - + - + - - @@@ -47,67 -33,45 +38,75 @@@ android:title="@string/prefs_instant_upload_path_title" android:key="instant_upload_path" /> - + android:dependency="instant_uploading" + android:disableDependentsState="true" + android:title="@string/instant_upload_on_wifi" + android:key="instant_upload_on_wifi"/> + + + + android:dependency="instant_video_uploading" + android:disableDependentsState="true" + android:title="@string/prefs_instant_video_upload_path_title" + android:key="instant_video_upload_path" /> + android:dependency="instant_video_uploading" + android:disableDependentsState="true" + android:title="@string/instant_video_upload_on_wifi" + android:key="instant_video_upload_on_wifi"/> + + - - - - - - - - - + + + + + diff --combined src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java index dc32ecc0,b6b8499f..d1ffd8f6 --- a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java +++ b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java @@@ -29,16 -29,15 +29,16 @@@ import com.owncloud.android.files.servi import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.utils.FileStorageUtils; - import android.accounts.Account; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; import android.database.Cursor; import android.net.ConnectivityManager; import android.net.NetworkInfo.State; +import android.os.BatteryManager; import android.preference.PreferenceManager; import android.provider.MediaStore.Images; import android.provider.MediaStore.Video; @@@ -60,7 -59,7 +60,7 @@@ public class InstantUploadBroadcastRece @Override public void onReceive(Context context, Intent intent) { Log_OC.d(TAG, "Received: " + intent.getAction()); - if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) { + if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION) || intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) { handleConnectivityAction(context, intent); }else if (intent.getAction().equals(NEW_PHOTO_ACTION_UNOFFICIAL)) { handleNewPictureAction(context, intent); @@@ -105,6 -104,7 +105,6 @@@ file_name = c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME)); mime_type = c.getString(c.getColumnIndex(Images.Media.MIME_TYPE)); c.close(); - Log_OC.d(TAG, file_path + ""); // save always temporally the picture to upload @@@ -112,10 -112,7 +112,10 @@@ db.putFileForLater(file_path, account.name, null); db.close(); - if (!isOnline(context) || (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))) { + if (!isOnline(context) + || (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context)) + || (instantUploadWhenChargingOnly(context) && !isCharging(context)) + ) { return; } @@@ -140,17 -137,10 +140,10 @@@ if (behaviour.equalsIgnoreCase("NOTHING")) { Log_OC.d(TAG, "upload file and do nothing"); i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_FORGET); - } else if (behaviour.equalsIgnoreCase("COPY")) { - i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_COPY); - Log_OC.d(TAG, "upload file and copy file to oc folder"); } else if (behaviour.equalsIgnoreCase("MOVE")) { i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE); Log_OC.d(TAG, "upload file and move file to oc folder"); - } else if (behaviour.equalsIgnoreCase("DELETE")){ - i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_REMOVE); - Log_OC.d(TAG, "upload file and delete file in original place"); } - return i; } @@@ -184,16 -174,8 +177,16 @@@ mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE)); c.close(); Log_OC.d(TAG, file_path + ""); + + // save always temporally the picture to upload + DbHandler db = new DbHandler(context); + db.putFileForLater(file_path, account.name, null); + db.close(); - if (!isOnline(context) || (instantVideoUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))) { + if (!isOnline(context) + || (instantVideoUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context)) + || (instantVideoUploadWhenChargingOnly(context) && !isCharging(context)) + ) { return; } @@@ -213,40 -195,18 +206,40 @@@ } private void handleConnectivityAction(Context context, Intent intent) { - if (!instantPictureUploadEnabled(context)) { + if (!instantPictureUploadEnabled(context) && !instantVideoUploadEnabled(context)) { Log_OC.d(TAG, "Instant upload disabled, don't upload anything"); return; } + if (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context)){ + Account account = AccountUtils.getCurrentOwnCloudAccount(context); + if (account == null) { + Log_OC.w(TAG, "No owncloud account found for instant upload, aborting"); + return; + } + + Intent i = new Intent(context, FileUploader.class); + i.putExtra(FileUploader.KEY_ACCOUNT, account); + i.putExtra(FileUploader.KEY_CANCEL_ALL, true); + context.startService(i); + } + if (!intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY) && isOnline(context) - && (!instantPictureUploadViaWiFiOnly(context) || (instantPictureUploadViaWiFiOnly(context) == isConnectedViaWiFi(context) == true))) { + && (!instantUploadWhenChargingOnly(context) || (instantUploadWhenChargingOnly(context) && isCharging(context))) + && (!instantVideoUploadWhenChargingOnly(context) || (instantVideoUploadWhenChargingOnly(context) && isCharging(context))) + && (!instantPictureUploadViaWiFiOnly(context) || (instantPictureUploadViaWiFiOnly(context) && isConnectedViaWiFi(context))) + && (!instantVideoUploadViaWiFiOnly(context) || (instantVideoUploadViaWiFiOnly(context) && isConnectedViaWiFi(context))) + ) { DbHandler db = new DbHandler(context); Cursor c = db.getAwaitingFiles(); if (c.moveToFirst()) { do { + if (instantPictureUploadViaWiFiOnly(context) && + !isConnectedViaWiFi(context)){ + break; + } + String account_name = c.getString(c.getColumnIndex("account")); String file_path = c.getString(c.getColumnIndex("path")); File f = new File(file_path); @@@ -284,6 -244,7 +277,6 @@@ c.close(); db.close(); } - } public static boolean isOnline(Context context) { @@@ -297,18 -258,6 +290,18 @@@ && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI && cm.getActiveNetworkInfo().getState() == State.CONNECTED; } + + public static boolean isCharging(Context context){ + IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + Intent batteryStatus = context.registerReceiver(null, ifilter); + + int status = 0; + if (batteryStatus != null) { + status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); + } + return status == BatteryManager.BATTERY_STATUS_CHARGING || + status == BatteryManager.BATTERY_STATUS_FULL; + } public static boolean instantPictureUploadEnabled(Context context) { return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_uploading", false); @@@ -325,10 -274,4 +318,10 @@@ public static boolean instantVideoUploadViaWiFiOnly(Context context) { return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_video_upload_on_wifi", false); } + public static boolean instantUploadWhenChargingOnly(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_upload_on_charging", false); + } + public static boolean instantVideoUploadWhenChargingOnly(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_video_upload_on_charging", false); + } } diff --combined src/com/owncloud/android/files/services/FileUploader.java index 9bc2742e,9188a891..7937f409 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@@ -98,12 -98,9 +98,11 @@@ public class FileUploader extends Servi public static final String KEY_INSTANT_UPLOAD = "INSTANT_UPLOAD"; public static final String KEY_LOCAL_BEHAVIOUR = "BEHAVIOUR"; + public static final String KEY_CANCEL_ALL = "CANCEL_ALL"; + public static final int LOCAL_BEHAVIOUR_COPY = 0; public static final int LOCAL_BEHAVIOUR_MOVE = 1; public static final int LOCAL_BEHAVIOUR_FORGET = 2; - public static final int LOCAL_BEHAVIOUR_REMOVE = 3; public static final int UPLOAD_SINGLE_FILE = 0; public static final int UPLOAD_MULTIPLE_FILES = 1; @@@ -197,21 -194,6 +196,21 @@@ public int onStartCommand(Intent intent, int flags, int startId) { Log_OC.d(TAG, "Starting command with id " + startId); + if (intent.hasExtra(KEY_CANCEL_ALL) && intent.hasExtra(KEY_ACCOUNT)){ + Account account = intent.getParcelableExtra(KEY_ACCOUNT); + + Log_OC.d(TAG, "Account= " + account.name); + + if (mCurrentUpload != null) { + Log_OC.d(TAG, "Current Upload Account= " + mCurrentUpload.getAccount().name); + if (mCurrentUpload.getAccount().name.equals(account.name)) { + mCurrentUpload.cancel(); + } + } + // Cancel pending uploads + cancelUploadsForAccount(account); + } + if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE) || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) { Log_OC.e(TAG, "Not enough information provided in intent"); @@@ -262,7 -244,7 +261,7 @@@ boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false); boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false); - int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_COPY); + int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET); if (intent.hasExtra(KEY_FILE) && files == null) { Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent"); @@@ -317,8 -299,10 +316,10 @@@ Pair putResult = mPendingUploads.putIfAbsent( account, files[i].getRemotePath(), newUpload ); - uploadKey = putResult.first; - requestedUploads.add(uploadKey); + if (putResult != null) { + uploadKey = putResult.first; + requestedUploads.add(uploadKey); + } // else, file already in the queue of uploads; don't repeat the request } } catch (IllegalArgumentException e) { diff --combined src/com/owncloud/android/operations/UploadFileOperation.java index 512056ba,33e07819..182ec0b3 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/com/owncloud/android/operations/UploadFileOperation.java @@@ -332,10 -332,7 +332,7 @@@ public class UploadFileOperation extend // location in the ownCloud local folder if (result.isSuccess()) { if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_FORGET) { - mFile.setStoragePath(null); - } else if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_REMOVE){ - mFile.setStoragePath(null); - originalFile.delete(); + mFile.setStoragePath(""); } else { mFile.setStoragePath(expectedPath); File fileToMove = null; @@@ -396,9 -393,6 +393,9 @@@ if (temporalFile != null && !originalFile.equals(temporalFile)) { temporalFile.delete(); } + if (result == null){ + return new RemoteOperationResult(false, 404, null); + } if (result.isSuccess()) { Log_OC.i(TAG, "Upload of " + mOriginalStoragePath + " to " + mRemotePath + ": " + result.getLogMessage()); diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index e69eb047,697d7b3e..c51484ae --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -26,7 -26,6 +26,7 @@@ import android.accounts.Account import android.accounts.AccountManager; import android.accounts.AuthenticatorException; import android.annotation.TargetApi; +import android.os.Parcelable; import android.support.v7.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.ComponentName; @@@ -51,7 -50,6 +51,7 @@@ import android.support.v4.app.FragmentM import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.view.GravityCompat; +import android.support.v7.app.AlertDialog; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@@ -81,11 -79,14 +81,11 @@@ import com.owncloud.android.lib.common. import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.operations.CopyFileOperation; import com.owncloud.android.operations.CreateFolderOperation; -import com.owncloud.android.operations.CreateShareViaLinkOperation; -import com.owncloud.android.operations.CreateShareWithShareeOperation; import com.owncloud.android.operations.MoveFileOperation; import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; -import com.owncloud.android.operations.UnshareOperation; import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.syncadapter.FileSyncAdapter; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; @@@ -107,8 -108,6 +107,8 @@@ import com.owncloud.android.utils.FileS import com.owncloud.android.utils.UriUtils; import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; /** * Displays, what files the user has available in his ownCloud. @@@ -149,14 -148,13 +149,14 @@@ public class FileDisplayActivity extend private boolean mSyncInProgress = false; private static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT"; - private static String DIALOG_CREATE_FOLDER = "DIALOG_CREATE_FOLDER"; + public static String DIALOG_CREATE_FOLDER = "DIALOG_CREATE_FOLDER"; private static String DIALOG_UPLOAD_SOURCE = "DIALOG_UPLOAD_SOURCE"; private static String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED"; private OCFile mWaitingToSend; + private Menu mOptionsMenu; + - @Override protected void onCreate(Bundle savedInstanceState) { Log_OC.v(TAG, "onCreate() start"); @@@ -273,7 -271,12 +273,7 @@@ setFile(file); if (mAccountWasSet) { - RelativeLayout navigationDrawerLayout = (RelativeLayout) findViewById(R.id.left_drawer); - if (navigationDrawerLayout != null && getAccount() != null) { - TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username); - int lastAtPos = getAccount().name.lastIndexOf("@"); - username.setText(getAccount().name.substring(0, lastAtPos)); - } + setUsernameInDrawer((RelativeLayout) findViewById(R.id.left_drawer), getAccount()); } if (!stateWasRecovered) { @@@ -302,7 -305,10 +302,7 @@@ /// First fragment OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { - listOfFiles.listDirectory(getCurrentDir()); - // TODO Enable when "On Device" is recovered - // listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice()); - + listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice()); } else { Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >("); } @@@ -321,8 -327,6 +321,8 @@@ startTextPreview(file); } + switchLayout(getFile()); + } else { Log_OC.wtf(TAG, "initFragments() called with invalid NULLs!"); if (getAccount() == null) { @@@ -334,14 -338,6 +334,14 @@@ } } + private void switchLayout(OCFile file){ + if (DisplayUtils.isGridView(file, getStorageManager())){ + switchToGridView(); + } else { + switchToListView(); + } + } + private Fragment chooseInitialSecondFragment(OCFile file) { Fragment secondFragment = null; if (file != null && !file.isFolder()) { @@@ -441,7 -437,9 +441,7 @@@ protected void refreshListOfFilesFragment() { OCFileListFragment fileListFragment = getListOfFilesFragment(); if (fileListFragment != null) { - fileListFragment.listDirectory(); - // TODO Enable when "On Device" is recovered ? - // fileListFragment.listDirectory(MainApp.getOnlyOnDevice()); + fileListFragment.listDirectory(MainApp.getOnlyOnDevice()); } } @@@ -493,9 -491,10 +493,9 @@@ @Override public boolean onPrepareOptionsMenu(Menu menu) { boolean drawerOpen = mDrawerLayout.isDrawerOpen(GravityCompat.START); - menu.findItem(R.id.action_upload).setVisible(!drawerOpen); - menu.findItem(R.id.action_create_dir).setVisible(!drawerOpen); menu.findItem(R.id.action_sort).setVisible(!drawerOpen); menu.findItem(R.id.action_sync_account).setVisible(!drawerOpen); + menu.findItem(R.id.action_switch_view).setVisible(!drawerOpen); return super.onPrepareOptionsMenu(menu); } @@@ -504,13 -503,6 +504,13 @@@ public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); + menu.findItem(R.id.action_create_dir).setVisible(false); + mOptionsMenu = menu; + + MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view); + + changeGridIcon(); + return true; } @@@ -519,10 -511,23 +519,10 @@@ public boolean onOptionsItemSelected(MenuItem item) { boolean retval = true; switch (item.getItemId()) { - case R.id.action_create_dir: { - CreateFolderDialogFragment dialog = - CreateFolderDialogFragment.newInstance(getCurrentDir()); - dialog.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER); - break; - } - case R.id.action_sync_account: { startSynchronization(); break; } - case R.id.action_upload: { - UploadSourceDialogFragment dialog = - UploadSourceDialogFragment.newInstance(getAccount()); - dialog.show(getSupportFragmentManager(), DIALOG_UPLOAD_SOURCE); - break; - } case android.R.id.home: { FileFragment second = getSecondFragment(); OCFile currentDir = getCurrentDir(); @@@ -565,57 -570,12 +565,57 @@@ builder.create().show(); break; } + case R.id.action_switch_view:{ + if (isGridView()){ + item.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view)); + item.setIcon(ContextCompat.getDrawable(getApplicationContext(), + R.drawable.ic_view_module)); + DisplayUtils.setViewMode(getFile(), false); + switchToListView(); + } else { + item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view)); + item.setIcon(ContextCompat.getDrawable(getApplicationContext(), + R.drawable.ic_view_list)); + DisplayUtils.setViewMode(getFile(), true); + switchToGridView(); + } + + return true; + } default: retval = super.onOptionsItemSelected(item); } return retval; } + public void createFolder() { + CreateFolderDialogFragment dialog = + CreateFolderDialogFragment.newInstance(getCurrentDir()); + dialog.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER); + } + + public void uploadLocalFilesSelected() { + Intent action = new Intent(this, UploadFilesActivity.class); + action.putExtra( + UploadFilesActivity.EXTRA_ACCOUNT, + getAccount() + ); + startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES); + } + + public void uploadFromOtherAppsSelected() { + Intent action = new Intent(Intent.ACTION_GET_CONTENT); + action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE); + //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + } + startActivityForResult( + Intent.createChooser(action, getString(R.string.upload_chooser_title)), + ACTION_SELECT_CONTENT_FROM_APPS + ); + } + private void startSynchronization() { Log_OC.d(TAG, "Got to start sync"); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) { @@@ -810,12 -770,8 +810,12 @@@ */ private void requestMoveOperation(Intent data, int resultCode) { OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER); - OCFile targetFile = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FILE); - getFileOperationsHelper().moveFile(folderToMoveAt, targetFile); + + ArrayList files = data.getParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES); + + for (Parcelable file : files) { + getFileOperationsHelper().moveFile(folderToMoveAt, (OCFile) file); + } } /** @@@ -826,36 -782,13 +826,36 @@@ */ private void requestCopyOperation(Intent data, int resultCode) { OCFile folderToMoveAt = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER); - OCFile targetFile = data.getParcelableExtra(FolderPickerActivity.EXTRA_FILE); - getFileOperationsHelper().copyFile(folderToMoveAt, targetFile); + + ArrayList files = data.getParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES); + + for (Parcelable file : files) { + getFileOperationsHelper().copyFile(folderToMoveAt, (OCFile) file); + } } @Override public void onBackPressed() { - if (!isDrawerOpen()){ + boolean isFabOpen = isFabOpen(); + boolean isDrawerOpen = isDrawerOpen(); + + /* + * BackPressed priority/hierarchy: + * 1. close drawer if opened + * 2. close FAB if open (only if drawer isn't open) + * 3. navigate up (only if drawer and FAB aren't open) + */ + if(isDrawerOpen && isFabOpen) { + // close drawer first + super.onBackPressed(); + } else if(isDrawerOpen && !isFabOpen) { + // close drawer + super.onBackPressed(); + } else if (!isDrawerOpen && isFabOpen) { + // close fab + getListOfFilesFragment().getFabMain().collapse(); + } else { + // all closed OCFileListFragment listOfFiles = getListOfFilesFragment(); if (mDualPane || getSecondFragment() == null) { OCFile currentDir = getCurrentDir(); @@@ -871,20 -804,8 +871,20 @@@ setFile(listOfFiles.getCurrentFile()); } cleanSecondFragment(); + changeGridIcon(); + } + } + + private void changeGridIcon(){ + MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view); + if (DisplayUtils.isGridView(getFile(), getStorageManager())){ + menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_list_view)); + menuItem.setIcon(ContextCompat.getDrawable(getApplicationContext(), + R.drawable.ic_view_list)); } else { - super.onBackPressed(); + menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view)); + menuItem.setIcon(ContextCompat.getDrawable(getApplicationContext(), + R.drawable.ic_view_module)); } } @@@ -963,14 -884,6 +963,14 @@@ Log_OC.v(TAG, "onPause() end"); } + public boolean isFabOpen() { + if(getListOfFilesFragment() != null && getListOfFilesFragment().getFabMain() != null && getListOfFilesFragment().getFabMain().isExpanded()) { + return true; + } else { + return false; + } + } + private class SyncBroadcastReceiver extends BroadcastReceiver { @@@ -1026,8 -939,10 +1026,8 @@@ currentDir.getRemotePath().equals(synchFolderRemotePath)) { OCFileListFragment fileListFragment = getListOfFilesFragment(); if (fileListFragment != null) { - fileListFragment.listDirectory(); - // TODO Enable when "On Device" is recovered ? - // fileListFragment.listDirectory(currentDir, - // MainApp.getOnlyOnDevice()); + fileListFragment.listDirectory(currentDir, + MainApp.getOnlyOnDevice()); } } setFile(currentFile); @@@ -1132,7 -1047,7 +1132,7 @@@ @Override public void onReceive(Context context, Intent intent) { try { - String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); + String uploadedRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name); OCFile currentDir = getCurrentDir(); @@@ -1141,7 -1056,7 +1141,7 @@@ if (sameAccount && isDescendant) { String linkedToRemotePath = - intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH); + intent.getStringExtra(FileUploader.EXTRA_LINKED_TO_PATH); if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) { refreshListOfFilesFragment(); } @@@ -1283,7 -1198,9 +1283,7 @@@ OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { // should never be null, indeed OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); - listOfFiles.listDirectory(root); - // TODO Enable when "On Device" is recovered ? - // listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice()); + listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice()); setFile(listOfFiles.getCurrentFile()); startSyncFolderOperation(root, false); } @@@ -1302,11 -1219,6 +1302,11 @@@ cleanSecondFragment(); // Sync Folder startSyncFolderOperation(directory, false); + + MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view); + + changeGridIcon(); + switchLayout(directory); } /** @@@ -1373,7 -1285,9 +1373,7 @@@ // getFileDownloadBinder() - THIS IS A MESS OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { - listOfFiles.listDirectory(); - // TODO Enable when "On Device" is recovered ? - // listOfFiles.listDirectory(MainApp.getOnlyOnDevice()); + listOfFiles.listDirectory(MainApp.getOnlyOnDevice()); } FileFragment secondFragment = getSecondFragment(); if (secondFragment != null && secondFragment instanceof FileDetailFragment) { @@@ -1439,6 -1353,15 +1439,6 @@@ } else if (operation instanceof CreateFolderOperation) { onCreateFolderOperationFinish((CreateFolderOperation) operation, result); - } else if (operation instanceof CreateShareViaLinkOperation || - operation instanceof CreateShareWithShareeOperation ) { - - refreshShowDetails(); - refreshListOfFilesFragment(); - - } else if (operation instanceof UnshareOperation) { - onUnshareLinkOperationFinish((UnshareOperation) operation, result); - } else if (operation instanceof MoveFileOperation) { onMoveFileOperationFinish((MoveFileOperation) operation, result); @@@ -1448,6 -1371,18 +1448,6 @@@ } - private void onUnshareLinkOperationFinish(UnshareOperation operation, - RemoteOperationResult result) { - if (result.isSuccess()) { - refreshShowDetails(); - refreshListOfFilesFragment(); - - } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { - cleanSecondFragment(); - refreshListOfFilesFragment(); - } - } - private void refreshShowDetails() { FileFragment details = getSecondFragment(); if (details != null) { @@@ -1902,19 -1837,8 +1902,19 @@@ private void sortByName(boolean ascending) { getListOfFilesFragment().sortByName(ascending); } + private boolean isGridView(){ return getListOfFilesFragment().isGridView(); } + private void switchToGridView() { + getListOfFilesFragment().switchToGridView(); + } + private void switchToListView() { + getListOfFilesFragment().switchToListView(); + } public void allFilesOption() { browseToRoot(); } + + public void refreshDirectory(){ + getListOfFilesFragment().refreshDirectory(); + } } diff --combined src/com/owncloud/android/ui/activity/Preferences.java index 61b4702e,d76d696e..d7288c91 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@@ -34,9 -34,7 +34,9 @@@ import android.content.pm.PackageInfo import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; 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; @@@ -64,7 -62,6 +64,7 @@@ import android.widget.AdapterView.OnIte import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; +import android.widget.Toast; import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; @@@ -73,25 -70,15 +73,25 @@@ import com.owncloud.android.authenticat import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.db.DbHandler; import com.owncloud.android.files.FileOperationsHelper; import com.owncloud.android.files.services.FileDownloader; 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.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.concurrent.ExecutionException; +import java.io.File; + /** * An Activity that allows the user to change the application's settings. @@@ -106,10 -93,6 +106,10 @@@ public class Preferences extends Prefer private static final int ACTION_SELECT_UPLOAD_PATH = 1; private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH = 2; + private static final int ACTION_REQUEST_PASSCODE = 5; + private static final int ACTION_CONFIRM_PASSCODE = 6; + private static final int ACTION_SELECT_STORAGE_PATH = 3; + private static final int ACTION_PERFORM_MIGRATION = 4; private DbHandler mDbHandler; private CheckBoxPreference pCode; @@@ -123,6 -106,7 +123,7 @@@ private String mUploadPath; private PreferenceCategory mPrefInstantUploadCategory; private Preference mPrefInstantUpload; + private Preference mPrefInstantUploadBehaviour; private Preference mPrefInstantUploadPath; private Preference mPrefInstantUploadPathWiFi; private Preference mPrefInstantVideoUpload; @@@ -133,9 -117,6 +134,9 @@@ protected FileDownloader.FileDownloaderBinder mDownloaderBinder = null; protected FileUploader.FileUploaderBinder mUploaderBinder = null; private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null; + private PreferenceWithLongSummary mPrefStoragePath; + private String mStoragePath; + @SuppressWarnings("deprecation") @Override @@@ -239,53 -220,28 +240,53 @@@ registerForContextMenu(getListView()); pCode = (CheckBoxPreference) findPreference("set_pincode"); - if (pCode != null){ + if (pCode != null) { pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Intent i = new Intent(getApplicationContext(), PassCodeActivity.class); - Boolean enable = (Boolean) newValue; + Boolean incoming = (Boolean) newValue; + i.setAction( - enable.booleanValue() ? PassCodeActivity.ACTION_ENABLE : - PassCodeActivity.ACTION_DISABLE + incoming.booleanValue() ? PassCodeActivity.ACTION_REQUEST_WITH_RESULT : + PassCodeActivity.ACTION_CHECK_WITH_RESULT ); - startActivity(i); - - return true; + + startActivityForResult(i, incoming.booleanValue() ? ACTION_REQUEST_PASSCODE : + ACTION_CONFIRM_PASSCODE); + + // Don't update just yet, we will decide on it in onActivityResult + return false; } - }); + }); } + final Preference pCacheSize = findPreference("pref_cache_size"); + if (pCacheSize != null){ + final SharedPreferences appPrefs = + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + Long cacheSize = ThumbnailsCacheManager.getMaxSize(); + pCacheSize.setSummary(cacheSize + " Mb"); + pCacheSize.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + int size = Integer.decode((String) newValue); + if (ThumbnailsCacheManager.setMaxSize(size)){ + appPrefs.edit().putInt("pref_cache_size", size); + pCacheSize.setSummary(size + " MB"); + return true; + } else { + return false; + } + } + }); + } + 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() { @@@ -307,7 -263,7 +308,7 @@@ } if (BuildConfig.DEBUG) { - Preference pLog = findPreference("log"); + Preference pLog = findPreference("log"); if (pLog != null ){ pLog.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override @@@ -350,7 -306,7 +351,7 @@@ intent.putExtra(Intent.EXTRA_TEXT, recommendText); startActivity(intent); - return(true); + return true; } }); @@@ -367,10 -323,9 +368,10 @@@ 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); @@@ -409,29 -364,7 +410,29 @@@ } } - 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() { @@@ -451,7 -384,7 +452,7 @@@ 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()); @@@ -461,6 -394,9 +462,9 @@@ @Override public boolean onPreferenceChange(Preference preference, Object newValue) { toggleInstantPictureOptions((Boolean) newValue); + toggleInstantUploadBehaviour( + ((CheckBoxPreference)mPrefInstantVideoUpload).isChecked(), + (Boolean) newValue); return true; } }); @@@ -488,30 -424,30 +492,38 @@@ toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked()); mPrefInstantVideoUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - + @Override public boolean onPreferenceChange(Preference preference, Object newValue) { toggleInstantVideoOptions((Boolean) newValue); + toggleInstantUploadBehaviour( + (Boolean) newValue, + ((CheckBoxPreference) mPrefInstantUpload).isChecked()); return true; } }); - + + mPrefInstantUploadBehaviour = findPreference("prefs_instant_behaviour"); + toggleInstantUploadBehaviour( + ((CheckBoxPreference)mPrefInstantVideoUpload).isChecked(), + ((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))); - pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion)); + pAboutApp.setTitle(String.format(getString(R.string.about_android), + getString(R.string.app_name))); + try { + Integer currentVersion = getPackageManager().getPackageInfo + (getPackageName(), 0).versionCode; + pAboutApp.setSummary(String.format(getString(R.string.about_version), + currentVersion)); + } catch (NameNotFoundException e) { + } } loadInstantUploadPath(); + loadStoragePath(); loadInstantUploadVideoPath(); /* ComponentsGetter */ @@@ -526,65 -462,6 +538,65 @@@ Context.BIND_AUTO_CREATE); } + /* Link to Beta apks */ + Preference pBetaLink = findPreference("beta_link"); + if (pBetaLink != null ){ + pBetaLink.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Integer latestVersion = -1; + Integer currentVersion = -1; + try { + currentVersion = getPackageManager().getPackageInfo + (getPackageName(), 0).versionCode; + LoadingVersionNumberTask loadTask = new LoadingVersionNumberTask(); + loadTask.execute(); + latestVersion = loadTask.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } catch (NameNotFoundException e) { + e.printStackTrace(); + } + if (latestVersion == -1 || currentVersion == -1) { + Toast.makeText(getApplicationContext(), "No information available!", + Toast.LENGTH_SHORT).show(); + } + if (latestVersion > currentVersion) { + String betaLinkWeb = (String) getText(R.string.beta_link) + + latestVersion + ".apk"; + if (betaLinkWeb != null && betaLinkWeb.length() > 0) { + Uri uriUrl = Uri.parse(betaLinkWeb); + Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl); + startActivity(intent); + return true; + } + } else { + Toast.makeText(getApplicationContext(), "No new version available!", + Toast.LENGTH_SHORT).show(); + return true; + } + return true; + } + }); + } + + /* Link to Beta apks */ + Preference pChangelogLink = findPreference("changelog_link"); + if (pChangelogLink != null) { + pChangelogLink.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + String betaLinkWeb = getString(R.string.changelog); + if (betaLinkWeb != null && betaLinkWeb.length() > 0) { + Uri uriUrl = Uri.parse(betaLinkWeb); + Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl); + startActivity(intent); + return true; + } + return true; + } + }); + } } private void toggleInstantPictureOptions(Boolean value){ @@@ -592,8 -469,8 +604,8 @@@ mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPathWiFi); mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPath); } else { - mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi); - mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath); +// mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi); +// mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath); } } @@@ -602,11 -479,19 +614,19 @@@ mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPathWiFi); mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPath); } else { - mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi); - mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath); +// mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi); +// mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath); } } + private void toggleInstantUploadBehaviour(Boolean video, Boolean picture){ + if (picture || video){ + mPrefInstantUploadCategory.addPreference(mPrefInstantUploadBehaviour); + } else { + mPrefInstantUploadCategory.removePreference(mPrefInstantUploadBehaviour); + } + } + @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { @@@ -689,7 -574,8 +709,7 @@@ 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(); @@@ -700,9 -586,10 +720,9 @@@ 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(); @@@ -712,44 -599,6 +732,44 @@@ 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); + } else if (requestCode == ACTION_REQUEST_PASSCODE && resultCode == RESULT_OK) { + String passcode = data.getStringExtra(PassCodeActivity.KEY_PASSCODE); + if (passcode != null && passcode.length() == 4) { + SharedPreferences.Editor appPrefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()).edit(); + + for (int i = 1; i <= 4; ++i) { + appPrefs.putString("PrefPinCode" + i, passcode.substring(i-1, i)); + } + appPrefs.putBoolean("set_pincode", true); + appPrefs.commit(); + Toast.makeText(this, R.string.pass_code_stored, Toast.LENGTH_LONG).show(); + } + } else if (requestCode == ACTION_CONFIRM_PASSCODE && resultCode == RESULT_OK) { + if (data.getBooleanExtra(PassCodeActivity.KEY_CHECK_RESULT, false)) { + + SharedPreferences.Editor appPrefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()).edit(); + appPrefs.putBoolean("set_pincode", false); + appPrefs.commit(); + + Toast.makeText(this, R.string.pass_code_removed, Toast.LENGTH_LONG).show(); + } } } @@@ -774,7 -623,6 +794,7 @@@ public void setContentView(View view) { getDelegate().setContentView(view); } + @Override public void setContentView(View view, ViewGroup.LayoutParams params) { getDelegate().setContentView(view, params); @@@ -960,31 -808,6 +980,31 @@@ } /** + * 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() { @@@ -999,7 -822,10 +1019,7 @@@ * 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()); } /** @@@ -1013,7 -839,7 +1033,7 @@@ editor.commit(); } - // Methods for ComponetsGetter + // Methods for ComponentsGetter @Override public FileDownloader.FileDownloaderBinder getFileDownloaderBinder() { return mDownloaderBinder; @@@ -1052,10 -878,14 +1072,10 @@@ 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 @@@ -1069,29 -899,4 +1089,29 @@@ } } }; + + /** + * + * Class for loading the version number + * + */ + private class LoadingVersionNumberTask extends AsyncTask { + protected Integer doInBackground(Void... args) { + try { + URL url = new URL("https://github.com/owncloud/android/raw/beta/apks/latest"); + BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); + + Integer latestVersion = Integer.parseInt(in.readLine()); + in.close(); + + return latestVersion; + + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return -1; + } + } } diff --combined tests/project.properties index 00cf62ba,00cf62ba..916037e3 --- a/tests/project.properties +++ b/tests/project.properties @@@ -11,4 -11,4 +11,4 @@@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. --target=android-22 ++target=android-23