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
|
package it.niedermann.nextcloud.deck.ui.card.attachments;
import static it.niedermann.nextcloud.deck.util.AttachmentUtil.getIconForMimeType;
import static it.niedermann.nextcloud.deck.util.AttachmentUtil.openAttachment;
import android.text.format.Formatter;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import it.niedermann.nextcloud.deck.databinding.ItemAttachmentDefaultBinding;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.ui.theme.ThemeUtils;
import it.niedermann.nextcloud.deck.util.DateUtil;
public class DefaultAttachmentViewHolder extends AttachmentViewHolder {
private final ItemAttachmentDefaultBinding binding;
@SuppressWarnings("WeakerAccess")
public DefaultAttachmentViewHolder(ItemAttachmentDefaultBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
@Override
protected ImageView getPreview() {
return binding.preview;
}
@Override
protected ImageView getNotSyncedYetStatusIcon() {
return binding.notSyncedYet;
}
public void bind(@NonNull Account account, @NonNull MenuInflater menuInflater, @NonNull FragmentManager fragmentManager, Long cardRemoteId, Attachment attachment, @Nullable View.OnClickListener onClickListener, @ColorInt int color) {
super.bind(account, menuInflater, fragmentManager, cardRemoteId, attachment, onClickListener, color);
getPreview().setImageResource(getIconForMimeType(attachment.getMimetype()));
itemView.setOnClickListener((event) -> openAttachment(account, itemView.getContext(), cardRemoteId, attachment));
binding.filename.setText(attachment.getBasename());
binding.filesize.setText(Formatter.formatFileSize(binding.filesize.getContext(), attachment.getFilesize()));
if (attachment.getLastModifiedLocal() != null) {
binding.modified.setText(DateUtil.getRelativeDateTimeString(binding.modified.getContext(), attachment.getLastModifiedLocal().toEpochMilli()));
binding.modified.setVisibility(View.VISIBLE);
} else if (attachment.getLastModified() != null) {
binding.modified.setText(DateUtil.getRelativeDateTimeString(binding.modified.getContext(), attachment.getLastModified().toEpochMilli()));
binding.modified.setVisibility(View.VISIBLE);
} else {
binding.modified.setVisibility(View.GONE);
}
applyTheme(color);
}
protected void applyTheme(@ColorInt int color) {
super.applyTheme(color);
final var utils = ThemeUtils.of(color, getPreview().getContext());
utils.platform.colorTextView(binding.filename, ColorRole.ON_SURFACE);
utils.platform.colorImageView(getPreview(), ColorRole.ON_SURFACE_VARIANT);
utils.platform.colorTextView(binding.filesize, ColorRole.ON_SURFACE_VARIANT);
utils.platform.colorTextView(binding.modified, ColorRole.ON_SURFACE_VARIANT);
}
}
|