diff options
author | brainbreaker <gautamprajapati06@gmail.com> | 2017-02-27 18:02:56 +0530 |
---|---|---|
committer | Aleksandar Stefanović <theonewithideas@gmail.com> | 2017-03-12 10:20:33 +0000 |
commit | 686651c30a9697463c9910f71736abe607efb270 (patch) | |
tree | 50fc60b693ebdb4740ff7c5255746135bc1795dc | |
parent | 6bf42c1cf0a4597fd2ef8034d6a5a4c5e1dd2ce8 (diff) |
Combine List Item & Grid Item Adapters of File Explorer View
This commit will combine the code of ListItemAdapter &
GridItemAdapter in LibreOfficeUIActivity to one
ExplorerItemAdapter which will handle both the view
types.
Change-Id: I45c1f5124afee82ff0b78f13609acd37be87fde1
Reviewed-on: https://gerrit.libreoffice.org/34680
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Aleksandar Stefanović <theonewithideas@gmail.com>
Tested-by: Aleksandar Stefanović <theonewithideas@gmail.com>
4 files changed, 41 insertions, 125 deletions
diff --git a/android/source/res/layout/file_explorer_grid_item.xml b/android/source/res/layout/file_explorer_grid_item.xml index 5604fe282a5a..e64fdc23a6a7 100644 --- a/android/source/res/layout/file_explorer_grid_item.xml +++ b/android/source/res/layout/file_explorer_grid_item.xml @@ -14,7 +14,7 @@ android:orientation="vertical" > <ImageView - android:id="@+id/grid_item_image" + android:id="@+id/file_item_icon" tools:src="@drawable/ic_folder_black_24dp" tools:tint="@color/text_color_secondary" android:layout_width="100dp" @@ -25,7 +25,7 @@ </ImageView> <TextView - android:id="@+id/grid_item_label" + android:id="@+id/file_item_name" tools:text="file or dirname" android:layout_width="wrap_content" android:layout_height="wrap_content" diff --git a/android/source/res/layout/file_list_item.xml b/android/source/res/layout/file_list_item.xml index 6ffc9282c45d..518885d4b296 100644 --- a/android/source/res/layout/file_list_item.xml +++ b/android/source/res/layout/file_list_item.xml @@ -15,7 +15,7 @@ android:layout_marginEnd="@dimen/list_item_margin" android:layout_marginRight="@dimen/list_item_margin"> <ImageView - android:id="@+id/file_list_item_icon" + android:id="@+id/file_item_icon" tools:src="@drawable/ic_folder_black_24dp" tools:tint="@color/text_color_secondary" android:layout_height="match_parent" @@ -29,7 +29,7 @@ android:layout_height="48dp" android:orientation="horizontal"> <TextView - android:id="@+id/file_list_item_name" + android:id="@+id/file_item_name" tools:text="file or dirname" style="@style/ListItemText" android:layout_height="match_parent" @@ -38,14 +38,14 @@ android:ellipsize="end" android:maxLines="1"/> <TextView - android:id="@+id/file_list_item_size" + android:id="@+id/file_item_size" tools:text="filesize" style="@style/ListItemText" android:layout_height="match_parent" android:layout_width="0dp" android:layout_weight="1" /> <TextView - android:id="@+id/file_list_item_date" + android:id="@+id/file_item_date" tools:text="date/time" style="@style/ListItemText" android:layout_height="match_parent" diff --git a/android/source/res/values/arrays.xml b/android/source/res/values/arrays.xml index 783a3713cd30..671424bfd13b 100644 --- a/android/source/res/values/arrays.xml +++ b/android/source/res/values/arrays.xml @@ -29,7 +29,6 @@ <item >0</item> <item >1</item> </string-array> - <string-array name="FilterTypeNames"> <item>Everything</item> <item>Documents</item> diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index 40726c3e6caf..a4daa454a346 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -268,13 +268,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings FileUtilities.sortFiles(filePaths, sortMode); // refresh view - if (viewMode == GRID_VIEW) { - fileRecyclerView.setLayoutManager(new GridLayoutManager(this, 3)); - fileRecyclerView.setAdapter(new GridItemAdapter(this, filePaths)); - } else { - fileRecyclerView.setLayoutManager(new LinearLayoutManager(this)); - fileRecyclerView.setAdapter(new ListItemAdapter(this, filePaths)); - } + fileRecyclerView.setLayoutManager(isViewModeList() ? new LinearLayoutManager(this) : new GridLayoutManager(this, 3)); + fileRecyclerView.setAdapter(new ExplorerItemAdapter(this, filePaths)); // close drawer if it was open drawerLayout.closeDrawer(navigationDrawer); } @@ -328,6 +323,10 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings } } + private boolean isViewModeList(){ + return viewMode == LIST_VIEW; + } + private void switchToDocumentProvider(IDocumentProvider provider) { new AsyncTask<IDocumentProvider, Void, Void>() { @@ -875,15 +874,14 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings } } - - class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ViewHolder> { + class ExplorerItemAdapter extends RecyclerView.Adapter<ExplorerItemAdapter.ViewHolder> { private Activity mActivity; private List<IFile> filePaths; private final long KB = 1024; private final long MB = 1048576; - ListItemAdapter(Activity activity, List<IFile> filePaths) { + ExplorerItemAdapter(Activity activity, List<IFile> filePaths) { this.mActivity = activity; this.filePaths = filePaths; } @@ -891,7 +889,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View item = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.file_list_item, parent, false); + .inflate(isViewModeList() ? R.layout.file_list_item : R.layout.file_explorer_grid_item, parent, false); return new ViewHolder(item); } @@ -917,24 +915,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings }); holder.filenameView.setText(file.getName()); - - if (!file.isDirectory()) { - String size; - long length = filePaths.get(position).getSize(); - if (length < KB){ - size = Long.toString(length) + "B"; - } else if (length < MB){ - size = Long.toString(length/KB) + "KB"; - } else { - size = Long.toString(length/MB) + "MB"; - } - holder.fileSizeView.setText(size); - } - SimpleDateFormat df = new SimpleDateFormat("dd MMM yyyy hh:ss"); - Date date = file.getLastModified(); - //TODO format date - holder.fileDateView.setText(df.format(date)); - switch (FileUtilities.getType(file.getName())) { case FileUtilities.DOC: holder.iconView.setImageResource(R.drawable.writer); @@ -954,96 +934,28 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings //Eventually have thumbnails of each sub file on a black circle //For now just a folder icon holder.iconView.setImageResource(R.drawable.ic_folder_black_24dp); - holder.iconView.setColorFilter(ContextCompat.getColor(mActivity,R.color.text_color_secondary)); - } - } - - @Override - public int getItemCount() { - return filePaths.size(); - } - - class ViewHolder extends RecyclerView.ViewHolder { - - View itemView; - TextView filenameView, fileSizeView, fileDateView; - ImageView iconView; - - ViewHolder(View itemView) { - super(itemView); - this.itemView = itemView; - filenameView = (TextView) itemView.findViewById(R.id.file_list_item_name); - fileSizeView = (TextView) itemView.findViewById(R.id.file_list_item_size); - fileDateView = (TextView) itemView.findViewById(R.id.file_list_item_date); - iconView = (ImageView) itemView.findViewById(R.id.file_list_item_icon); + holder.iconView.setColorFilter(ContextCompat.getColor(mActivity, R.color.text_color_secondary)); } - } - } - - class GridItemAdapter extends RecyclerView.Adapter<GridItemAdapter.ViewHolder> { - - private Activity mActivity; - private List<IFile> filePaths; - - GridItemAdapter(Activity mActivity, List<IFile> filePaths) { - this.mActivity = mActivity; - this.filePaths = filePaths; - } - - @Override - public GridItemAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View item = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.file_explorer_grid_item, parent, false); - return new ViewHolder(item); - } - - @Override - public void onBindViewHolder(final GridItemAdapter.ViewHolder holder, final int position) { - final IFile file = filePaths.get(position); - holder.itemView.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - open(position); - } - }); - - holder.itemView.setOnLongClickListener(new OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - //to be picked out by floating context menu (workaround-ish) - currentlySelectedFile = position; - //must return false so the click is not consumed - return false; + // Date and Size field only exist when we are displaying items in a list. + if(isViewModeList()) { + if (!file.isDirectory()) { + String size; + long length = filePaths.get(position).getSize(); + if (length < KB) { + size = Long.toString(length) + "B"; + } else if (length < MB) { + size = Long.toString(length / KB) + "KB"; + } else { + size = Long.toString(length / MB) + "MB"; + } + holder.fileSizeView.setText(size); } - }); - - String filename = file.getName(); - - holder.filenameView.setText(filename); - - switch (FileUtilities.getType(filename)) { - case FileUtilities.DOC: - holder.iconView.setImageResource(R.drawable.writer); - break; - case FileUtilities.CALC: - holder.iconView.setImageResource(R.drawable.calc); - break; - case FileUtilities.DRAWING: - holder.iconView.setImageResource(R.drawable.draw); - break; - case FileUtilities.IMPRESS: - holder.iconView.setImageResource(R.drawable.impress); - break; - } - - if (file.isDirectory()) { - //Eventually have thumbnails of each sub file on a black circle - //For now just a folder icon - holder.iconView.setImageResource(R.drawable.ic_folder_black_24dp); - holder.iconView.setColorFilter(ContextCompat.getColor(mActivity,R.color.text_color_secondary)); + SimpleDateFormat df = new SimpleDateFormat("dd MMM yyyy hh:ss"); + Date date = file.getLastModified(); + //TODO format date + holder.fileDateView.setText(df.format(date)); } - } @Override @@ -1054,14 +966,19 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings class ViewHolder extends RecyclerView.ViewHolder { View itemView; - TextView filenameView; + TextView filenameView, fileSizeView, fileDateView; ImageView iconView; ViewHolder(View itemView) { super(itemView); this.itemView = itemView; - this.filenameView = (TextView) itemView.findViewById(R.id.grid_item_label); - this.iconView = (ImageView) itemView.findViewById(R.id.grid_item_image); + filenameView = (TextView) itemView.findViewById(R.id.file_item_name); + iconView = (ImageView) itemView.findViewById(R.id.file_item_icon); + // Check if view mode is List, only then initialise Size and Date field + if (isViewModeList()) { + fileSizeView = (TextView) itemView.findViewById(R.id.file_item_size); + fileDateView = (TextView) itemView.findViewById(R.id.file_item_date); + } } } } |