package com.rtnmapsgl import android.os.Handler import android.os.Looper import android.util.Log import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.MutableLiveData import androidx.lifecycle.LiveData import com.rtnmapsgl.interop.JSBuilder import com.rtnmapsgl.model.Legend import com.rtnmapsgl.model.MapLayer /* * Description: ViewModel */ class MainViewModel : ViewModel() { var mapLayers = MapLayer.listAll() var jsBuilder: JSBuilder? = null private val _isWebViewReady = MutableLiveData() val isWebViewReady: LiveData get() = _isWebViewReady fun setWebViewReady(ready: Boolean) { // Check if current thread is the main thread, if not, switch to it if (Looper.getMainLooper() == Looper.myLooper()) { _isWebViewReady.postValue(ready) } else { val handler = Handler(Looper.getMainLooper()) handler.post { _isWebViewReady.postValue(ready) } } } val openMenu = mutableStateOf(false) val openDialog = mutableStateOf(false) val openSnackbar = mutableStateOf(false) val openProgress = mutableStateOf(false) val openAnimateControl = mutableStateOf(false) val animateTime = mutableStateOf("00:00:00") val animateState = mutableStateOf(TimelineState.Stop) val openLegends = mutableStateOf>(emptyList()) val msg = mutableStateOf("") val showSnackbar: (open: Boolean, msg: String?) -> Unit = { isOpen, str -> openSnackbar.value = isOpen msg.value = str ?: "" } val updateTime: (time: String) -> Unit = { animateTime.value = it } val showProgress: (show: Boolean) -> Unit = { openProgress.value = it } fun hasSelectedLayer():Boolean { for (layer in mapLayers) { if (layer.isEnabled) return true } return false } } sealed class TimelineState { object Play : TimelineState() object Stop : TimelineState() }