Merge branch 'master' of https://github.com/owncloud/android into material_buttons
authorAndy Scherzinger <info@andy-scherzinger.de>
Mon, 2 Nov 2015 07:41:51 +0000 (08:41 +0100)
committerAndy Scherzinger <info@andy-scherzinger.de>
Mon, 2 Nov 2015 07:41:51 +0000 (08:41 +0100)
1  2 
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/adapter/FileListListAdapter.java
src/com/owncloud/android/utils/DisplayUtils.java

@@@ -265,7 -265,12 +265,7 @@@ public class FileDisplayActivity extend
              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) {
                          (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
  
                  if (sameAccount && isDescendant) {
-                     refreshListOfFilesFragment();
+                     String linkedToRemotePath =
+                             intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
+                     if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
+                         refreshListOfFilesFragment();
+                     }
                  }
  
                  boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT,
  
          }
  
+         // TODO refactor this receiver, and maybe DownloadFinishReceiver; this method is duplicated :S
+         private boolean isAscendant(String linkedToRemotePath) {
+             OCFile currentDir = getCurrentDir();
+             return (
+                     currentDir != null &&
+                             currentDir.getRemotePath().startsWith(linkedToRemotePath)
+             );
+         }
      }
  
  
       */
      private class DownloadFinishReceiver extends BroadcastReceiver {
  
-         //int refreshCounter = 0;
          @Override
          public void onReceive(Context context, Intent intent) {
              try {
-                 boolean sameAccount = isSameAccount(context, intent);
+                 boolean sameAccount = isSameAccount(intent);
                  String downloadedRemotePath =
                          intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
                  boolean isDescendant = isDescendant(downloadedRemotePath);
                      String linkedToRemotePath =
                              intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
                      if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
-                         //Log_OC.v(TAG, "refresh #" + ++refreshCounter);
                          refreshListOfFilesFragment();
                      }
                      refreshSecondFragment(
              );
          }
  
-         private boolean isSameAccount(Context context, Intent intent) {
+         private boolean isSameAccount(Intent intent) {
              String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
              return (accountName != null && getAccount() != null &&
                      accountName.equals(getAccount().name));
@@@ -194,7 -194,6 +194,7 @@@ public class FileListListAdapter extend
              switch (viewType){\r
                  case LIST_ITEM:\r
                      TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);\r
 +                    TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator);\r
                      TextView lastModV = (TextView) view.findViewById(R.id.last_mod);\r
                      ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);\r
  \r
  \r
                      checkBoxV.setVisibility(View.GONE);\r
  \r
 +                    fileSizeSeparatorV.setVisibility(View.VISIBLE);\r
                      fileSizeV.setVisibility(View.VISIBLE);\r
                      fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));\r
  \r
                              } else {\r
                                  if (parentList.isItemChecked(position)) {\r
                                      checkBoxV.setImageResource(\r
 -                                            android.R.drawable.checkbox_on_background);\r
 +                                            R.drawable.ic_checkbox_marked);\r
                                  } else {\r
                                      checkBoxV.setImageResource(\r
 -                                            android.R.drawable.checkbox_off_background);\r
 +                                            R.drawable.ic_checkbox_blank_outline);\r
                                  }\r
                                  checkBoxV.setVisibility(View.VISIBLE);\r
                              }\r
                          }\r
  \r
                      } else { //Folder\r
 +                        fileSizeSeparatorV.setVisibility(View.INVISIBLE);\r
                          fileSizeV.setVisibility(View.INVISIBLE);\r
                      }\r
  \r
                              mTransferServiceGetter.getFileDownloaderBinder();\r
                      FileUploaderBinder uploaderBinder =\r
                              mTransferServiceGetter.getFileUploaderBinder();\r
-                     boolean downloading = (downloaderBinder != null &&\r
-                             downloaderBinder.isDownloading(mAccount, file));\r
                      OperationsServiceBinder opsBinder =\r
                              mTransferServiceGetter.getOperationsServiceBinder();\r
-                     downloading |= (opsBinder != null &&\r
-                             opsBinder.isSynchronizing(mAccount, file.getRemotePath()));\r
-                     if (downloading) {\r
-                         localStateView.setImageResource(R.drawable.downloading_file_indicator);\r
\r
+                     localStateView.setVisibility(View.INVISIBLE);   // default first\r
\r
+                     if ( //synchronizing\r
+                                 opsBinder != null &&\r
+                                 opsBinder.isSynchronizing(mAccount, file.getRemotePath())\r
+                             ) {\r
+                         localStateView.setImageResource(R.drawable.synchronizing_file_indicator);\r
+                         localStateView.setVisibility(View.VISIBLE);\r
\r
+                     } else if ( // downloading\r
+                                 downloaderBinder != null &&\r
+                                 downloaderBinder.isDownloading(mAccount, file)\r
+                             ) {\r
+                         localStateView.setImageResource(\r
+                                 file.isFolder() ?\r
+                                         R.drawable.synchronizing_file_indicator :\r
+                                         R.drawable.downloading_file_indicator\r
+                         );\r
                          localStateView.setVisibility(View.VISIBLE);\r
-                     } else if (uploaderBinder != null &&\r
-                             uploaderBinder.isUploading(mAccount, file)) {\r
-                         localStateView.setImageResource(R.drawable.uploading_file_indicator);\r
\r
+                     } else if ( //uploading\r
+                                 uploaderBinder != null &&\r
+                                 uploaderBinder.isUploading(mAccount, file)\r
+                             ) {\r
+                         localStateView.setImageResource(\r
+                                 file.isFolder() ?\r
+                                         R.drawable.synchronizing_file_indicator :\r
+                                         R.drawable.uploading_file_indicator\r
+                         );\r
                          localStateView.setVisibility(View.VISIBLE);\r
\r
+                     } else if (file.getEtagInConflict() != null) {   // conflict\r
+                         localStateView.setImageResource(R.drawable.conflict_file_indicator);\r
+                         localStateView.setVisibility(View.VISIBLE);\r
\r
                      } else if (file.isDown()) {\r
                          localStateView.setImageResource(R.drawable.local_file_indicator);\r
                          localStateView.setVisibility(View.VISIBLE);\r
-                     } else {\r
-                         localStateView.setVisibility(View.INVISIBLE);\r
                      }\r
  \r
                      // share with me icon\r
          return view;\r
      }\r
  \r
-     /**\r
-      * Local Folder size in human readable format\r
-      * \r
-      * @param path\r
-      *            String\r
-      * @return Size in human readable format\r
-      */\r
-     private String getFolderSizeHuman(String path) {\r
\r
-         File dir = new File(path);\r
\r
-         if (dir.exists()) {\r
-             long bytes = FileStorageUtils.getFolderSize(dir);\r
-             return DisplayUtils.bytesToHumanReadable(bytes);\r
-         }\r
\r
-         return "0 B";\r
-     }\r
\r
-     /**\r
-      * Local Folder size\r
-      * @param dir File\r
-      * @return Size in bytes\r
-      */\r
-     private long getFolderSize(File dir) {\r
-         if (dir.exists()) {\r
-             long result = 0;\r
-             File[] fileList = dir.listFiles();\r
-             for(int i = 0; i < fileList.length; i++) {\r
-                 if(fileList[i].isDirectory()) {\r
-                     result += getFolderSize(fileList[i]);\r
-                 } else {\r
-                     result += fileList[i].length();\r
-                 }\r
-             }\r
-             return result;\r
-         }\r
-         return 0;\r
-     } \r
\r
      @Override\r
      public int getViewTypeCount() {\r
          return 1;\r
@@@ -37,7 -37,6 +37,7 @@@ import com.owncloud.android.MainApp
  import com.owncloud.android.R;\r
  import com.owncloud.android.datamodel.OCFile;\r
  \r
 +import java.math.BigDecimal;\r
  import java.net.IDN;\r
  import java.text.DateFormat;\r
  import java.util.Calendar;\r
@@@ -53,7 -52,6 +53,7 @@@ public class DisplayUtils 
      private static final String OWNCLOUD_APP_NAME = "ownCloud";\r
      \r
      private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };\r
 +    private static final int[] sizeScales = { 0, 0, 0, 1, 1, 2, 2, 2, 2 };\r
  \r
      private static Map<String, String> mimeType2HumanReadable;\r
  \r
  \r
      /**\r
       * Converts the file size in bytes to human readable output.\r
 -     * \r
 +     * <ul>\r
 +     *     <li>appends a size suffix, e.g. B, KB, MB etc.</li>\r
 +     *     <li>rounds the size based on the suffix to 0,1 or 2 decimals</li>\r
 +     * </ul>\r
 +     *\r
       * @param bytes Input file size\r
       * @return Like something readable like "12 MB"\r
       */\r
      public static String bytesToHumanReadable(long bytes) {\r
          double result = bytes;\r
 -        int attachedsuff = 0;\r
 -        while (result > 1024 && attachedsuff < sizeSuffixes.length) {\r
 +        int attachedSuff = 0;\r
 +        while (result > 1024 && attachedSuff < sizeSuffixes.length) {\r
              result /= 1024.;\r
 -            attachedsuff++;\r
 +            attachedSuff++;\r
          }\r
 -        result = ((int) (result * 100)) / 100.;\r
 -        return result + " " + sizeSuffixes[attachedsuff];\r
 +\r
 +        return new BigDecimal(result).setScale(\r
 +                sizeScales[attachedSuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedSuff];\r
      }\r
  \r
      /**\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 && \r
-                     (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(\r
-                         c, date.getTime(), minResolution, transitionResolution, flags\r
-                 );\r
-             } else {\r
-                 dateString = DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);\r
+             dateString = DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);\r
+         }\r
\r
+         String[] parts = dateString.toString().split(",");\r
+         if (parts.length == 2) {\r
+             if (parts[1].contains(":") && !parts[0].contains(":")) {\r
+                 return parts[0];\r
+             } else if (parts[0].contains(":") && !parts[1].contains(":")) {\r
+                 return parts[1];\r
              }\r
          }\r
-         \r
-         return dateString.toString().split(",")[0];\r
+         //dateString contains unexpected format. fallback: use relative date time string from android api as is.\r
+         return dateString.toString();\r
      }\r
  \r
      /**\r