use of com.amaze.filemanager.adapters.data.LayoutElementParcelable in project AmazeFileManager by TeamAmaze.
the class MainFragment method addTo.
// method to add search result entry to the LIST_ELEMENT arrayList
private LayoutElementParcelable addTo(HybridFileParcelable mFile) {
File f = new File(mFile.getPath());
String size = "";
if (!dataUtils.isFileHidden(mFile.getPath())) {
if (mFile.isDirectory()) {
size = "";
LayoutElementParcelable layoutElement = new LayoutElementParcelable(f.getPath(), mFile.getPermission(), mFile.getLink(), size, 0, true, false, mFile.getDate() + "", getBoolean(PREFERENCE_SHOW_THUMB));
layoutElement.setMode(mFile.getMode());
LIST_ELEMENTS.add(layoutElement);
folder_count++;
return layoutElement;
} else {
long longSize = 0;
try {
if (mFile.getSize() != -1) {
longSize = mFile.getSize();
size = Formatter.formatFileSize(getContext(), longSize);
} else {
size = "";
longSize = 0;
}
} catch (NumberFormatException e) {
// e.printStackTrace();
}
try {
LayoutElementParcelable layoutElement = new LayoutElementParcelable(f.getPath(), mFile.getPermission(), mFile.getLink(), size, longSize, false, false, mFile.getDate() + "", getBoolean(PREFERENCE_SHOW_THUMB));
layoutElement.setMode(mFile.getMode());
LIST_ELEMENTS.add(layoutElement);
file_count++;
return layoutElement;
} catch (Exception e) {
e.printStackTrace();
}
}
}
return null;
}
use of com.amaze.filemanager.adapters.data.LayoutElementParcelable in project AmazeFileManager by TeamAmaze.
the class GeneralDialogCreation method deleteFilesDialog.
@SuppressWarnings("ConstantConditions")
public static void deleteFilesDialog(final Context c, final ArrayList<LayoutElementParcelable> layoutElements, final MainActivity mainActivity, final List<LayoutElementParcelable> positions, AppTheme appTheme) {
final ArrayList<HybridFileParcelable> itemsToDelete = new ArrayList<>();
int accentColor = mainActivity.getColorPreference().getColor(ColorUsage.ACCENT);
// Build dialog with custom view layout and accent color.
MaterialDialog dialog = new MaterialDialog.Builder(c).title(c.getString(R.string.dialog_delete_title)).customView(R.layout.dialog_delete, true).theme(appTheme.getMaterialDialogTheme()).negativeText(c.getString(R.string.cancel).toUpperCase()).positiveText(c.getString(R.string.delete).toUpperCase()).positiveColor(accentColor).negativeColor(accentColor).onPositive((dialog1, which) -> {
Toast.makeText(c, c.getString(R.string.deleting), Toast.LENGTH_SHORT).show();
mainActivity.mainActivityHelper.deleteFiles(itemsToDelete);
}).build();
// Get views from custom layout to set text values.
final TextView categoryDirectories = (TextView) dialog.getCustomView().findViewById(R.id.category_directories);
final TextView categoryFiles = (TextView) dialog.getCustomView().findViewById(R.id.category_files);
final TextView listDirectories = (TextView) dialog.getCustomView().findViewById(R.id.list_directories);
final TextView listFiles = (TextView) dialog.getCustomView().findViewById(R.id.list_files);
final TextView total = (TextView) dialog.getCustomView().findViewById(R.id.total);
// Parse items to delete.
new AsyncTask<Void, Object, Void>() {
long sizeTotal = 0;
StringBuilder files = new StringBuilder();
StringBuilder directories = new StringBuilder();
int counterDirectories = 0;
int counterFiles = 0;
@Override
protected void onPreExecute() {
super.onPreExecute();
listFiles.setText(c.getString(R.string.loading));
listDirectories.setText(c.getString(R.string.loading));
total.setText(c.getString(R.string.loading));
}
@Override
protected Void doInBackground(Void... params) {
for (int i = 0; i < positions.size(); i++) {
final LayoutElementParcelable layoutElement = positions.get(i);
itemsToDelete.add(layoutElement.generateBaseFile());
// Build list of directories to delete.
if (layoutElement.isDirectory) {
// Don't add newline between category and list.
if (counterDirectories != 0) {
directories.append("\n");
}
long sizeDirectory = layoutElement.generateBaseFile().folderSize(c);
directories.append(++counterDirectories).append(". ").append(layoutElement.title).append(" (").append(Formatter.formatFileSize(c, sizeDirectory)).append(")");
sizeTotal += sizeDirectory;
// Build list of files to delete.
} else {
// Don't add newline between category and list.
if (counterFiles != 0) {
files.append("\n");
}
files.append(++counterFiles).append(". ").append(layoutElement.title).append(" (").append(layoutElement.size).append(")");
sizeTotal += layoutElement.longSize;
}
publishProgress(sizeTotal, counterFiles, counterDirectories, files, directories);
}
return null;
}
@Override
protected void onProgressUpdate(Object... result) {
super.onProgressUpdate(result);
int tempCounterFiles = (int) result[1];
int tempCounterDirectories = (int) result[2];
long tempSizeTotal = (long) result[0];
StringBuilder tempFilesStringBuilder = (StringBuilder) result[3];
StringBuilder tempDirectoriesStringBuilder = (StringBuilder) result[4];
updateViews(tempSizeTotal, tempFilesStringBuilder, tempDirectoriesStringBuilder, tempCounterFiles, tempCounterDirectories);
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
updateViews(sizeTotal, files, directories, counterFiles, counterDirectories);
}
private void updateViews(long tempSizeTotal, StringBuilder filesStringBuilder, StringBuilder directoriesStringBuilder, int... values) {
int tempCounterFiles = values[0];
int tempCounterDirectories = values[1];
// Hide category and list for directories when zero.
if (tempCounterDirectories == 0) {
if (tempCounterDirectories == 0) {
categoryDirectories.setVisibility(View.GONE);
listDirectories.setVisibility(View.GONE);
}
// Hide category and list for files when zero.
}
if (tempCounterFiles == 0) {
categoryFiles.setVisibility(View.GONE);
listFiles.setVisibility(View.GONE);
}
if (tempCounterDirectories != 0 || tempCounterFiles != 0) {
listDirectories.setText(directoriesStringBuilder);
if (listDirectories.getVisibility() != View.VISIBLE && tempCounterDirectories != 0)
listDirectories.setVisibility(View.VISIBLE);
listFiles.setText(filesStringBuilder);
if (listFiles.getVisibility() != View.VISIBLE && tempCounterFiles != 0)
listFiles.setVisibility(View.VISIBLE);
if (categoryDirectories.getVisibility() != View.VISIBLE && tempCounterDirectories != 0)
categoryDirectories.setVisibility(View.VISIBLE);
if (categoryFiles.getVisibility() != View.VISIBLE && tempCounterFiles != 0)
categoryFiles.setVisibility(View.VISIBLE);
}
// Show total size with at least one directory or file and size is not zero.
if (tempCounterFiles + tempCounterDirectories > 1 && tempSizeTotal > 0) {
StringBuilder builderTotal = new StringBuilder().append(c.getString(R.string.total)).append(" ").append(Formatter.formatFileSize(c, tempSizeTotal));
total.setText(builderTotal);
if (total.getVisibility() != View.VISIBLE)
total.setVisibility(View.VISIBLE);
} else {
total.setVisibility(View.GONE);
}
}
}.execute();
// Set category text color for Jelly Bean (API 16) and later.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
categoryDirectories.setTextColor(accentColor);
categoryFiles.setTextColor(accentColor);
}
// Show dialog on screen.
dialog.show();
}
use of com.amaze.filemanager.adapters.data.LayoutElementParcelable in project AmazeFileManager by TeamAmaze.
the class HybridFile method generateLayoutElement.
/**
* Generates a {@link LayoutElementParcelable} adapted compatible element.
* Currently supports only local filesystem
*/
public LayoutElementParcelable generateLayoutElement(boolean showThumbs) {
switch(mode) {
case FILE:
case ROOT:
File file = new File(path);
LayoutElementParcelable layoutElement;
if (isDirectory()) {
layoutElement = new LayoutElementParcelable(path, RootHelper.parseFilePermission(file), "", folderSize() + "", 0, true, false, file.lastModified() + "", showThumbs);
} else {
layoutElement = new LayoutElementParcelable(file.getPath(), RootHelper.parseFilePermission(file), file.getPath(), file.length() + "", file.length(), false, false, file.lastModified() + "", showThumbs);
}
layoutElement.setMode(mode);
return layoutElement;
default:
return null;
}
}
use of com.amaze.filemanager.adapters.data.LayoutElementParcelable in project AmazeFileManager by TeamAmaze.
the class RecyclerAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder vholder, int p) {
if (vholder instanceof ItemViewHolder) {
final ItemViewHolder holder = (ItemViewHolder) vholder;
final boolean isBackButton = getBoolean(PREFERENCE_SHOW_GOBACK_BUTTON) && p == 0;
if (isBackButton) {
holder.about.setVisibility(View.GONE);
}
if (mainFrag.IS_LIST) {
if (p == getItemCount() - 1) {
holder.rl.setMinimumHeight((int) minRowHeight);
if (itemsDigested.size() == (getBoolean(PREFERENCE_SHOW_GOBACK_BUTTON) ? 1 : 0))
holder.txtTitle.setText(R.string.nofiles);
else
holder.txtTitle.setText("");
return;
}
}
if (!this.stoppedAnimation && !itemsDigested.get(p).getAnimating()) {
animate(holder);
itemsDigested.get(p).setAnimate(true);
}
final LayoutElementParcelable rowItem = itemsDigested.get(p).elem;
if (mainFrag.IS_LIST) {
holder.rl.setOnClickListener(v -> {
mainFrag.onListItemClicked(isBackButton, vholder.getAdapterPosition(), rowItem, holder.checkImageView);
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.checkImageView.setBackground(new CircleGradientDrawable(accentColor, utilsProvider.getAppTheme(), mainFrag.getResources().getDisplayMetrics()));
} else {
holder.checkImageView.setBackgroundDrawable(new CircleGradientDrawable(accentColor, utilsProvider.getAppTheme(), mainFrag.getResources().getDisplayMetrics()));
}
holder.rl.setOnLongClickListener(p1 -> {
// check if the item on which action is performed is not the first {goback} item
if (!isBackButton) {
toggleChecked(vholder.getAdapterPosition(), holder.checkImageView);
}
return true;
});
holder.txtTitle.setText(rowItem.title);
holder.genericText.setText("");
if (holder.about != null) {
if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT))
holder.about.setColorFilter(grey_color);
showPopup(holder.about, rowItem, p);
}
holder.genericIcon.setOnClickListener(v -> {
int id = v.getId();
if (id == R.id.generic_icon || id == R.id.picture_icon || id == R.id.apk_icon) {
// TODO: transform icon on press to the properties dialog with animation
if (!isBackButton) {
toggleChecked(vholder.getAdapterPosition(), holder.checkImageView);
} else
mainFrag.goBack();
}
});
holder.pictureIcon.setOnClickListener(view -> {
if (!isBackButton) {
toggleChecked(vholder.getAdapterPosition(), holder.checkImageView);
} else
mainFrag.goBack();
});
holder.apkIcon.setOnClickListener(view -> {
if (!isBackButton) {
toggleChecked(vholder.getAdapterPosition(), holder.checkImageView);
} else
mainFrag.goBack();
});
// resetting icons visibility
holder.genericIcon.setVisibility(View.GONE);
holder.pictureIcon.setVisibility(View.GONE);
holder.apkIcon.setVisibility(View.GONE);
holder.checkImageView.setVisibility(View.INVISIBLE);
// pictureIcon is circular drawable
switch(rowItem.filetype) {
case Icons.IMAGE:
case Icons.VIDEO:
if (getBoolean(PREFERENCE_SHOW_THUMB)) {
if (getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES)) {
showThumbnailWithBackground(holder, rowItem.iconData, holder.pictureIcon, rowItem.iconData::setImageBroken);
} else {
showThumbnailWithBackground(holder, rowItem.iconData, holder.apkIcon, rowItem.iconData::setImageBroken);
}
}
break;
case Icons.APK:
if (getBoolean(PREFERENCE_SHOW_THUMB)) {
showThumbnailWithBackground(holder, rowItem.iconData, holder.apkIcon, rowItem.iconData::setImageBroken);
}
break;
case Icons.NOT_KNOWN:
holder.genericIcon.setVisibility(View.VISIBLE);
// if the file type is any unknown variable
String ext = !rowItem.isDirectory ? MimeTypes.getExtension(rowItem.title) : null;
if (ext != null && ext.trim().length() != 0) {
holder.genericText.setText(ext);
holder.genericIcon.setImageDrawable(null);
// holder.genericIcon.setVisibility(View.INVISIBLE);
} else {
// we could not find the extension, set a generic file type icon probably a directory
modelProvider.getPreloadRequestBuilder(rowItem.iconData).into(holder.genericIcon);
}
break;
case Icons.ENCRYPTED:
if (getBoolean(PREFERENCE_SHOW_THUMB)) {
holder.genericIcon.setVisibility(View.VISIBLE);
modelProvider.getPreloadRequestBuilder(rowItem.iconData).into(holder.genericIcon);
}
break;
default:
holder.genericIcon.setVisibility(View.VISIBLE);
modelProvider.getPreloadRequestBuilder(rowItem.iconData).into(holder.genericIcon);
break;
}
if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT)) {
holder.rl.setBackgroundResource(R.drawable.safr_ripple_white);
} else {
holder.rl.setBackgroundResource(R.drawable.safr_ripple_black);
}
holder.rl.setSelected(false);
if (itemsDigested.get(p).getChecked() == ListItem.CHECKED) {
holder.checkImageView.setVisibility(View.VISIBLE);
// so that user can still look at the thumbs even after selection
if ((rowItem.filetype != Icons.IMAGE && rowItem.filetype != Icons.APK && rowItem.filetype != Icons.VIDEO)) {
holder.apkIcon.setVisibility(View.GONE);
holder.pictureIcon.setVisibility(View.GONE);
holder.genericIcon.setVisibility(View.VISIBLE);
GradientDrawable gradientDrawable = (GradientDrawable) holder.genericIcon.getBackground();
gradientDrawable.setColor(goBackColor);
}
holder.rl.setSelected(true);
// holder.genericText.setText("");
} else {
holder.checkImageView.setVisibility(View.INVISIBLE);
if (!rowItem.iconData.isImageBroken()) {
GradientDrawable gradientDrawable = (GradientDrawable) holder.genericIcon.getBackground();
if (getBoolean(PREFERENCE_COLORIZE_ICONS)) {
if (rowItem.isDirectory) {
gradientDrawable.setColor(iconSkinColor);
} else {
ColorUtils.colorizeIcons(context, rowItem.filetype, gradientDrawable, iconSkinColor);
}
} else
gradientDrawable.setColor(iconSkinColor);
if (isBackButton) {
gradientDrawable.setColor(goBackColor);
}
}
}
if (getBoolean(PREFERENCE_SHOW_PERMISSIONS))
holder.perm.setText(rowItem.permissions);
if (getBoolean(PREFERENCE_SHOW_LAST_MODIFIED)) {
holder.date.setText(rowItem.date1);
} else {
holder.date.setVisibility(View.GONE);
}
if (isBackButton) {
holder.date.setText(rowItem.size);
holder.txtDesc.setText("");
} else if (getBoolean(PREFERENCE_SHOW_FILE_SIZE)) {
holder.txtDesc.setText(rowItem.size);
}
} else {
// view is a grid view
holder.checkImageViewGrid.setColorFilter(accentColor);
holder.rl.setOnClickListener(v -> {
mainFrag.onListItemClicked(isBackButton, vholder.getAdapterPosition(), rowItem, holder.checkImageViewGrid);
});
holder.rl.setOnLongClickListener(p1 -> {
if (!isBackButton) {
toggleChecked(vholder.getAdapterPosition(), holder.checkImageViewGrid);
}
return true;
});
holder.txtTitle.setText(rowItem.title);
holder.imageView1.setVisibility(View.INVISIBLE);
holder.genericIcon.setVisibility(View.VISIBLE);
holder.checkImageViewGrid.setVisibility(View.INVISIBLE);
((RoundedImageView) holder.genericIcon).setRelativeSize(1.25f, 1.25f);
GlideApp.with(mainFrag).load(rowItem.iconData.image).into(holder.genericIcon);
if (rowItem.filetype == Icons.IMAGE || rowItem.filetype == Icons.VIDEO) {
holder.imageView1.setVisibility(View.VISIBLE);
holder.imageView1.setImageDrawable(null);
if (utilsProvider.getAppTheme().equals(AppTheme.DARK) || utilsProvider.getAppTheme().equals(AppTheme.BLACK))
holder.imageView1.setBackgroundColor(Color.BLACK);
showRoundedThumbnail(holder, rowItem.iconData, holder.imageView1, rowItem.iconData::setImageBroken);
} else if (rowItem.filetype == Icons.APK) {
showRoundedThumbnail(holder, rowItem.iconData, holder.genericIcon, rowItem.iconData::setImageBroken);
}
if (holder.genericIcon.getVisibility() == View.VISIBLE) {
View iconBackground = getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES) ? holder.genericIcon : holder.iconLayout;
if (rowItem.isDirectory) {
iconBackground.setBackgroundColor(iconSkinColor);
} else {
switch(rowItem.filetype) {
case Icons.VIDEO:
iconBackground.setBackgroundColor(videoColor);
break;
case Icons.AUDIO:
iconBackground.setBackgroundColor(audioColor);
break;
case Icons.PDF:
iconBackground.setBackgroundColor(pdfColor);
break;
case Icons.CODE:
iconBackground.setBackgroundColor(codeColor);
break;
case Icons.TEXT:
iconBackground.setBackgroundColor(textColor);
break;
case Icons.COMPRESSED:
iconBackground.setBackgroundColor(archiveColor);
break;
case Icons.NOT_KNOWN:
iconBackground.setBackgroundColor(genericColor);
break;
case Icons.APK:
case Icons.IMAGE:
// While these are loading or if they fail, color has to be set (done in showRoundedThumbnail()).
break;
default:
iconBackground.setBackgroundColor(iconSkinColor);
break;
}
}
if (isBackButton) {
iconBackground.setBackgroundColor(goBackColor);
}
}
if (itemsDigested.get(p).getChecked() == ListItem.CHECKED) {
if (holder.genericIcon.getVisibility() == View.VISIBLE) {
View iconBackground = getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES) ? holder.genericIcon : holder.iconLayout;
iconBackground.setBackgroundColor(iconSkinColor);
// holder.genericIcon.setImageDrawable(main.getResources().getDrawable(R.drawable.abc_ic_cab_done_holo_dark));
}
holder.checkImageViewGrid.setVisibility(View.VISIBLE);
holder.rl.setBackgroundColor(Utils.getColor(context, R.color.item_background));
} else {
holder.checkImageViewGrid.setVisibility(View.INVISIBLE);
if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT))
holder.rl.setBackgroundResource(R.drawable.item_doc_grid);
else {
holder.rl.setBackgroundResource(R.drawable.ic_grid_card_background_dark);
holder.rl.findViewById(R.id.icon_frame).setBackgroundColor(Utils.getColor(context, R.color.icon_background_dark));
}
}
if (holder.about != null) {
if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT))
holder.about.setColorFilter(grey_color);
showPopup(holder.about, rowItem, p);
}
if (getBoolean(PREFERENCE_SHOW_LAST_MODIFIED))
holder.date.setText(rowItem.date1);
if (isBackButton) {
holder.date.setText(rowItem.size);
holder.txtDesc.setText("");
}
/*else if(main.SHOW_SIZE)
holder.txtDesc.setText(rowItem.getSize());
*/
if (getBoolean(PREFERENCE_SHOW_PERMISSIONS))
holder.perm.setText(rowItem.permissions);
}
}
}
use of com.amaze.filemanager.adapters.data.LayoutElementParcelable in project AmazeFileManager by TeamAmaze.
the class RecyclerAdapter method createHeaders.
public void createHeaders(boolean invalidate, List<IconDataParcelable> uris) {
boolean[] headers = new boolean[] { false, false };
for (int i = 0; i < itemsDigested.size(); i++) {
if (itemsDigested.get(i).elem != null) {
LayoutElementParcelable nextItem = itemsDigested.get(i).elem;
if (!headers[0] && nextItem.isDirectory) {
headers[0] = true;
itemsDigested.add(i, new ListItem(TYPE_HEADER_FOLDERS));
uris.add(i, null);
continue;
}
if (!headers[1] && !nextItem.isDirectory && !nextItem.title.equals(".") && !nextItem.title.equals("..")) {
headers[1] = true;
itemsDigested.add(i, new ListItem(TYPE_HEADER_FILES));
uris.add(i, null);
// leave this continue for symmetry
continue;
}
}
}
if (invalidate) {
notifyDataSetChanged();
}
}
Aggregations