Skip to content

Commit

Permalink
fix calendar sync options checkbox updating
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Aug 7, 2024
1 parent ee43846 commit c6d2d21
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.rebble.cobble.shared.domain.calendar.CalendarSync
import io.rebble.cobble.shared.domain.state.ConnectionState
import io.rebble.cobble.util.Debouncer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
Expand All @@ -29,10 +30,12 @@ class CalendarControlFlutterBridge @Inject constructor(

init {
bridgeLifecycleController.setupControl(Pigeons.CalendarControl::setup, this)
calendarSync.getUpdatesFlow().onEach { calendars ->
calendarSync.getUpdatesFlow().debounce(50).onEach { calendars ->
Timber.d("Calendar list updated: %d", calendars.size)
calendarCallbacks.onCalendarListUpdated(calendars.map {
Pigeons.CalendarPigeon.Builder()
.setId(it.id.toLong())
.setAccount(it.ownerName)
.setName(it.name)
.setColor(it.color.toLong())
.setEnabled(it.enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CalendarSync(
private val metadataFlow: Flow<WatchVersion.WatchVersionResponse> by inject(named("connectedWatchMetadata"))
private val timelinePinDao: TimelinePinDao by inject()
private val calendarDao: CalendarDao by inject()
private val calendarEnableChangeFlow: MutableSharedFlow<List<Calendar>> = MutableSharedFlow()

init {
Logging.d("CalendarSync init")
Expand Down
51 changes: 34 additions & 17 deletions lib/ui/screens/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../../infrastructure/pigeons/pigeons.g.dart';

class Calendar extends HookConsumerWidget implements CobbleScreen {
const Calendar({super.key});

Expand Down Expand Up @@ -51,24 +53,15 @@ class Calendar extends HookConsumerWidget implements CobbleScreen {
}

final calendarElements = groupBy(calendarList, (e) => e.account).entries.map((grp) {
return <CobbleTile>[
return [
CobbleTile.sectionTitle(key: ValueKey("head${grp.key}"), title: grp.key),
...grp.value.map((c) {
return CobbleTile.setting(
key: ValueKey(c.id),
leading: BoxDecoration(
color: Color(c.color).withOpacity(1),
shape: BoxShape.circle,
),
title: c.name,
child: Checkbox(
value: c.enabled,
onChanged: (enabled) {
calendarControl.setCalendarEnabled(c.id, enabled!);
},
),
);
})
...grp.value.map(
(c) => _CalendarSettings(
key: ValueKey(c.id),
calendarPigeon: c,
calendarControl: calendarControl,
),
),
];
}).toList();

Expand Down Expand Up @@ -99,3 +92,27 @@ class Calendar extends HookConsumerWidget implements CobbleScreen {
);
}
}


class _CalendarSettings extends StatelessWidget {
final CalendarPigeon calendarPigeon;
final CalendarControl calendarControl;
const _CalendarSettings({Key? key, required this.calendarPigeon, required this.calendarControl}) : super(key: key);

@override
Widget build(BuildContext context) {
return CobbleTile.setting(
leading: BoxDecoration(
color: Color(calendarPigeon.color).withOpacity(1),
shape: BoxShape.circle,
),
title: calendarPigeon.name,
child: Checkbox(
value: calendarPigeon.enabled,
onChanged: (enabled) {
calendarControl.setCalendarEnabled(calendarPigeon.id, enabled!);
},
),
);
}
}

0 comments on commit c6d2d21

Please sign in to comment.