mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
implement the same for videos and do some code cleanup
This commit is contained in:
parent
89ae5bfe1a
commit
3c388ad120
5 changed files with 50 additions and 15 deletions
|
@ -41,6 +41,10 @@
|
||||||
<com.owncloud.android.ui.PreferenceWithLongSummary
|
<com.owncloud.android.ui.PreferenceWithLongSummary
|
||||||
android:title="@string/prefs_instant_video_upload_path_title"
|
android:title="@string/prefs_instant_video_upload_path_title"
|
||||||
android:key="instant_video_upload_path" />
|
android:key="instant_video_upload_path" />
|
||||||
|
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
|
||||||
|
android:title="@string/prefs_instant_upload_path_use_subfolders_title"
|
||||||
|
android:summary="@string/prefs_instant_upload_path_use_subfolders_summary"
|
||||||
|
android:key="instant_video_upload_path_use_subfolders" />
|
||||||
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
|
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
|
||||||
android:title="@string/instant_video_upload_on_wifi"
|
android:title="@string/instant_video_upload_on_wifi"
|
||||||
android:key="instant_video_upload_on_wifi"/>
|
android:key="instant_video_upload_on_wifi"/>
|
||||||
|
|
|
@ -40,6 +40,7 @@ public abstract class PreferenceManager {
|
||||||
private static final String PREF__INSTANT_UPLOAD_PATH_USE_SUBFOLDERS = "instant_upload_path_use_subfolders";
|
private static final String PREF__INSTANT_UPLOAD_PATH_USE_SUBFOLDERS = "instant_upload_path_use_subfolders";
|
||||||
private static final String PREF__INSTANT_UPLOAD_ON_WIFI = "instant_upload_on_wifi";
|
private static final String PREF__INSTANT_UPLOAD_ON_WIFI = "instant_upload_on_wifi";
|
||||||
private static final String PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI = "instant_video_upload_on_wifi";
|
private static final String PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI = "instant_video_upload_on_wifi";
|
||||||
|
private static final String PREF__INSTANT_VIDEO_UPLOAD_PATH_USE_SUBFOLDERS = "instant_video_upload_path_use_subfolders";
|
||||||
|
|
||||||
public static boolean instantPictureUploadEnabled(Context context) {
|
public static boolean instantPictureUploadEnabled(Context context) {
|
||||||
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOADING, false);
|
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOADING, false);
|
||||||
|
@ -57,6 +58,10 @@ public abstract class PreferenceManager {
|
||||||
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOAD_ON_WIFI, false);
|
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOAD_ON_WIFI, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean instantVideoUploadPathUseSubfolders(Context context) {
|
||||||
|
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOAD_PATH_USE_SUBFOLDERS, false);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean instantVideoUploadViaWiFiOnly(Context context) {
|
public static boolean instantVideoUploadViaWiFiOnly(Context context) {
|
||||||
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI, false);
|
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
|
||||||
String file_path = null;
|
String file_path = null;
|
||||||
String file_name = null;
|
String file_name = null;
|
||||||
String mime_type = null;
|
String mime_type = null;
|
||||||
|
long date_taken = 0;
|
||||||
|
|
||||||
Log_OC.i(TAG, "New video received");
|
Log_OC.i(TAG, "New video received");
|
||||||
|
|
||||||
|
@ -188,6 +189,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
|
||||||
file_name = c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));
|
file_name = c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));
|
||||||
mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE));
|
mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE));
|
||||||
c.close();
|
c.close();
|
||||||
|
date_taken = System.currentTimeMillis();
|
||||||
Log_OC.d(TAG, file_path + "");
|
Log_OC.d(TAG, file_path + "");
|
||||||
|
|
||||||
int behaviour = getUploadBehaviour(context);
|
int behaviour = getUploadBehaviour(context);
|
||||||
|
@ -196,7 +198,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
|
||||||
context,
|
context,
|
||||||
account,
|
account,
|
||||||
file_path,
|
file_path,
|
||||||
FileStorageUtils.getInstantVideoUploadFilePath(context, file_name),
|
FileStorageUtils.getInstantVideoUploadFilePath(context, file_name, date_taken),
|
||||||
behaviour,
|
behaviour,
|
||||||
mime_type,
|
mime_type,
|
||||||
true, // create parent folder if not existent
|
true, // create parent folder if not existent
|
||||||
|
|
|
@ -114,6 +114,7 @@ public class Preferences extends PreferenceActivity
|
||||||
private Preference mPrefInstantUploadPathWiFi;
|
private Preference mPrefInstantUploadPathWiFi;
|
||||||
private Preference mPrefInstantVideoUpload;
|
private Preference mPrefInstantVideoUpload;
|
||||||
private Preference mPrefInstantVideoUploadPath;
|
private Preference mPrefInstantVideoUploadPath;
|
||||||
|
private Preference mPrefInstantVideoUploadUseSubfolders;
|
||||||
private Preference mPrefInstantVideoUploadPathWiFi;
|
private Preference mPrefInstantVideoUploadPathWiFi;
|
||||||
private String mUploadVideoPath;
|
private String mUploadVideoPath;
|
||||||
|
|
||||||
|
@ -429,6 +430,7 @@ public class Preferences extends PreferenceActivity
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mPrefInstantVideoUploadUseSubfolders = findPreference("instant_video_upload_path_use_subfolders");
|
||||||
mPrefInstantVideoUploadPathWiFi = findPreference("instant_video_upload_on_wifi");
|
mPrefInstantVideoUploadPathWiFi = findPreference("instant_video_upload_on_wifi");
|
||||||
mPrefInstantVideoUpload = findPreference("instant_video_uploading");
|
mPrefInstantVideoUpload = findPreference("instant_video_uploading");
|
||||||
toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked());
|
toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked());
|
||||||
|
@ -491,9 +493,11 @@ public class Preferences extends PreferenceActivity
|
||||||
if (value){
|
if (value){
|
||||||
mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPathWiFi);
|
mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPathWiFi);
|
||||||
mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPath);
|
mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPath);
|
||||||
|
mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadUseSubfolders);
|
||||||
} else {
|
} else {
|
||||||
mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi);
|
mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi);
|
||||||
mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath);
|
mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath);
|
||||||
|
mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadUseSubfolders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,27 @@ public class FileStorageUtils {
|
||||||
return Environment.getExternalStorageDirectory() + File.separator + MainApp.getDataFolder() + File.separator + "log";
|
return Environment.getExternalStorageDirectory() + File.separator + MainApp.getDataFolder() + File.separator + "log";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the a string like 2016/08/ for the passed date. If date is 0 an empty
|
||||||
|
* string is returned
|
||||||
|
*
|
||||||
|
* @param date: date in microseconds since 1st January 1970
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String getSubpathFromDate(long date) {
|
||||||
|
try {
|
||||||
|
if(date == 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat(
|
||||||
|
"yyyy" + OCFile.PATH_SEPARATOR + "MM" + OCFile.PATH_SEPARATOR, Locale.ENGLISH);
|
||||||
|
return formatter.format(new Date(date));
|
||||||
|
}
|
||||||
|
catch(RuntimeException ex) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the InstantUploadFilePath on the owncloud instance
|
* Returns the InstantUploadFilePath on the owncloud instance
|
||||||
*
|
*
|
||||||
|
@ -132,18 +153,12 @@ public class FileStorageUtils {
|
||||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
String uploadPathdef = context.getString(R.string.instant_upload_path);
|
String uploadPathdef = context.getString(R.string.instant_upload_path);
|
||||||
String uploadPath = pref.getString("instant_upload_path", uploadPathdef);
|
String uploadPath = pref.getString("instant_upload_path", uploadPathdef);
|
||||||
String subFolders = null;
|
String subPath = "";
|
||||||
if(dateTaken != 0 && com.owncloud.android.db.PreferenceManager.instantPictureUploadPathUseSubfolders(context)) {
|
if(com.owncloud.android.db.PreferenceManager.instantPictureUploadPathUseSubfolders(context)) {
|
||||||
try {
|
subPath = getSubpathFromDate(dateTaken);
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy" + OCFile.PATH_SEPARATOR + "MM" + OCFile.PATH_SEPARATOR, Locale.ENGLISH);
|
|
||||||
subFolders = formatter.format(new Date(dateTaken));
|
|
||||||
Date d = new Date(dateTaken);
|
|
||||||
}
|
}
|
||||||
catch(RuntimeException ex) {
|
String value = uploadPath + OCFile.PATH_SEPARATOR + subPath
|
||||||
// don´t use a subfolder if we can´t parse the date
|
+ (fileName == null ? "" : fileName);
|
||||||
}
|
|
||||||
}
|
|
||||||
String value = uploadPath + OCFile.PATH_SEPARATOR + (subFolders != null ? subFolders : "") + (fileName == null ? "" : fileName);
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,11 +168,16 @@ public class FileStorageUtils {
|
||||||
* @param fileName: video file name
|
* @param fileName: video file name
|
||||||
* @return String: video file path composed
|
* @return String: video file path composed
|
||||||
*/
|
*/
|
||||||
public static String getInstantVideoUploadFilePath(Context context, String fileName) {
|
public static String getInstantVideoUploadFilePath(Context context, String fileName, long dateTaken) {
|
||||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
String uploadVideoPathdef = context.getString(R.string.instant_upload_path);
|
String uploadVideoPathdef = context.getString(R.string.instant_upload_path);
|
||||||
String uploadVideoPath = pref.getString("instant_video_upload_path", uploadVideoPathdef);
|
String uploadVideoPath = pref.getString("instant_video_upload_path", uploadVideoPathdef);
|
||||||
String value = uploadVideoPath + OCFile.PATH_SEPARATOR + (fileName == null ? "" : fileName);
|
String subPath = "";
|
||||||
|
if(com.owncloud.android.db.PreferenceManager.instantVideoUploadPathUseSubfolders(context)) {
|
||||||
|
subPath = getSubpathFromDate(dateTaken);
|
||||||
|
}
|
||||||
|
String value = uploadVideoPath + OCFile.PATH_SEPARATOR + subPath
|
||||||
|
+ (fileName == null ? "" : fileName);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue