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
|
package it.niedermann.nextcloud.deck.ui.archivedcards;
import android.app.Activity;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.LifecycleOwner;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.api.ResponseCallback;
import it.niedermann.nextcloud.deck.model.Card;
import it.niedermann.nextcloud.deck.model.full.FullCard;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
import it.niedermann.nextcloud.deck.ui.MainViewModel;
import it.niedermann.nextcloud.deck.ui.card.AbstractCardViewHolder;
import it.niedermann.nextcloud.deck.ui.card.CardAdapter;
import it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment;
public class ArchivedCardsAdapter extends CardAdapter {
@SuppressWarnings("WeakerAccess")
public ArchivedCardsAdapter(@NonNull Activity activity, @NonNull FragmentManager fragmentManager, @NonNull MainViewModel viewModel, @NonNull LifecycleOwner lifecycleOwner) {
super(activity, fragmentManager, 0L, viewModel, lifecycleOwner, null);
}
@Override
public void onBindViewHolder(@NonNull AbstractCardViewHolder viewHolder, int position) {
viewHolder.bind(cardList.get(position), mainViewModel.getCurrentAccount(), mainViewModel.getCurrentBoardRemoteId(), false, R.menu.archived_card_menu, this, counterMaxValue, mainColor);
}
@Override
public boolean onCardOptionsItemSelected(@NonNull MenuItem menuItem, @NonNull FullCard fullCard) {
int itemId = menuItem.getItemId();
if (itemId == R.id.action_card_dearchive) {
mainViewModel.dearchiveCard(fullCard, new ResponseCallback<FullCard>() {
@Override
public void onResponse(FullCard response) {
DeckLog.info("Successfully dearchived", Card.class.getSimpleName(), fullCard.getCard().getTitle());
}
@Override
public void onError(Throwable throwable) {
ResponseCallback.super.onError(throwable);
activity.runOnUiThread(() -> ExceptionDialogFragment.newInstance(throwable, mainViewModel.getCurrentAccount()).show(fragmentManager, ExceptionDialogFragment.class.getSimpleName()));
}
});
return true;
} else if (itemId == R.id.action_card_delete) {
mainViewModel.deleteCard(fullCard.getCard(), new ResponseCallback<Void>() {
@Override
public void onResponse(Void response) {
DeckLog.info("Successfully deleted card", fullCard.getCard().getTitle());
}
@Override
public void onError(Throwable throwable) {
if (!SyncManager.ignoreExceptionOnVoidError(throwable)) {
ResponseCallback.super.onError(throwable);
activity.runOnUiThread(() -> ExceptionDialogFragment.newInstance(throwable, mainViewModel.getCurrentAccount()).show(fragmentManager, ExceptionDialogFragment.class.getSimpleName()));
}
}
});
return true;
}
return super.onCardOptionsItemSelected(menuItem, fullCard);
}
}
|