blob: f30a3bcf4587c4dbc6ca9f0741016bd3ad8649c0 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package it.niedermann.nextcloud.deck.ui.sharetarget;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import java.util.ArrayList;
import java.util.List;
import it.niedermann.nextcloud.deck.DeckLog;
public class ShareProgressViewModel extends ViewModel {
@NonNull
public String targetCardTitle = "";
@NonNull
private MutableLiveData<List<Throwable>> exceptions = new MutableLiveData<>(new ArrayList<>());
@NonNull
private MutableLiveData<List<String>> duplicateAttachments = new MutableLiveData<>(new ArrayList<>());
@NonNull
private MutableLiveData<Integer> max = new MutableLiveData<>();
@NonNull
private MutableLiveData<Integer> progress = new MutableLiveData<>(0);
public void setMax(int max) {
this.max.setValue(max);
}
public LiveData<Integer> getMax() {
return this.max;
}
public Integer getMaxValue() {
return this.max.getValue();
}
public void increaseProgress() {
final Integer currentValue = this.progress.getValue();
if (currentValue == null) {
this.progress.setValue(0);
} else {
this.progress.setValue(currentValue + 1);
}
}
public LiveData<Integer> getProgress() {
return this.progress;
}
public void addDuplicateAttachment(String fileName) {
List<String> fileNames = this.duplicateAttachments.getValue();
if (fileNames == null) {
fileNames = new ArrayList<>();
}
fileNames.add(fileName);
this.duplicateAttachments.setValue(fileNames);
increaseProgress();
}
public boolean hasAlreadyDuplicateAttachments() {
List<String> duplicateAttachments = this.duplicateAttachments.getValue();
if (duplicateAttachments == null) {
return false;
}
return duplicateAttachments.size() > 0;
}
public LiveData<List<String>> getDuplicateAttachments() {
return this.duplicateAttachments;
}
public void addException(Throwable exception) {
DeckLog.logError(exception);
List<Throwable> exceptionList = this.exceptions.getValue();
if (exceptionList == null) {
exceptionList = new ArrayList<>();
}
exceptionList.add(exception);
this.exceptions.setValue(exceptionList);
increaseProgress();
}
public boolean hasExceptions() {
List<Throwable> exceptions = this.exceptions.getValue();
if (exceptions == null) {
return false;
}
return exceptions.size() > 0;
}
public LiveData<List<Throwable>> getExceptions() {
return this.exceptions;
}
}
|