Эх сурвалжийг харах

- renamed ImageViews
- switch to 80x80px filetype icon

tobiasKaminsky 10 жил өмнө
parent
commit
5434504486

+ 1 - 1
res/layout-land/account_setup.xml

@@ -32,7 +32,7 @@
         android:orientation="horizontal" >
         
 		<ImageView
-			android:id="@+id/imageView1"
+			android:id="@+id/thumbnail"
 			android:layout_width="0dp"
 			android:layout_height="wrap_content"
 			android:layout_weight="1"

+ 1 - 1
res/layout/account_setup.xml

@@ -35,7 +35,7 @@
         android:padding="8dp" >
 
         <ImageView
-            android:id="@+id/imageView1"
+            android:id="@+id/thumbnail"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginBottom="10dp"

+ 14 - 81
res/layout/grid_image.xml

@@ -27,95 +27,28 @@
     android:gravity="center_horizontal"
     android:orientation="vertical" >
 
-    <com.owncloud.android.ui.SquareImageView
-        android:id="@+id/imageView1"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:layout_gravity="fill"
-        android:paddingLeft="10dp"
-        android:paddingRight="10dp"
-        android:scaleType="centerCrop"
-        android:src="@drawable/ic_menu_archive" />
-
     <FrameLayout
-        android:id="@+id/imageItemFrame"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:focusable="false"
-        android:focusableInTouchMode="false" >
-
-        <ImageView
-            android:id="@+id/sharedIcon"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginBottom="4dp"
-            android:layout_marginLeft="4dp"
-            android:layout_marginRight="4dp"
-            android:src="@drawable/sharedlink" />
-
-        <ImageView
-            android:id="@+id/sharedWithMeIcon"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="4dp"
-            android:layout_marginRight="4dp"
-            android:layout_marginTop="4dp"
-            android:src="@drawable/shared_with_me" />
-
-        <ImageView
-            android:id="@+id/custom_checkbox"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="4dp"
-            android:layout_marginRight="4dp"
-            android:src="@android:drawable/checkbox_off_background" />
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
 
-        <TextView
-            android:id="@+id/Filename"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="4dp"
-            android:layout_marginRight="4dp"
-            android:ellipsize="middle"
-            android:singleLine="true"
-            android:text="TextView"
-            android:textColor="#303030"
-            android:textSize="16dip" />
+        <com.owncloud.android.ui.SquareImageView
+            android:id="@+id/thumbnail"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:paddingLeft="10dp"
+            android:paddingRight="10dp"
+            android:scaleType="centerCrop"
+            android:src="@drawable/ic_menu_archive" />
 
         <ImageView
-            android:id="@+id/imageView3"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:id="@+id/favoriteIcon"
+            android:layout_width="15dp"
+            android:layout_height="15dp"
             android:layout_gravity="bottom|right"
-            android:layout_marginBottom="10dp"
+            android:layout_marginBottom="2dp"
             android:layout_marginRight="2dp"
             android:src="@drawable/ic_favorite" />
 
-        <TextView
-            android:id="@+id/last_mod"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_weight=".5"
-            android:text="TextView"
-            android:textColor="@color/list_item_lastmod_and_filesize_text"
-            android:textSize="12dip" />
-
-        <TextView
-            android:id="@+id/file_size"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_weight=".5"
-            android:gravity="right"
-            android:text="TextView"
-            android:textColor="@color/list_item_lastmod_and_filesize_text"
-            android:textSize="12dip" />
     </FrameLayout>
 
-    <ImageView
-        android:id="@+id/imageView2"
-        android:layout_width="40dp"
-        android:layout_height="22dp"
-        android:layout_marginLeft="22dp"
-        android:src="@drawable/local_file_indicator" />
-
 </LinearLayout>

+ 27 - 80
res/layout/grid_item.xml

@@ -18,7 +18,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   
 -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<com.owncloud.android.ui.SquareLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/ListItemLayout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
@@ -27,19 +27,35 @@
     android:gravity="center"
     android:orientation="vertical" >
 
-    <ImageView
-        android:id="@+id/imageView1"
-        android:layout_width="90dp"
-        android:layout_height="90dp"
-        android:layout_marginLeft="10dp"
-        android:layout_marginRight="10dp"
-        android:src="@drawable/ic_menu_archive" />
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_horizontal" >
+
+        <ImageView
+            android:id="@+id/favoriteIcon"
+            android:layout_width="15dp"
+            android:layout_height="15dp"
+            android:layout_gravity="bottom|right"
+            android:layout_marginBottom="2dp"
+            android:layout_marginRight="2dp"
+            android:src="@drawable/ic_favorite" />
+
+        <ImageView
+            android:id="@+id/thumbnail"
+            android:layout_width="80dp"
+            android:layout_height="80dp"
+            android:layout_gravity="center_horizontal"
+            android:layout_marginLeft="10dp"
+            android:layout_marginRight="10dp"
+            android:src="@drawable/ic_menu_archive" />
+
+    </FrameLayout>
 
     <TextView
         android:id="@+id/Filename"
-        android:layout_width="100dp"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_gravity="center_horizontal"
         android:layout_marginLeft="4dp"
         android:layout_marginRight="4dp"
         android:ellipsize="middle"
@@ -49,73 +65,4 @@
         android:textColor="#303030"
         android:textSize="16dip" />
 
-    <ImageView
-        android:id="@+id/imageView2"
-        android:layout_width="40dp"
-        android:layout_height="22dp"
-        android:layout_marginLeft="22dp"
-        android:src="@drawable/local_file_indicator" />
-
-    <TextView
-        android:id="@+id/file_size"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_weight=".5"
-        android:gravity="right"
-        android:text="TextView"
-        android:textColor="@color/list_item_lastmod_and_filesize_text"
-        android:textSize="12dip" />
-
-    <FrameLayout
-        android:id="@+id/imageItemFrame"
-        android:layout_width="56dp"
-        android:layout_height="56dp"
-        android:focusable="false"
-        android:focusableInTouchMode="false" >
-
-        <ImageView
-            android:id="@+id/sharedIcon"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginBottom="4dp"
-            android:layout_marginLeft="4dp"
-            android:layout_marginRight="4dp"
-            android:src="@drawable/sharedlink" />
-
-        <ImageView
-            android:id="@+id/sharedWithMeIcon"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="4dp"
-            android:layout_marginRight="4dp"
-            android:layout_marginTop="4dp"
-            android:src="@drawable/shared_with_me" />
-
-        <ImageView
-            android:id="@+id/custom_checkbox"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="4dp"
-            android:layout_marginRight="4dp"
-            android:src="@android:drawable/checkbox_off_background" />
-
-        <ImageView
-            android:id="@+id/imageView3"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="bottom|right"
-            android:layout_marginBottom="10dp"
-            android:layout_marginRight="2dp"
-            android:src="@drawable/ic_favorite" />
-
-        <TextView
-            android:id="@+id/last_mod"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_weight=".5"
-            android:text="TextView"
-            android:textColor="@color/list_item_lastmod_and_filesize_text"
-            android:textSize="12dip" />
-    </FrameLayout>
-
-</LinearLayout>
+</com.owncloud.android.ui.SquareLinearLayout>

+ 3 - 3
res/layout/list_item.xml

@@ -31,7 +31,7 @@
         android:focusableInTouchMode="false">
 
         <ImageView
-            android:id="@+id/imageView2"
+            android:id="@+id/localFileIndicator"
             android:layout_width="32dp"
             android:layout_height="32dp"
             android:layout_gravity="center_vertical"
@@ -39,7 +39,7 @@
             android:src="@drawable/local_file_indicator" />
 
         <ImageView
-            android:id="@+id/imageView1"
+            android:id="@+id/thumbnail"
             android:layout_width="32dp"
             android:layout_height="32dp"
             android:layout_gravity="center_vertical"
@@ -47,7 +47,7 @@
             android:src="@drawable/ic_menu_archive" />
 
         <ImageView
-            android:id="@+id/imageView3"
+            android:id="@+id/favoriteIcon"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="bottom|right"

+ 1 - 1
res/layout/uploader_list_item_layout.xml

@@ -30,7 +30,7 @@
         android:layout_gravity="center_vertical|center"
         android:layout_margin="4dp"
         android:src="@drawable/ic_menu_archive" 
-        android:id="@+id/imageView1" />
+        android:id="@+id/thumbnail" />
     
     <TextView 
         android:text="TextView" 

+ 25 - 0
src/com/owncloud/android/ui/SquareLinearLayout.java

@@ -0,0 +1,25 @@
+package com.owncloud.android.ui;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.LinearLayout;
+
+public class SquareLinearLayout extends LinearLayout {
+
+    public SquareLinearLayout(Context context) {
+        super(context);
+    }
+
+    public SquareLinearLayout(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public SquareLinearLayout(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, widthMeasureSpec);
+    }
+}

+ 114 - 89
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -63,6 +63,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     private FileDataStorageManager mStorageManager;
     private Account mAccount;
     private ComponentsGetter mTransferServiceGetter;
+    private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM };
     
     public FileListListAdapter(
             boolean justFolders, 
@@ -138,120 +139,144 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
             file = mFiles.get(position);
         }
         
+        // Find out which layout should be displayed
+        ViewType viewType;
         if (fileView){
-            view = inflator.inflate(R.layout.list_item, null);
+            viewType = ViewType.LIST_ITEM;
+        } else if (file.isImage()){
+            viewType = ViewType.GRID_IMAGE;
         } else {
-            if (file.isImage()){
-                view = inflator.inflate(R.layout.grid_image, null);
-            } else {
-                view = inflator.inflate(R.layout.grid_item, null);
-            }
-            
-            View frame = view.findViewById(R.id.imageItemFrame);
-            frame.setVisibility(View.GONE);
+            viewType = ViewType.GRID_ITEM;
+        }
+
+        // Create View
+        switch (viewType){
+        case GRID_IMAGE:
+            view = inflator.inflate(R.layout.grid_image, null);
+            break;
+        case GRID_ITEM:
+            view = inflator.inflate(R.layout.grid_item, null);
+            break;
+        case LIST_ITEM:
+            view = inflator.inflate(R.layout.list_item, null);
+            break;
         }
+
         view.invalidate();
-    
-       if (file != null){
-            TextView fileName = (TextView) view.findViewById(R.id.Filename);
-            // if (!fileView){fileName.setVisibility(View.GONE);}
-            String name = file.getFileName();
 
-            fileName.setText(name);
-            ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
-            ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon);
-            ImageView sharedWithMeIconV = (ImageView) view.findViewById(R.id.sharedWithMeIcon);
-            sharedWithMeIconV.setVisibility(View.GONE);
+        if (file != null){
 
-            ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
-            localStateView.bringToFront();
-            FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
-            FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
-            if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
-                localStateView.setImageResource(R.drawable.downloading_file_indicator);
-                localStateView.setVisibility(View.VISIBLE);
-            } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
-                localStateView.setImageResource(R.drawable.uploading_file_indicator);
-                localStateView.setVisibility(View.VISIBLE);
-            } else if (file.isDown()) {
-                localStateView.setImageResource(R.drawable.local_file_indicator);
-                localStateView.setVisibility(View.VISIBLE);
-            } else {
-                localStateView.setVisibility(View.INVISIBLE);
-            }
+            ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
+            TextView fileName;
+            String name;
             
-            if (!fileView){
-                localStateView.setVisibility(View.GONE);
-            }
-            
-            TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
-            TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
-            ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
-            
-            if (!file.isFolder()) {
-                fileSizeV.setVisibility(View.VISIBLE);
-                fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
+            switch (viewType){
+            case LIST_ITEM:
+                fileName = (TextView) view.findViewById(R.id.Filename);
+                name = file.getFileName();
+                fileName.setText(name);
+                
+                TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
+                TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
+                ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
+                
                 lastModV.setVisibility(View.VISIBLE);
                 lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
-                // this if-else is needed even thoe fav icon is visible by default
-                // because android reuses views in listview
-                if (!file.keepInSync()) {
-                    view.findViewById(R.id.imageView3).setVisibility(View.GONE);
+                
+                checkBoxV.setVisibility(View.GONE);
+                
+                fileSizeV.setVisibility(View.VISIBLE);
+                fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
+                
+                ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon);
+                
+
+                if (file.isShareByLink()) {
+                    sharedIconV.setVisibility(View.VISIBLE);
                 } else {
-                    view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
+                    sharedIconV.setVisibility(View.GONE);
                 }
                 
-                GridView parentList = (GridView)parent;
-                if (parentList.getChoiceMode() == GridView.CHOICE_MODE_NONE) { 
-                    checkBoxV.setVisibility(View.GONE);
-                } else {
-                    if (parentList.isItemChecked(position)) {
-                        checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
+                ImageView localStateView = (ImageView) view.findViewById(R.id.localFileIndicator);
+                
+                if (!file.isFolder()) {
+                    GridView parentList = (GridView)parent;
+                    if (parentList.getChoiceMode() == GridView.CHOICE_MODE_NONE) { 
+                        checkBoxV.setVisibility(View.GONE);
                     } else {
-                        checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
+                        if (parentList.isItemChecked(position)) {
+                            checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
+                        } else {
+                            checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
+                        }
+                        checkBoxV.setVisibility(View.VISIBLE);
                     }
-                    checkBoxV.setVisibility(View.VISIBLE);
+                    
+                    localStateView.bringToFront();
+                    FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
+                    FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
+                    if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
+                        localStateView.setImageResource(R.drawable.downloading_file_indicator);
+                        localStateView.setVisibility(View.VISIBLE);
+                    } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
+                        localStateView.setImageResource(R.drawable.uploading_file_indicator);
+                        localStateView.setVisibility(View.VISIBLE);
+                    } else if (file.isDown()) {
+                        localStateView.setImageResource(R.drawable.local_file_indicator);
+                        localStateView.setVisibility(View.VISIBLE);
+                    } else {
+                        localStateView.setVisibility(View.INVISIBLE);
+                    }
+                    
+                    ImageView sharedWithMeIconV = (ImageView) view.findViewById(R.id.sharedWithMeIcon);
+                    if (checkIfFileIsSharedWithMe(file)) {
+                        sharedWithMeIconV.setVisibility(View.VISIBLE);
+                    } else {
+                        sharedWithMeIconV.setVisibility(View.GONE);
+                    }
+                } else {
+                    localStateView.setVisibility(View.INVISIBLE);
                 }
-
+                break;
+            case GRID_ITEM:
+                fileName = (TextView) view.findViewById(R.id.Filename);
+                name = file.getFileName();
+                fileName.setText(name);
+                break;
+            case GRID_IMAGE:
+                break;
+            }
+            
+            // For all Views
+            
+            // this if-else is needed even though favorite icon is visible by default
+            // because android reuses views in listview
+            if (!file.keepInSync()) {
+                view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE);
+            } else {
+                view.findViewById(R.id.favoriteIcon).setVisibility(View.VISIBLE);
+            }
+            
+            // No Folder
+            if (!file.isFolder()) {
                 if (file.isImage() && file.isDown()){
                     Bitmap bitmap = BitmapFactory.decodeFile(file.getStoragePath());
-                    fileIcon.setImageBitmap(ThumbnailUtils.extractThumbnail(bitmap, 100, 100));
+                    fileIcon.setImageBitmap(ThumbnailUtils.extractThumbnail(bitmap, 200, 200));
                 } else {
                     fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype(), file.getFileName()));
                 }
-
-                if (checkIfFileIsSharedWithMe(file)) {
-                    sharedWithMeIconV.setVisibility(View.VISIBLE);
-                }
-            } 
-            else {
-                
-                fileSizeV.setVisibility(View.INVISIBLE);
-                //fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
-                lastModV.setVisibility(View.VISIBLE);
-                lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
-                checkBoxV.setVisibility(View.GONE);
-                view.findViewById(R.id.imageView3).setVisibility(View.GONE);
-
+            } else {
+                // Folder
                 if (checkIfFileIsSharedWithMe(file)) {
                     fileIcon.setImageResource(R.drawable.shared_with_me_folder);
-                    sharedWithMeIconV.setVisibility(View.VISIBLE);
+                } else if (file.isShareByLink()) {
+                    // If folder is sharedByLink, icon folder must be changed to
+                    // folder-public one
+                    fileIcon.setImageResource(R.drawable.folder_public);
                 } else {
                     fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype(), file.getFileName()));
                 }
-
-                // If folder is sharedByLink, icon folder must be changed to
-                // folder-public one
-                if (file.isShareByLink()) {
-                    fileIcon.setImageResource(R.drawable.folder_public);
-                }
-            }
-
-            if (file.isShareByLink()) {
-                sharedIconV.setVisibility(View.VISIBLE);
-            } else {
-                sharedIconV.setVisibility(View.GONE);
-            }
+            }           
         }
 
         return view;

+ 7 - 6
src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java

@@ -99,7 +99,7 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
             String name = file.getName();
             fileName.setText(name);
             
-            ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
+            ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
             if (!file.isDirectory()) {
                 fileIcon.setImageResource(R.drawable.file);
             } else {
@@ -110,8 +110,7 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
             TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
             ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
             if (!file.isDirectory()) {
-                fileSizeV.setVisibility(View.VISIBLE);
-                fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length()));
+                
                 lastModV.setVisibility(View.VISIBLE);
                 lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.lastModified()));
                 ListView parentList = (ListView)parent;
@@ -127,13 +126,15 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
                 }
 
             } else {
-                fileSizeV.setVisibility(View.GONE);
+                //fileSizeV.setVisibility(View.GONE);
                 lastModV.setVisibility(View.GONE);
                 checkBoxV.setVisibility(View.GONE);
             }
+            fileSizeV.setVisibility(View.VISIBLE);
+            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length()));
             
-            view.findViewById(R.id.imageView2).setVisibility(View.INVISIBLE);   // not GONE; the alignment changes; ugly way to keep it
-            view.findViewById(R.id.imageView3).setVisibility(View.GONE);
+            view.findViewById(R.id.localFileIndicator).setVisibility(View.INVISIBLE);   // not GONE; the alignment changes; ugly way to keep it
+            view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE);
             
             view.findViewById(R.id.sharedIcon).setVisibility(View.GONE);
             view.findViewById(R.id.sharedWithMeIcon).setVisibility(View.GONE);