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

fix: Visual glitch in alarm and clock lists #303

Merged
merged 1 commit into from
Feb 27, 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
4 changes: 0 additions & 4 deletions app/src/main/java/com/bnyro/clock/ui/components/AlarmRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
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
Expand Down Expand Up @@ -136,9 +135,6 @@ fun AlarmRow(alarm: Alarm, alarmModel: AlarmModel) {
var isEnabled by remember {
mutableStateOf(alarm.enabled)
}
LaunchedEffect(alarm) {
isEnabled = alarm.enabled
}

Switch(
checked = isEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fun AlarmScreen(

}

items(alarms) {
items(items = alarms, key = { it.id }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very neat, I didn't know this feature/argument exists. That's probably very useful at other places of some You Apps too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that until today. I discovered this while trying to fix a totally different problem.

var showDeletionDialog by remember {
mutableStateOf(false)
}
Expand Down
62 changes: 28 additions & 34 deletions app/src/main/java/com/bnyro/clock/ui/screens/ClockScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Create
import androidx.compose.material.icons.filled.Sort
Expand Down Expand Up @@ -104,42 +102,40 @@ fun ClockScreen(
Icon(Icons.Default.Create, null)
}
}) { pv ->
val scrollState = rememberScrollState()
Column(

val selectedZones by clockModel.selectedTimeZones.collectAsState()
LazyColumn(
modifier = Modifier
.padding(horizontal = 12.dp, vertical = 6.dp)
.padding(pv)
.verticalScroll(scrollState)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 28.dp, vertical = 28.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
val dateTime by produceState(
initialValue = TimeHelper.formatDateTime(TimeHelper.getTimeByZone()),
producer = {
while (isActive) {
value = TimeHelper.formatDateTime(TimeHelper.getTimeByZone())
delay(1000)
item {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 28.dp, vertical = 28.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
val dateTime by produceState(
initialValue = TimeHelper.formatDateTime(TimeHelper.getTimeByZone()),
producer = {
while (isActive) {
value = TimeHelper.formatDateTime(TimeHelper.getTimeByZone())
delay(1000)
}
}
}
)
Text(
text = dateTime.second,
style = MaterialTheme.typography.displayMedium
)
Text(
text = dateTime.first,
style = MaterialTheme.typography.bodyLarge
)
)
Text(
text = dateTime.second,
style = MaterialTheme.typography.displayMedium
)
Text(
text = dateTime.first,
style = MaterialTheme.typography.bodyLarge
)
}
}

Spacer(modifier = Modifier.height(6.dp))

val selectedZones by clockModel.selectedTimeZones.collectAsState()
selectedZones.forEach { timeZone ->
items(items = selectedZones, key = { it.zoneId }) { timeZone ->
Box(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -215,8 +211,6 @@ fun ClockScreen(
}
}
}

Spacer(modifier = Modifier.height(10.dp))
}
}

Expand Down
Loading