diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Utils.java b/app/src/main/java/com/simplemobiletools/filemanager/Utils.java index 9a4451be..8b2408b9 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/Utils.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/Utils.java @@ -3,6 +3,14 @@ package com.simplemobiletools.filemanager; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.support.v4.content.ContextCompat; import android.widget.Toast; @@ -22,4 +30,16 @@ public class Utils { public static boolean hasStoragePermission(Context cxt) { return ContextCompat.checkSelfPermission(cxt, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; } + + public static Bitmap getColoredIcon(Resources res, int newColor, int id) { + final BitmapFactory.Options options = new BitmapFactory.Options(); + options.inMutable = true; + final Bitmap bmp = BitmapFactory.decodeResource(res, id, options); + final Paint paint = new Paint(); + final ColorFilter filter = new PorterDuffColorFilter(newColor, PorterDuff.Mode.SRC_IN); + paint.setColorFilter(filter); + final Canvas canvas = new Canvas(bmp); + canvas.drawBitmap(bmp, 0, 0, paint); + return bmp; + } } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java b/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java index 5d9e393a..00bd44fd 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java @@ -1,13 +1,17 @@ package com.simplemobiletools.filemanager.adapters; import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +import android.widget.ImageView; import android.widget.TextView; import com.simplemobiletools.filemanager.R; +import com.simplemobiletools.filemanager.Utils; import com.simplemobiletools.filemanager.models.FileDirItem; import java.util.List; @@ -18,10 +22,16 @@ import butterknife.ButterKnife; public class ItemsAdapter extends BaseAdapter { private final List mItems; private final LayoutInflater mInflater; + private final Bitmap mFileBmp; + private final Bitmap mDirectoryBmp; public ItemsAdapter(Context context, List items) { mItems = items; mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + final Resources res = context.getResources(); + mDirectoryBmp = Utils.getColoredIcon(res, res.getColor(R.color.lightGrey), R.mipmap.directory); + mFileBmp = Utils.getColoredIcon(res, res.getColor(R.color.lightGrey), R.mipmap.file); } @Override @@ -38,6 +48,12 @@ public class ItemsAdapter extends BaseAdapter { final FileDirItem item = mItems.get(position); viewHolder.name.setText(item.getName()); + if (item.getIsDirectory()) { + viewHolder.icon.setImageBitmap(mDirectoryBmp); + } else { + viewHolder.icon.setImageBitmap(mFileBmp); + } + return convertView; } @@ -56,14 +72,9 @@ public class ItemsAdapter extends BaseAdapter { return 0; } - public void updateItems(List newItems) { - mItems.clear(); - mItems.addAll(newItems); - notifyDataSetChanged(); - } - static class ViewHolder { @BindView(R.id.item_name) TextView name; + @BindView(R.id.item_icon) ImageView icon; public ViewHolder(View view) { ButterKnife.bind(this, view); diff --git a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java index b2bf9c66..38af6b3e 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java @@ -73,7 +73,8 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad public void onItemClick(AdapterView parent, View view, int position, long id) { final FileDirItem item = mItems.get(position); if (item.getIsDirectory()) { - mListener.itemClicked(item.getPath()); + if (mListener != null) + mListener.itemClicked(item.getPath()); } else { final String path = item.getPath(); final File file = new File(path); diff --git a/app/src/main/res/layout/list_item.xml b/app/src/main/res/layout/list_item.xml index cd8b3c0b..afc3f13e 100644 --- a/app/src/main/res/layout/list_item.xml +++ b/app/src/main/res/layout/list_item.xml @@ -4,13 +4,25 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingBottom="@dimen/activity_margin" - android:paddingRight="@dimen/activity_margin" - android:paddingTop="@dimen/activity_margin"> + android:paddingRight="@dimen/activity_margin"> + + + android:layout_height="match_parent" + android:layout_alignBottom="@+id/item_icon" + android:layout_alignTop="@+id/item_icon" + android:layout_toRightOf="@+id/item_icon" + android:gravity="center_vertical" + android:paddingLeft="@dimen/medium_margin" + android:text="Directory"/> diff --git a/app/src/main/res/mipmap-hdpi/directory.png b/app/src/main/res/mipmap-hdpi/directory.png new file mode 100644 index 00000000..02ea533a Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/directory.png differ diff --git a/app/src/main/res/mipmap-hdpi/file.png b/app/src/main/res/mipmap-hdpi/file.png new file mode 100644 index 00000000..84755e48 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/file.png differ diff --git a/app/src/main/res/mipmap-mdpi/directory.png b/app/src/main/res/mipmap-mdpi/directory.png new file mode 100644 index 00000000..831d723b Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/directory.png differ diff --git a/app/src/main/res/mipmap-mdpi/file.png b/app/src/main/res/mipmap-mdpi/file.png new file mode 100644 index 00000000..b51ce3ed Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/file.png differ diff --git a/app/src/main/res/mipmap-xhdpi/directory.png b/app/src/main/res/mipmap-xhdpi/directory.png new file mode 100644 index 00000000..71a5a137 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/directory.png differ diff --git a/app/src/main/res/mipmap-xhdpi/file.png b/app/src/main/res/mipmap-xhdpi/file.png new file mode 100644 index 00000000..798ebd4e Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/file.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/directory.png b/app/src/main/res/mipmap-xxhdpi/directory.png new file mode 100644 index 00000000..b93d5a1e Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/directory.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/file.png b/app/src/main/res/mipmap-xxhdpi/file.png new file mode 100644 index 00000000..f3e153b4 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/file.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/directory.png b/app/src/main/res/mipmap-xxxhdpi/directory.png new file mode 100644 index 00000000..a1afbe9d Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/directory.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/file.png b/app/src/main/res/mipmap-xxxhdpi/file.png new file mode 100644 index 00000000..5bd56903 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/file.png differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ca8ad635..b95ecaad 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,6 @@ #fff68630 #ffe27725 @color/colorPrimary + + #33000000 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index a8c097c9..4edf4c29 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,6 @@ 16dp 14sp + 8dp + 44dp