Skip to content

Commit

Permalink
评论支持显示最后修改时间
Browse files Browse the repository at this point in the history
优化排行榜和历史记录的日志提示
  • Loading branch information
jiangtian616 committed Apr 5, 2022
1 parent cd17627 commit 443c3af
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 34 deletions.
2 changes: 2 additions & 0 deletions lib/src/l18n/en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class en_US {
'uploader': 'Uploader',
'allComments': 'All Comments',
'noComments': 'No Comments',
'lastEditedOn': 'Last edited on',
'getGalleryDetailFailed': 'Get Gallery Detail Failed',
'invisible2User': 'This Gallery is invisible to You',
'invisibleHints': 'This gallery is removed or unavailable.',
Expand Down Expand Up @@ -196,6 +197,7 @@ class en_US {

/// ranklist view
'getRanklistFailed': 'Get Ranklist Failed',
'getSomeOfGallerysFailed': 'Get Some of Gallerys Failed',

/// history view
'getHistoryGallerysFailed': 'Get Some of History Gallerys Failed',
Expand Down
5 changes: 4 additions & 1 deletion lib/src/l18n/zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class zh_CN {
'uploader': '上传者',
'allComments': '所有评论',
'noComments': '暂无评论',
'lastEditedOn': '最后修改于',
'getGalleryDetailFailed': '获取画廊详情失败',
'invisible2User': '此画廊对您不可见',
'invisibleHints': '画廊已被删除或对您进行了限制',
Expand Down Expand Up @@ -195,9 +196,11 @@ class zh_CN {

/// ranklist view
'getRanklistFailed': '获取排行榜数据失败',
'getSomeOfGallerysFailed': '获取部分画廊数据失败',

/// history view
'getHistoryGallerysFailed': '获取部分历史数据失败',
'getHistoryGallerysFailed': '获取历史数据失败',


/// search page
'search': '搜索',
Expand Down
3 changes: 2 additions & 1 deletion lib/src/model/gallery_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ class GalleryComment {
String score;
String content;
String time;
String? lastEditTime;

GalleryComment({
required this.id,
required this.userName,
required this.score,
required this.content,
required this.time,
this.lastEditTime,
});

}
10 changes: 9 additions & 1 deletion lib/src/pages/details/widget/eh_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ class _EHCommentState extends State<EHComment> {
factoryBuilder: () => _WidgetFactoryWithTextMaxLine(),
).marginOnly(top: 2, bottom: 14),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (widget.comment.lastEditTime != null)
Text(
'${'lastEditedOn'.tr}: ${widget.comment.lastEditTime}',
style: TextStyle(
fontSize: 9,
color: Colors.grey.shade600,
),
),
const Expanded(child: SizedBox()),
if (widget.comment.score.isNotEmpty)
LikeButton(
size: 18,
Expand Down
17 changes: 11 additions & 6 deletions lib/src/pages/home/tab_view/gallerys/gallerys_view_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,21 @@ class GallerysViewLogic extends GetxController with GetTickerProviderStateMixin
galleryUrls
.mapIndexed(
(index, url) => EHRequest.requestDetailPage(galleryUrl: url, parser: EHSpiderParser.detailPage2Gallery)
.then((value) => gallerys[index] = value),
.then((value) => gallerys[index] = value)
.catchError((error) {
/// 404 => hide or remove
if (error.response?.statusCode != 404) {
Log.error('${'getHistoryGallerysFailed'.tr}:$url', error.message);
} else {
Log.info('Gallery 404: $url', false);
}
throw error;
}),
)
.toList(),
);
} on DioError catch (e) {
/// 404 => hide or remove
if (e.response?.statusCode != 404) {
Log.error('getHistoryGallerysFailed'.tr, e.message);
snack('getHistoryGallerysFailed'.tr, e.message, longDuration: true, snackPosition: SnackPosition.BOTTOM);
}
snack('getSomeOfGallerysFailed'.tr, e.message, longDuration: true, snackPosition: SnackPosition.BOTTOM);
}

gallerys.removeWhere((r) => r == null);
Expand Down
23 changes: 15 additions & 8 deletions lib/src/pages/home/tab_view/ranklist/ranklist_view_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,25 @@ class RanklistViewLogic extends GetxController {
(index, baseGallery) => EHRequest.requestDetailPage<Map<String, dynamic>>(
galleryUrl: baseGallery.galleryUrl,
parser: EHSpiderParser.detailPage2GalleryAndDetailAndApikey,
).then(
(value) => results[index] = value,
),
).then((value) => results[index] = value).catchError((error) {
/// 404 => hide or remove
if (error.response?.statusCode != 404) {
Log.error('${'getRanklistFailed'.tr}: ${baseGallery.galleryUrl}', error.message);
} else {
Log.info('Gallery 404: ${baseGallery.galleryUrl}', false);
}
throw error;
}),
)
.toList(),
);
} on DioError catch (e) {
/// 404 => hide or remove
if (e.response?.statusCode != 404) {
Log.error('getRanklistFailed'.tr, e.message);
snack('getRanklistFailed'.tr, e.message, longDuration: true, snackPosition: SnackPosition.BOTTOM);
}
snack(
'getSomeOfGallerysFailed'.tr,
e.message,
longDuration: true,
snackPosition: SnackPosition.BOTTOM,
);
}

results.removeWhere((r) => r == null);
Expand Down
54 changes: 37 additions & 17 deletions lib/src/utils/eh_spider_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -713,23 +713,43 @@ class EHSpiderParser {
}

static List<GalleryComment> _parseGalleryDetailsComments(List<Element> commentElements) {
return commentElements.map((element) {
/// eg: 'Posted on 10 March 2022, 03:49 by: hibiki'
String timeDesc = element.querySelector('.c2 > .c3')?.text ?? '';

/// eg: '10 March 2022, 03:49'
String timeString = RegExp(r'Posted on (.+, .+) by:').firstMatch(timeDesc)?.group(1) ?? '';
final DateTime utcTime = DateFormat('dd MMMM yyyy, HH:mm', 'en_US').parseUtc(timeString).toLocal();
final String localTime = DateFormat('yyyy-MM-dd HH:mm').format(utcTime);

return GalleryComment(
id: int.parse(element.querySelector('.c6')?.attributes['id']?.split('_')[1] ?? ''),
userName: element.querySelector('.c2 > .c3')?.children[0].text ?? '',
score: element.querySelector('.c2 > .c5.nosel > span')?.text ?? '',
content: element.querySelector('.c6')?.outerHtml ?? '',
time: localTime,
);
}).toList();
return commentElements
.map(
(element) => GalleryComment(
id: int.parse(element.querySelector('.c6')?.attributes['id']?.split('_')[1] ?? ''),
userName: element.querySelector('.c2 > .c3')?.children[0].text ?? '',
score: element.querySelector('.c2 > .c5.nosel > span')?.text ?? '',
content: element.querySelector('.c6')?.outerHtml ?? '',
time: _parsePostedLocalTime(element),
lastEditTime: _parsePostedEditedTime(element),
),
)
.toList();
}

static String _parsePostedLocalTime(Element element) {
/// eg: 'Posted on 10 March 2022, 03:49 by: hibiki'
String postedTimeDesc = element.querySelector('.c2 > .c3')?.text ?? '';

/// eg: '10 March 2022, 03:49'
String postedTimeString = RegExp(r'Posted on (.+, .+) by:').firstMatch(postedTimeDesc)?.group(1) ?? '';
final DateTime postedUTCTime = DateFormat('dd MMMM yyyy, HH:mm', 'en_US').parseUtc(postedTimeString).toLocal();
final String postedLocalTime = DateFormat('yyyy-MM-dd HH:mm').format(postedUTCTime);

return postedLocalTime;
}

static String? _parsePostedEditedTime(Element element) {
/// eg: '10 March 2022, 03:49'
String? postedTimeString = element.querySelector('.c8 > strong')?.text;
if (postedTimeString == null) {
return null;
}

final DateTime postedUTCTime = DateFormat('dd MMMM yyyy, HH:mm', 'en_US').parseUtc(postedTimeString).toLocal();
final String postedLocalTime = DateFormat('yyyy-MM-dd HH:mm').format(postedUTCTime);

return postedLocalTime;
}

static List<GalleryThumbnail> _parseGalleryDetailsSmallThumbnails(List<Element> thumbNailElements) {
Expand Down

0 comments on commit 443c3af

Please sign in to comment.