WIP: extract transaction view computation; bug on delimiter redondance
This commit is contained in:
parent
c055dbfe3a
commit
f7fe3fa7df
|
@ -200,15 +200,58 @@ class _ActivityScreenState extends State<ActivityScreen> {
|
||||||
|
|
||||||
Widget getHistory(BuildContext context, DuniterIndexer duniterIndexer) {
|
Widget getHistory(BuildContext context, DuniterIndexer duniterIndexer) {
|
||||||
int keyID = 0;
|
int keyID = 0;
|
||||||
String? dateDelimiter;
|
|
||||||
String? lastDateDelimiter;
|
|
||||||
const double avatarSize = 200;
|
const double avatarSize = 200;
|
||||||
|
String? lastDateDelimiter;
|
||||||
|
bool? isDouble;
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: duniterIndexer.transBC!.map((repository) {
|
||||||
|
final answer =
|
||||||
|
_computeHistoryView(repository, lastDateDelimiter, isDouble);
|
||||||
|
isDouble = lastDateDelimiter == answer['dateDelimiter'];
|
||||||
|
lastDateDelimiter = answer['dateDelimiter'];
|
||||||
|
|
||||||
|
return Column(children: <Widget>[
|
||||||
|
if (answer['isMigrationTime'])
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 30),
|
||||||
|
child: Text(
|
||||||
|
'Début de la ĞDev',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 25,
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (!isDouble! && answer['dateDelimiter'] != '')
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 30),
|
||||||
|
child: Text(
|
||||||
|
answer['dateDelimiter'],
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 23, color: orangeC, fontWeight: FontWeight.w300),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TransactionTile(
|
||||||
|
widget: widget,
|
||||||
|
keyID: keyID,
|
||||||
|
avatarSize: avatarSize,
|
||||||
|
repository: repository,
|
||||||
|
dateForm: answer['dateForm'],
|
||||||
|
finalAmount: answer['finalAmount'],
|
||||||
|
duniterIndexer: duniterIndexer,
|
||||||
|
context: context),
|
||||||
|
]);
|
||||||
|
}).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map _computeHistoryView(repository, lastDateDelimiter, isDouble) {
|
||||||
bool isTody = false;
|
bool isTody = false;
|
||||||
bool isYesterday = false;
|
bool isYesterday = false;
|
||||||
bool isThisWeek = false;
|
bool isThisWeek = false;
|
||||||
bool isMigrationTime = false;
|
bool isMigrationTime = false;
|
||||||
bool isMigrationTimePassed = false;
|
bool isMigrationTimePassed = false;
|
||||||
|
String? dateDelimiter;
|
||||||
|
|
||||||
final Map<int, String> monthsInYear = {
|
final Map<int, String> monthsInYear = {
|
||||||
1: "month1".tr(),
|
1: "month1".tr(),
|
||||||
|
@ -224,111 +267,85 @@ class _ActivityScreenState extends State<ActivityScreen> {
|
||||||
11: "month11".tr(),
|
11: "month11".tr(),
|
||||||
12: "month12".tr()
|
12: "month12".tr()
|
||||||
};
|
};
|
||||||
|
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
||||||
|
late double amount;
|
||||||
|
late String finalAmount;
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
DateTime date = repository[0];
|
||||||
|
String dateForm;
|
||||||
|
bool isDelimiter = true;
|
||||||
|
|
||||||
return Column(
|
if ({4, 10, 11, 12}.contains(date.month)) {
|
||||||
children: duniterIndexer.transBC!.map((repository) {
|
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 3)}.";
|
||||||
// log.d('bbbbbbbbbbbbbbbbbbbbbb: ' + repository.toString());
|
} else if ({1, 2, 7, 9}.contains(date.month)) {
|
||||||
|
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 4)}.";
|
||||||
|
} else {
|
||||||
|
dateForm = "${date.day} ${monthsInYear[date.month]}";
|
||||||
|
}
|
||||||
|
|
||||||
DateTime now = DateTime.now();
|
int weekNumber(DateTime date) {
|
||||||
DateTime date = repository[0];
|
int dayOfYear = int.parse(DateFormat("D").format(date));
|
||||||
|
return ((dayOfYear - date.weekday + 10) / 7).floor();
|
||||||
|
}
|
||||||
|
|
||||||
String dateForm;
|
final transactionDate = DateTime(date.year, date.month, date.day);
|
||||||
if ({4, 10, 11, 12}.contains(date.month)) {
|
final todayDate = DateTime(now.year, now.month, now.day);
|
||||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 3)}.";
|
final yesterdayDate = DateTime(now.year, now.month, now.day - 1);
|
||||||
} else if ({1, 2, 7, 9}.contains(date.month)) {
|
|
||||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 4)}.";
|
if (transactionDate == todayDate && !isTody) {
|
||||||
|
dateDelimiter = lastDateDelimiter = "today".tr();
|
||||||
|
isTody = true;
|
||||||
|
} else if (transactionDate == yesterdayDate && !isYesterday) {
|
||||||
|
dateDelimiter = lastDateDelimiter = "yesterday".tr();
|
||||||
|
isYesterday = true;
|
||||||
|
} else if (weekNumber(date) == weekNumber(now) &&
|
||||||
|
date.year == now.year &&
|
||||||
|
lastDateDelimiter != "thisWeek".tr() &&
|
||||||
|
transactionDate != yesterdayDate &&
|
||||||
|
transactionDate != todayDate &&
|
||||||
|
!isThisWeek) {
|
||||||
|
dateDelimiter = lastDateDelimiter = "thisWeek".tr();
|
||||||
|
isThisWeek = true;
|
||||||
|
} else if (lastDateDelimiter != monthsInYear[date.month] &&
|
||||||
|
lastDateDelimiter != "${monthsInYear[date.month]} ${date.year}" &&
|
||||||
|
transactionDate != todayDate &&
|
||||||
|
transactionDate != yesterdayDate &&
|
||||||
|
!(weekNumber(date) == weekNumber(now) && date.year == now.year)) {
|
||||||
|
if (date.year == now.year) {
|
||||||
|
dateDelimiter = lastDateDelimiter = monthsInYear[date.month];
|
||||||
} else {
|
} else {
|
||||||
dateForm = "${date.day} ${monthsInYear[date.month]}";
|
dateDelimiter =
|
||||||
|
lastDateDelimiter = "${monthsInYear[date.month]} ${date.year}";
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
isDelimiter = false;
|
||||||
|
}
|
||||||
|
|
||||||
int weekNumber(DateTime date) {
|
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
|
||||||
int dayOfYear = int.parse(DateFormat("D").format(date));
|
|
||||||
return ((dayOfYear - date.weekday + 10) / 7).floor();
|
|
||||||
}
|
|
||||||
|
|
||||||
final transactionDate = DateTime(date.year, date.month, date.day);
|
if (isUdUnit) {
|
||||||
final todayDate = DateTime(now.year, now.month, now.day);
|
amount = round(amount / balanceRatio);
|
||||||
final yesterdayDate = DateTime(now.year, now.month, now.day - 1);
|
finalAmount = 'ud'.tr(args: ['$amount ']);
|
||||||
|
} else {
|
||||||
|
finalAmount = '$amount $currencyName';
|
||||||
|
}
|
||||||
|
|
||||||
if (transactionDate == todayDate && !isTody) {
|
if (!isMigrationTimePassed && date.compareTo(startBlockchainTime) < 0) {
|
||||||
dateDelimiter = lastDateDelimiter = "today".tr();
|
isMigrationTimePassed = true;
|
||||||
isTody = true;
|
isMigrationTime = true;
|
||||||
} else if (transactionDate == yesterdayDate && !isYesterday) {
|
} else {
|
||||||
dateDelimiter = lastDateDelimiter = "yesterday".tr();
|
isMigrationTime = false;
|
||||||
isYesterday = true;
|
}
|
||||||
} else if (weekNumber(date) == weekNumber(now) &&
|
|
||||||
date.year == now.year &&
|
|
||||||
lastDateDelimiter != "thisWeek".tr() &&
|
|
||||||
transactionDate != yesterdayDate &&
|
|
||||||
transactionDate != todayDate &&
|
|
||||||
!isThisWeek) {
|
|
||||||
dateDelimiter = lastDateDelimiter = "thisWeek".tr();
|
|
||||||
isThisWeek = true;
|
|
||||||
} else if (lastDateDelimiter != monthsInYear[date.month] &&
|
|
||||||
lastDateDelimiter != "${monthsInYear[date.month]} ${date.year}" &&
|
|
||||||
transactionDate != todayDate &&
|
|
||||||
transactionDate != yesterdayDate &&
|
|
||||||
!(weekNumber(date) == weekNumber(now) && date.year == now.year)) {
|
|
||||||
if (date.year == now.year) {
|
|
||||||
dateDelimiter = lastDateDelimiter = monthsInYear[date.month];
|
|
||||||
} else {
|
|
||||||
dateDelimiter =
|
|
||||||
lastDateDelimiter = "${monthsInYear[date.month]} ${date.year}";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dateDelimiter = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
log.d('dateDelimiter: $dateDelimiter');
|
||||||
late double amount;
|
log.d('lastDateDelimiter: $lastDateDelimiter');
|
||||||
late String finalAmount;
|
|
||||||
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
|
|
||||||
|
|
||||||
if (isUdUnit) {
|
return {
|
||||||
amount = round(amount / balanceRatio);
|
'finalAmount': finalAmount,
|
||||||
finalAmount = 'ud'.tr(args: ['$amount ']);
|
'isMigrationTime': isMigrationTime,
|
||||||
} else {
|
'dateDelimiter': dateDelimiter ?? '',
|
||||||
finalAmount = '$amount $currencyName';
|
'isDelimiter': isDelimiter,
|
||||||
}
|
'dateForm': dateForm,
|
||||||
|
};
|
||||||
if (!isMigrationTimePassed && date.compareTo(startBlockchainTime) < 0) {
|
|
||||||
isMigrationTimePassed = true;
|
|
||||||
isMigrationTime = true;
|
|
||||||
} else {
|
|
||||||
isMigrationTime = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(children: <Widget>[
|
|
||||||
if (isMigrationTime)
|
|
||||||
const Padding(
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 30),
|
|
||||||
child: Text(
|
|
||||||
'Début de la ĞDev',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 25,
|
|
||||||
color: Colors.blueAccent,
|
|
||||||
fontWeight: FontWeight.w500),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (dateDelimiter != null)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 30),
|
|
||||||
child: Text(
|
|
||||||
dateDelimiter!,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 23, color: orangeC, fontWeight: FontWeight.w300),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TransactionTile(
|
|
||||||
widget: widget,
|
|
||||||
keyID: keyID,
|
|
||||||
avatarSize: avatarSize,
|
|
||||||
repository: repository,
|
|
||||||
dateForm: dateForm,
|
|
||||||
finalAmount: finalAmount,
|
|
||||||
duniterIndexer: duniterIndexer,
|
|
||||||
context: context),
|
|
||||||
]);
|
|
||||||
}).toList());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue