From d5fef6a7d97b60e836b03600c1a75225b815ce39 Mon Sep 17 00:00:00 2001 From: orz12 Date: Sun, 18 Feb 2024 17:53:38 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E9=99=90=E5=88=B6=E6=A8=AA=E7=89=88?= =?UTF-8?q?=E5=8D=A1=E7=89=87=E5=86=85=E5=AE=B9=E9=AB=98=E5=BA=A6=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E7=89=B9=E5=AE=9A=E8=AE=BE=E5=A4=87=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E8=B6=85=E5=87=BA=E8=8C=83=E5=9B=B4=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9B=B4=E6=96=B0=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/widgets/video_card_h.dart | 37 ++++++++++----------- lib/utils/utils.dart | 49 +++++++++++++++------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/lib/common/widgets/video_card_h.dart b/lib/common/widgets/video_card_h.dart index 2a1bedf2..a94612e4 100644 --- a/lib/common/widgets/video_card_h.dart +++ b/lib/common/widgets/video_card_h.dart @@ -159,8 +159,11 @@ class VideoContent extends StatelessWidget { Text( videoItem.title as String, textAlign: TextAlign.start, - style: const TextStyle( + style: TextStyle( fontWeight: FontWeight.w500, + fontSize: Theme.of(context).textTheme.bodyMedium!.fontSize, + height: 1.4, + letterSpacing: 0.3, ), maxLines: 2, overflow: TextOverflow.ellipsis, @@ -175,6 +178,8 @@ class VideoContent extends StatelessWidget { text: i['text'] as String, style: TextStyle( fontWeight: FontWeight.w500, + fontSize: + Theme.of(context).textTheme.bodyMedium!.fontSize, letterSpacing: 0.3, color: i['type'] == 'em' ? Theme.of(context).colorScheme.primary @@ -204,24 +209,19 @@ class VideoContent extends StatelessWidget { // ), // ), // const SizedBox(height: 4), - if (showPubdate) - Text( - Utils.dateFormat(videoItem.pubdate!), - style: TextStyle( - fontSize: 11, color: Theme.of(context).colorScheme.outline), - ), - if (showOwner) - Row( - children: [ - Text( - videoItem.owner.name as String, - style: TextStyle( - fontSize: - Theme.of(context).textTheme.labelMedium!.fontSize, - color: Theme.of(context).colorScheme.outline, - ), + if (showOwner || showPubdate) + Expanded( + flex: 0, + child: Text( + "${showPubdate ? Utils.dateFormat(videoItem.pubdate!, formatType: 'day') + ' ' : ''} ${showOwner ? videoItem.owner.name : ''}", + maxLines: 1, + style: TextStyle( + fontSize: 11, + height: 1, + color: Theme.of(context).colorScheme.outline, + overflow: TextOverflow.fade, ), - ], + ), ), Row( children: [ @@ -237,7 +237,6 @@ class VideoContent extends StatelessWidget { theme: 'gray', danmu: videoItem.stat.danmaku as int, ), - const Spacer(), if (source == 'normal') SizedBox( diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index e0a9434e..a24f9858 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -97,10 +97,20 @@ class Utils { currentYearStr = 'MM-DD hh:mm'; lastYearStr = 'YY-MM-DD hh:mm'; return CustomStamp_str( + timestamp: timeStamp, date: lastYearStr, toInt: false); + } else if (formatType == 'day') { + if (distance <= 43200) { + return CustomStamp_str( timestamp: timeStamp, - date: lastYearStr, - toInt: false, - formatType: formatType); + date: 'hh:mm', + toInt: true, + ); + } + return CustomStamp_str( + timestamp: timeStamp, + date: 'YY-MM-DD', + toInt: true, + ); } if (distance <= 60) { return '刚刚'; @@ -111,25 +121,19 @@ class Utils { } else if (DateTime.fromMillisecondsSinceEpoch(time * 1000).year == DateTime.fromMillisecondsSinceEpoch(timeStamp * 1000).year) { return CustomStamp_str( - timestamp: timeStamp, - date: currentYearStr, - toInt: false, - formatType: formatType); + timestamp: timeStamp, date: currentYearStr, toInt: false); } else { return CustomStamp_str( - timestamp: timeStamp, - date: lastYearStr, - toInt: false, - formatType: formatType); + timestamp: timeStamp, date: lastYearStr, toInt: false); } } // 时间戳转时间 - static String CustomStamp_str( - {int? timestamp, // 为空则显示当前时间 - String? date, // 显示格式,比如:'YY年MM月DD日 hh:mm:ss' - bool toInt = true, // 去除0开头 - String? formatType}) { + static String CustomStamp_str({ + int? timestamp, // 为空则显示当前时间 + String? date, // 显示格式,比如:'YY年MM月DD日 hh:mm:ss' + bool toInt = true, // 去除0开头 + }) { timestamp ??= (DateTime.now().millisecondsSinceEpoch / 1000).round(); String timeStr = (DateTime.fromMillisecondsSinceEpoch(timestamp * 1000)).toString(); @@ -159,10 +163,6 @@ class Utils { return timeStr; } - // if (formatType == 'list' && int.parse(DD) > DateTime.now().day - 2) { - // return '昨天'; - // } - date = date .replaceAll('YY', YY) .replaceAll('MM', MM) @@ -229,7 +229,8 @@ class Utils { if (Platform.isAndroid) { buildNumber = buildNumber.substring(0, buildNumber.length - 1); } - bool isUpdate = Utils.needUpdate("v${currentInfo.version}+$buildNumber", data.tagName!); + bool isUpdate = + Utils.needUpdate("${currentInfo.version}+$buildNumber", data.tagName!); if (isUpdate) { SmartDialog.show( animationType: SmartAnimationType.centerFade_otherSlide, @@ -336,11 +337,13 @@ class Utils { } static String generateRandomString(int minLength, int maxLength) { - const String printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#\$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ '; + const String printable = + '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#\$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ '; var random = Random(); int length = minLength + random.nextInt(maxLength - minLength + 1); - return List.generate(length, (index) => printable[random.nextInt(printable.length)]).join(); + return List.generate( + length, (index) => printable[random.nextInt(printable.length)]).join(); } static String base64EncodeRandomString(int minLength, int maxLength) {