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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
package it.niedermann.nextcloud.deck.ui.upcomingcards;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.databinding.ActivityUpcomingCardsBinding;
import it.niedermann.nextcloud.deck.model.Card;
import it.niedermann.nextcloud.deck.model.Stack;
import it.niedermann.nextcloud.deck.model.full.FullCard;
import it.niedermann.nextcloud.deck.remote.api.IResponseCallback;
import it.niedermann.nextcloud.deck.repository.SyncRepository;
import it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment;
import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler;
import it.niedermann.nextcloud.deck.ui.movecard.MoveCardListener;
public class UpcomingCardsActivity extends AppCompatActivity implements MoveCardListener {
private UpcomingCardsViewModel viewModel;
private ActivityUpcomingCardsBinding binding;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
binding = ActivityUpcomingCardsBinding.inflate(getLayoutInflater());
viewModel = new ViewModelProvider(this).get(UpcomingCardsViewModel.class);
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
binding.loadingSpinner.show();
final var adapter = new UpcomingCardsAdapter(this, getSupportFragmentManager(),
(a, c) -> {
try {
viewModel.assignUser(a, c);
} catch (NextcloudFilesAppAccountNotFoundException e) {
ExceptionDialogFragment.newInstance(e, a).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
}
},
(a, c) -> {
try {
viewModel.unassignUser(a, c);
} catch (NextcloudFilesAppAccountNotFoundException e) {
ExceptionDialogFragment.newInstance(e, a).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
}
},
(fullCard) -> viewModel.archiveCard(fullCard, new IResponseCallback<>() {
@Override
public void onResponse(FullCard response) {
DeckLog.info("Successfully archived", Card.class.getSimpleName(), fullCard.getCard().getTitle());
}
@Override
public void onError(Throwable throwable) {
IResponseCallback.super.onError(throwable);
runOnUiThread(() -> ExceptionDialogFragment.newInstance(throwable, null).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()));
}
}),
(card) -> viewModel.deleteCard(card, new IResponseCallback<>() {
@Override
public void onResponse(Void response) {
DeckLog.info("Successfully deleted card", card.getTitle());
}
@Override
public void onError(Throwable throwable) {
if (SyncRepository.isNoOnVoidError(throwable)) {
IResponseCallback.super.onError(throwable);
runOnUiThread(() -> ExceptionDialogFragment.newInstance(throwable, null).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()));
}
}
})
);
binding.recyclerView.setAdapter(adapter);
viewModel.getUpcomingCards().observe(this, items -> {
binding.loadingSpinner.hide();
if (items.size() > 0) {
binding.recyclerView.setVisibility(View.VISIBLE);
binding.emptyContentView.setVisibility(View.GONE);
} else {
binding.recyclerView.setVisibility(View.GONE);
binding.emptyContentView.setVisibility(View.VISIBLE);
}
adapter.setItems(items);
});
}
@Override
protected void onDestroy() {
super.onDestroy();
this.binding = null;
}
@NonNull
public static Intent createIntent(@NonNull Context context) {
return new Intent(context, UpcomingCardsActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
@Override
public void move(long originAccountId, long originCardLocalId, long targetAccountId, long targetBoardLocalId, long targetStackLocalId) {
viewModel.moveCard(originAccountId, originCardLocalId, targetAccountId, targetBoardLocalId, targetStackLocalId, new IResponseCallback<>() {
@Override
public void onResponse(Void response) {
DeckLog.log("Moved", Card.class.getSimpleName(), originCardLocalId, "to", Stack.class.getSimpleName(), targetStackLocalId);
}
@Override
public void onError(Throwable throwable) {
IResponseCallback.super.onError(throwable);
if (SyncRepository.isNoOnVoidError(throwable)) {
ExceptionDialogFragment.newInstance(throwable, null).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
}
}
});
}
}
|