couple more misc changes

This commit is contained in:
tibbi 2016-10-11 20:57:43 +02:00
parent 8b260a7c7b
commit 727acce7ff
8 changed files with 95 additions and 107 deletions

View file

@ -6,7 +6,6 @@ import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import android.widget.Toast;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -32,13 +31,4 @@ public class Utils {
final Matcher matcher = pattern.matcher(name);
return matcher.matches();
}
public static String formatSize(long size) {
if (size <= 0)
return "0 B";
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];
}
}

View file

@ -1,90 +0,0 @@
package com.simplemobiletools.filemanager.dialogs;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.TextView;
import com.simplemobiletools.filemanager.Config;
import com.simplemobiletools.filemanager.R;
import com.simplemobiletools.filemanager.Utils;
import com.simplemobiletools.filepicker.models.FileDirItem;
import java.io.File;
import java.util.Calendar;
import java.util.Locale;
public class PropertiesDialog extends DialogFragment {
private static FileDirItem mItem;
private static int mFilesCnt;
private static boolean mShowHidden;
public static PropertiesDialog newInstance(FileDirItem item) {
mItem = item;
mFilesCnt = 0;
return new PropertiesDialog();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
mShowHidden = Config.newInstance(getContext()).getShowHidden();
final int title = (mItem.isDirectory()) ? R.string.directory_properties : R.string.file_properties;
final View infoView = getActivity().getLayoutInflater().inflate(R.layout.item_properties, null);
((TextView) infoView.findViewById(R.id.properties_name)).setText(mItem.getName());
((TextView) infoView.findViewById(R.id.properties_path)).setText(mItem.getPath());
((TextView) infoView.findViewById(R.id.properties_size)).setText(getItemSize());
if (mItem.isDirectory()) {
infoView.findViewById(R.id.properties_files_count_label).setVisibility(View.VISIBLE);
infoView.findViewById(R.id.properties_files_count).setVisibility(View.VISIBLE);
((TextView) infoView.findViewById(R.id.properties_files_count)).setText(String.valueOf(mFilesCnt));
}
final File file = new File(mItem.getPath());
((TextView) infoView.findViewById(R.id.properties_last_modified)).setText(formatLastModified(file.lastModified()));
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getResources().getString(title));
builder.setView(infoView);
builder.setPositiveButton(R.string.smtfp_ok, null);
return builder.create();
}
private String getItemSize() {
if (mItem.isDirectory()) {
return Utils.formatSize(getDirectorySize(new File(mItem.getPath())));
}
return "";
//return Utils.getFormattedSize(mItem);
}
private String formatLastModified(long ts) {
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
cal.setTimeInMillis(ts);
return DateFormat.format("dd/MM/yyyy HH:mm", cal).toString();
}
private long getDirectorySize(File dir) {
if (dir.exists()) {
long size = 0;
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
size += getDirectorySize(files[i]);
} else {
size += files[i].length();
if ((!files[i].isHidden() && !dir.isHidden()) || mShowHidden)
mFilesCnt++;
}
}
return size;
}
return 0;
}
}

View file

@ -377,7 +377,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment
if (item == null)
return;
PropertiesDialog dialog = PropertiesDialog.newInstance(item);
PropertiesDialog dialog = PropertiesDialog.Companion.newInstance(item);
dialog.show(getFragmentManager(), "properties");
}

View file

@ -13,7 +13,7 @@ import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.extensions.formatSize
import com.simplemobiletools.filemanager.extensions.getColoredIcon
import com.simplemobiletools.filepicker.models.FileDirItem
import kotlinx.android.synthetic.main.smtfp_list_item.view.*
import kotlinx.android.synthetic.main.list_item.view.*
class ItemsAdapter(context: Context, private val mItems: List<FileDirItem>) : BaseAdapter() {
private val mInflater: LayoutInflater
@ -33,7 +33,7 @@ class ItemsAdapter(context: Context, private val mItems: List<FileDirItem>) : Ba
var view = convertView
val viewHolder: ViewHolder
if (view == null) {
view = mInflater.inflate(R.layout.smtfp_list_item, parent, false)
view = mInflater.inflate(R.layout.list_item, parent, false)
viewHolder = ViewHolder(view)
view!!.tag = viewHolder
} else {

View file

@ -0,0 +1,88 @@
package com.simplemobiletools.filemanager.dialogs
import android.app.Dialog
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.support.v7.app.AlertDialog
import android.text.format.DateFormat
import android.view.View
import android.widget.TextView
import com.simplemobiletools.filemanager.Config
import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.extensions.formatSize
import com.simplemobiletools.filepicker.models.FileDirItem
import java.io.File
import java.util.*
class PropertiesDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
mShowHidden = Config.newInstance(context).showHidden
val title = if (mItem!!.isDirectory) R.string.directory_properties else R.string.file_properties
val infoView = activity.layoutInflater.inflate(R.layout.item_properties, null)
(infoView.findViewById(R.id.properties_name) as TextView).text = mItem!!.name
(infoView.findViewById(R.id.properties_path) as TextView).text = mItem!!.path
(infoView.findViewById(R.id.properties_size) as TextView).text = getItemSize()
if (mItem!!.isDirectory) {
infoView.findViewById(R.id.properties_files_count_label).visibility = View.VISIBLE
infoView.findViewById(R.id.properties_files_count).visibility = View.VISIBLE
(infoView.findViewById(R.id.properties_files_count) as TextView).text = mFilesCnt.toString()
}
val file = File(mItem!!.path)
(infoView.findViewById(R.id.properties_last_modified) as TextView).text = formatLastModified(file.lastModified())
val builder = AlertDialog.Builder(context)
builder.setTitle(resources.getString(title))
builder.setView(infoView)
builder.setPositiveButton(R.string.smtfp_ok, null)
return builder.create()
}
fun getItemSize(): String {
if (mItem!!.isDirectory) {
return getDirectorySize(File(mItem!!.path)).formatSize()
}
return ""
}
private fun formatLastModified(ts: Long): String {
val cal = Calendar.getInstance(Locale.ENGLISH)
cal.timeInMillis = ts
return DateFormat.format("dd/MM/yyyy HH:mm", cal).toString()
}
private fun getDirectorySize(dir: File): Long {
if (dir.exists()) {
var size: Long = 0
val files = dir.listFiles()
for (i in files.indices) {
if (files[i].isDirectory) {
size += getDirectorySize(files[i])
} else {
size += files[i].length()
if (!files[i].isHidden && !dir.isHidden || mShowHidden)
mFilesCnt++
}
}
return size
}
return 0
}
companion object {
private var mItem: FileDirItem? = null
private var mFilesCnt: Int = 0
private var mShowHidden: Boolean = false
fun newInstance(item: FileDirItem): PropertiesDialog {
mItem = item
mFilesCnt = 0
return PropertiesDialog()
}
}
}

View file

@ -13,7 +13,7 @@ import com.simplemobiletools.filemanager.Utils
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.fragments.ItemsFragment
import com.simplemobiletools.filepicker.models.FileDirItem
import kotlinx.android.synthetic.main.smtfp_directory_picker.view.*
import kotlinx.android.synthetic.main.directory_picker.view.*
import java.io.File
import java.util.*
import kotlin.comparisons.compareBy

View file

@ -25,8 +25,8 @@ class ItemsAdapter(context: Context, private val mItems: List<FileDirItem>) : Ba
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mRes = context.resources
mDirectoryBmp = mRes.getColoredIcon(R.color.smtfp_thumbnail_grey, R.mipmap.directory)
mFileBmp = mRes.getColoredIcon(R.color.smtfp_thumbnail_grey, R.mipmap.file)
mDirectoryBmp = mRes.getColoredIcon(R.color.smtfp_thumbnail_grey, R.mipmap.smtfp_directory)
mFileBmp = mRes.getColoredIcon(R.color.smtfp_thumbnail_grey, R.mipmap.smtfp_file)
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {

View file

@ -2,7 +2,7 @@
<dimen name="smtfp_activity_margin">16dp</dimen>
<dimen name="smtfp_small_margin">6dp</dimen>
<dimen name="smtfp_medium_margin">10dp</dimen>
<dimen name="icon_size">48dp</dimen>
<dimen name="smtfp_icon_size">48dp</dimen>
<dimen name="smtfp_details_text_size">12sp</dimen>
<dimen name="smtfp_normal_text_size">14sp</dimen>