Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mod: bangumi item: add timestamp data #447

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions lib/modules/bangumi/bangumi_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class BangumiItem {
@HiveField(8)
Map<String, String> images;
// Map<String, int>? collection;
@HiveField(9)
int? timeStamp;

BangumiItem({
required this.id,
Expand All @@ -40,6 +42,7 @@ class BangumiItem {
required this.rank,
required this.images,
// this.collection,
this.timeStamp,
});

factory BangumiItem.fromJson(Map<String, dynamic> json) {
Expand All @@ -49,17 +52,20 @@ class BangumiItem {
name: json['name'] ?? '',
nameCn: (json['name_cn'] ?? '') == '' ? (json['name'] ?? '') : json['name_cn'],
summary: json['summary'] ?? '',
airDate: json['air_date'] ?? json ['date'],
airWeekday: json['air_weekday'] ?? Utils.dateStringToWeekday(json ['date']) ?? 1,
airDate: json['air_date'] ?? json['date'],
airWeekday: json['air_weekday'] ?? Utils.dateStringToWeekday(json['date']) ?? 1,
// rating: Rating.fromJson(json['rating']),
rank: json['rating']['rank'] ?? 0,
images: Map<String, String>.from(json['images'] ?? {
"large": json['image'],
"common": "",
"medium": "",
"small": "",
"grid": ""
},),
images: Map<String, String>.from(
json['images'] ??
{
"large": json['image'],
"common": "",
"medium": "",
"small": "",
"grid": "",
},
),
// collection: Map<String, int>.from(json['collection']),
);
}
Expand Down
11 changes: 6 additions & 5 deletions lib/modules/bangumi/bangumi_item.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions lib/pages/favorite/favorite_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,30 @@ import 'package:kazumi/utils/logger.dart';

part 'favorite_controller.g.dart';

class FavoriteController = _FavoriteController with _$FavoriteController;
class FavoriteController = _FavoriteController with _$FavoriteController;

abstract class _FavoriteController with Store {
// late var storedFavorites = GStorage.favorites;
Box setting = GStorage.setting;

List<BangumiItem> get favorites => GStorage.favorites.values.toList();
List<BangumiItem> get favorites => GStorage.favorites.values.toList()
..sort((a, b) => a.timeStamp != null && b.timeStamp != null
? b.timeStamp!.compareTo(a.timeStamp!)
: a.timeStamp != null
? -1
: b.timeStamp != null
? 1
: 0);

bool isFavorite(BangumiItem bangumiItem) {
return !(GStorage.favorites.get(bangumiItem.id) == null);
}

Future<void> addFavorite(BangumiItem bangumiItem) async {
await GStorage.favorites.put(bangumiItem.id, bangumiItem);
await GStorage.favorites.put(
bangumiItem.id,
bangumiItem..timeStamp = DateTime.now().millisecondsSinceEpoch,
);
await GStorage.favorites.flush();
bool webDavEnable = await setting.get(SettingBoxKey.webDavEnable, defaultValue: false);
bool webDavEnableFavorite = await setting.get(SettingBoxKey.webDavEnableFavorite, defaultValue: false);
Expand All @@ -49,7 +59,7 @@ abstract class _FavoriteController with Store {
}
}

Future<void> updateFavorite() async{
Future<void> updateFavorite() async {
KazumiLogger().log(Level.debug, '提交到WebDav的追番列表长度 ${GStorage.favorites.length}');
await WebDav().updateFavorite();
}
Expand Down
Loading