mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 04:48:51 +00:00
Improved the way the date is shown
This commit is contained in:
parent
7666af0975
commit
c94a294252
@ -1,4 +1,5 @@
|
||||
import 'package:comunic/models/conversation.dart';
|
||||
import 'package:comunic/utils/date_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -36,7 +37,8 @@ class ConversationTile extends StatelessWidget {
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
_buildSubInformation(Icons.access_time, "time"), //TODO : improve the way the time is shown
|
||||
_buildSubInformation(
|
||||
Icons.access_time, diffTimeFromNowToStr(conversation.lastActive)),
|
||||
_buildSubInformation(
|
||||
Icons.group,
|
||||
conversation.members.length == 1
|
||||
|
48
lib/utils/date_utils.dart
Normal file
48
lib/utils/date_utils.dart
Normal file
@ -0,0 +1,48 @@
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
|
||||
/// Date utilities
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
/// Get current timestamp
|
||||
int time() {
|
||||
return (DateTime.now().millisecondsSinceEpoch / 1000).floor();
|
||||
}
|
||||
|
||||
String diffTimeToStr(int amount) {
|
||||
if (amount < 0) amount = 0;
|
||||
|
||||
// Seconds
|
||||
if (amount < 60) return tr("%secs%s", args: {"secs": amount.toString()});
|
||||
|
||||
// Minutes
|
||||
if (amount < 60 * 60)
|
||||
return tr("%mins% min", args: {"mins": (amount / 60).floor().toString()});
|
||||
|
||||
// Hours
|
||||
if (amount < 60 * 60 * 24)
|
||||
return tr("%hours% h",
|
||||
args: {"hours": (amount / (60 * 60)).floor().toString()});
|
||||
|
||||
// Days
|
||||
if (amount < 60 * 60 * 24 * 30)
|
||||
return tr("%days%d",
|
||||
args: {"days": (amount / (60 * 60 * 24)).floor().toString()});
|
||||
|
||||
// Months
|
||||
if (amount < 60 * 60 * 24 * 365) {
|
||||
final months = (amount / (60 * 60 * 24 * 30)).floor();
|
||||
return months == 1
|
||||
? tr("1 month")
|
||||
: tr("%months% months", args: {"months": months.toString()});
|
||||
}
|
||||
|
||||
// Years
|
||||
final years = (amount / (60 * 60 * 24 * 365)).floor();
|
||||
return years == 1 ? tr("1 year") : tr("%years% years",
|
||||
args: {"years": years.toString()});
|
||||
}
|
||||
|
||||
String diffTimeFromNowToStr(int date) {
|
||||
return diffTimeToStr(time() - date);
|
||||
}
|
Loading…
Reference in New Issue
Block a user