Skip to content

Commit

Permalink
Minor optimizations and deadline remaining indicator (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
thermitex authored Aug 2, 2024
1 parent 9d3e0ef commit fcba56b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 33 deletions.
18 changes: 17 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
namespace "com.example.cuckoo"
compileSdk flutter.compileSdkVersion
Expand Down Expand Up @@ -52,11 +58,21 @@ android {
multiDexEnabled true
}

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
// signingConfig signingConfigs.debug
signingConfig signingConfigs.release
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/common/services/widget_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class WidgetControl {
}
// Auto create pin
else if (activeLiveActivityId == null &&
trueSettingsValue(SettingsKey.autoPinEvent)) {
falseSettingsValue(SettingsKey.autoPinEvent)) {
// Check latest event
final event = Moodle().eventManager.nextEvent();
if (event != null &&
Expand Down
9 changes: 4 additions & 5 deletions lib/src/routes/events/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EventsPage extends StatefulWidget {
}

class _EventsPageState extends State<EventsPage> {
/// Rebuild events at midnight to show potential date changes.
/// Rebuild events every minute.
Timer? rebuildTimer;

/// Build app bar action items.
Expand Down Expand Up @@ -209,11 +209,10 @@ class _EventsPageState extends State<EventsPage> {
void initState() {
// Set up rebuild timer
final now = DateTime.now();
final secsTillMidnight =
(60 - now.second) + (59 - now.minute) * 60 + (23 - now.hour) * 3600;
Future.delayed(Duration(seconds: secsTillMidnight), () {
final secsTillNextMin = 60 - now.second;
Future.delayed(Duration(seconds: secsTillNextMin), () {
Moodle().eventManager.rebuildNow();
rebuildTimer = Timer.periodic(const Duration(days: 1),
rebuildTimer = Timer.periodic(const Duration(minutes: 1),
(timer) => Moodle().eventManager.rebuildNow());
});
super.initState();
Expand Down
105 changes: 80 additions & 25 deletions lib/src/routes/events/events_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ class MoodleEventListTile extends StatelessWidget {
final bool displayDeadline;

bool _canShowCompleted(BuildContext context) =>
context.settingsValue<bool>(SettingsKey.greyOutCompleted) ?? true;
event.isCompleted &&
(context.settingsValue<bool>(SettingsKey.greyOutCompleted) ?? true);

Color _eventTintColor(BuildContext context) {
final fallbackColor = context.isDarkMode
? const Color.fromARGB(255, 91, 91, 95)
: const Color.fromARGB(255, 187, 187, 191);
if (event.isCompleted && _canShowCompleted(context)) {
if (_canShowCompleted(context)) {
return fallbackColor;
}
return event.contextWatchedColor(context) ?? fallbackColor;
Expand All @@ -138,17 +139,17 @@ class MoodleEventListTile extends StatelessWidget {
size: 10.5,
weight: FontWeight.bold,
color: _eventTintColor(context))))
..add(const SizedBox(height: 1.0));
..add(const SizedBox(height: 0.5));
}
children.add(Text(event.name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: CuckooTextStyles.body(size: 15, weight: FontWeight.normal)
.copyWith(
color: event.isCompleted && _canShowCompleted(context)
color: _canShowCompleted(context)
? context.theme.tertiaryText
: context.theme.primaryText,
decoration: event.isCompleted && _canShowCompleted(context)
decoration: _canShowCompleted(context)
? TextDecoration.lineThrough
: null,
decorationColor: context.theme.tertiaryText)));
Expand All @@ -161,7 +162,10 @@ class MoodleEventListTile extends StatelessWidget {
);
}

Widget _eventDeadline(BuildContext context) {
Widget _eventDeadline(BuildContext context, double? colorLerp) {
bool canShowRemaining =
!_canShowCompleted(context) && event.remainingTime < 24 * 3600;

String deadlineDisplay(DeadlineDisplayStyle style) {
DateTime eventTime = event.time;
final date = DateFormat.MMMd().format(eventTime);
Expand All @@ -185,27 +189,73 @@ class MoodleEventListTile extends StatelessWidget {
}
}

String remainingDisplay() {
final remainingSecs = event.remainingTime;
final remainingHours = remainingSecs ~/ 3600;
final remainingMins =
max((remainingSecs - remainingHours * 3600) ~/ 60, 0);

return "${remainingHours > 0 ? '${remainingHours}h ' : ''}${remainingMins}m";
}

Color lerpedColor() {
final defaultColor = context.theme.primaryInverseBackground.withAlpha(18);
if (event.color == null ||
colorLerp == null ||
_canShowCompleted(context)) return defaultColor;

const interimThreshold = 0.8;
final interimColor = event.color!.withAlpha(35);
final destColor = event.color!.withAlpha(context.isDarkMode ? 50 : 40);
if (colorLerp < interimThreshold) {
return Color.lerp(
defaultColor, interimColor, colorLerp / interimThreshold)!;
} else {
return Color.lerp(interimColor, destColor,
(colorLerp - interimThreshold) / (1 - interimThreshold))!;
}
}

return GestureDetector(
onTap: () => Settings().switchChoice(
SettingsKey.deadlineDisplay, DeadlineDisplayStyle.values.length,
defaultChoice: DeadlineDisplayStyle.daysRemainingAndTime.index),
child: Container(
width: 70.0,
color: context.theme.tertiaryBackground,
child: Center(
child: Text(
deadlineDisplay(DeadlineDisplayStyle.values[
context.settingsValue<int>(SettingsKey.deadlineDisplay) ??
DeadlineDisplayStyle.daysRemainingAndTime.index]),
textAlign: TextAlign.center,
style: CuckooTextStyles.body(
size: 11,
weight: FontWeight.w600,
color: event.isCompleted && _canShowCompleted(context)
? context.theme.tertiaryText
: context.theme.primaryText,
height: 1.3),
)),
color: lerpedColor(),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
deadlineDisplay(DeadlineDisplayStyle.values[
context.settingsValue<int>(SettingsKey.deadlineDisplay) ??
DeadlineDisplayStyle.daysRemainingAndTime.index]),
textAlign: TextAlign.center,
style: CuckooTextStyles.body(
size: 11,
weight: FontWeight.w600,
color: _canShowCompleted(context)
? context.theme.tertiaryText
: context.theme.primaryText,
height: 1.3),
),
if (canShowRemaining) const SizedBox(height: 2.0),
if (canShowRemaining)
Container(
decoration: BoxDecoration(
color: Colors.orange[context.isDarkMode ? 800 : 500],
borderRadius: BorderRadius.circular(5.0),
),
padding:
const EdgeInsets.symmetric(horizontal: 4.5, vertical: 2.5),
child: Text(
remainingDisplay(),
style: CuckooTextStyles.body(
size: 9,
weight: FontWeight.bold,
color: context.theme.secondaryBackground,
height: 1.0),
),
)
]),
),
);
}
Expand Down Expand Up @@ -237,8 +287,7 @@ class MoodleEventListTile extends StatelessWidget {
Color baseColor = _eventTintColor(context);

late Color stripeColor;
if (event.color == null ||
(event.isCompleted && _canShowCompleted(context))) {
if (event.color == null || _canShowCompleted(context)) {
stripeColor = context.isDarkMode
? const Color.fromARGB(100, 91, 91, 95)
: const Color.fromARGB(80, 187, 187, 191);
Expand Down Expand Up @@ -282,7 +331,7 @@ class MoodleEventListTile extends StatelessWidget {
final total = event.timestart - event.timemodified!;
final passed = DateTime.now().secondEpoch - event.timemodified!;
if (total > 0) {
progress = (passed / total).clamp(0.0, 1.0);
progress = (passed / total).clamp(0.0, 0.99);
}
}

Expand Down Expand Up @@ -347,7 +396,13 @@ class MoodleEventListTile extends StatelessWidget {
],
),
)),
if (displayDeadline) _eventDeadline(context)
if (displayDeadline)
_eventDeadline(
context,
progress == null
? null
: ((progress - 0.6) / 0.4).clamp(0.0, 1.0),
)
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/routes/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class SettingsPage extends StatelessWidget {
const SettingsItem(SettingsKey.autoPinEvent,
label: Constants.kSettingsEventsAutoPin,
description: Constants.kSettingsEventsAutoPinDesc,
defaultValue: true),
defaultValue: false),
const SettingsItem(SettingsKey.greyOutCompleted,
label: Constants.kSettingsEventsGreyOutComleted,
description:
Expand Down

0 comments on commit fcba56b

Please sign in to comment.