blob: 1d7307ccd04ff3a4f7b5920990a442fe6640f290 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package it.niedermann.nextcloud.deck.ui.attachments;
import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import java.util.List;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.databinding.ItemAttachmentBinding;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.util.AttachmentUtil;
public class AttachmentAdapter extends RecyclerView.Adapter<AttachmentAdapter.AttachmentViewHolder> {
private final Account account;
private final long cardRemoteId;
@NonNull
private List<Attachment> attachments;
private Context context;
public AttachmentAdapter(@NonNull Account account, long cardRemoteId, @NonNull List<Attachment> attachments) {
super();
this.attachments = attachments;
this.account = account;
this.cardRemoteId = cardRemoteId;
}
@NonNull
@Override
public AttachmentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
this.context = parent.getContext();
return new AttachmentViewHolder(ItemAttachmentBinding.inflate(LayoutInflater.from(context), parent, false));
}
@Override
public void onBindViewHolder(@NonNull AttachmentViewHolder holder, int position) {
Attachment attachment = attachments.get(position);
String uri = AttachmentUtil.getUrl(account.getUrl(), cardRemoteId, attachment.getId());
if (attachment.getMimetype() != null) {
if (attachment.getMimetype().startsWith("image")) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
holder.binding.preview.setTransitionName(context.getString(R.string.transition_attachment_preview, String.valueOf(attachment.getLocalId())));
}
holder.binding.preview.setImageResource(R.drawable.ic_image_grey600_24dp);
Glide.with(context)
.load(uri)
.error(R.drawable.ic_image_grey600_24dp)
.into(holder.binding.preview);
}
}
}
@Override
public int getItemCount() {
return attachments.size();
}
static class AttachmentViewHolder extends RecyclerView.ViewHolder {
private ItemAttachmentBinding binding;
private AttachmentViewHolder(ItemAttachmentBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}
|