Browse Source

grid spacing added + negative/shortened margins for containers for nice image grids

AndyScherzinger 8 years ago
parent
commit
0889f8a69e

+ 2 - 2
res/layout/folder_sync_item_header.xml

@@ -21,8 +21,8 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:paddingTop="@dimen/standard_half_padding"
-                android:paddingBottom="@dimen/standard_half_padding"
+                android:paddingTop="@dimen/alternate_half_padding"
+                android:paddingBottom="@dimen/alternate_half_padding"
                 android:paddingLeft="@dimen/standard_padding">
 
     <TextView

+ 4 - 1
res/layout/folder_sync_layout.xml

@@ -45,7 +45,10 @@
                 android:clipToPadding="false"
                 android:scrollbarStyle="outsideOverlay"
                 android:scrollbars="vertical"
-                android:visibility="visible"/>
+                android:visibility="visible"
+                android:layout_marginRight="-3dp"
+                android:layout_marginLeft="-3dp"
+                android:layout_marginBottom="-3dp"/>
 
             <LinearLayout
                 android:id="@android:id/progress"

+ 2 - 6
res/layout/grid_sync_item.xml

@@ -18,7 +18,7 @@
   You should have received a copy of the GNU Affero General Public
   License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
-<LinearLayout android:id="@+id/ListItemLayout"
+<LinearLayout android:id="@+id/grid_item_container"
               xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
@@ -29,14 +29,12 @@
 
     <FrameLayout
         android:layout_width="match_parent"
-        android:layout_height="wrap_content">
+        android:layout_height="match_parent">
 
         <com.owncloud.android.ui.SquareImageView
             android:id="@+id/thumbnail"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:paddingLeft="8dp"
-            android:paddingRight="8dp"
             android:scaleType="centerCrop"
             android:src="@drawable/ic_menu_archive"/>
 
@@ -44,8 +42,6 @@
             android:id="@+id/thumbnailDarkener"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:paddingLeft="8dp"
-            android:paddingRight="8dp"
             android:scaleType="centerCrop"
             android:background="#99000000"/>
 

+ 1 - 0
res/values/dims.xml

@@ -99,4 +99,5 @@
     <dimen name="upload_list_item_text_size_independent">12dip</dimen>
     <dimen name="upload_list_item_image_size">35dp</dimen>
     <dimen name="uploader_list_item_layout_image_margin">12dp</dimen>
+    <dimen name="mediaGridSpacing">2dp</dimen>
 </resources>

+ 3 - 0
src/com/owncloud/android/ui/activity/FolderSyncActivity.java

@@ -44,6 +44,7 @@ import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolderItem;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.ui.adapter.FolderSyncAdapter;
+import com.owncloud.android.ui.decoration.MediaGridItemDecoration;
 import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment;
 import com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable;
 
@@ -105,6 +106,8 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
 
         final GridLayoutManager lm = new GridLayoutManager(this, gridWidth);
         mAdapter.setLayoutManager(lm);
+        int spacing = getResources().getDimensionPixelSize(R.dimen.mediaGridSpacing);
+        mRecyclerView.addItemDecoration(new MediaGridItemDecoration(spacing));
         mRecyclerView.setLayoutManager(lm);
         mRecyclerView.setAdapter(mAdapter);
 

+ 2 - 0
src/com/owncloud/android/ui/adapter/FolderSyncAdapter.java

@@ -162,6 +162,8 @@ public class FolderSyncAdapter extends SectionedRecyclerViewAdapter<FolderSyncAd
             holder.image.setImageResource(MimetypeIconUtil.getFileTypeIconId(null, file.getName()));
         }
 
+        holder.itemView.setTag(relativePosition % (mGridWidth/2));
+
         if (mSyncFolderItems.get(section).getNumberOfFiles() > 8 && relativePosition >= 8 - 1) {
             holder.counterValue.setText(Long.toString(mSyncFolderItems.get(section).getNumberOfFiles() - 8));
             holder.counterBar.setVisibility(View.VISIBLE);

+ 44 - 0
src/com/owncloud/android/ui/decoration/MediaGridItemDecoration.java

@@ -0,0 +1,44 @@
+/**
+ *   Nextcloud Android client application
+ *
+ *   Copyright (C) 2016 Andy Scherzinger
+ *   Copyright (C) 2016 Nextcloud.
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ *   License as published by the Free Software Foundation; either
+ *   version 3 of the License, or any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ *   You should have received a copy of the GNU Affero General Public
+ *   License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.owncloud.android.ui.decoration;
+
+import android.graphics.Rect;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.RecyclerView.ItemDecoration;
+import android.view.View;
+
+/**
+ * Decoration for media grid items.
+ */
+public class MediaGridItemDecoration extends ItemDecoration {
+    private int space;
+
+    public MediaGridItemDecoration(int space) {
+        this.space = space;
+    }
+
+    @Override
+    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
+        outRect.right = space;
+        outRect.bottom = space;
+        outRect.left = space;
+        outRect.top = space;
+    }
+}