Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AttachmentViewHolder.java « attachments « card « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd586bd84910da67b437519b0edd4fff7ff89c25 (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
package it.niedermann.nextcloud.deck.ui.card.attachments;

import android.view.MenuInflater;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.CallSuper;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;

import com.nextcloud.android.common.ui.theme.utils.ColorRole;

import it.niedermann.android.util.ClipboardUtil;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.model.enums.DBStatus;
import it.niedermann.nextcloud.deck.ui.theme.ThemeUtils;
import it.niedermann.nextcloud.deck.util.AttachmentUtil;

public abstract class AttachmentViewHolder extends RecyclerView.ViewHolder {
    AttachmentViewHolder(@NonNull View itemView) {
        super(itemView);
    }

    public void bind(@NonNull Account account, @NonNull MenuInflater menuInflater, @NonNull FragmentManager fragmentManager, Long cardRemoteId, Attachment attachment, @Nullable View.OnClickListener onClickListener, @ColorInt int color) {
        final String attachmentUri = (attachment.getId() == null || cardRemoteId == null)
                ? attachment.getLocalPath()
                : AttachmentUtil.getCopyDownloadUrl(account, cardRemoteId, attachment);

        final var synced = !DBStatus.LOCAL_EDITED.equals(attachment.getStatusEnum());
        getNotSyncedYetStatusIcon().setVisibility(synced ? View.GONE : View.VISIBLE);
        itemView.setOnCreateContextMenuListener((menu, v, menuInfo) -> {
            menuInflater.inflate(R.menu.attachment_menu, menu);
            menu.findItem(R.id.delete).setOnMenuItemClickListener(item -> {
                DeleteAttachmentDialogFragment.newInstance(attachment).show(fragmentManager, DeleteAttachmentDialogFragment.class.getCanonicalName());
                return false;
            });
            if (attachmentUri == null || attachment.getId() == null || cardRemoteId == null) {
                menu.findItem(android.R.id.copyUrl).setVisible(false);
            } else {
                menu.findItem(android.R.id.copyUrl).setVisible(true);
                menu.findItem(android.R.id.copyUrl).setOnMenuItemClickListener(item -> ClipboardUtil.copyToClipboard(itemView.getContext(), attachment.getFilename(), attachmentUri));
            }
        });

        applyTheme(color);
    }

    @CallSuper
    protected void applyTheme(@ColorInt int color) {
        final var utils = ThemeUtils.of(color, getPreview().getContext());

        utils.platform.colorImageView(getNotSyncedYetStatusIcon(), ColorRole.PRIMARY);
    }

    abstract protected ImageView getPreview();

    abstract protected ImageView getNotSyncedYetStatusIcon();
}