2020-04-26 16:15:48 +00:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
|
2020-05-06 16:31:38 +00:00
|
|
|
import 'date_time_extension.dart';
|
2020-04-26 16:15:48 +00:00
|
|
|
|
2020-10-28 06:23:50 +00:00
|
|
|
extension on PresenceType {
|
|
|
|
String getLocalized(BuildContext context) {
|
|
|
|
switch (this) {
|
|
|
|
case PresenceType.online:
|
|
|
|
return L10n.of(context).online;
|
|
|
|
case PresenceType.unavailable:
|
|
|
|
return L10n.of(context).unavailable;
|
|
|
|
case PresenceType.offline:
|
|
|
|
default:
|
|
|
|
return L10n.of(context).offline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-26 16:15:48 +00:00
|
|
|
extension PresenceExtension on Presence {
|
2020-10-28 06:23:50 +00:00
|
|
|
String getLocalizedLastActiveAgo(BuildContext context) {
|
|
|
|
if (presence.lastActiveAgo != null && presence.lastActiveAgo != 0) {
|
|
|
|
return L10n.of(context).lastActiveAgo(DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
DateTime.now().millisecondsSinceEpoch - presence.lastActiveAgo)
|
|
|
|
.localizedTimeShort(context));
|
|
|
|
}
|
|
|
|
return L10n.of(context).lastSeenLongTimeAgo;
|
|
|
|
}
|
2020-10-03 13:53:08 +00:00
|
|
|
|
2020-04-26 16:15:48 +00:00
|
|
|
String getLocalizedStatusMessage(BuildContext context) {
|
2020-06-10 08:07:01 +00:00
|
|
|
if (presence.statusMsg?.isNotEmpty ?? false) {
|
|
|
|
return presence.statusMsg;
|
2020-04-26 16:15:48 +00:00
|
|
|
}
|
2020-10-28 14:01:16 +00:00
|
|
|
if (presence.currentlyActive ?? false) {
|
2020-08-23 16:10:33 +00:00
|
|
|
return L10n.of(context).currentlyActive;
|
|
|
|
}
|
2020-10-28 06:23:50 +00:00
|
|
|
return presence.presence.getLocalized(context);
|
2020-04-26 16:15:48 +00:00
|
|
|
}
|
|
|
|
}
|