瀏覽代碼

Merge pull request #3008 from NilsGriebner/filepicker_grid

Use grid_item view for gridview in upload filepicker
Tobias Kaminsky 6 年之前
父節點
當前提交
0c371b9603

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

@@ -519,6 +519,10 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
         return output;
     }
 
+    public void setGridView(boolean gridView) {
+        this.gridView = gridView;
+    }
+
     static class LocalFileListItemViewHolder extends LocalFileListGridViewHolder {
         private final TextView fileSize;
         private final TextView lastModification;
@@ -530,6 +534,8 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
             fileSize = itemView.findViewById(R.id.file_size);
             fileSeparator = itemView.findViewById(R.id.file_separator);
             lastModification = itemView.findViewById(R.id.last_mod);
+
+            itemView.findViewById(R.id.overflow_menu).setVisibility(View.GONE);
         }
     }
 
@@ -547,7 +553,6 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
             checkbox = itemView.findViewById(R.id.custom_checkbox);
             itemLayout = itemView.findViewById(R.id.ListItemLayout);
 
-            itemView.findViewById(R.id.overflow_menu).setVisibility(View.GONE);
             itemView.findViewById(R.id.sharedIcon).setVisibility(View.GONE);
             itemView.findViewById(R.id.favorite_action).setVisibility(View.GONE);
             itemView.findViewById(R.id.keptOfflineIcon).setVisibility(View.GONE);

+ 21 - 0
src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java

@@ -271,6 +271,27 @@ public class LocalFileListFragment extends ExtendedListFragment implements Local
         }
     }
 
+    @Override
+    public void switchToGridView() {
+        mAdapter.setGridView(true);
+        /**
+         * Set recyclerview adapter again to force new view for items. If this is not done
+         * a few items keep their old view.
+         *
+         * https://stackoverflow.com/questions/36495009/force-recyclerview-to-redraw-android
+         */
+        getRecyclerView().setAdapter(mAdapter);
+        super.switchToGridView();
+    }
+
+    @Override
+    public void switchToListView() {
+        mAdapter.setGridView(false);
+        /** Same problem here, see switchToGridView() */
+        getRecyclerView().setAdapter(mAdapter);
+        super.switchToListView();
+    }
+
     /**
      * Interface to implement by any Activity that includes some instance of LocalFileListFragment
      */