Skip to content

Commit

Permalink
Merge pull request #50 from t-regbs/snackbar-dismiss
Browse files Browse the repository at this point in the history
Fix Nearest Alarm Message
  • Loading branch information
t-regbs authored May 25, 2024
2 parents 1cc000f + 4b93df0 commit 7819602
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 21 deletions.
16 changes: 16 additions & 0 deletions .idea/CamelCaseConfigNew.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

196 changes: 196 additions & 0 deletions .idea/cody_history.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/studiobot.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.timilehinaregbesola.mathalarm.domain.model.Alarm
import com.timilehinaregbesola.mathalarm.presentation.alarmlist.components.AlarmListHeader.LIST_HEADER_ALPHA
import com.timilehinaregbesola.mathalarm.presentation.alarmlist.components.AlarmListHeader.LIST_HEADER_ELEVATION
import com.timilehinaregbesola.mathalarm.presentation.alarmlist.components.AlarmListHeader.LIST_HEADER_FONT_SIZE
import com.timilehinaregbesola.mathalarm.presentation.alarmlist.components.AlarmListHeader.ONE_WEEK_IN_MILLISECONDS
import com.timilehinaregbesola.mathalarm.presentation.ui.darkPrimaryLight
import com.timilehinaregbesola.mathalarm.presentation.ui.spacing
import com.timilehinaregbesola.mathalarm.utils.getCalendarFromAlarm
Expand Down Expand Up @@ -57,7 +58,11 @@ fun ListHeader(
) {
with(MaterialTheme.spacing) {
Text(
text = if (enabled) "Next alarm in $nearestAlarmMessage" else "No upcoming alarms",
text = if (enabled && nearestAlarmMessage != null) {
"Next alarm in $nearestAlarmMessage"
} else {
"No upcoming alarms"
},
modifier = Modifier
.padding(
start = extraMedium,
Expand All @@ -77,24 +82,23 @@ private fun buildNearestTime(
var nearestTime: Long? = null
var nearestIndex = -1
if (alarmList.isNotEmpty()) {
nearestTime = alarmList.firstOrNull { it.isOn }?.let { it1 ->
getCalendarFromAlarm(it1, calendar).timeInMillis
}
nearestIndex = alarmList.indexOfFirst { it.isOn }
val now = System.currentTimeMillis()
val onAlarms = alarmList.filter { it.isOn }
onAlarms.forEachIndexed { index, alarm ->
val cal = getCalendarFromAlarm(alarm, calendar)
val time = cal.timeInMillis
Timber.d("time = $time")
val currentEval = time - now
val nearestEval = nearestTime!! - now
Timber.d("index = $index, currentEval = $currentEval, nearestEval = $nearestEval")
if (currentEval < nearestEval) {
nearestTime = time
nearestIndex = index
alarmList
.filter { it.isOn }
.forEachIndexed { index, alarm ->
val cal = getCalendarFromAlarm(alarm, calendar)
var alarmTime = cal.timeInMillis

val now = System.currentTimeMillis()
Timber.d("time = $alarmTime")
if (alarmTime < now) {
alarmTime += ONE_WEEK_IN_MILLISECONDS
}
val timeToAlarm = alarmTime - now
if (nearestTime == null || timeToAlarm < nearestTime!!) {
nearestTime = timeToAlarm
nearestIndex = index
}
}
}
}
return Pair(nearestTime, nearestIndex)
}
Expand All @@ -114,6 +118,7 @@ private fun ListHeaderPreview() {

private object AlarmListHeader {
const val LIST_HEADER_ALPHA = 0.1f
const val ONE_WEEK_IN_MILLISECONDS = 7 * 24 * 60 * 60 * 1000
val LIST_HEADER_ELEVATION = 4.dp
val LIST_HEADER_FONT_SIZE = 16.sp
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fun ListDisplayScreen(
val result = snackbarHoststate.showSnackbar(
message = event.message,
actionLabel = event.action,
withDismissAction = true,
duration = SnackbarDuration.Short
)
if (result == ActionPerformed) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
accompanist = "0.35.0-alpha"
# @keep
android_compile_sdk = "34"
android_gradle_plugin = "8.4.0-alpha03"
android_gradle_plugin = "8.4.1"
# @keep
android_min_sdk = "21"
# @keep
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 11 00:07:56 GMT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 7819602

Please sign in to comment.