Skip to content

Commit

Permalink
Improve moving folders (#19, #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakethpathike committed Oct 3, 2024
1 parent 51fccbe commit 083eea3
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import com.sakethh.linkora.ui.CoilImage
import com.sakethh.linkora.ui.commonComposables.pulsateEffect
import com.sakethh.linkora.ui.commonComposables.viewmodels.commonBtmSheets.OptionsBtmSheetType
import com.sakethh.linkora.ui.commonComposables.viewmodels.commonBtmSheets.OptionsBtmSheetVM
import com.sakethh.linkora.ui.screens.collections.FolderIndividualComponent
import com.sakethh.linkora.ui.screens.settings.SettingsPreference
import com.sakethh.linkora.ui.transferActions.TransferActionType
import com.sakethh.linkora.ui.transferActions.TransferActionsBtmBarValues
Expand Down Expand Up @@ -177,24 +176,50 @@ fun MenuBtmSheetUI(
color = MaterialTheme.colorScheme.outline.copy(0.25f)
)
} else {
FolderIndividualComponent(
folderName = if (menuBtmSheetParam.btmSheetFor == OptionsBtmSheetType.FOLDER) menuBtmSheetParam.folderName else menuBtmSheetParam.linkTitle,
folderNote = "",
onMoreIconClick = {
localClipBoardManager.setText(AnnotatedString(if (menuBtmSheetParam.btmSheetFor == OptionsBtmSheetType.FOLDER) menuBtmSheetParam.folderName else menuBtmSheetParam.linkTitle))
Toast.makeText(
context,
LocalizedStrings.titleCopiedToClipboard.value,
Toast.LENGTH_SHORT
)
.show()
},
onFolderClick = { },
maxLines = 2,
showMoreIcon = false,
folderIcon = if (menuBtmSheetParam.btmSheetFor == OptionsBtmSheetType.FOLDER) Icons.Outlined.Folder else Icons.Outlined.Link
Row(
modifier = Modifier
.combinedClickable(interactionSource = remember {
MutableInteractionSource()
}, indication = null,
onClick = {
localClipBoardManager.setText(AnnotatedString(if (menuBtmSheetParam.btmSheetFor == OptionsBtmSheetType.FOLDER) menuBtmSheetParam.folderName else menuBtmSheetParam.linkTitle))
Toast
.makeText(
context,
LocalizedStrings.titleCopiedToClipboard.value,
Toast.LENGTH_SHORT
)
.show()
})
.pulsateEffect()
.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = if (menuBtmSheetParam.btmSheetFor == OptionsBtmSheetType.FOLDER) Icons.Outlined.Folder else Icons.Outlined.Link,
null,
modifier = Modifier
.padding(20.dp)
.size(28.dp)
)

Text(
text = if (menuBtmSheetParam.btmSheetFor == OptionsBtmSheetType.FOLDER) menuBtmSheetParam.folderName else menuBtmSheetParam.linkTitle,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.titleSmall,
fontSize = 16.sp,
modifier = Modifier.padding(
end = 20.dp
),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
lineHeight = 20.sp
)
}
HorizontalDivider(
modifier = Modifier.padding(start = 25.dp, end = 25.dp),
thickness = 1.dp,
color = MaterialTheme.colorScheme.outline.copy(0.25f)
)
Spacer(modifier = Modifier.height(5.dp))
}
if (!isNoteBtnSelected.value) {
IndividualMenuComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,34 @@ fun CollectionsScreen(navController: NavController) {
foldersData.id.toString() + foldersData.folderName
}) { folderIndex, folderData ->
FolderIndividualComponent(
isCheckBoxChecked = if (TransferActionsBtmBarValues.currentTransferActionType.value == TransferActionType.NOTHING) mutableStateOf(
collectionsScreenVM.selectedFoldersData.contains(
folderData
)
) else mutableStateOf(TransferActionsBtmBarValues.sourceFolders.map { it.id }
.contains(folderData.id)),
checkBoxState = { checkBoxState ->
if (TransferActionsBtmBarValues.currentTransferActionType.value == TransferActionType.NOTHING) {
if (checkBoxState) {
collectionsScreenVM.selectedFoldersData.add(
folderData
)
} else {
collectionsScreenVM.selectedFoldersData.removeAll {
it == folderData
}
}
} else {
if (checkBoxState) {
TransferActionsBtmBarValues.sourceFolders.add(folderData)
} else {
TransferActionsBtmBarValues.sourceFolders.removeAll {
it == folderData
}
}
}
},
showCheckBoxInsteadOfMoreIcon = areFoldersSelectable,
showMoreIcon = !areFoldersSelectable.value,
folderName = folderData.folderName,
folderNote = folderData.infoForSaving,
Expand All @@ -543,14 +571,23 @@ fun CollectionsScreen(navController: NavController) {
shouldOptionsBtmModalSheetBeVisible.value = true
},
onFolderClick = {
if (!areFoldersSelectable.value) {
if (!areFoldersSelectable.value && !TransferActionsBtmBarValues.sourceFolders.map { it.id }
.contains(folderData.id)) {
SpecificCollectionsScreenVM.inARegularFolder.value = true
SpecificCollectionsScreenVM.screenType.value =
SpecificScreenType.SPECIFIC_FOLDER_LINKS_SCREEN
CollectionsScreenVM.currentClickedFolderData.value = folderData
CollectionsScreenVM.rootFolderID = folderData.id
navController.navigate(NavigationRoutes.SPECIFIC_COLLECTION_SCREEN.name)
}
if (TransferActionsBtmBarValues.sourceFolders.map { it.id }
.contains(folderData.id)) {
Toast.makeText(
context,
"You cannot move a folder in itself",
Toast.LENGTH_SHORT
).show()
}
},
onLongClick = {
if (!areFoldersSelectable.value) {
Expand All @@ -559,21 +596,6 @@ fun CollectionsScreen(navController: NavController) {
collectionsScreenVM.changeAllFoldersSelectedData()
collectionsScreenVM.selectedFoldersData.add(folderData)
}
},
showCheckBoxInsteadOfMoreIcon = areFoldersSelectable,
isCheckBoxChecked = mutableStateOf(
collectionsScreenVM.selectedFoldersData.contains(
folderData
)
),
checkBoxState = { checkBoxState ->
if (checkBoxState) {
collectionsScreenVM.selectedFoldersData.add(folderData)
} else {
collectionsScreenVM.selectedFoldersData.removeAll {
it == folderData
}
}
})
}
} else {
Expand Down Expand Up @@ -609,6 +631,16 @@ fun CollectionsScreen(navController: NavController) {
}
MenuBtmSheetUI(
MenuBtmSheetParam(
onMoveItemClick = {
TransferActionsBtmBarValues.currentTransferActionType.value =
TransferActionType.MOVING_OF_FOLDERS
TransferActionsBtmBarValues.sourceFolders.add(CollectionsScreenVM.selectedFolderData.value)
coroutineScope.launch {
btmModalSheetState.hide()
}.invokeOnCompletion {
shouldOptionsBtmModalSheetBeVisible.value = false
}
},
btmModalSheetState = btmModalSheetState,
shouldBtmModalSheetBeVisible = shouldOptionsBtmModalSheetBeVisible,
btmSheetFor = OptionsBtmSheetType.FOLDER,
Expand Down Expand Up @@ -795,7 +827,9 @@ fun CollectionsScreen(navController: NavController) {
)
}
BackHandler {
if (isMainFabRotated.value) {
if (TransferActionsBtmBarValues.currentTransferActionType.value != TransferActionType.NOTHING) {
TransferActionsBtmBarValues.reset()
} else if (isMainFabRotated.value) {
shouldScreenTransparencyDecreasedBoxVisible.value = false
coroutineScope.launch {
awaitAll(async {
Expand Down Expand Up @@ -867,8 +901,10 @@ fun FolderIndividualComponent(
}, indication = null,
onClick = {
onFolderClick(isCheckBoxChecked.value)
isCheckBoxChecked.value = !isCheckBoxChecked.value
checkBoxState(isCheckBoxChecked.value)
if (TransferActionsBtmBarValues.currentTransferActionType.value == TransferActionType.NOTHING) {
isCheckBoxChecked.value = !isCheckBoxChecked.value
checkBoxState(isCheckBoxChecked.value)
}
},
onLongClick = {
onLongClick()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.sakethh.linkora.ui.transferActions

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
Expand All @@ -25,12 +26,13 @@ import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import com.sakethh.linkora.ui.screens.collections.CollectionsScreenVM

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun TransferActionsBtmBar() {
val transferActionsBtmBarVM: TransferActionsBtmBarVM = hiltViewModel()
BottomAppBar {
IconButton(onClick = {
TransferActionsBtmBarVM.reset()
TransferActionsBtmBarValues.reset()
}) {
Icon(Icons.Default.Cancel, null)
}
Expand All @@ -45,13 +47,15 @@ fun TransferActionsBtmBar() {
style = MaterialTheme.typography.titleSmall,
fontSize = 12.sp
)
Spacer(Modifier.height(2.dp))
Text(
text = TransferActionsBtmBarValues.sourceFolders.toList()
.joinToString { it.toString() },
text = TransferActionsBtmBarValues.sourceFolders.toList().map { it.folderName }
.asReversed()
.joinToString { it },
style = MaterialTheme.typography.titleMedium,
fontSize = 16.sp,
modifier = Modifier
.padding(end = 100.dp)
.fillMaxWidth(0.8f)
.horizontalScroll(rememberScrollState()),
maxLines = 1
)
Expand All @@ -72,7 +76,7 @@ fun TransferActionsBtmBar() {
TransferActionType.MOVING_OF_LINKS -> TODO()
TransferActionType.NOTHING -> TODO()
}
TransferActionsBtmBarVM.reset()
TransferActionsBtmBarValues.reset()
}) {
Icon(Icons.Default.ContentPaste, null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@ class TransferActionsBtmBarVM @Inject constructor(
foldersRepo.changeTheParentIdOfASpecificFolder(sourceFolderIds, targetParentId)
}
}

companion object {
fun reset() {
TransferActionsBtmBarValues.currentTransferActionType.value = TransferActionType.NOTHING
TransferActionsBtmBarValues.sourceFolders.clear()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ object TransferActionsBtmBarValues {
snapshotFlow {
sourceFolders.toList()
}.collectLatest {
if (it.toList().isEmpty()) {
reset()
}
linkoraLog(it.toList().map { it.folderName }.toString())
}
}
}

fun reset() {
currentTransferActionType.value = TransferActionType.NOTHING
sourceFolders.clear()
}
}

0 comments on commit 083eea3

Please sign in to comment.