mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
Merge pull request #658 from owncloud/instant_upload_path_chooseable
Instant upload path chooseable
This commit is contained in:
commit
6ed394195d
6 changed files with 148 additions and 52 deletions
25
.travis.yml
25
.travis.yml
|
@ -1,15 +1,20 @@
|
|||
language: java
|
||||
language: android
|
||||
android:
|
||||
components:
|
||||
- build-tools-20.0.0
|
||||
- android-19
|
||||
- android-17
|
||||
- android-14
|
||||
- extra-android-support
|
||||
licenses:
|
||||
- 'android-sdk-license-5be876d5'
|
||||
- 'android-sdk-license-598b93a6'
|
||||
|
||||
jdk: oraclejdk7
|
||||
|
||||
before_install:
|
||||
# Install base Android SDK
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq libstdc++6:i386 lib32z1 expect
|
||||
- export COMPONENTS="build-tools-20.0.0,android-14,android-17,android-19,sysimg-19,extra-android-support"
|
||||
- export LICENSES="android-sdk-license-5be876d5|android-sdk-license-598b93a6"
|
||||
- curl -3L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS --accept=$LICENSES
|
||||
- source ~/.android-sdk-installer/env
|
||||
- rm pom.xml
|
||||
- ./setup_env.sh
|
||||
- rm pom.xml
|
||||
- ./setup_env.sh
|
||||
|
||||
script:
|
||||
- ant clean
|
||||
|
|
|
@ -251,6 +251,7 @@
|
|||
<string name="preview_image_error_unknown_format">This image cannot be shown</string>
|
||||
|
||||
<string name="error__upload__local_file_not_copied">%1$s could not be copied to %2$s local folder</string>
|
||||
<string name="prefs_instant_upload_path_title">Upload Path</string>
|
||||
|
||||
<string name="share_link_no_support_share_api">Sorry, sharing is not enabled on your server. Please contact your
|
||||
administrator.</string>
|
||||
|
@ -302,4 +303,7 @@
|
|||
<string name="move_file_error">An error occurred while trying to move this file or folder</string>
|
||||
<string name="forbidden_permissions_move">to move this file</string>
|
||||
|
||||
<string name="prefs_category_instant_uploading">Instant Uploads</string>
|
||||
<string name="prefs_category_security">Security</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -21,35 +21,41 @@
|
|||
<PreferenceCategory android:title="@string/prefs_category_accounts" android:key="accounts_category">
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/prefs_category_general">
|
||||
<!-- ListPreference
|
||||
android:key="select_oc_account"
|
||||
android:title="@string/prefs_select_oc_account"
|
||||
android:summary="@string/prefs_summary_select_oc_account"
|
||||
/ -->
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:title="@string/prefs_pincode" android:key="set_pincode"
|
||||
<PreferenceCategory android:title="@string/prefs_category_security">
|
||||
<!-- ListPreference
|
||||
android:key="select_oc_account"
|
||||
android:title="@string/prefs_select_oc_account"
|
||||
android:summary="@string/prefs_summary_select_oc_account"
|
||||
/ -->
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:title="@string/prefs_pincode" android:key="set_pincode"
|
||||
android:summary="@string/prefs_pincode_summary"/>
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
|
||||
android:title="@string/prefs_instant_upload"
|
||||
android:summary="@string/prefs_instant_upload_summary"/>
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_uploading"
|
||||
android:disableDependentsState="true"
|
||||
android:title="@string/instant_upload_on_wifi"
|
||||
android:key="instant_upload_on_wifi"/>
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_video_uploading"
|
||||
android:title="@string/prefs_instant_video_upload"
|
||||
android:summary="@string/prefs_instant_video_upload_summary"/>
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_video_uploading"
|
||||
android:disableDependentsState="true"
|
||||
android:title="@string/instant_video_upload_on_wifi"
|
||||
android:key="instant_video_upload_on_wifi"/>
|
||||
<!-- DISABLED FOR RELEASE UNTIL FIXED
|
||||
CheckBoxPreference android:key="log_to_file"
|
||||
android:title="@string/prefs_log_title"
|
||||
android:summary="@string/prefs_log_summary"/>
|
||||
<Preference android:key="log_history"
|
||||
android:title="@string/prefs_log_title_history"
|
||||
android:summary="@string/prefs_log_summary_history"/ -->
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/prefs_category_instant_uploading">
|
||||
<EditTextPreference android:title="@string/prefs_instant_upload_path_title"
|
||||
android:defaultValue="@string/instant_upload_path"
|
||||
android:key="instant_upload_path"/>
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
|
||||
android:title="@string/prefs_instant_upload"
|
||||
android:summary="@string/prefs_instant_upload_summary"/>
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_uploading"
|
||||
android:disableDependentsState="true"
|
||||
android:title="@string/instant_upload_on_wifi"
|
||||
android:key="instant_upload_on_wifi"/>
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_video_uploading"
|
||||
android:title="@string/prefs_instant_video_upload"
|
||||
android:summary="@string/prefs_instant_video_upload_summary"/>
|
||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_video_uploading"
|
||||
android:disableDependentsState="true"
|
||||
android:title="@string/instant_video_upload_on_wifi"
|
||||
android:key="instant_video_upload_on_wifi"/>
|
||||
<!-- DISABLED FOR RELEASE UNTIL FIXED
|
||||
CheckBoxPreference android:key="log_to_file"
|
||||
android:title="@string/prefs_log_title"
|
||||
android:summary="@string/prefs_log_summary"/>
|
||||
<Preference android:key="log_history"
|
||||
android:title="@string/prefs_log_title_history"
|
||||
android:summary="@string/prefs_log_summary_history"/ -->
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
@ -65,4 +71,4 @@
|
|||
</PreferenceCategory>
|
||||
|
||||
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
|
|
|
@ -84,21 +84,36 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save new directory in local database
|
||||
*/
|
||||
public void saveFolderInDB() {
|
||||
OCFile newDir = new OCFile(mRemotePath);
|
||||
newDir.setMimetype("DIR");
|
||||
long parentId = getStorageManager().getFileByPath(FileStorageUtils.getParentPath(mRemotePath)).getFileId();
|
||||
newDir.setParentId(parentId);
|
||||
newDir.setModificationTimestamp(System.currentTimeMillis());
|
||||
getStorageManager().saveFile(newDir);
|
||||
if (mCreateFullPath && getStorageManager().
|
||||
getFileByPath(FileStorageUtils.getParentPath(mRemotePath)) == null){// When parent
|
||||
// of remote path
|
||||
// is not created
|
||||
String[] subFolders = mRemotePath.split("/");
|
||||
String composedRemotePath = "/";
|
||||
|
||||
Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database");
|
||||
// For each antecesor folders create them recursively
|
||||
for (int i=0; i<subFolders.length; i++) {
|
||||
String subFolder = subFolders[i];
|
||||
if (!subFolder.isEmpty()) {
|
||||
composedRemotePath = composedRemotePath + subFolder + "/";
|
||||
mRemotePath = composedRemotePath;
|
||||
saveFolderInDB();
|
||||
}
|
||||
}
|
||||
} else { // Create directory on DB
|
||||
OCFile newDir = new OCFile(mRemotePath);
|
||||
newDir.setMimetype("DIR");
|
||||
long parentId = getStorageManager().
|
||||
getFileByPath(FileStorageUtils.getParentPath(mRemotePath)).getFileId();
|
||||
newDir.setParentId(parentId);
|
||||
newDir.setModificationTimestamp(System.currentTimeMillis());
|
||||
getStorageManager().saveFile(newDir);
|
||||
|
||||
Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
|
|||
private final Handler mHandler = new Handler();
|
||||
private String mAccountName;
|
||||
private boolean mShowContextMenu = false;
|
||||
private String mUploadPath;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -87,7 +88,9 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
|
|||
actionBar.setIcon(DisplayUtils.getSeasonalIconId());
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setTitle(R.string.actionbar_settings);
|
||||
|
||||
|
||||
loadInstantUploadPath();
|
||||
|
||||
// Load the accounts category for adding the list of accounts
|
||||
mAccountsPrefCategory = (PreferenceCategory) findPreference("accounts_category");
|
||||
|
||||
|
@ -239,6 +242,16 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
|
|||
preferenceCategory.removePreference(pImprint);
|
||||
}
|
||||
}
|
||||
|
||||
Preference pInstantUploadPathApp = (Preference) findPreference("instant_upload_path");
|
||||
|
||||
pInstantUploadPathApp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
mUploadPath = updateInstantUploadPath(newValue.toString());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
/* About App */
|
||||
pAboutApp = (Preference) findPreference("about_app");
|
||||
|
@ -254,6 +267,12 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
saveInstantUploadPathOnPreferences();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
|
||||
|
@ -462,4 +481,47 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the upload path checking that it is a correct path
|
||||
* @param uploadPath: path write by user
|
||||
* @return String: uploadPath
|
||||
*/
|
||||
private String updateInstantUploadPath(String uploadPath) {
|
||||
String slashString = "/";
|
||||
|
||||
// If slashes are duplicated, replace them for only one slash
|
||||
uploadPath = uploadPath.replaceAll("/+", slashString);
|
||||
|
||||
// Remove last slash from path
|
||||
if (uploadPath.length() > 0 && uploadPath.charAt(uploadPath.length()-1) == slashString.charAt(0)) {
|
||||
uploadPath = uploadPath.substring(0, uploadPath.length()-1);
|
||||
}
|
||||
|
||||
if (uploadPath.isEmpty()) { // Set default instant upload path
|
||||
uploadPath = getString(R.string.instant_upload_path);
|
||||
}else {
|
||||
if (!uploadPath.startsWith(slashString)) { // Add initial slash on path if necessary
|
||||
uploadPath = slashString.concat(uploadPath);
|
||||
}
|
||||
}
|
||||
return uploadPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load upload path set on preferences
|
||||
*/
|
||||
private void loadInstantUploadPath() {
|
||||
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
mUploadPath = appPrefs.getString("instant_upload_path", getString(R.string.instant_upload_path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the "Instant Upload Path" on preferences
|
||||
*/
|
||||
private void saveInstantUploadPathOnPreferences() {
|
||||
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
SharedPreferences.Editor editor = appPrefs.edit();
|
||||
editor.putString("instant_upload_path", mUploadPath);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ import com.owncloud.android.lib.resources.files.RemoteFile;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.os.StatFs;
|
||||
|
@ -73,7 +75,9 @@ public class FileStorageUtils {
|
|||
}
|
||||
|
||||
public static String getInstantUploadFilePath(Context context, String fileName) {
|
||||
String uploadPath = context.getString(R.string.instant_upload_path);
|
||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String uploadPathdef = context.getString(R.string.instant_upload_path);
|
||||
String uploadPath = pref.getString("instant_upload_path", uploadPathdef);
|
||||
String value = uploadPath + OCFile.PATH_SEPARATOR + (fileName == null ? "" : fileName);
|
||||
return value;
|
||||
}
|
||||
|
@ -120,4 +124,4 @@ public class FileStorageUtils {
|
|||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue