Skip to content

Commit

Permalink
Merge pull request #19 from brumhard/feature/conditional-time-colors
Browse files Browse the repository at this point in the history
Add conditionally colored PR timestamps
  • Loading branch information
brumhard committed Apr 27, 2022
2 parents add8011 + b04b420 commit 155226b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
15 changes: 15 additions & 0 deletions app/lib/ui/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ MaterialColor createMaterialColor(Color color) {
}
return MaterialColor(color.value, swatch);
}

extension CustomColorScheme on ColorScheme {
Color get fresh => brightness == Brightness.light
? const Color(0xFFc9d3f8)
: const Color(0xFF3b60e4);
Color get waiting => brightness == Brightness.light
? const Color(0xFFd7eae0)
: const Color(0xFF519872);
Color get stale => brightness == Brightness.light
? const Color(0xFFf4b8c2)
: const Color(0xFF721121);
Color get rotten => brightness == Brightness.light
? const Color(0xFFebdbc1)
: const Color(0xFF563f1b);
}
43 changes: 31 additions & 12 deletions app/lib/ui/pr_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:primate/services/pr.dart';
import 'package:primate/ui/colors.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:crypto/crypto.dart';
import 'package:timeago/timeago.dart' as timeago;

class PRCard extends StatefulWidget {
final PR pr;
Expand Down Expand Up @@ -103,13 +103,7 @@ List<Widget> cardContentForSize(BuildContext context, PR pr) {
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.overline,
),
Text(
DateFormat("dd MMM. yyyy").format(pr.created) +
" by " +
pr.user,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.overline,
),
Text(timeago.format(pr.created)),
],
),
),
Expand Down Expand Up @@ -156,10 +150,7 @@ List<Widget> cardContentForSize(BuildContext context, PR pr) {
),
Row(
children: [
Text(
DateFormat("dd MMM. yyyy").format(pr.created),
overflow: TextOverflow.ellipsis,
),
conditionallyColoredDuration(context, pr.created),
Padding(
padding: const EdgeInsets.only(left: 5),
child: Tooltip(
Expand Down Expand Up @@ -193,3 +184,31 @@ IconData iconForPRStatus(String status) {
return FontAwesomeIcons.codeBranch;
}
}

Widget conditionallyColoredDuration(BuildContext context, DateTime created) {
DateTime now = DateTime.now();
int ageInDays = now.difference(created).inDays;
Color color = Theme.of(context).colorScheme.rotten;

if (ageInDays < 14) {
color = Theme.of(context).colorScheme.stale;
}

if (ageInDays < 5) {
color = Theme.of(context).colorScheme.waiting;
}

if (ageInDays < 1) {
color = Theme.of(context).colorScheme.fresh;
}

return Container(
margin: const EdgeInsets.fromLTRB(0, 6, 6, 6),
padding: const EdgeInsets.fromLTRB(12, 4, 12, 4),
decoration: BoxDecoration(
color: color,
borderRadius: const BorderRadius.all(Radius.circular(20))
),
child: Text(timeago.format(created)),
);
}
16 changes: 15 additions & 1 deletion app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -391,7 +398,14 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.8"
timeago:
dependency: "direct main"
description:
name: timeago
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.2"
typed_data:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
intl: ^0.17.0
flutter_svg: ^1.0.0
google_fonts: ^2.2.0
timeago: ^3.2.2

dev_dependencies:
flutter_launcher_icons: ^0.9.2
Expand Down

0 comments on commit 155226b

Please sign in to comment.