-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlobalStateViewModel.kt
95 lines (69 loc) · 2.83 KB
/
GlobalStateViewModel.kt
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 li.garteroboter.pren
import android.app.Application
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import li.garteroboter.pren.Constants.STOP_FINISH_LINE
import java.io.File
/** This ViewModel is used to track the current state of the Roboter.
*
* fragment [CameraFragment] updates images and Logs to this fragment
* fragment [IntermediateFragment] updates changes of which camera implementation to use
* Activity [NanodetncnnActivity] observes this viewModel
* fragment [TerminalFragment] only updates this to set the inital start command
*/
class GlobalStateViewModel(application: Application) : AndroidViewModel(application) {
/** Object detection result is dismissed as long as this flag this flag is set to true. */
var ROBOTER_DRIVING = false
private val context = getApplication<Application>().applicationContext
private val currentImage = MutableLiveData<File>()
private val currentSpecies = MutableLiveData<String>()
private val mutableDriveState = MutableLiveData<String>()
private val triggerNavigateToCameraFragment = MutableLiveData<Boolean>(false)
private val currentLog = MutableLiveData<LogType>()
private val currentDeubggingLog = MutableLiveData<String>()
/** Stops the roboter, finish line. */
fun stop() {
Log.e(TAG ,"stop()")
ROBOTER_DRIVING = false
mutableDriveState.value = STOP_FINISH_LINE
}
fun set_triggerNavigateToCameraFragment(value: Boolean) {
Log.d(TAG, "set_triggerNavigateToCameraFragment")
triggerNavigateToCameraFragment.value = value
}
fun get_triggerNavigateToCameraFragment(): MutableLiveData<Boolean> {
return triggerNavigateToCameraFragment
}
fun setCurrentImage(image: File) {
Log.i(TAG, "setCurrentImage: postvalue")
currentImage.postValue(image)
}
fun getCurrentImage() : MutableLiveData<File> {
return currentImage
}
fun setDriveState(state: String) {
mutableDriveState.value = state
}
fun getMutableDriveState() : MutableLiveData<String> {
return mutableDriveState
}
fun setCurrentLog(newLog: LogType) {
Log.d(TAG, "setCurrentLog: $newLog")
currentLog.value = newLog
}
fun getCurrentLog() : MutableLiveData<LogType> {
return currentLog
}
enum class LogType(val state: String) {
STARTED("Knopf gedrückt. Garteroboterli fährt los."),
RESUME("Foto gemacht. Weiterfahren."),
OBJECT_DETECTION_TRIGGERED("Objekterkennung: Potted Plant"),
QR_CODE_DETECTED("QR-Code erkannt"),
WEBSOCKET("Websocket Open: Handshake"),
STOP("Roboter Stopp-QR-Code. Ende Gelände. \n Websocket Close: Handshake")
}
companion object {
const val TAG = "GlobalStateViewModel"
}
}