Skip to content

Commit ed9a67e

Browse files
sentinelwebsentinelweb
authored andcommitted
#496 - switch on transport edit and up buttons on files
1 parent df7cda8 commit ed9a67e

File tree

7 files changed

+81
-20
lines changed

7 files changed

+81
-20
lines changed

app/src/main/java/uk/co/sentinelweb/cuer/app/ui/filebrowser/dialog/FilesDialogFragment.kt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,42 @@ class FilesDialogFragment(
8989
},
9090
onClickConfirm = { path ->
9191
selectedNode?.also { selectedListener.invoke(it, path) }
92-
}
92+
},
93+
onUp = {
94+
val parent = viewModel.path?.getParentPath()
95+
log.d("onUp: $parent")
96+
viewModel.setPath(
97+
node = null,
98+
path = parent
99+
)
100+
},
93101
)
94102
}
95103
}
96104

105+
fun String.getParentPath(): String? {
106+
// Handle special cases
107+
if (this.isEmpty()) return null
108+
if (this == "/" || this == "\\") return null
109+
110+
// Normalize path by removing trailing slashes
111+
val normalizedPath = this.trimEnd('/', '\\')
112+
if (normalizedPath.isEmpty()) return null
113+
114+
// Find the last separator
115+
val lastSeparatorIndex = normalizedPath.lastIndexOfAny(charArrayOf('/', '\\'))
116+
117+
// If no separator found, there's no parent path
118+
if (lastSeparatorIndex == -1) return null
119+
120+
// If separator is at the beginning, return root path
121+
if (lastSeparatorIndex == 0) return "/"
122+
123+
// Return the parent path
124+
return normalizedPath.substring(0, lastSeparatorIndex)
125+
}
126+
127+
97128
override fun onAttach(context: Context) {
98129
super.onAttach(context)
99130
requireActivity().onBackPressedDispatcher.addCallback(this, upCallback)

app/src/main/java/uk/co/sentinelweb/cuer/app/ui/playlist_edit/PlaylistEditFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class PlaylistEditFragment : DialogFragment(), AndroidScopeComponent {
159159
binding.peImage.setOnTouchListener { iv, e ->
160160
when (e.actionMasked) {
161161
MotionEvent.ACTION_DOWN -> {
162-
viewModel.onImageClick(e.x > iv.width / 2)
162+
viewModel.onImageClick()// e.x > iv.width / 2
163163
true
164164
}
165165

app/src/main/java/uk/co/sentinelweb/cuer/app/ui/playlist_edit/PlaylistEditViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class PlaylistEditViewModel constructor(
262262
)
263263
}
264264

265-
private fun onParentSelected(parent: PlaylistDomain?) = viewModelScope.launch {
265+
private fun onParentSelected(parent: PlaylistDomain?, checked: Boolean) = viewModelScope.launch {
266266
if (parent == ADD_PLAYLIST_DUMMY) {
267267
return@launch
268268
}

shared/src/commonMain/kotlin/uk/co/sentinelweb/cuer/app/ui/filebrowser/dialog/FilesDialogComposeables.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package uk.co.sentinelweb.cuer.app.ui.filebrowser.dialog
22

3+
import androidx.compose.foundation.layout.Arrangement
34
import androidx.compose.foundation.layout.Column
4-
import androidx.compose.foundation.layout.fillMaxWidth
5+
import androidx.compose.foundation.layout.Row
56
import androidx.compose.foundation.layout.padding
67
import androidx.compose.runtime.Composable
78
import androidx.compose.runtime.collectAsState
@@ -16,6 +17,7 @@ import uk.co.sentinelweb.cuer.domain.PlaylistDomain
1617
import uk.co.sentinelweb.cuer.domain.PlaylistItemDomain
1718
import uk.co.sentinelweb.cuer.shared.generated.resources.Res
1819
import uk.co.sentinelweb.cuer.shared.generated.resources.ic_tick
20+
import uk.co.sentinelweb.cuer.shared.generated.resources.ic_up
1921

2022
object FilesDialogComposeables {
2123

@@ -25,6 +27,7 @@ object FilesDialogComposeables {
2527
onClickFile: (PlaylistItemDomain) -> Unit,
2628
onClickFolder: (PlaylistDomain) -> Unit,
2729
onClickConfirm: (PlaylistDomain) -> Unit,
30+
onUp: () -> Unit,
2831
) {
2932
val model = viewModel.model.collectAsState(initial = FilesContract.Model.Initial)
3033
CuerSharedTheme {
@@ -33,6 +36,7 @@ object FilesDialogComposeables {
3336
onClickFile = onClickFile,
3437
onClickFolder = onClickFolder,
3538
onClickConfirm = onClickConfirm,
39+
onUp = onUp,
3640
)
3741
}
3842
}
@@ -44,17 +48,27 @@ object FilesDialogComposeables {
4448
onClickFile: (PlaylistItemDomain) -> Unit,
4549
onClickFolder: (PlaylistDomain) -> Unit,
4650
onClickConfirm: (PlaylistDomain) -> Unit,
51+
onUp: () -> Unit,
4752
) {
4853
Column(horizontalAlignment = androidx.compose.ui.Alignment.End) {
4954
FilesView(model, onClickFile, onClickFolder, viewModel, modifier = Modifier.weight(1f))
55+
Row(horizontalArrangement = Arrangement.End) {
56+
HeaderButton(
57+
text = "Up",
58+
icon = Res.drawable.ic_up,
59+
modifier = Modifier
60+
.weight(0.3f)
61+
.padding(4.dp)
62+
) { viewModel.currentFolder?.playlist?.also { onUp() } }
5063

51-
HeaderButton(
52-
text = "Select",
53-
icon = Res.drawable.ic_tick,
54-
modifier = Modifier
55-
.fillMaxWidth()
56-
.padding(4.dp)
57-
) { viewModel.currentFolder?.playlist?.also { onClickConfirm(it) } }
64+
HeaderButton(
65+
text = "OK",
66+
icon = Res.drawable.ic_tick,
67+
modifier = Modifier
68+
.weight(0.4f)
69+
.padding(4.dp)
70+
) { viewModel.currentFolder?.playlist?.also { onClickConfirm(it) } }
71+
}
5872
}
5973
}
6074
}

shared/src/commonMain/kotlin/uk/co/sentinelweb/cuer/app/ui/filebrowser/transfers/TransfersComposeables.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ object TransfersComposeables {
129129

130130
@Composable
131131
fun TransfersQueueView(queue: List<Transfer>, viewModel: ViewModel) {
132-
LazyColumn() {
132+
LazyColumn {
133133
itemsIndexed(
134134
items = queue,
135135
key = { _, item -> item.domain?.id?.id?.value ?: "noid" } // fixme
@@ -260,15 +260,23 @@ object TransfersComposeables {
260260
}
261261
}
262262
Row(
263+
horizontalArrangement = Arrangement.End,
263264
modifier = Modifier
264265
.padding(2.dp)
265266
.align(BottomCenter)
266267
) {
268+
HeaderButton(
269+
text = "Switch",
270+
icon = Res.drawable.ic_refresh,
271+
modifier = Modifier
272+
.padding(4.dp)
273+
) { viewModel.onSwitchSourceTarget() }
274+
275+
267276
HeaderButton(
268277
text = "Select",
269278
icon = Res.drawable.ic_tick,
270279
modifier = Modifier
271-
.fillMaxWidth()
272280
.padding(4.dp)
273281

274282
) { viewModel.onSelectTransfer(null) }
@@ -302,14 +310,14 @@ object TransfersComposeables {
302310
Row(
303311
verticalAlignment = Alignment.CenterVertically,
304312
modifier = modifier
305-
.padding(4.dp)
313+
.padding(horizontal = 4.dp)
306314
) {
307315
Image(
308316
painter = painterResource(resId),
309317
contentDescription = null,
310318
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface),
311319
modifier = Modifier
312-
.padding(8.dp)
320+
.padding(horizontal = 4.dp)
313321
.size(iconSize)
314322
.align(CenterVertically)
315323
)
@@ -320,7 +328,7 @@ object TransfersComposeables {
320328
maxLines = 3,
321329
modifier = Modifier
322330
.weight(1f)
323-
.padding(4.dp)
331+
.padding(horizontal = 4.dp)
324332
)
325333
}
326334
}

shared/src/commonMain/kotlin/uk/co/sentinelweb/cuer/app/ui/filebrowser/transfers/TransfersViewModel.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ class TransfersViewModel(
116116
}
117117

118118
override fun onSwitchSourceTarget() {
119-
119+
val newValue = _stateObservable.value.selectedTransfer?.let {
120+
it.copy(
121+
source = it.target,
122+
target = it.source
123+
)
124+
}?.also { service.replaceTransfer(it) }
125+
_stateObservable.update { last ->
126+
last.copy(selectedTransfer = newValue)
127+
}
120128
}
121129

122130
override fun onSelectTransfer(path: TransferDomain?) {
@@ -126,12 +134,12 @@ class TransfersViewModel(
126134
}
127135

128136
override fun onSelectTransfer(index: Int) {
129-
val newValue = index
137+
val newQueueValue = index
130138
.takeIf { it < _stateObservable.value.queue.size && it >= 0 }
131139
?.let { _stateObservable.value.queue[it] }
132140

133141
_stateObservable.update { last ->
134-
last.copy(selectedTransfer = newValue)
142+
last.copy(selectedTransfer = newQueueValue)
135143
}
136144
}
137145
}

shared/src/commonMain/kotlin/uk/co/sentinelweb/cuer/app/ui/playlists/dialog/PlaylistsMviDialogContract.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ interface PlaylistsMviDialogContract {
5555
val ROOT_LEVEL_PLAYLIST_ID = Identifier("root-level".toGUID(), MEMORY)
5656
val ROOT_PLAYLIST_DUMMY = PlaylistDomain.createDummy(id = ROOT_LEVEL_PLAYLIST_ID, title = "Top level")
5757
}
58-
}
58+
}

0 commit comments

Comments
 (0)