-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Feature uploadsubfolders #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f68b53b
bd8ab10
89ae5bf
3c388ad
e231caa
23e1071
7f02bb0
f85cf5d
6401731
bed4644
9b4a4d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,9 +25,13 @@ | |
| <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.PreferenceWithLongSummary | ||
| <com.owncloud.android.ui.PreferenceWithLongSummary | ||
| android:title="@string/prefs_instant_upload_path_title" | ||
| android:key="instant_upload_path" /> | ||
| <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle | ||
| android:title="@string/prefs_instant_upload_path_use_subfolders_title" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please only lines with 80 chars, this makes review on github a lot easier.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tobiasKaminsky 120 is fine with me ;) Since this is still enough for the files changed tab :D So I would vote to go for 120 line length. @przybylski
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Longer line would be great I would vote to stick to how android code is written, which is 100 lines.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tobiasKaminsky what do you think? I am with @przybylski on this, so I also vote for 100 💯
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 100 is also fine for me. I do not know who said 80 back on owncloud, but if 100 is still visible in changes tab on github everything is fine.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I introduced 80 chars limit. I don't recall why :D
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Github would also work with 120, not sure though... |
||
| android:summary="@string/prefs_instant_upload_path_use_subfolders_summary" | ||
| android:key="instant_upload_path_use_subfolders" /> | ||
| <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle | ||
| android:title="@string/instant_upload_on_wifi" | ||
| android:key="instant_upload_on_wifi"/> | ||
|
|
@@ -37,6 +41,10 @@ | |
| <com.owncloud.android.ui.PreferenceWithLongSummary | ||
| android:title="@string/prefs_instant_video_upload_path_title" | ||
| 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 | ||
| android:title="@string/instant_video_upload_on_wifi" | ||
| android:key="instant_video_upload_on_wifi"/> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,7 @@ private void handleNewPictureAction(Context context, Intent intent) { | |
| String file_path = null; | ||
| String file_name = null; | ||
| String mime_type = null; | ||
| long date_taken = 0; | ||
|
|
||
| Log_OC.i(TAG, "New photo received"); | ||
|
|
||
|
|
@@ -116,6 +117,7 @@ private void handleNewPictureAction(Context context, Intent intent) { | |
| file_path = c.getString(c.getColumnIndex(Images.Media.DATA)); | ||
| file_name = c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME)); | ||
| mime_type = c.getString(c.getColumnIndex(Images.Media.MIME_TYPE)); | ||
| date_taken = System.currentTimeMillis(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you separate declaration and initialization?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cause it´s done like that in the code above it, and i don´t want to break the codeflow for better readability
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO declarasion should be also initialization. I would even fix wrong other stuff. @AndyScherzinger @tobiasKaminsky you agree?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would leave it like that until we are done with most of the open PRs and then open refactoring tasks |
||
| c.close(); | ||
|
|
||
| if (file_path.equals(lastUploadedPhotoPath)) { | ||
|
|
@@ -134,7 +136,7 @@ private void handleNewPictureAction(Context context, Intent intent) { | |
| context, | ||
| account, | ||
| file_path, | ||
| FileStorageUtils.getInstantUploadFilePath(context, file_name), | ||
| FileStorageUtils.getInstantUploadFilePath(context, file_name, date_taken), | ||
| behaviour, | ||
| mime_type, | ||
| true, // create parent folder if not existent | ||
|
|
@@ -161,6 +163,7 @@ private void handleNewVideoAction(Context context, Intent intent) { | |
| String file_path = null; | ||
| String file_name = null; | ||
| String mime_type = null; | ||
| long date_taken = 0; | ||
|
|
||
| Log_OC.i(TAG, "New video received"); | ||
|
|
||
|
|
@@ -186,6 +189,7 @@ private void handleNewVideoAction(Context context, Intent intent) { | |
| file_name = c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME)); | ||
| mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE)); | ||
| c.close(); | ||
| date_taken = System.currentTimeMillis(); | ||
| Log_OC.d(TAG, file_path + ""); | ||
|
|
||
| int behaviour = getUploadBehaviour(context); | ||
|
|
@@ -194,7 +198,7 @@ private void handleNewVideoAction(Context context, Intent intent) { | |
| context, | ||
| account, | ||
| file_path, | ||
| FileStorageUtils.getInstantVideoUploadFilePath(context, file_name), | ||
| FileStorageUtils.getInstantVideoUploadFilePath(context, file_name, date_taken), | ||
| behaviour, | ||
| mime_type, | ||
| true, // create parent folder if not existent | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,15 +21,19 @@ | |
| package com.owncloud.android.utils; | ||
|
|
||
| import java.io.File; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.Date; | ||
| import java.util.Locale; | ||
| import java.util.Vector; | ||
|
|
||
| import third_parties.daveKoeller.AlphanumComparator; | ||
|
|
||
| import com.owncloud.android.MainApp; | ||
| import com.owncloud.android.R; | ||
| import com.owncloud.android.datamodel.OCFile; | ||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||
| import com.owncloud.android.lib.resources.files.RemoteFile; | ||
|
|
||
| import android.accounts.Account; | ||
|
|
@@ -47,6 +51,8 @@ | |
| * Static methods to help in access to local file system. | ||
| */ | ||
| public class FileStorageUtils { | ||
| private static final String TAG = FileStorageUtils.class.getSimpleName(); | ||
|
|
||
| public static final Integer SORT_NAME = 0; | ||
| public static final Integer SORT_DATE = 1; | ||
| public static final Integer SORT_SIZE = 2; | ||
|
|
@@ -117,12 +123,46 @@ public static final String getLogPath() { | |
| return Environment.getExternalStorageDirectory() + File.separator + MainApp.getDataFolder() + File.separator + "log"; | ||
| } | ||
|
|
||
| public static String getInstantUploadFilePath(Context context, String fileName) { | ||
| /** | ||
| * 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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that passing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I introduced the parameter, i might later on want to upload existing photos (upload all media on the device, which hasn´t been uploaded already). This would require us to read the timestamp from the pictures and use this timestamp for folderpath. Thats why i made it into a parameter on the method. |
||
| if (date == 0) { | ||
| return ""; | ||
| } | ||
| try { | ||
| SimpleDateFormat formatter = new SimpleDateFormat( | ||
| "yyyy" + OCFile.PATH_SEPARATOR + "MM" + OCFile.PATH_SEPARATOR, Locale.ENGLISH); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO it should be Locale.getDefault() |
||
| return formatter.format(new Date(date)); | ||
| } | ||
| catch(RuntimeException ex) { | ||
| Log_OC.w(TAG, "could not extract date from timestamp"); | ||
| return ""; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please log what went wrong |
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the InstantUploadFilePath on the owncloud instance | ||
| * | ||
| * @param context | ||
| * @param fileName | ||
| * @param dateTaken: Time in milliseconds since 1970 when the picture was taken. | ||
| * @return | ||
| */ | ||
| public static String getInstantUploadFilePath(Context context, String fileName, long dateTaken) { | ||
| 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; | ||
| String subPath = ""; | ||
| if (com.owncloud.android.db.PreferenceManager.instantPictureUploadPathUseSubfolders(context)) { | ||
| subPath = getSubpathFromDate(dateTaken); | ||
| } | ||
| return uploadPath + OCFile.PATH_SEPARATOR + subPath | ||
| + (fileName == null ? "" : fileName); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -131,12 +171,16 @@ public static String getInstantUploadFilePath(Context context, String fileName) | |
| * @param fileName: video file name | ||
| * @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); | ||
| String uploadVideoPathdef = context.getString(R.string.instant_upload_path); | ||
| String uploadVideoPath = pref.getString("instant_video_upload_path", uploadVideoPathdef); | ||
| String value = uploadVideoPath + OCFile.PATH_SEPARATOR + (fileName == null ? "" : fileName); | ||
| return value; | ||
| String subPath = ""; | ||
| if (com.owncloud.android.db.PreferenceManager.instantVideoUploadPathUseSubfolders(context)) { | ||
| subPath = getSubpathFromDate(dateTaken); | ||
| } | ||
| return uploadVideoPath + OCFile.PATH_SEPARATOR + subPath | ||
| + (fileName == null ? "" : fileName); | ||
| } | ||
|
|
||
| public static String getParentPath(String remotePath) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
year & month: plural or singular ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both, as year and month refers to a single subfolder, but multiple subfolders are created.