Merge branch 'develop' of github.com:owncloud/android into svgTransparentBackground
authortobiasKaminsky <tobias@kaminsky.me>
Fri, 21 Aug 2015 15:48:58 +0000 (17:48 +0200)
committertobiasKaminsky <tobias@kaminsky.me>
Fri, 21 Aug 2015 15:48:58 +0000 (17:48 +0200)
1  2 
src/com/owncloud/android/ui/adapter/FileListListAdapter.java
src/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@@ -30,7 -30,6 +30,7 @@@ import android.accounts.Account
  import android.content.Context;\r
  import android.content.SharedPreferences;\r
  import android.graphics.Bitmap;\r
 +import android.graphics.drawable.Drawable;\r
  import android.os.Build;\r
  import android.preference.PreferenceManager;\r
  import android.text.format.DateUtils;\r
@@@ -269,15 -268,14 +269,14 @@@ public class FileListListAdapter extend
                      }\r
  \r
                      // share with me icon\r
-                     if (!file.isFolder()) {\r
-                         ImageView sharedWithMeIconV = (ImageView)\r
-                                 view.findViewById(R.id.sharedWithMeIcon);\r
-                         sharedWithMeIconV.bringToFront();\r
-                         if (checkIfFileIsSharedWithMe(file)) {\r
-                             sharedWithMeIconV.setVisibility(View.VISIBLE);\r
-                         } else {\r
-                             sharedWithMeIconV.setVisibility(View.GONE);\r
-                         }\r
+                     ImageView sharedWithMeIconV = (ImageView)\r
+                             view.findViewById(R.id.sharedWithMeIcon);\r
+                     sharedWithMeIconV.bringToFront();\r
+                     if (checkIfFileIsSharedWithMe(file) &&\r
+                             (!file.isFolder() || !mGridMode)) {\r
+                         sharedWithMeIconV.setVisibility(View.VISIBLE);\r
+                     } else {\r
+                         sharedWithMeIconV.setVisibility(View.GONE);\r
                      }\r
  \r
                      break;\r
              \r
              // this if-else is needed even though favorite icon is visible by default\r
              // because android reuses views in listview\r
-             if (!file.keepInSync()) {\r
+             if (!file.isFavorite()) {\r
                  view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE);\r
              } else {\r
                  view.findViewById(R.id.favoriteIcon).setVisibility(View.VISIBLE);\r
                              task.execute(file);\r
                          }\r
                      }\r
 +\r
 +                    if (file.getMimetype().equalsIgnoreCase("image/png")){\r
 +                        Drawable backrepeat = mContext.getResources().\r
 +                                              getDrawable(R.drawable.backrepeat);\r
 +                        fileIcon.setBackground(backrepeat);\r
 +                    }\r
 +\r
                  } else {\r
                      fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(),\r
                              file.getFileName()));\r
@@@ -26,7 -26,6 +26,7 @@@ import android.annotation.SuppressLint
  import android.app.Activity;
  import android.graphics.Bitmap;
  import android.graphics.Point;
 +import android.graphics.drawable.Drawable;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v4.app.FragmentStatePagerAdapter;
@@@ -201,8 -200,7 +201,8 @@@ public class PreviewImageFragment exten
          if (getFile() != null) {
              mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel);
              //mLoadBitmapTask.execute(new String[]{getFile().getStoragePath()});
 -            mLoadBitmapTask.execute(getFile().getStoragePath());
 +//            mLoadBitmapTask.execute(getFile().getStoragePath());
 +            mLoadBitmapTask.execute(getFile());
          }
      }
      
                  mContainerActivity.getFileOperationsHelper().syncFile(getFile());
                  return true;
              }
-             
+             case R.id.action_favorite_file:{
+                 mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), true);
+                 return true;
+             }
+             case R.id.action_unfavorite_file:{
+                 mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), false);
+                 return true;
+             }
              default:
                  return false;
          }
      }
      
      
 -    private class LoadBitmapTask extends AsyncTask<String, Void, Bitmap> {
 +    private class LoadBitmapTask extends AsyncTask<OCFile, Void, LoadImage> {
  
          /**
           * Weak reference to the target {@link ImageView} where the bitmap will be loaded into.
              mProgressWheelRef = new WeakReference<ProgressBar>(progressWheel);
          }
          
 -        
          @Override
 -        protected Bitmap doInBackground(String... params) {
 +        protected LoadImage doInBackground(OCFile... params) {
              Bitmap result = null;
              if (params.length != 1) return null;
 -            String storagePath = params[0];
 +            OCFile ocFile = params[0];
 +            String storagePath = ocFile.getStoragePath();
              try {
  
                  int maxDownScale = 3;   // could be a parameter passed to doInBackground(...)
                          result = BitmapUtils.decodeSampledBitmapFromFile(storagePath, minWidth,
                                  minHeight);
  
 -                        if (isCancelled()) return result;
 +                        if (isCancelled()) return new LoadImage(result, ocFile);
  
                          if (result == null) {
                              mErrorMessageId = R.string.preview_image_error_unknown_format;
                  Log_OC.e(TAG, "Unexpected error loading " + getFile().getStoragePath(), t);
                  
              }
 -            
 -            return result;
 +            return new LoadImage(result, ocFile);
          }
          
          @Override
 -        protected void onCancelled(Bitmap result) {
 -            if (result != null) {
 -                result.recycle();
 +        protected void onCancelled(LoadImage result) {
 +            if (result.bitmap != null) {
 +                result.bitmap.recycle();
              }
          }
  
          @Override
 -        protected void onPostExecute(Bitmap result) {
 +        protected void onPostExecute(LoadImage result) {
              hideProgressWheel();
 -            if (result != null) {
 +            if (result.bitmap != null) {
                  showLoadedImage(result);
              } else {
                  showErrorMessage();
              }
 -            if (result != null && mBitmap != result)  {
 +            if (result.bitmap != null && mBitmap != result.bitmap)  {
                  // unused bitmap, release it! (just in case)
 -                result.recycle();
 +                result.bitmap.recycle();
              }
          }
          
          @SuppressLint("InlinedApi")
 -        private void showLoadedImage(Bitmap result) {
 +        private void showLoadedImage(LoadImage result) {
              final ImageViewCustom imageView = mImageViewRef.get();
 +            Bitmap bitmap = result.bitmap;
              if (imageView != null) {
 -                Log_OC.d(TAG, "Showing image with resolution " + result.getWidth() + "x" +
 -                        result.getHeight());
 -                imageView.setImageBitmap(result);
 +                Log_OC.d(TAG, "Showing image with resolution " + bitmap.getWidth() + "x" +
 +                        bitmap.getHeight());
 +
 +                if (result.ocFile.getMimetype().equalsIgnoreCase("image/png")){
 +                    Drawable backrepeat = getResources().getDrawable(R.drawable.backrepeat);
 +                    imageView.setBackground(backrepeat);
 +                }
 +
 +                imageView.setImageBitmap(bitmap);
                  imageView.setVisibility(View.VISIBLE);
 -                mBitmap  = result;  // needs to be kept for recycling when not useful
 +                mBitmap  = bitmap;  // needs to be kept for recycling when not useful
              }
  
              final TextView messageView = mMessageViewRef.get();
          return mImageView;
      }
  
 +    private class LoadImage {
 +        private Bitmap bitmap;
 +        private OCFile ocFile;
 +
 +        public LoadImage(Bitmap bitmap, OCFile ocFile){
 +            this.bitmap = bitmap;
 +            this.ocFile = ocFile;
 +        }
 +
 +    }
 +
  }