1- import 'package:flutter/material.dart' ;
2-
1+ import 'package:clock/clock.dart' ;
32import 'package:intl/intl.dart' ;
43
4+ import 'package:flutter/material.dart' ;
5+
56import 'package:webtrit_phone/l10n/l10n.dart' ;
67import 'package:webtrit_phone/models/models.dart' ;
8+ import 'package:webtrit_phone/extensions/extensions.dart' ;
9+ import 'package:webtrit_phone/widgets/widgets.dart' ;
710
811class PresenceInfoView extends StatelessWidget {
912 const PresenceInfoView ({required this .presenceInfo, super .key});
@@ -23,87 +26,89 @@ class PresenceInfoView extends StatelessWidget {
2326 style: Theme .of (context).textTheme.bodyMedium? .copyWith (fontWeight: FontWeight .bold),
2427 ),
2528 for (final info in presenceInfo)
26- Column (
27- crossAxisAlignment: CrossAxisAlignment .stretch,
28- children: [
29- Text (
30- '${l10n .presence_infoView_device } ${presenceInfo .indexOf (info ) + 1 }' ,
31- style: Theme .of (context).textTheme.bodyMedium? .copyWith (fontWeight: FontWeight .bold),
32- ),
33- Row (
34- mainAxisAlignment: MainAxisAlignment .start,
29+ Builder (
30+ builder: (context) {
31+ final maybeActivityText = info.activities.isNotEmpty
32+ ? info.activities.first.l10n (l10n)
33+ : (info.available ? l10n.presence_infoView_available_true : l10n.presence_infoView_available_false);
34+
35+ final shouldDisplayNote = info.note.isNotEmpty && info.note.trim () != maybeActivityText;
36+
37+ return Column (
38+ crossAxisAlignment: CrossAxisAlignment .stretch,
39+ spacing: 2 ,
3540 children: [
36- Text (l10n.presence_infoView_available, style: Theme .of (context).textTheme.bodyMedium),
37- const SizedBox (width: 4 ),
38- Text (
39- info.available ? l10n.presence_infoView_available_true : l10n.presence_infoView_available_false,
40- style: Theme .of (context).textTheme.bodyMedium,
41- ),
42- ],
43- ),
44- if (info.note.isNotEmpty)
45- Row (
46- mainAxisAlignment: MainAxisAlignment .start,
47- children: [
48- Text (l10n.presence_infoView_note, style: Theme .of (context).textTheme.bodyMedium),
49- const SizedBox (width: 4 ),
50- Text (info.note, style: Theme .of (context).textTheme.bodyMedium),
51- ],
52- ),
53- if (info.activities.isNotEmpty)
54- Row (
55- mainAxisAlignment: MainAxisAlignment .start,
56- children: [
57- Text (l10n.presence_infoView_activity, style: Theme .of (context).textTheme.bodyMedium),
58- const SizedBox (width: 4 ),
59- Text (info.activities.first.name, style: Theme .of (context).textTheme.bodyMedium),
60- ],
61- ),
62- if (info.statusIcon != null && info.statusIcon! .isNotEmpty)
63- Row (
64- mainAxisAlignment: MainAxisAlignment .start,
65- children: [
66- Text (l10n.presence_infoView_statusIcon, style: Theme .of (context).textTheme.bodyMedium),
67- const SizedBox (width: 4 ),
68- Text (info.statusIcon! , style: Theme .of (context).textTheme.bodyMedium),
69- ],
70- ),
71- if (info.timeOffsetMin != null )
72- Row (
73- mainAxisAlignment: MainAxisAlignment .start,
74- children: [
75- Text (l10n.presence_infoView_timeZone, style: Theme .of (context).textTheme.bodyMedium),
76- const SizedBox (width: 4 ),
41+ if (presenceInfo.length > 1 )
7742 Text (
78- 'UTC${info .timeOffsetMin ! >= 0 ? '+' : '' }${(info .timeOffsetMin ! ~/ 60 )}' ,
79- style: Theme .of (context).textTheme.bodyMedium,
43+ '${l10n .presence_infoView_device } ${presenceInfo .indexOf (info ) + 1 }' ,
44+ style: Theme .of (context).textTheme.bodyMedium? .copyWith (fontWeight: FontWeight .bold),
45+ ),
46+ Row (
47+ children: [
48+ SizedBox (
49+ width: 16 ,
50+ height: 16 ,
51+ child: SipPresenceIndicator (
52+ presenceInfo: presenceInfo,
53+ presenceRect: Rect .fromLTWH (0 , 0 , 16 , 16 ),
54+ ),
55+ ),
56+ const SizedBox (width: 4 ),
57+ Text (maybeActivityText, style: Theme .of (context).textTheme.bodySmall),
58+ ],
59+ ),
60+
61+ if (shouldDisplayNote)
62+ Row (
63+ mainAxisAlignment: MainAxisAlignment .start,
64+ children: [
65+ Flexible (child: Text (info.note, style: Theme .of (context).textTheme.bodySmall)),
66+ const SizedBox (width: 4 ),
67+
68+ if (info.statusIcon != null && info.statusIcon! .isNotEmpty)
69+ Text (info.statusIcon! , style: Theme .of (context).textTheme.bodySmall),
70+ ],
8071 ),
81- ],
82- ),
8372
84- if (info.timestamp != null )
85- Row (
86- mainAxisAlignment: MainAxisAlignment .start,
87- children: [
88- Text (l10n.presence_infoView_updated, style: Theme .of (context).textTheme.bodyMedium),
89- const SizedBox (width: 4 ),
90- Text (
91- DateFormat .yMd ().add_Hm ().format (info.timestamp! .toLocal ()),
92- style: Theme .of (context).textTheme.bodyMedium,
73+ if (info.timeOffsetMin != null )
74+ Row (
75+ mainAxisAlignment: MainAxisAlignment .start,
76+ children: [
77+ Text (l10n.presence_infoView_localTime, style: Theme .of (context).textTheme.bodySmall),
78+ const SizedBox (width: 4 ),
79+ Text (
80+ DateFormat .Hm ().format (clock.now ().toUtc ().add (Duration (minutes: info.timeOffsetMin ?? 0 ))),
81+ style: Theme .of (context).textTheme.bodySmall,
82+ ),
83+ Text (
84+ ' (UTC${info .timeOffsetMin ! >= 0 ? '+' : '' }${(info .timeOffsetMin ! ~/ 60 )})' ,
85+ style: Theme .of (context).textTheme.bodySmall,
86+ ),
87+ ],
9388 ),
94- ],
95- ),
96- if (info.device != null && info.device! .isNotEmpty)
97- Row (
98- mainAxisAlignment: MainAxisAlignment .start,
99- children: [
100- Text (l10n.presence_infoView_client, style: Theme .of (context).textTheme.bodyMedium),
101- const SizedBox (width: 4 ),
102- Text (info.device! , style: Theme .of (context).textTheme.bodyMedium),
103- ],
104- ),
105- // const Divider(),
106- ],
89+
90+ if (info.timestamp != null )
91+ Row (
92+ mainAxisAlignment: MainAxisAlignment .start,
93+ children: [
94+ Text (l10n.presence_infoView_updated, style: Theme .of (context).textTheme.bodySmall),
95+ const SizedBox (width: 4 ),
96+
97+ AgoTicker (
98+ timestamp: info.timestamp! ,
99+ builder: (ago) => Text (ago, style: Theme .of (context).textTheme.bodySmall),
100+ ),
101+ ],
102+ ),
103+ if (info.device != null && info.device! .isNotEmpty)
104+ Row (
105+ mainAxisAlignment: MainAxisAlignment .start,
106+ children: [Text (info.device! , style: Theme .of (context).textTheme.bodySmall)],
107+ ),
108+ // const Divider(),
109+ ],
110+ );
111+ },
107112 ),
108113 ],
109114 ),
0 commit comments