Search in sources :

Example 1 with RichObject

use of com.owncloud.android.lib.resources.activities.model.RichObject in project android by nextcloud.

the class ActivityListAdapter method createThumbnailNew.

private ImageView createThumbnailNew(PreviewObject previewObject, List<RichObject> richObjectList) {
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(px, px);
    params.setMargins(10, 10, 10, 10);
    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(params);
    for (RichObject object : richObjectList) {
        int objectId = -1;
        try {
            objectId = Integer.parseInt(object.getId());
        } catch (NumberFormatException e) {
        // object.getId() can also be a string if RichObjects refers to an user
        }
        if (objectId == previewObject.getFileId()) {
            imageView.setOnClickListener(v -> activityListInterface.onActivityClicked(object));
            break;
        }
    }
    if (MimeTypeUtil.isImageOrVideo(previewObject.getMimeType())) {
        int placeholder;
        if (MimeTypeUtil.isImage(previewObject.getMimeType())) {
            placeholder = R.drawable.file_image;
        } else {
            placeholder = R.drawable.file_movie;
        }
        Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider.getUser(), clientFactory)).load(previewObject.getSource()).placeholder(placeholder).error(placeholder).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(imageView);
    } else {
        if (MimeTypeUtil.isFolder(previewObject.getMimeType())) {
            imageView.setImageDrawable(MimeTypeUtil.getDefaultFolderIcon(context));
        } else {
            imageView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(previewObject.getMimeType(), "", context));
        }
    }
    return imageView;
}
Also used : RichObject(com.owncloud.android.lib.resources.activities.model.RichObject) ImageView(android.widget.ImageView) CustomGlideStreamLoader(com.owncloud.android.utils.glide.CustomGlideStreamLoader) LinearLayout(android.widget.LinearLayout) TextPaint(android.text.TextPaint)

Example 2 with RichObject

use of com.owncloud.android.lib.resources.activities.model.RichObject in project android by nextcloud.

the class ActivityListAdapter method addClickablePart.

private SpannableStringBuilder addClickablePart(RichElement richElement) {
    String text = richElement.getRichSubject();
    SpannableStringBuilder ssb = new SpannableStringBuilder(text);
    int idx1 = text.indexOf('{');
    int idx2;
    while (idx1 != -1) {
        idx2 = text.indexOf('}', idx1) + 1;
        final String clickString = text.substring(idx1 + 1, idx2 - 1);
        final RichObject richObject = searchObjectByName(richElement.getRichObjectList(), clickString);
        if (richObject != null) {
            String name = richObject.getName();
            ssb.replace(idx1, idx2, name);
            text = ssb.toString();
            idx2 = idx1 + name.length();
            ssb.setSpan(new ClickableSpan() {

                @Override
                public void onClick(@NonNull View widget) {
                    activityListInterface.onActivityClicked(richObject);
                }

                @Override
                public void updateDrawState(@NonNull TextPaint ds) {
                    ds.setUnderlineText(false);
                }
            }, idx1, idx2, 0);
            ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), idx1, idx2, 0);
            ssb.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.text_color)), idx1, idx2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        idx1 = text.indexOf('{', idx2);
    }
    return ssb;
}
Also used : RichObject(com.owncloud.android.lib.resources.activities.model.RichObject) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) ClickableSpan(android.text.style.ClickableSpan) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SpannableStringBuilder(android.text.SpannableStringBuilder) TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint)

Aggregations

TextPaint (android.text.TextPaint)2 ImageView (android.widget.ImageView)2 RichObject (com.owncloud.android.lib.resources.activities.model.RichObject)2 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ClickableSpan (android.text.style.ClickableSpan)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 StyleSpan (android.text.style.StyleSpan)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 CustomGlideStreamLoader (com.owncloud.android.utils.glide.CustomGlideStreamLoader)1