|
|
@ -39,10 +39,13 @@ import com.iqball.app.component.StepsTree
|
|
|
|
import com.iqball.app.model.TacticInfo
|
|
|
|
import com.iqball.app.model.TacticInfo
|
|
|
|
import com.iqball.app.model.tactic.ComponentId
|
|
|
|
import com.iqball.app.model.tactic.ComponentId
|
|
|
|
import com.iqball.app.model.tactic.CourtType
|
|
|
|
import com.iqball.app.model.tactic.CourtType
|
|
|
|
|
|
|
|
import com.iqball.app.model.tactic.StepContent
|
|
|
|
import com.iqball.app.model.tactic.StepNodeInfo
|
|
|
|
import com.iqball.app.model.tactic.StepNodeInfo
|
|
|
|
|
|
|
|
import com.iqball.app.model.tactic.getParent
|
|
|
|
import com.iqball.app.net.service.TacticService
|
|
|
|
import com.iqball.app.net.service.TacticService
|
|
|
|
import com.iqball.app.session.Token
|
|
|
|
import com.iqball.app.session.Token
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
|
|
|
|
import net.engawapg.lib.zoomable.ZoomState
|
|
|
|
import net.engawapg.lib.zoomable.rememberZoomState
|
|
|
|
import net.engawapg.lib.zoomable.rememberZoomState
|
|
|
|
import java.time.Instant
|
|
|
|
import java.time.Instant
|
|
|
|
import java.time.LocalDateTime
|
|
|
|
import java.time.LocalDateTime
|
|
|
@ -62,47 +65,52 @@ fun VisualizerPage(
|
|
|
|
val dataEither = remember { initializeVisualizer(service, auth, tacticId) }
|
|
|
|
val dataEither = remember { initializeVisualizer(service, auth, tacticId) }
|
|
|
|
val showTree = remember { mutableStateOf(true) }
|
|
|
|
val showTree = remember { mutableStateOf(true) }
|
|
|
|
|
|
|
|
|
|
|
|
val (info, rootStep) = when (dataEither) {
|
|
|
|
val (info, stepsTree) = when (dataEither) {
|
|
|
|
// On error return a text to print it to the user
|
|
|
|
// On error return a text to print it to the user
|
|
|
|
is Either.Left -> return Text(text = dataEither.value)
|
|
|
|
is Either.Left -> return Text(text = dataEither.value)
|
|
|
|
is Either.Right -> dataEither.value
|
|
|
|
is Either.Right -> dataEither.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
val screenOrientation = LocalConfiguration.current.orientation
|
|
|
|
fun getStepContent(step: Int): StepContent = runBlocking {
|
|
|
|
var selectedStepId by rememberSaveable { mutableIntStateOf(rootStep.id) }
|
|
|
|
val result = service.getTacticStepContent(auth, tacticId, step).onLeft {
|
|
|
|
val content = remember(selectedStepId) {
|
|
|
|
Log.e(
|
|
|
|
runBlocking {
|
|
|
|
"received error response from server when retrieving step content: {}",
|
|
|
|
val result = service.getTacticStepContent(auth, tacticId, selectedStepId).onLeft {
|
|
|
|
it.toString()
|
|
|
|
Log.e(
|
|
|
|
)
|
|
|
|
"received error response from server when retrieving root content: {}",
|
|
|
|
}
|
|
|
|
it.toString()
|
|
|
|
when (result) {
|
|
|
|
)
|
|
|
|
is Either.Left -> throw Error("Unexpected error")
|
|
|
|
}
|
|
|
|
is Either.Right -> result.value
|
|
|
|
when (result) {
|
|
|
|
|
|
|
|
is Either.Left -> throw Error("Unexpected error")
|
|
|
|
|
|
|
|
is Either.Right -> result.value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val screenOrientation = LocalConfiguration.current.orientation
|
|
|
|
|
|
|
|
var selectedStepId by rememberSaveable { mutableIntStateOf(stepsTree.id) }
|
|
|
|
|
|
|
|
val (content, parentContent) = remember(selectedStepId) {
|
|
|
|
|
|
|
|
val parentId = getParent(stepsTree, selectedStepId)?.id
|
|
|
|
|
|
|
|
Pair(
|
|
|
|
|
|
|
|
getStepContent(selectedStepId),
|
|
|
|
|
|
|
|
if (parentId == null) null else getStepContent(parentId)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
Column {
|
|
|
|
VisualizerHeader(title = info.name, showTree)
|
|
|
|
VisualizerHeader(title = info.name, showTree)
|
|
|
|
when (screenOrientation) {
|
|
|
|
when (screenOrientation) {
|
|
|
|
Configuration.ORIENTATION_PORTRAIT -> StepsTree(root = rootStep,
|
|
|
|
Configuration.ORIENTATION_PORTRAIT -> StepsTree(root = stepsTree,
|
|
|
|
selectedNodeId = selectedStepId,
|
|
|
|
selectedNodeId = selectedStepId,
|
|
|
|
onNodeSelected = { selectedStepId = it.id })
|
|
|
|
onNodeSelected = { selectedStepId = it.id })
|
|
|
|
|
|
|
|
|
|
|
|
Configuration.ORIENTATION_LANDSCAPE -> {
|
|
|
|
Configuration.ORIENTATION_LANDSCAPE -> {
|
|
|
|
val courtOffsets =
|
|
|
|
val stepOffsets =
|
|
|
|
remember(showTree.value, content) { mutableStateMapOf<ComponentId, Offset>() }
|
|
|
|
remember(showTree.value, content) { mutableStateMapOf<ComponentId, Offset>() }
|
|
|
|
|
|
|
|
val parentOffsets =
|
|
|
|
|
|
|
|
remember(showTree.value, parentContent) { mutableStateMapOf<ComponentId, Offset>() }
|
|
|
|
val courtArea = remember(showTree.value) { mutableStateOf(Rect.Zero) }
|
|
|
|
val courtArea = remember(showTree.value) { mutableStateOf(Rect.Zero) }
|
|
|
|
val courtZoomState = rememberZoomState()
|
|
|
|
val courtZoomState = remember(showTree.value, selectedStepId) { ZoomState() }
|
|
|
|
remember(showTree.value, content) {
|
|
|
|
|
|
|
|
runBlocking {
|
|
|
|
|
|
|
|
courtZoomState.reset()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val courtModifier =
|
|
|
|
val courtModifier =
|
|
|
|
if (showTree.value) Modifier.width(IntrinsicSize.Min) else Modifier.fillMaxWidth()
|
|
|
|
if (showTree.value) Modifier.width(IntrinsicSize.Min) else Modifier.fillMaxWidth()
|
|
|
@ -110,12 +118,13 @@ fun VisualizerPage(
|
|
|
|
Row(modifier = Modifier.background(Color.LightGray)) {
|
|
|
|
Row(modifier = Modifier.background(Color.LightGray)) {
|
|
|
|
BasketCourt(
|
|
|
|
BasketCourt(
|
|
|
|
content = content,
|
|
|
|
content = content,
|
|
|
|
|
|
|
|
parentContent,
|
|
|
|
type = info.type,
|
|
|
|
type = info.type,
|
|
|
|
modifier = courtModifier,
|
|
|
|
modifier = courtModifier,
|
|
|
|
state = BasketCourtStates(courtOffsets, courtArea, courtZoomState)
|
|
|
|
state = BasketCourtStates(stepOffsets, parentOffsets, courtArea, courtZoomState)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if (showTree.value) {
|
|
|
|
if (showTree.value) {
|
|
|
|
StepsTree(root = rootStep,
|
|
|
|
StepsTree(root = stepsTree,
|
|
|
|
selectedNodeId = selectedStepId,
|
|
|
|
selectedNodeId = selectedStepId,
|
|
|
|
onNodeSelected = { selectedStepId = it.id })
|
|
|
|
onNodeSelected = { selectedStepId = it.id })
|
|
|
|
}
|
|
|
|
}
|
|
|
|