Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Undo animation when delete item & Fix FDroid Build #98

Merged
merged 3 commits into from
Oct 6, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/captures
.externalNativeBuild
keystore.jks
./**/keykeystore.jks
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ android {
applicationId = "com.lolo.io.onelist"
// version code elvis right operand should be incremented too when publishing a new release, for fDroid build.
versionCode = versionCodeCI ?: 21
versionName = "1.5.1"
versionName = "1.5.2"
vectorDrawables.useSupportLibrary = true
testBuildType = "instrumented"

Expand Down
Binary file removed app/keystore.jks
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun OneListTheme(
MaterialTheme(
colorScheme = colorScheme,
content = content,
typography = typography(colorScheme),
typography = typography(),
shapes = Shapes
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lolo.io.onelist.core.designsystem

import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
Expand All @@ -12,7 +11,7 @@ import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.sp

@Composable
fun typography(colorScheme: ColorScheme) = Typography(
fun typography() = Typography(
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ data class AppColors(
val itemComment: Color,
val itemDone: Color,
val swipeDeleteBackground: Color,
val swipeDeleteText: Color,
val swipeDeleteProgressBackground: Color,
val swipeEditBackground: Color,
val itemArrow: Color,
val itemRowForeground: Color,
val itemRowBackground: Color,
val swipeIcons: Color,

// Add Item
val addItemCheck: Color,
Expand Down Expand Up @@ -127,6 +130,9 @@ fun appColors(
textFieldPlaceholder = MaterialTheme.colorScheme.outline,
textFieldBackgroundNoBorder = Color.Transparent,
itemRowBackground = MaterialTheme.colorScheme.surface,
swipeIcons = MaterialTheme.colorScheme.onPrimary,
swipeDeleteText = MaterialTheme.colorScheme.tertiary,
swipeDeleteProgressBackground = MaterialTheme.colorScheme.tertiary,
textFieldColors = TextFieldDefaults.colors(
focusedContainerColor = MaterialTheme.colorScheme.background,
unfocusedContainerColor = MaterialTheme.colorScheme.background,
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/1.5.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Small UI change - add animation when delete item.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lolo.io.onelist.feature.lists

import android.content.res.Configuration
import android.util.Log
import android.view.SoundEffectConstants
import android.widget.Toast
import androidx.compose.foundation.gestures.detectTapGestures
Expand Down Expand Up @@ -58,6 +59,8 @@ import kotlinx.coroutines.launch
import org.koin.compose.koinInject
import kotlin.math.roundToInt

const val DELETE_ANIMATION_DURATION = 800L

@Composable
fun ListsScreen(
navigateToSettings: () -> Unit
Expand Down Expand Up @@ -97,6 +100,7 @@ fun ListsScreen(
override fun createListThenAddItem(item: Item) = viewModel.createListThenAddItem(
ItemList(context.getString(R.string.list_default_name)), item
)

override fun switchItemStatus(item: Item) = viewModel.switchItemStatus(item)
override fun removeItem(item: Item) = viewModel.removeItem(item)
override fun switchItemCommentShown(item: Item) = viewModel.switchItemCommentShown(item)
Expand Down Expand Up @@ -226,12 +230,12 @@ internal fun ListsScreenUI(
onCommentValueChange = { addItemComment = it },
onSubmit = {

val itemToAdd = Item(
val itemToAdd = Item(
title = addItemTitle,
comment = addItemComment,
commentDisplayed = addItemComment.isNotEmpty()
)
if(selectedList != null) {
if (selectedList != null) {
actions.addItem(itemToAdd)
} else {
actions.createListThenAddItem(itemToAdd)
Expand Down Expand Up @@ -259,13 +263,17 @@ internal fun ListsScreenUI(
},
items = displayedItems,
onItemSwipedToStart = {
Log.d("ANIM", "onItemSwipedToStart")
if (deleteItemJobs[it.id] == null) {
deleteItemJobs[it.id] = coroutineScope.launch {
delay(2000)
actions.removeItem(it)
delay(DELETE_ANIMATION_DURATION + 500)
if (deleteItemJobs[it.id] != null) {
Log.d("ANIM", "onItemSwipedToStart")
actions.removeItem(it)
}
deleteItemJobs -= it.id
}
}

},
onItemSwipedToEnd = {
showDialog = DialogShown.EditItemDialog
Expand All @@ -274,6 +282,7 @@ internal fun ListsScreenUI(
onItemSwipedBackToCenter = {
deleteItemJobs[it.id]?.cancel(CancellationException("Canceled by user"))
deleteItemJobs -= it.id
Log.d("ANIM", "onItemSwipedBackToCenter")
},
onShowOrHideComment = {
actions.switchItemCommentShown(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lolo.io.onelist.feature.lists.components.core.reorderable_swipeable_list

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
import androidx.compose.foundation.layout.Row
Expand All @@ -15,7 +16,11 @@ import androidx.compose.material3.SwipeToDismissBoxValue.StartToEnd
import androidx.compose.material3.rememberSwipeToDismissBoxState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -51,6 +56,7 @@ fun SwipeableRowScope.SwipeableRow(
onSwipedToEnd: () -> Unit = {},
onSwipedToStart: () -> Unit = {},
onSwipedBackToCenter: () -> Unit = {},
onInitiateSwipeBackToCenter: () -> Unit = {},
content: @Composable() (() -> Unit),
) {

Expand All @@ -61,21 +67,35 @@ fun SwipeableRowScope.SwipeableRow(
.fillMaxWidth()
) {

var localSwipeState = remember {
Settled
}

val state = rememberSwipeToDismissBoxState(
confirmValueChange = {
when (it) {
StartToEnd -> {
onSwipedToEnd()
if (localSwipeState != StartToEnd) {
localSwipeState = StartToEnd
onSwipedToEnd()
}
true
}

EndToStart -> {
onSwipedToStart()

if (localSwipeState != EndToStart) {
localSwipeState = EndToStart
onSwipedToStart()
}
true
}

Settled -> {
onSwipedBackToCenter()
if (localSwipeState != Settled) {
localSwipeState = Settled
onSwipedBackToCenter()
}
true
}
}
Expand All @@ -92,12 +112,21 @@ fun SwipeableRowScope.SwipeableRow(
}
}

var hasInitiatedSwipeBackToCenter by remember {
mutableStateOf(false)
}

SwipeToDismissBox(
state = state, backgroundContent = when (state.dismissDirection) {
StartToEnd -> backgroundStartToEnd
EndToStart -> ({
Row(modifier = Modifier.pointerInput(Unit) {
detectHorizontalDragGestures { change, dragAmount ->
detectHorizontalDragGestures { _, _ ->
if (!hasInitiatedSwipeBackToCenter) {
hasInitiatedSwipeBackToCenter = true
onInitiateSwipeBackToCenter()

}
coroutineScope.launch {
state.reset()
}
Expand All @@ -107,7 +136,9 @@ fun SwipeableRowScope.SwipeableRow(
}
})

Settled -> ({})
Settled -> ({
hasInitiatedSwipeBackToCenter = false
})
}
) {
Row(
Expand Down
Loading
Loading