convert FileDirItem to kotlin

This commit is contained in:
tibbi 2016-09-08 22:00:52 +02:00
parent de71cef1d2
commit bb371a3cc9
6 changed files with 26 additions and 66 deletions

View File

@ -49,7 +49,7 @@ public class ItemsAdapter extends BaseAdapter {
final FileDirItem item = mItems.get(position); final FileDirItem item = mItems.get(position);
viewHolder.name.setText(item.getName()); viewHolder.name.setText(item.getName());
if (item.getIsDirectory()) { if (item.isDirectory()) {
viewHolder.icon.setImageBitmap(mDirectoryBmp); viewHolder.icon.setImageBitmap(mDirectoryBmp);
viewHolder.details.setText(getChildrenCnt(item)); viewHolder.details.setText(getChildrenCnt(item));
} else { } else {

View File

@ -31,14 +31,14 @@ public class PropertiesDialog extends DialogFragment {
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
mShowHidden = Config.newInstance(getContext()).getShowHidden(); mShowHidden = Config.newInstance(getContext()).getShowHidden();
final int title = (mItem.getIsDirectory()) ? R.string.directory_properties : R.string.file_properties; final int title = (mItem.isDirectory()) ? R.string.directory_properties : R.string.file_properties;
final View infoView = getActivity().getLayoutInflater().inflate(R.layout.item_properties, null); 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_name)).setText(mItem.getName());
((TextView) infoView.findViewById(R.id.properties_path)).setText(mItem.getPath()); ((TextView) infoView.findViewById(R.id.properties_path)).setText(mItem.getPath());
((TextView) infoView.findViewById(R.id.properties_size)).setText(getItemSize()); ((TextView) infoView.findViewById(R.id.properties_size)).setText(getItemSize());
if (mItem.getIsDirectory()) { if (mItem.isDirectory()) {
infoView.findViewById(R.id.properties_files_count_label).setVisibility(View.VISIBLE); infoView.findViewById(R.id.properties_files_count_label).setVisibility(View.VISIBLE);
infoView.findViewById(R.id.properties_files_count).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)); ((TextView) infoView.findViewById(R.id.properties_files_count)).setText(String.valueOf(mFilesCnt));
@ -56,7 +56,7 @@ public class PropertiesDialog extends DialogFragment {
} }
private String getItemSize() { private String getItemSize() {
if (mItem.getIsDirectory()) { if (mItem.isDirectory()) {
return Utils.formatSize(directorySize(new File(mItem.getPath()))); return Utils.formatSize(directorySize(new File(mItem.getPath())));
} }

View File

@ -53,7 +53,7 @@ class SelectFolderDialog : DialogFragment() {
return return
} }
items = items.sortedWith(compareBy({ !it.isDirectory }, { it.name.toLowerCase() })) items = items.sortedWith(compareBy({ !it.isDirectory }, { it.name }))
val adapter = ItemsAdapter(context, items) val adapter = ItemsAdapter(context, items)
dialog.directory_picker_list.adapter = adapter dialog.directory_picker_list.adapter = adapter

View File

@ -173,7 +173,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment
@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);
if (item.getIsDirectory()) { if (item.isDirectory()) {
if (mListener != null) if (mListener != null)
mListener.itemClicked(item); mListener.itemClicked(item);
} else { } else {
@ -389,7 +389,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment
final EditText itemName = (EditText) renameView.findViewById(R.id.item_name); final EditText itemName = (EditText) renameView.findViewById(R.id.item_name);
itemName.setText(item.getName()); itemName.setText(item.getName());
final int title = (item.getIsDirectory()) ? R.string.rename_directory : R.string.rename_file; final int title = (item.isDirectory()) ? R.string.rename_directory : R.string.rename_file;
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getResources().getString(title)); builder.setTitle(getResources().getString(title));
builder.setView(renameView); builder.setView(renameView);

View File

@ -1,59 +0,0 @@
package com.simplemobiletools.filemanager.models;
public class FileDirItem implements Comparable {
private final String mPath;
private final String mName;
private final boolean mIsDirectory;
private final int mChildren;
private final long mSize;
public FileDirItem(String path, String name, boolean isDirectory, int children, long size) {
mPath = path;
mName = name;
mIsDirectory = isDirectory;
mChildren = children;
mSize = size;
}
public String getPath() {
return mPath;
}
public String getName() {
return mName;
}
public boolean getIsDirectory() {
return mIsDirectory;
}
public int getChildren() {
return mChildren;
}
public long getSize() {
return mSize;
}
@Override
public int compareTo(Object object) {
final FileDirItem item = (FileDirItem) object;
if (mIsDirectory && !item.getIsDirectory()) {
return -1;
} else if (!mIsDirectory && item.getIsDirectory()) {
return 1;
}
return mName.compareToIgnoreCase(item.getName());
}
@Override
public String toString() {
return "FileDirItem{" +
"name=" + getName() +
", isDirectory=" + getIsDirectory() +
", path=" + getPath() +
", children=" + getChildren() +
", size=" + getSize() +"}";
}
}

View File

@ -0,0 +1,19 @@
package com.simplemobiletools.filemanager.models
class FileDirItem(val path: String, val name: String, val isDirectory: Boolean, val children: Int, val size: Long) :
Comparable<FileDirItem> {
override fun compareTo(other: FileDirItem): Int {
if (isDirectory && !other.isDirectory) {
return -1
} else if (!isDirectory && other.isDirectory) {
return 1
}
return name.compareTo(other.name)
}
override fun toString(): String {
return "FileDirItem{name=$name, isDirectory=$isDirectory, path=$path, children=$children, size=$size}"
}
}