Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ GEM
httpclient (2.9.0)
mutex_m
jmespath (1.6.2)
json (2.18.0)
json (2.19.2)
jwt (2.10.2)
base64
logger (1.7.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import io.github.z4kn4fein.semver.toVersion

sealed class InfoDisplay {
data object DataSource : InfoDisplay()
data object LuaScript : InfoDisplay()
data class Function(val metadata: LuaFunctionMetadata) : InfoDisplay()
}

Expand Down Expand Up @@ -86,7 +85,6 @@ fun NodeDescriptionDialog(
// Header
when (infoDisplay) {
is InfoDisplay.Function -> FunctionHeader(infoDisplay.metadata)
is InfoDisplay.LuaScript -> DefaultHeader(stringResource(R.string.lua_script))
is InfoDisplay.DataSource -> DefaultHeader(stringResource(R.string.data_source))
}

Expand All @@ -101,10 +99,6 @@ fun NodeDescriptionDialog(
stringResource(R.string.data_source_description)
}

is InfoDisplay.LuaScript -> {
stringResource(R.string.lua_script_description)
}

is InfoDisplay.Function -> {
infoDisplay.metadata.description.resolve()?.trim() ?: ""
}
Expand Down Expand Up @@ -150,17 +144,6 @@ private fun InfoDisplayDialogDataSourcePreview() {
}
}

@Preview(showBackground = true)
@Composable
private fun InfoDisplayDialogLuaScriptPreview() {
TnGComposeTheme {
NodeDescriptionDialog(
infoDisplay = InfoDisplay.LuaScript,
onDismiss = {}
)
}
}

@Preview(showBackground = true)
@Composable
private fun InfoDisplayDialogFunctionPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ fun NodeSelectionDialog(
isLandscape = isLandscape,
infoDisplay = infoDisplay,
onShowInfo = { infoDisplay = it },
onCloseInfo = { infoDisplay = null }
onCloseInfo = { infoDisplay = null },
onLuaScriptInfoClick = viewModel::navigateToLuaCustomFunctionsDocs
)
}

Expand All @@ -116,6 +117,7 @@ private fun NodeSelectionDialogUi(
infoDisplay: InfoDisplay? = null,
onShowInfo: (InfoDisplay) -> Unit = {},
onCloseInfo: () -> Unit = {},
onLuaScriptInfoClick: () -> Unit = {},
) {
val usePlatformDefaultWidth = when {
state !is NodeSelectionUiState.Ready -> true
Expand Down Expand Up @@ -143,7 +145,8 @@ private fun NodeSelectionDialogUi(
},
onRetry = onRetry,
onSelectCategory = onSelectCategory,
onShowInfo = onShowInfo
onShowInfo = onShowInfo,
onLuaScriptInfoClick = onLuaScriptInfoClick
)
}
}
Expand All @@ -165,6 +168,7 @@ private fun SelectionView(
onRetry: () -> Unit,
onSelectCategory: (String?) -> Unit,
onShowInfo: (InfoDisplay) -> Unit,
onLuaScriptInfoClick: () -> Unit,
) {
Row(
modifier = Modifier.sizeIn(minHeight = buttonSize),
Expand Down Expand Up @@ -207,14 +211,16 @@ private fun SelectionView(
state = state,
onSelect = onSelect,
onSelectCategory = onSelectCategory,
onShowInfo = onShowInfo
onShowInfo = onShowInfo,
onLuaScriptInfoClick = onLuaScriptInfoClick
)
} else {
PortraitReadyState(
state = state,
onSelect = onSelect,
onSelectCategory = onSelectCategory,
onShowInfo = onShowInfo
onShowInfo = onShowInfo,
onLuaScriptInfoClick = onLuaScriptInfoClick
)
}
}
Expand All @@ -234,6 +240,7 @@ private fun PortraitReadyState(
onSelect: (AddNodeData) -> Unit,
onSelectCategory: (String?) -> Unit,
onShowInfo: (InfoDisplay) -> Unit,
onLuaScriptInfoClick: () -> Unit,
) = AnimatedContent(state.selectedCategory) {
if (it == null) {
// Show category list first
Expand All @@ -242,6 +249,7 @@ private fun PortraitReadyState(
onSelect = onSelect,
onSelectCategory = onSelectCategory,
onShowInfo = onShowInfo,
onLuaScriptInfoClick = onLuaScriptInfoClick,
modifier = Modifier.fillMaxWidth()
)
} else {
Expand Down Expand Up @@ -276,6 +284,7 @@ private fun CategoryList(
onSelect: (AddNodeData) -> Unit,
onSelectCategory: (String?) -> Unit,
onShowInfo: (InfoDisplay) -> Unit,
onLuaScriptInfoClick: () -> Unit,
modifier: Modifier = Modifier
) {
FadingScrollColumn(modifier = modifier) {
Expand Down Expand Up @@ -320,9 +329,7 @@ private fun CategoryList(
onSelect(AddNodeData.LuaScriptNode)
},
showInfoIcon = true,
onInfoClick = {
onShowInfo(InfoDisplay.LuaScript)
}
onInfoClick = onLuaScriptInfoClick
)

Divider()
Expand Down Expand Up @@ -370,6 +377,7 @@ private fun LandscapeReadyState(
onSelect: (AddNodeData) -> Unit,
onSelectCategory: (String?) -> Unit,
onShowInfo: (InfoDisplay) -> Unit,
onLuaScriptInfoClick: () -> Unit,
) = Row(
modifier = Modifier.fillMaxWidth()
) {
Expand All @@ -379,6 +387,7 @@ private fun LandscapeReadyState(
onSelect = onSelect,
onSelectCategory = onSelectCategory,
onShowInfo = onShowInfo,
onLuaScriptInfoClick = onLuaScriptInfoClick,
modifier = Modifier.weight(1f)
)

Expand Down Expand Up @@ -602,29 +611,6 @@ private fun NodeSelectionDialogDataSourceInfoPreview() {
}
}

@Preview(showBackground = true)
@Composable
private fun NodeSelectionDialogLuaScriptInfoPreview() {
TnGComposeTheme {
NodeSelectionDialogUi(
state = NodeSelectionUiState.Ready(
allFunctions = emptyList(),
displayedFunctions = emptyList(),
selectedCategory = null,
allCategories = emptyMap()
),
onDismiss = {},
onSelect = {},
onRetry = {},
onSelectCategory = {},
isLandscape = true,
infoDisplay = InfoDisplay.LuaScript,
onShowInfo = {},
onCloseInfo = {}
)
}
}

@Preview(showBackground = true)
@Composable
private fun NodeSelectionDialogFunctionInfoPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
*/
package com.samco.trackandgraph.functions.node_selector

import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.samco.trackandgraph.data.lua.dto.LuaFunctionMetadata
import com.samco.trackandgraph.data.localisation.TranslatedString
import com.samco.trackandgraph.functions.repository.FunctionsRepository
import com.samco.trackandgraph.functions.repository.SignatureVerificationException
import com.samco.trackandgraph.remoteconfig.UrlNavigator
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -52,11 +55,14 @@ interface NodeSelectionViewModel {
fun selectCategory(categoryId: String?)
fun clearSelection()
fun retry()
fun navigateToLuaCustomFunctionsDocs()
}

@HiltViewModel
class NodeSelectionViewModelImpl @Inject constructor(
@ApplicationContext private val context: Context,
private val repository: FunctionsRepository,
private val urlNavigator: UrlNavigator,
) : ViewModel(), NodeSelectionViewModel {

private val _state = MutableStateFlow<NodeSelectionUiState>(NodeSelectionUiState.Loading)
Expand Down Expand Up @@ -85,6 +91,10 @@ class NodeSelectionViewModelImpl @Inject constructor(
fetchFunctions()
}

override fun navigateToLuaCustomFunctionsDocs() {
urlNavigator.triggerNavigation(context, UrlNavigator.Location.LUA_CUSTOM_FUNCTIONS_DOCS)
}

private fun updateReadyState() {
if (_state.value !is NodeSelectionUiState.Ready) return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class GraphStatClickListener(
val onEdit: (graphStat: IGraphStatViewData) -> Unit,
val onClick: (graphStat: IGraphStatViewData) -> Unit,
val onMove: (graphStat: IGraphStatViewData) -> Unit,
val onDuplicate: (graphStat: IGraphStatViewData) -> Unit
val onDuplicate: (graphStat: IGraphStatViewData) -> Unit,
val onSymlinks: (graphStat: IGraphStatViewData) -> Unit = {},
)

@Composable
Expand Down Expand Up @@ -140,5 +141,14 @@ private fun MenuSection(
expanded = false
}
)
if (!graphStatViewData.graphOrStat.unique) {
DropdownMenuItem(
text = { Text(stringResource(id = R.string.symlinks)) },
onClick = {
clickListener.onSymlinks(graphStatViewData)
expanded = false
}
)
}
}
}
18 changes: 16 additions & 2 deletions app/app/src/main/java/com/samco/trackandgraph/group/Function.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fun Function(
onDelete: (DisplayFunction) -> Unit,
onMoveTo: (DisplayFunction) -> Unit,
onDuplicate: (DisplayFunction) -> Unit,
onSymlinks: (DisplayFunction) -> Unit,
onClick: (DisplayFunction) -> Unit,
) = Box(modifier = modifier.fillMaxWidth()) {
var showContextMenu by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -140,7 +141,8 @@ fun Function(
onEdit = onEdit,
onDelete = onDelete,
onMoveTo = onMoveTo,
onDuplicate = onDuplicate
onDuplicate = onDuplicate,
onSymlinks = onSymlinks,
)
// Function name
FunctionNameText(functionName = displayFunction.name)
Expand Down Expand Up @@ -168,7 +170,8 @@ private fun FunctionMenuButton(
onEdit: (DisplayFunction) -> Unit,
onDelete: (DisplayFunction) -> Unit,
onMoveTo: (DisplayFunction) -> Unit,
onDuplicate: (DisplayFunction) -> Unit
onDuplicate: (DisplayFunction) -> Unit,
onSymlinks: (DisplayFunction) -> Unit,
) {
Box(modifier = modifier) {
IconButton(
Expand Down Expand Up @@ -217,6 +220,15 @@ private fun FunctionMenuButton(
onDuplicate(displayFunction)
}
)
if (!displayFunction.unique) {
DropdownMenuItem(
text = { Text(stringResource(R.string.symlinks)) },
onClick = {
onShowContextMenu(false)
onSymlinks(displayFunction)
}
)
}
}
}
}
Expand Down Expand Up @@ -258,6 +270,7 @@ fun FunctionPreview() {
onDelete = {},
onMoveTo = {},
onDuplicate = {},
onSymlinks = {},
onClick = {}
)

Expand All @@ -274,6 +287,7 @@ fun FunctionPreview() {
onDelete = {},
onMoveTo = {},
onDuplicate = {},
onSymlinks = {},
onClick = {}
)
}
Expand Down
18 changes: 16 additions & 2 deletions app/app/src/main/java/com/samco/trackandgraph/group/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fun Group(
onEdit: (Group) -> Unit,
onDelete: (Group) -> Unit,
onMoveTo: (Group) -> Unit,
onSymlinks: (Group) -> Unit,
onClick: (Group) -> Unit,
) = Box(modifier = modifier.fillMaxWidth()) {
var showContextMenu by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -113,7 +114,8 @@ fun Group(
group = group,
onEdit = onEdit,
onDelete = onDelete,
onMoveTo = onMoveTo
onMoveTo = onMoveTo,
onSymlinks = onSymlinks,
)

// Group name text
Expand All @@ -138,7 +140,8 @@ private fun GroupMenuButton(
group: Group,
onEdit: (Group) -> Unit,
onDelete: (Group) -> Unit,
onMoveTo: (Group) -> Unit
onMoveTo: (Group) -> Unit,
onSymlinks: (Group) -> Unit,
) {
Box(
modifier = modifier.size(buttonSize)
Expand Down Expand Up @@ -180,6 +183,15 @@ private fun GroupMenuButton(
onMoveTo(group)
}
)
if (!group.unique) {
DropdownMenuItem(
text = { Text(stringResource(R.string.symlinks)) },
onClick = {
onShowContextMenu(false)
onSymlinks(group)
}
)
}
}
}
}
Expand All @@ -198,6 +210,7 @@ private fun GroupPreview() {
onEdit = {},
onDelete = {},
onMoveTo = {},
onSymlinks = {},
onClick = {}
)
}
Expand All @@ -218,6 +231,7 @@ private fun GroupElevatedPreview() {
onEdit = {},
onDelete = {},
onMoveTo = {},
onSymlinks = {},
onClick = {}
)
}
Expand Down
Loading