That fuck shit the fascists are using
1package org.tm.archive.help;
2
3import androidx.annotation.NonNull;
4import androidx.lifecycle.LiveData;
5import androidx.lifecycle.MutableLiveData;
6import androidx.lifecycle.ViewModel;
7
8import org.tm.archive.logsubmit.SubmitDebugLogRepository;
9import org.tm.archive.util.livedata.LiveDataUtil;
10
11import java.util.Optional;
12
13
14public class HelpViewModel extends ViewModel {
15
16 private static final int MINIMUM_PROBLEM_CHARS = 10;
17
18 private final MutableLiveData<Boolean> problemMeetsLengthRequirements;
19 private final MutableLiveData<Integer> categoryIndex;
20 private final LiveData<Boolean> isFormValid;
21
22 private final SubmitDebugLogRepository submitDebugLogRepository;
23
24 public HelpViewModel() {
25 submitDebugLogRepository = new SubmitDebugLogRepository();
26 problemMeetsLengthRequirements = new MutableLiveData<>();
27 categoryIndex = new MutableLiveData<>(0);
28
29 isFormValid = LiveDataUtil.combineLatest(problemMeetsLengthRequirements, categoryIndex, (meetsLengthRequirements, index) -> {
30 return meetsLengthRequirements == Boolean.TRUE && index > 0;
31 });
32 }
33
34 LiveData<Boolean> isFormValid() {
35 return isFormValid;
36 }
37
38 void onProblemChanged(@NonNull String problem) {
39 problemMeetsLengthRequirements.setValue(problem.length() >= MINIMUM_PROBLEM_CHARS);
40 }
41
42 void onCategorySelected(int index) {
43 this.categoryIndex.setValue(index);
44 }
45
46 int getCategoryIndex() {
47 return Optional.ofNullable(this.categoryIndex.getValue()).orElse(0);
48 }
49
50 LiveData<SubmitResult> onSubmitClicked(boolean includeDebugLogs) {
51 MutableLiveData<SubmitResult> resultLiveData = new MutableLiveData<>();
52
53 if (includeDebugLogs) {
54 submitDebugLogRepository.buildAndSubmitLog(result -> resultLiveData.postValue(new SubmitResult(result, result.isPresent())));
55 } else {
56 resultLiveData.postValue(new SubmitResult(Optional.empty(), false));
57 }
58
59 return resultLiveData;
60 }
61
62 static class SubmitResult {
63 private final Optional<String> debugLogUrl;
64 private final boolean isError;
65
66 private SubmitResult(@NonNull Optional<String> debugLogUrl, boolean isError) {
67 this.debugLogUrl = debugLogUrl;
68 this.isError = isError;
69 }
70
71 @NonNull Optional<String> getDebugLogUrl() {
72 return debugLogUrl;
73 }
74
75 boolean isError() {
76 return isError;
77 }
78 }
79}