Skip to content

Commit

Permalink
时间排序,订阅图标
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Aug 28, 2024
1 parent 4ab0608 commit a800015
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MioFeed - Modern RSS reader
- [x] 更新订阅
- [x] 删除订阅
- [x] 获取订阅
- [x] 时间排序
- [ ] 主题功能
- [ ] 订阅分组

Expand Down
10 changes: 8 additions & 2 deletions lib/models/universal_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UniversalFeed {
: title = atom.title ?? '无标题',
author = _atomToUniversalPersonList(atom.authors),
description = '没有介绍',
icon = atom.logo ?? '',
icon = atom.icon ?? '',
link = atom.links.first.href ?? '',//atom.links,
copyright = atom.rights ?? '',
categories = _atomToStringCategories(atom.categories),
Expand All @@ -51,7 +51,7 @@ class UniversalFeed {
: title = rss.title ?? '无标题',
author = [UniversalPerson(name: rss.author)],
description = rss.description ?? '没有介绍',
icon = rss.image?.link ?? '',
icon = rss.image?.url ?? '',
link = rss.link ?? '',
copyright = rss.copyright ?? '没有版权信息',
categories = _rssToStringCategories(rss.categories),
Expand Down Expand Up @@ -186,6 +186,12 @@ class UniversalFeed {
} catch (ignored) {
// ignored
}
} else {
try {
return DateTime.parse(dateString);
} catch (ignored) {
// ignored
}
}
return null;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/models/universal_item.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:miofeed/models/universal_feed.dart';

import 'generator.dart';

class UniversalItem {
Expand All @@ -22,4 +24,9 @@ class UniversalItem {
final DateTime? publishTime;
final DateTime? updateTime;
final String content;

@override
String toString() {
return title;
}
}
61 changes: 58 additions & 3 deletions lib/ui/home.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:miofeed/controllers/navigator_controller.dart';
import 'package:miofeed/models/universal_feed.dart';
import 'package:miofeed/models/universal_item.dart';
import 'package:miofeed/ui/paragraph.dart';
import 'package:miofeed/utils/after_layout.dart';
import 'package:miofeed/utils/paragraph_utils.dart';

import '../controllers/progressbar_controller.dart';
import '../utils/rss/rss_utils.dart';
Expand Down Expand Up @@ -47,16 +49,23 @@ class HomeUI extends StatelessWidget {
itemBuilder: (context, index) {
final para = hctr.allParagraph[index];
final UniversalItem paraData = para['item'];
final UniversalFeed paraFeed = para['feed_data'];

// print(paraIconUrl);

final paraDesc = paraData.content
.replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), ' ')
.replaceAll(RegExp(r'\n{2,}'), ' ')
.replaceAll(RegExp(r'\r{2,}'), ' ')
.replaceAll(RegExp(r' {2,}'), ' ')
.trim();

return InkWell(
onTap: () async {
Get.to(() => ParagraphUI(data: paraData));
Get.to(() => ParagraphUI(
data: paraData,
parent: paraFeed,
));
},
child: Card(
child: Container(
Expand All @@ -77,7 +86,43 @@ class HomeUI extends StatelessWidget {
? paraDesc
: '${paraDesc.substring(0, 320)}......'),
),
_buildLabels(paraData.categories ?? []),
Row(
children: [
// 图标
Tooltip(
message: paraFeed.title,
child: Container(
margin: const EdgeInsets.only(right: 5),
child: ClipRRect(
borderRadius:
BorderRadius.circular(5),
child: SizedBox(
width: 20,
height: 20,
child: paraFeed.icon.isNotEmpty
? Image.network(
paraFeed.icon,
errorBuilder: (
context,
error,
stackTrace,
) {
return ParagraphUtils
.buildColorIcon(
paraFeed.title,
);
},
)
: ParagraphUtils.buildColorIcon(
paraFeed.title,
),
),
),
),
),
_buildLabels(paraData.categories ?? []),
],
)
],
),
),
Expand All @@ -101,6 +146,7 @@ class HomeUI extends StatelessWidget {
labels += ' | $label';
}
labels = labels.length > 3 ? labels.substring(3, labels.length) : labels;
if (labels.isEmpty) labels = '没有分类信息';
return Row(
children: [
Container(
Expand All @@ -126,6 +172,15 @@ class _HomeController extends GetxController {
var allParagraph = [].obs;

load() {
allParagraph.value = RssUtils.allRssParagraph;
final dataParagraph = RssUtils.allRssParagraph;
dataParagraph.sort((a, b) {
// TODO: 正序还是倒序显示文章
final aTime = a['item'].publishTime ?? DateTime(0);
final bTime = b['item'].publishTime ?? DateTime(0);
final result = bTime.compareTo(aTime);
// print('${b['item'].title} $bTime, ${a['item'].title} $aTime, RES: $result');
return result;
});
allParagraph.value = dataParagraph;
}
}
36 changes: 36 additions & 0 deletions lib/ui/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@ import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:miofeed/controllers/progressbar_controller.dart';
import 'package:miofeed/main.dart';
import 'package:miofeed/models/universal_feed.dart';
import 'package:miofeed/models/universal_item.dart';
import 'package:miofeed/ui/models/navigation_bar.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher.dart';

import '../utils/paragraph_utils.dart';

class ParagraphUI extends StatelessWidget {
ParagraphUI({
super.key,
// this.title,
required this.data,
required this.parent,
});

// final title;
final UniversalItem data;
final UniversalFeed parent;

final ProgressbarController progressbar = Get.find();

Expand Down Expand Up @@ -48,6 +53,37 @@ class ParagraphUI extends StatelessWidget {
data.title,
style: const TextStyle(fontSize: 30),
),
Row(
children: [
Container(
margin: const EdgeInsets.only(right: 5),
child: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: SizedBox(
width: 20,
height: 20,
child: parent.icon.isNotEmpty
? Image.network(
parent.icon,
errorBuilder: (
context,
error,
stackTrace,
) {
return ParagraphUtils.buildColorIcon(
parent.title);
},
)
: ParagraphUtils.buildColorIcon(parent.title)),
),
),
Text(
'${parent.title} | ${data.publishTime != null ? dateFormatter.format(data.publishTime!) : '未知'}'),
],
),
Container(
margin: const EdgeInsets.only(bottom: 5),
),
Row(
children: [
const Icon(
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/settings/rss_sub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class _RssSubController extends GetxController {
RSS data = await RssStorage().getRss(key);
var uuid = const Uuid();
subListWidgets.add(
// 手势
Dismissible(
key: Key('${uuid.v8()}@${data.name}'),
onDismissed: (direction) {
Expand All @@ -265,6 +266,7 @@ class _RssSubController extends GetxController {
color: Colors.white,
),
),
// 点击
child: InkWell(
child: ListTile(
title: Text('${data.showName} (${data.name})'),
Expand Down
24 changes: 24 additions & 0 deletions lib/utils/color.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter/material.dart' as md;

class Color {
/// 根据字符串生成一个颜色
/// [string] 字符串
static md.Color stringToColor(String string) {
string = string.length > 20 ? string.substring(0, 20) : string;

int hash = 0;
for (int i = 0; i < string.length; i++) {
hash = string.codeUnitAt(i) + ((hash << 5) - hash);
}

String colorString = '#';
for (int i = 0; i < 3; i++) {
int value = (hash >> (i * 8)) & 0xFF;
colorString += value.toRadixString(16).padLeft(2, '0');
}

return md.Color(
int.parse(colorString.substring(1), radix: 16) + 0xFF000000,
);
}
}
11 changes: 11 additions & 0 deletions lib/utils/paragraph_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter/material.dart';
import 'package:miofeed/utils/color.dart' as color_utils;

class ParagraphUtils {
static Widget buildColorIcon(String subName) {
return Container(
color: color_utils.Color.stringToColor(subName),
child: Center(child: Text(subName.substring(0, 1))),
);
}
}

0 comments on commit a800015

Please sign in to comment.