Skip to content

Commit

Permalink
feat: 实机测试和问题修复
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyray-fan committed Jan 5, 2025
1 parent a875c03 commit aee64a3
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 203 deletions.
8 changes: 4 additions & 4 deletions assets/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"Date Desc": "日期降序",
"Start": "开始",
"Export App Data": "导出应用数据",
"Import App Data": "导入应用数据",
"Import App Data (Please restart after success)": "导入应用数据(成功后请手动重启)",
"Export": "导出",
"Download Threads": "下载线程数",
"Update Time": "更新时间",
Expand Down Expand Up @@ -256,7 +256,7 @@
"Collect the image": "收藏图片",
"Support sliding to collect images": "支持滑动收藏图片",
"On the image browsing page, you can quickly collect images by sliding horizontally or vertically according to your reading mode": "在图片浏览页面, 你可以根据你的阅读模式横滑或者竖滑快速收藏图片",
"Calculate your favorite from @a comics and @b images": "从 @a 本漫画和 @b 张图片中, 计算你最喜欢的",
"Calculate your favorite from @a comics and @b images, After the parentheses are the number of pictures or the number of pictures compared to the number of comic pages": "从 @a 本漫画和 @b 张图片中, 计算你最喜欢的, 括号后是图片数量或图片数比漫画页数",
"Author: ": "作者: ",
"Tags: ": "标签: ",
"Comics(number): ": "漫画(数量): ",
Expand Down Expand Up @@ -461,7 +461,7 @@
"Date Desc": "日期降序",
"Start": "開始",
"Export App Data": "匯出應用數據",
"Import App Data": "匯入應用數據",
"Import App Data (Please restart after success)": "匯入應用數據(成功后請手動重啟)",
"Export": "匯出",
"Download Threads": "下載線程數",
"Update Time": "更新時間",
Expand Down Expand Up @@ -557,7 +557,7 @@
"Collect the image": "收藏圖片",
"Support sliding to collect images": "支持滑動收藏圖片",
"On the image browsing page, you can quickly collect images by sliding horizontally or vertically according to your reading mode": "在圖片瀏覽頁面, 你可以根據你的閱讀模式橫向或者縱向滑動快速收藏圖片",
"Calculate your favorite from @a comics and @b images": "從 @a 本漫畫和 @b 張圖片中, 計算你最喜歡的",
"Calculate your favorite from @a comics and @b images, After the parentheses are the number of pictures or the number of pictures compared to the number of comic pages": "從 @a 本漫畫和 @b 張圖片中, 計算你最喜歡的, 括號後是圖片數量或圖片數比漫畫頁數",
"Author: ": "作者: ",
"Tags: ": "標籤: ",
"Comics(number): ": "漫畫(數量): ",
Expand Down
26 changes: 21 additions & 5 deletions lib/foundation/image_favorites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ class ImageFavoritePro extends ImageFavorite {
ImageFavoritePro.copy(ImageFavoritePro other)
: this(other.page, other.imageKey, other.isAutoFavorite, other.eid,
other.id, other.ep, other.sourceKey, other.epName);
@override
bool operator ==(Object other) {
return other is ImageFavoritePro &&
other.id == id &&
other.sourceKey == sourceKey &&
other.page == page &&
other.eid == eid &&
other.ep == ep;
}

@override
int get hashCode => Object.hash(id, sourceKey, page, eid, ep);
}

class ImageFavoritesEp {
Expand Down Expand Up @@ -239,19 +251,19 @@ class ImageFavoritesComic {
class ImageFavoriteManager with ChangeNotifier {
static Database get _db => HistoryManager()._db;
static ImageFavoriteManager? cache;
final Throttler _throttler = Throttler(duration: Duration(seconds: 2));
final Debouncer _debouncer = Debouncer();
static List<ImageFavoritesComic> imageFavoritesComicList = getAll(null);
ImageFavoriteManager.create();
static bool hasInit = false;
factory ImageFavoriteManager() {
return cache == null ? (cache = ImageFavoriteManager.create()) : cache!;
}
void updateValue() {
// 避免从pica导入的时候, 疯狂触发
_throttler.run(() {
// 避免从pica导入的时候, 疯狂触发更新
_debouncer.run(() {
imageFavoritesComicList = getAll(null);
notifyListeners();
});
}, Duration(seconds: 5));
}

/// 检查表image_favorites是否存在, 不存在则创建
Expand Down Expand Up @@ -285,7 +297,8 @@ class ImageFavoriteManager with ChangeNotifier {
List<ImageFavoritesEp> tempImageFavoritesEp = [];
for (var e in favorite.imageFavoritesEp) {
int index = tempImageFavoritesEp.indexWhere((i) => i.ep == e.ep);
if (index == -1) {
// 再做一层保险, 防止出现ep为0的脏数据
if (index == -1 && e.ep > 0) {
tempImageFavoritesEp.add(e);
}
}
Expand Down Expand Up @@ -462,6 +475,9 @@ class ImageFavoriteManager with ChangeNotifier {

static List<String> get earliestTimeToNow {
var res = _db.select("select MIN(time) from image_favorites;");
if (res.first.values.first == null) {
return [];
}
int earliestYear =
DateTime.fromMillisecondsSinceEpoch(res.first.values.first! as int)
.year;
Expand Down
116 changes: 64 additions & 52 deletions lib/pages/home_page/image_favorites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ part of '../home_page.dart';

class ImageFavoritesFindComic {
final String id;
final String title;
final String fullTitle;
final String showTitle;
final String sourceKey;

const ImageFavoritesFindComic(this.id, this.title, this.sourceKey);
const ImageFavoritesFindComic(
this.id, this.fullTitle, this.showTitle, this.sourceKey);
}

class ImageFavoritesTextWithCount {
final String text;
final int count;
const ImageFavoritesTextWithCount(this.text, this.count);
}

// 算出最喜欢的
class ImageFavoritesCompute {
final List<String> tags;
final List<String> authors;
final List<ImageFavoritesTextWithCount> tags;
final List<ImageFavoritesTextWithCount> authors;
// 喜欢的图片数
final List<ImageFavoritesFindComic> comicByNum;
// 图片数比上总页数
Expand All @@ -35,22 +43,29 @@ class ImageFavorites extends StatefulWidget {
State<ImageFavorites> createState() => ImageFavoritesState();
}

List<String> exceptTags = ['連載中'];
// 去掉这些没有意义的标签
List<String> exceptTags = [
'連載中',
'',
'translated',
'chinese',
'sole male',
'sole female',
'original',
'doujinshi',
'manga',
'multi-work series',
'mosaic censorship',
'dilf',
'bbm',
'uncensored',
'full censorship'
].map((e) => e.toLowerCase()).toList();

class ImageFavoritesState extends State<ImageFavorites> {
ImageFavoritesCompute? imageFavoritesCompute;
List<ImageFavoritePro> allImageFavoritePros = [];
static String separator = "*venera*";
static var enableTranslate = App.locale.languageCode == 'zh';
static Color getColor(Color baseColor, double depth) {
// 将 RGB 颜色转换为 HSV 颜色
HSVColor hsvColor = HSVColor.fromColor(baseColor);
// 根据深度调整明度
HSVColor adjustedColor = hsvColor.withValue((1 - depth) * hsvColor.value);
// 将调整后的 HSV 颜色转换回 RGB 颜色
Color finalColor = adjustedColor.toColor();
return finalColor;
}

static ImageFavoritesFindComic fromStringToImageFavoritesFindComic(
String str, String suffix, List<ImageFavoritesComic> tempComicsList) {
Expand All @@ -62,7 +77,8 @@ class ImageFavoritesState extends State<ImageFavorites> {
});
return ImageFavoritesFindComic(
id,
'${comic.title.length > 10 ? comic.title.substring(0, 10) : comic.title}... $suffix',
comic.title,
'${comic.title.length > 36 ? comic.title.substring(0, 36) : comic.title}... $suffix',
sourceKey);
}

Expand All @@ -76,19 +92,20 @@ class ImageFavoritesState extends State<ImageFavorites> {
Map<String, int> comicMaxPages = {};

for (ImageFavoritesComic imageFavoritesComic in tempComics) {
// 统计标签
for (var tag in imageFavoritesComic.tags) {
String finalTag = enableTranslate ? tag.translateTagsToCN : tag;
String finalTag = tag;
tagCount[finalTag] = (tagCount[finalTag] ?? 0) + 1;
}

// 统计作者下的图片数
if (imageFavoritesComic.author != "") {
authorCount[imageFavoritesComic.author] =
(authorCount[imageFavoritesComic.author] ?? 0) +
imageFavoritesComic.sortedImageFavoritePros.length;
String finalAuthor = imageFavoritesComic.author;
authorCount[finalAuthor] = (authorCount[finalAuthor] ?? 0) +
imageFavoritesComic.sortedImageFavoritePros.length;
}
// 小于10页的漫画不统计
if (imageFavoritesComic.maxPageFromEp < 10) {
continue;
}

// 统计漫画图片数和总页数
String comicId =
'${imageFavoritesComic.sourceKey}$separator${imageFavoritesComic.id}';
Expand Down Expand Up @@ -121,24 +138,20 @@ class ImageFavoritesState extends State<ImageFavorites> {
return percentageB.compareTo(percentageA);
});

// 只返回前10个结果
return ImageFavoritesCompute(
sortedTags
.where((tag) => !exceptTags.contains(tag))
.take(10)
.map((tag) => '$tag (${tagCount[tag]})')
.where((tag) => !exceptTags.contains(tag.toLowerCase()))
.map((tag) => ImageFavoritesTextWithCount(tag, tagCount[tag]!))
.toList(),
sortedAuthors
.take(10)
.map((author) => '$author (${authorCount[author]})')
.map((author) =>
ImageFavoritesTextWithCount(author, authorCount[author]!))
.toList(),
sortedComicsByNum
.take(10)
.map((comic) => fromStringToImageFavoritesFindComic(
comic.key, '(${comic.value})', tempComics))
.toList(),
sortedComicsByPercentage
.take(10)
.map((comic) => fromStringToImageFavoritesFindComic(
comic.key,
'(${(comicImageCount[comic.key]! / comicMaxPages[comic.key]! * 100).toStringAsFixed(1)}%)',
Expand All @@ -147,7 +160,7 @@ class ImageFavoritesState extends State<ImageFavorites> {
}

void refreshImageFavorites() async {
if(mounted){
if (mounted) {
imageFavoritesCompute = null;
allImageFavoritePros = [];
for (var comic in ImageFavoriteManager.imageFavoritesComicList) {
Expand Down Expand Up @@ -178,26 +191,23 @@ class ImageFavoritesState extends State<ImageFavorites> {
Object text,
ImageFavoritesComputeType type,
) {
bool isString = text is String;
bool textWithCount = text is ImageFavoritesTextWithCount;
bool isAuthor = type == ImageFavoritesComputeType.authors;
var enableTranslate = App.locale.languageCode == 'zh';
String translateText = '';
if (textWithCount) {
translateText = enableTranslate ? text.text.translateTagsToCN : text.text;
if (isAuthor) {
translateText = TagsTranslation.artistTags[text.text] ?? text.text;
}
}
return InkWell(
onTap: () {
RegExp regExp = RegExp(r" \(\d+\)");
if (type == ImageFavoritesComputeType.tags) {
// 跳转到标签搜索页面
context.to(() => ImageFavoritesPage(
initialKeyword: (text as String).replaceAll(regExp, '')));
}
if (type == ImageFavoritesComputeType.authors) {
context.to(() => ImageFavoritesPage(
initialKeyword: (text as String).replaceAll(regExp, '')));
}
if (type == ImageFavoritesComputeType.comicByNum ||
type == ImageFavoritesComputeType.comicByPercentage) {
context.to(() => ComicPage(
id: (text as ImageFavoritesFindComic).id,
sourceKey: text.sourceKey,
));
}
RegExp regExpForTag = RegExp(r" \(\d+\)$");
context.to(() => ImageFavoritesPage(
initialKeyword: (textWithCount
? text.text.replaceAll(regExpForTag, '')
: (text as ImageFavoritesFindComic).fullTitle)));
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
Expand All @@ -206,7 +216,9 @@ class ImageFavoritesState extends State<ImageFavorites> {
borderRadius: BorderRadius.circular(8),
),
child: Text(
isString ? text : (text as ImageFavoritesFindComic).title,
textWithCount
? "${enableTranslate ? translateText : text.text} (${text.count})"
: (text as ImageFavoritesFindComic).showTitle,
),
),
);
Expand Down Expand Up @@ -263,7 +275,7 @@ class ImageFavoritesState extends State<ImageFavorites> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Calculate your favorite from @a comics and @b images"
"Calculate your favorite from @a comics and @b images, After the parentheses are the number of pictures or the number of pictures compared to the number of comic pages"
.tlParams({
"a": ImageFavoriteManager.length.toString(),
"b": allImageFavoritePros.length
Expand Down
Loading

0 comments on commit aee64a3

Please sign in to comment.