Merge pull request #685 from tobiasKaminsky/beautifyTimestamps
authorDavid A. Velasco <dvelasco@owncloud.com>
Thu, 13 Nov 2014 11:21:49 +0000 (12:21 +0100)
committerDavid A. Velasco <dvelasco@owncloud.com>
Thu, 13 Nov 2014 11:21:49 +0000 (12:21 +0100)
Relative time stamps in the list of files.

owncloud-android-library
res/values/strings.xml
src/com/owncloud/android/ui/adapter/FileListListAdapter.java
src/com/owncloud/android/utils/DisplayUtils.java

index 4f315c7..5bd0d73 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 4f315c7e06f6eef48df246be0ee9252fdfccdf00
+Subproject commit 5bd0d7387712ce3f53869294761ac4d8537841cd
index 2655e29..d8f1e93 100644 (file)
@@ -62,6 +62,7 @@
     <string name="uploader_wrn_no_content_text">No content was received. Nothing to upload.</string>
     <string name="uploader_error_forbidden_content">%1$s is not allowed to access the shared content</string>
     <string name="uploader_info_uploading">Uploading</string>
+    <string name="file_list_seconds_ago">seconds ago</string>
     <string name="file_list_empty">Nothing in here. Upload something!</string>
     <string name="file_list_loading">Loading...</string>
     <string name="local_file_list_empty">There are no files in this folder.</string>
index e002efb..1035632 100644 (file)
@@ -29,6 +29,7 @@ import android.content.Context;
 import android.content.SharedPreferences;\r
 import android.graphics.Bitmap;\r
 import android.preference.PreferenceManager;\r
+import android.text.format.DateUtils;\r
 import android.view.LayoutInflater;\r
 import android.view.View;\r
 import android.view.ViewGroup;\r
@@ -46,6 +47,7 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable;\r
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
+import com.owncloud.android.lib.common.utils.Log_OC;\r
 import com.owncloud.android.ui.activity.ComponentsGetter;\r
 import com.owncloud.android.utils.DisplayUtils;\r
 import com.owncloud.android.utils.FileStorageUtils;\r
@@ -183,9 +185,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                 fileSizeV.setVisibility(View.VISIBLE);\r
                 fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));\r
                 lastModV.setVisibility(View.VISIBLE);\r
-                lastModV.setText(\r
-                        DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp())\r
-                );\r
+                lastModV.setText(showRelativeTimestamp(file));\r
                 // this if-else is needed even thoe fav icon is visible by default\r
                 // because android reuses views in listview\r
                 if (!file.keepInSync()) {\r
@@ -253,9 +253,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
 //                }\r
 
                 lastModV.setVisibility(View.VISIBLE);\r
-                lastModV.setText(\r
-                        DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp())\r
-                );\r
+                lastModV.setText(showRelativeTimestamp(file));\r
                 checkBoxV.setVisibility(View.GONE);\r
                 view.findViewById(R.id.imageView3).setVisibility(View.GONE);\r
 \r
@@ -517,5 +515,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
         mSortAscending = ascending;\r
         \r
         sortDirectory();\r
-    }    
+    }    \r
+    \r
+    private CharSequence showRelativeTimestamp(OCFile file){\r
+        return DisplayUtils.getRelativeDateTimeString(mContext, file.getModificationTimestamp(),\r
+                DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0);\r
+    }
 }\r
index 804a4dd..d8bf88f 100644 (file)
@@ -27,7 +27,10 @@ import java.util.HashSet;
 import java.util.Set;\r
 \r
 import android.annotation.TargetApi;\r
+import android.content.Context;\r
 import android.os.Build;\r
+import android.text.format.DateFormat;\r
+import android.text.format.DateUtils;\r
 \r
 import com.owncloud.android.MainApp;\r
 import com.owncloud.android.R;\r
@@ -274,4 +277,30 @@ public class DisplayUtils {
             return url;\r
         }\r
     }\r
+    \r
+    public static CharSequence getRelativeDateTimeString(Context c, long time, long minResolution, long transitionResolution, int flags){\r
+        CharSequence dateString = "";\r
+        \r
+        // in Future\r
+        if (time > System.currentTimeMillis()){\r
+            return DisplayUtils.unixTimeToHumanReadable(time);\r
+        } \r
+        // < 60 seconds -> seconds ago\r
+        else if ((System.currentTimeMillis() - time) < 60 * 1000) {\r
+            return c.getString(R.string.file_list_seconds_ago);\r
+        } else {\r
+            // Workaround 2.x bug (see https://github.com/owncloud/android/issues/716)\r
+            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && (System.currentTimeMillis() - time) > 24 * 60 * 60 * 1000){\r
+                Date date = new Date(time);\r
+                date.setHours(0);\r
+                date.setMinutes(0);\r
+                date.setSeconds(0);\r
+                dateString = DateUtils.getRelativeDateTimeString(c, date.getTime(), minResolution, transitionResolution, flags);\r
+            } else {\r
+                dateString = DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);\r
+            }\r
+        }\r
+        \r
+        return dateString.toString().split(",")[0];\r
+    }\r
 }\r