display some details at the files and directories
This commit is contained in:
parent
ef4d505b6f
commit
5633bfcbc2
|
@ -34,12 +34,13 @@ public class Utils {
|
||||||
return ContextCompat.checkSelfPermission(cxt, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
|
return ContextCompat.checkSelfPermission(cxt, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getColoredIcon(Resources res, int newColor, int id) {
|
public static Bitmap getColoredIcon(Resources res, int colorId, int id) {
|
||||||
|
final int color = res.getColor(colorId);
|
||||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inMutable = true;
|
options.inMutable = true;
|
||||||
final Bitmap bmp = BitmapFactory.decodeResource(res, id, options);
|
final Bitmap bmp = BitmapFactory.decodeResource(res, id, options);
|
||||||
final Paint paint = new Paint();
|
final Paint paint = new Paint();
|
||||||
final ColorFilter filter = new PorterDuffColorFilter(newColor, PorterDuff.Mode.SRC_IN);
|
final ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||||
paint.setColorFilter(filter);
|
paint.setColorFilter(filter);
|
||||||
final Canvas canvas = new Canvas(bmp);
|
final Canvas canvas = new Canvas(bmp);
|
||||||
canvas.drawBitmap(bmp, 0, 0, paint);
|
canvas.drawBitmap(bmp, 0, 0, paint);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.simplemobiletools.filemanager.R;
|
||||||
import com.simplemobiletools.filemanager.Utils;
|
import com.simplemobiletools.filemanager.Utils;
|
||||||
import com.simplemobiletools.filemanager.models.FileDirItem;
|
import com.simplemobiletools.filemanager.models.FileDirItem;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
|
@ -24,14 +25,15 @@ public class ItemsAdapter extends BaseAdapter {
|
||||||
private final LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
private final Bitmap mFileBmp;
|
private final Bitmap mFileBmp;
|
||||||
private final Bitmap mDirectoryBmp;
|
private final Bitmap mDirectoryBmp;
|
||||||
|
private final Resources mRes;
|
||||||
|
|
||||||
public ItemsAdapter(Context context, List<FileDirItem> items) {
|
public ItemsAdapter(Context context, List<FileDirItem> items) {
|
||||||
mItems = items;
|
mItems = items;
|
||||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
|
||||||
final Resources res = context.getResources();
|
mRes = context.getResources();
|
||||||
mDirectoryBmp = Utils.getColoredIcon(res, res.getColor(R.color.lightGrey), R.mipmap.directory);
|
mDirectoryBmp = Utils.getColoredIcon(mRes, R.color.lightGrey, R.mipmap.directory);
|
||||||
mFileBmp = Utils.getColoredIcon(res, res.getColor(R.color.lightGrey), R.mipmap.file);
|
mFileBmp = Utils.getColoredIcon(mRes, R.color.lightGrey, R.mipmap.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,13 +52,29 @@ public class ItemsAdapter extends BaseAdapter {
|
||||||
|
|
||||||
if (item.getIsDirectory()) {
|
if (item.getIsDirectory()) {
|
||||||
viewHolder.icon.setImageBitmap(mDirectoryBmp);
|
viewHolder.icon.setImageBitmap(mDirectoryBmp);
|
||||||
|
viewHolder.details.setText(getChildrenCnt(item));
|
||||||
} else {
|
} else {
|
||||||
viewHolder.icon.setImageBitmap(mFileBmp);
|
viewHolder.icon.setImageBitmap(mFileBmp);
|
||||||
|
viewHolder.details.setText(getFormattedSize(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getChildrenCnt(FileDirItem item) {
|
||||||
|
final int children = item.getChildren();
|
||||||
|
return mRes.getQuantityString(R.plurals.items, children, children);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFormattedSize(FileDirItem item) {
|
||||||
|
final long size = item.getSize();
|
||||||
|
if (size <= 0)
|
||||||
|
return "0";
|
||||||
|
final String[] units = {"B", "kB", "MB", "GB", "TB"};
|
||||||
|
final int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
|
||||||
|
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return mItems.size();
|
return mItems.size();
|
||||||
|
@ -75,6 +93,7 @@ public class ItemsAdapter extends BaseAdapter {
|
||||||
static class ViewHolder {
|
static class ViewHolder {
|
||||||
@BindView(R.id.item_name) TextView name;
|
@BindView(R.id.item_name) TextView name;
|
||||||
@BindView(R.id.item_icon) ImageView icon;
|
@BindView(R.id.item_icon) ImageView icon;
|
||||||
|
@BindView(R.id.item_details) TextView details;
|
||||||
|
|
||||||
public ViewHolder(View view) {
|
public ViewHolder(View view) {
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
|
@ -126,11 +126,18 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
||||||
if (mToBeDeleted.contains(curPath))
|
if (mToBeDeleted.contains(curPath))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
items.add(new FileDirItem(curPath, curName, file.isDirectory()));
|
int children = getChildren(file);
|
||||||
|
long size = file.length();
|
||||||
|
|
||||||
|
items.add(new FileDirItem(curPath, curName, file.isDirectory(), children, size));
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getChildren(File file) {
|
||||||
|
return (file.isDirectory()) ? file.listFiles().length : 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
final FileDirItem item = mItems.get(position);
|
final FileDirItem item = mItems.get(position);
|
||||||
|
|
|
@ -4,11 +4,15 @@ public class FileDirItem implements Comparable {
|
||||||
private final String mPath;
|
private final String mPath;
|
||||||
private final String mName;
|
private final String mName;
|
||||||
private final boolean mIsDirectory;
|
private final boolean mIsDirectory;
|
||||||
|
private final int mChildren;
|
||||||
|
private final long mSize;
|
||||||
|
|
||||||
public FileDirItem(String path, String name, boolean isDirectory) {
|
public FileDirItem(String path, String name, boolean isDirectory, int children, long size) {
|
||||||
mPath = path;
|
mPath = path;
|
||||||
mName = name;
|
mName = name;
|
||||||
mIsDirectory = isDirectory;
|
mIsDirectory = isDirectory;
|
||||||
|
mChildren = children;
|
||||||
|
mSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
|
@ -23,6 +27,14 @@ public class FileDirItem implements Comparable {
|
||||||
return mIsDirectory;
|
return mIsDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getChildren() {
|
||||||
|
return mChildren;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSize() {
|
||||||
|
return mSize;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Object object) {
|
public int compareTo(Object object) {
|
||||||
final FileDirItem item = (FileDirItem) object;
|
final FileDirItem item = (FileDirItem) object;
|
||||||
|
@ -40,6 +52,8 @@ public class FileDirItem implements Comparable {
|
||||||
return "FileDirItem{" +
|
return "FileDirItem{" +
|
||||||
"name=" + getName() +
|
"name=" + getName() +
|
||||||
", isDirectory=" + getIsDirectory() +
|
", isDirectory=" + getIsDirectory() +
|
||||||
", path=" + getPath() + "}";
|
", path=" + getPath() +
|
||||||
|
", children=" + getChildren() +
|
||||||
|
", size=" + getSize() +"}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,22 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/item_name"
|
android:id="@+id/item_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignBottom="@+id/item_icon"
|
|
||||||
android:layout_alignTop="@+id/item_icon"
|
android:layout_alignTop="@+id/item_icon"
|
||||||
android:layout_toRightOf="@+id/item_icon"
|
android:layout_toRightOf="@+id/item_icon"
|
||||||
android:gravity="center_vertical"
|
android:paddingLeft="@dimen/small_margin"
|
||||||
android:paddingLeft="@dimen/medium_margin"
|
android:paddingTop="@dimen/small_margin"
|
||||||
android:text="Directory"/>
|
android:text="Directory"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/item_details"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/item_name"
|
||||||
|
android:layout_toRightOf="@+id/item_icon"
|
||||||
|
android:paddingLeft="@dimen/small_margin"
|
||||||
|
android:text="1 KB"
|
||||||
|
android:textColor="@color/details_grey"
|
||||||
|
android:textSize="@dimen/details_text_size"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
|
@ -7,4 +7,5 @@
|
||||||
<color name="lightGrey">#33000000</color>
|
<color name="lightGrey">#33000000</color>
|
||||||
<color name="pressed_item_foreground">#08000000</color>
|
<color name="pressed_item_foreground">#08000000</color>
|
||||||
<color name="activated_item_foreground">#11000000</color>
|
<color name="activated_item_foreground">#11000000</color>
|
||||||
|
<color name="details_grey">#33000000</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="activity_margin">16dp</dimen>
|
<dimen name="activity_margin">16dp</dimen>
|
||||||
|
<dimen name="small_margin">6dp</dimen>
|
||||||
<dimen name="medium_margin">10dp</dimen>
|
<dimen name="medium_margin">10dp</dimen>
|
||||||
<dimen name="icon_size">48dp</dimen>
|
<dimen name="icon_size">48dp</dimen>
|
||||||
<dimen name="social_padding">8dp</dimen>
|
<dimen name="social_padding">8dp</dimen>
|
||||||
<dimen name="social_logo">40dp</dimen>
|
<dimen name="social_logo">40dp</dimen>
|
||||||
<dimen name="settings_padding">8dp</dimen>
|
<dimen name="settings_padding">8dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="details_text_size">12sp</dimen>
|
||||||
<dimen name="normal_text_size">14sp</dimen>
|
<dimen name="normal_text_size">14sp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -19,6 +19,11 @@
|
||||||
<item quantity="other">%1$d items deleted</item>
|
<item quantity="other">%1$d items deleted</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
|
<plurals name="items">
|
||||||
|
<item quantity="one">1 item</item>
|
||||||
|
<item quantity="other">%1$d items</item>
|
||||||
|
</plurals>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">About</string>
|
<string name="about">About</string>
|
||||||
<string name="website">More simple apps and source code at:\nhttp://simplemobiletools.com</string>
|
<string name="website">More simple apps and source code at:\nhttp://simplemobiletools.com</string>
|
||||||
|
|
Loading…
Reference in New Issue