Skip to content

Commit

Permalink
Closes #128; Improve GesturesExt.kt and implement change months with …
Browse files Browse the repository at this point in the history
…swipe
  • Loading branch information
Iliyan Germanov committed Nov 15, 2021
1 parent 3df7122 commit cb7ef2d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
28 changes: 24 additions & 4 deletions app/src/main/java/com/ivy/wallet/base/GesturesExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ fun Modifier.verticalSwipeListener(
var swipeOffset by remember {
mutableStateOf(0f)
}
var gestureConsumed by remember {
mutableStateOf(false)
}

this.pointerInput(Unit) {
detectVerticalDragGestures(
onDragEnd = {
swipeOffset = 0f
gestureConsumed = false
},
onVerticalDrag = { _, dragAmount ->
//dragAmount: positive when scrolling down; negative when scrolling up
Expand All @@ -31,12 +35,18 @@ fun Modifier.verticalSwipeListener(
when {
swipeOffset > sensitivity -> {
//offset > 0 when swipe down
onSwipeDown()
if (!gestureConsumed) {
onSwipeDown()
gestureConsumed = true
}
}

swipeOffset < -sensitivity -> {
//offset < 0 when swipe up
onSwipeUp()
if (!gestureConsumed) {
onSwipeUp()
gestureConsumed = true
}
}
}

Expand All @@ -53,11 +63,15 @@ fun Modifier.horizontalSwipeListener(
var swipeOffset by remember {
mutableStateOf(0f)
}
var gestureConsumed by remember {
mutableStateOf(false)
}

this.pointerInput(Unit) {
detectHorizontalDragGestures(
onDragEnd = {
swipeOffset = 0f
gestureConsumed = false
},
onHorizontalDrag = { _, dragAmount ->
//dragAmount: positive when scrolling down; negative when scrolling up
Expand All @@ -66,12 +80,18 @@ fun Modifier.horizontalSwipeListener(
when {
swipeOffset > sensitivity -> {
//offset > 0 when swipe right
onSwipeRight()
if (!gestureConsumed) {
onSwipeRight()
gestureConsumed = true
}
}

swipeOffset < -sensitivity -> {
//offset < 0 when swipe left
onSwipeLeft()
if (!gestureConsumed) {
onSwipeLeft()
gestureConsumed = true
}
}
}

Expand Down
22 changes: 20 additions & 2 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeHeader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ internal fun HomeHeader(

onShowMonthModal: () -> Unit,
onOpenMoreMenu: () -> Unit,
onBalanceClick: () -> Unit
onBalanceClick: () -> Unit,

onSelectNextMonth: () -> Unit,
onSelectPreviousMonth: () -> Unit,
) {
val percentExpanded by animateFloatAsState(
targetValue = if (expanded) 1f else 0f,
Expand All @@ -75,7 +78,10 @@ internal fun HomeHeader(
balance = balance,

onShowMonthModal = onShowMonthModal,
onBalanceClick = onBalanceClick
onBalanceClick = onBalanceClick,

onSelectNextMonth = onSelectNextMonth,
onSelectPreviousMonth = onSelectPreviousMonth
)

Spacer(Modifier.height(16.dp))
Expand Down Expand Up @@ -115,6 +121,9 @@ private fun HeaderStickyRow(

onShowMonthModal: () -> Unit,
onBalanceClick: () -> Unit,

onSelectNextMonth: () -> Unit,
onSelectPreviousMonth: () -> Unit,
) {
Row(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -151,6 +160,15 @@ private fun HeaderStickyRow(
Spacer(Modifier.weight(1f))

IvyOutlinedButton(
modifier = Modifier.horizontalSwipeListener(
sensitivity = 100,
onSwipeLeft = {
onSelectPreviousMonth()
},
onSwipeRight = {
onSelectNextMonth()
}
),
iconStart = R.drawable.ic_calendar,
text = period.toDisplayShort(LocalIvyContext.current.startDayOfMonth),
) {
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ fun BoxWithConstraintsScope.HomeTab(screen: Screen.Main) {
onSetCurrency = viewModel::setCurrency,
onSetPeriod = viewModel::setPeriod,
onPayOrGet = viewModel::payOrGet,
onDismissCustomerJourneyCard = viewModel::dismissCustomerJourneyCard
onDismissCustomerJourneyCard = viewModel::dismissCustomerJourneyCard,
onSelectNextMonth = viewModel::nextMonth,
onSelectPreviousMonth = viewModel::previousMonth
)
}

Expand Down Expand Up @@ -157,7 +159,9 @@ private fun BoxWithConstraintsScope.UI(
onSetBuffer: (Double) -> Unit = {},
onSetPeriod: (TimePeriod) -> Unit = {},
onPayOrGet: (Transaction) -> Unit = {},
onDismissCustomerJourneyCard: (CustomerJourneyCardData) -> Unit = {}
onDismissCustomerJourneyCard: (CustomerJourneyCardData) -> Unit = {},
onSelectNextMonth: () -> Unit = {},
onSelectPreviousMonth: () -> Unit = {},
) {
var bufferModalData: BufferModalData? by remember { mutableStateOf(null) }
var currencyModalVisible by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -213,7 +217,9 @@ private fun BoxWithConstraintsScope.UI(
},
onBalanceClick = {
onBalanceClick()
}
},
onSelectNextMonth = onSelectNextMonth,
onSelectPreviousMonth = onSelectPreviousMonth
)

HomeTransactionsLazyColumn(
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,22 @@ class HomeViewModel @Inject constructor(
customerJourneyLogic.dismissCard(card)
load()
}

fun nextMonth() {
val month = period.value?.month
if (month != null) {
load(
period = month.incrementMonthPeriod(ivyContext, 1L),
)
}
}

fun previousMonth() {
val month = period.value?.month
if (month != null) {
load(
period = month.incrementMonthPeriod(ivyContext, -1L),
)
}
}
}

0 comments on commit cb7ef2d

Please sign in to comment.