use of com.amaze.filemanager.ui.views.CircleGradientDrawable 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.ui.views.CircleGradientDrawable in project AmazeFileManager by TeamAmaze.
the class CompressedExplorerAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final CompressedItemViewHolder holder, int position) {
if (!stoppedAnimation) {
animate(holder);
}
final CompressedObjectParcelable rowItem = items.get(position);
GradientDrawable gradientDrawable = (GradientDrawable) holder.genericIcon.getBackground();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.checkImageView.setBackground(new CircleGradientDrawable(compressedExplorerFragment.accentColor, utilsProvider.getAppTheme(), compressedExplorerFragment.getResources().getDisplayMetrics()));
} else
holder.checkImageView.setBackgroundDrawable(new CircleGradientDrawable(compressedExplorerFragment.accentColor, utilsProvider.getAppTheme(), compressedExplorerFragment.getResources().getDisplayMetrics()));
if (rowItem.type == CompressedObjectParcelable.TYPE_GOBACK) {
GlideApp.with(compressedExplorerFragment).load(R.drawable.ic_arrow_left_white_24dp).into(holder.genericIcon);
gradientDrawable.setColor(Utils.getColor(context, R.color.goback_item));
holder.txtTitle.setText("..");
holder.txtDesc.setText("");
holder.date.setText(R.string.goback);
} else {
GlideApp.with(compressedExplorerFragment).load(rowItem.iconData.image).into(holder.genericIcon);
final StringBuilder stringBuilder = new StringBuilder(rowItem.name);
if (compressedExplorerFragment.showLastModified)
holder.date.setText(Utils.getDate(rowItem.date, compressedExplorerFragment.year));
if (rowItem.directory) {
holder.genericIcon.setImageDrawable(folder);
gradientDrawable.setColor(Color.parseColor(compressedExplorerFragment.iconskin));
if (stringBuilder.toString().length() > 0) {
stringBuilder.deleteCharAt(rowItem.name.length() - 1);
try {
holder.txtTitle.setText(stringBuilder.toString().substring(stringBuilder.toString().lastIndexOf("/") + 1));
} catch (Exception e) {
holder.txtTitle.setText(rowItem.name.substring(0, rowItem.name.lastIndexOf("/")));
}
}
} else {
if (compressedExplorerFragment.showSize)
holder.txtDesc.setText(Formatter.formatFileSize(context, rowItem.size));
holder.txtTitle.setText(rowItem.name.substring(rowItem.name.lastIndexOf("/") + 1));
if (compressedExplorerFragment.coloriseIcons) {
ColorUtils.colorizeIcons(context, rowItem.filetype, gradientDrawable, Color.parseColor(compressedExplorerFragment.iconskin));
} else
gradientDrawable.setColor(Color.parseColor(compressedExplorerFragment.iconskin));
}
}
holder.rl.setOnLongClickListener(view -> {
if (rowItem.type != CompressedObjectParcelable.TYPE_GOBACK) {
toggleChecked(position, holder.checkImageView);
}
return true;
});
holder.genericIcon.setOnClickListener(view -> {
if (rowItem.type != CompressedObjectParcelable.TYPE_GOBACK) {
toggleChecked(position, holder.checkImageView);
} else {
compressedExplorerFragment.goBack();
}
});
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 (itemsChecked[position]) {
// holder.genericIcon.setImageDrawable(compressedExplorerFragment.getResources().getDrawable(R.drawable.abc_ic_cab_done_holo_dark));
holder.checkImageView.setVisibility(View.VISIBLE);
gradientDrawable.setColor(Utils.getColor(context, R.color.goback_item));
holder.rl.setSelected(true);
} else
holder.checkImageView.setVisibility(View.INVISIBLE);
holder.rl.setOnClickListener(p1 -> {
if (rowItem.type == CompressedObjectParcelable.TYPE_GOBACK)
compressedExplorerFragment.goBack();
else {
if (compressedExplorerFragment.selection) {
toggleChecked(position, holder.checkImageView);
} else {
final StringBuilder stringBuilder = new StringBuilder(rowItem.name);
if (rowItem.directory)
stringBuilder.deleteCharAt(rowItem.name.length() - 1);
if (rowItem.directory) {
compressedExplorerFragment.changePath(stringBuilder.toString());
} else {
String fileName = compressedExplorerFragment.compressedFile.getName().substring(0, compressedExplorerFragment.compressedFile.getName().lastIndexOf("."));
String archiveCacheDirPath = compressedExplorerFragment.getActivity().getExternalCacheDir().getPath() + CompressedHelper.SEPARATOR + fileName;
HybridFileParcelable file = new HybridFileParcelable(archiveCacheDirPath + CompressedHelper.SEPARATOR + rowItem.name.replaceAll("\\\\", CompressedHelper.SEPARATOR));
file.setMode(OpenMode.FILE);
// this file will be opened once service finishes up it's extraction
compressedExplorerFragment.files.add(file);
// setting flag for binder to know
compressedExplorerFragment.isOpen = true;
Toast.makeText(compressedExplorerFragment.getContext(), compressedExplorerFragment.getContext().getResources().getString(R.string.please_wait), Toast.LENGTH_SHORT).show();
decompressor.decompress(compressedExplorerFragment.getActivity().getExternalCacheDir().getPath(), new String[] { rowItem.name });
}
}
}
});
}
Aggregations