Merge branch 'main' into feature-danmaku

This commit is contained in:
guozhigq
2023-08-22 14:28:19 +08:00
91 changed files with 1633 additions and 715 deletions

View File

@ -27,3 +27,20 @@ extension SearchTypeExtension on SearchType {
['video', 'media_bangumi', 'live_room', 'bili_user'][index];
String get label => ['视频', '番剧', '直播间', '用户'][index];
}
// 搜索类型为视频、专栏及相簿时
enum ArchiveFilterType {
totalrank,
click,
pubdate,
dm,
stow,
scores,
// 专栏
// attention,
}
extension ArchiveFilterTypeExtension on ArchiveFilterType {
String get description =>
['默认排序', '播放多', '新发布', '弹幕多', '收藏多', '评论多', '最多喜欢'][index];
}

View File

@ -408,6 +408,7 @@ class DynamicMajorModel {
this.live,
this.none,
this.type,
this.courses,
});
DynamicArchiveModel? archive;
@ -422,6 +423,7 @@ class DynamicMajorModel {
// MAJOR_TYPE_ARCHIVE 视频
// MAJOR_TYPE_OPUS 图文/文章
String? type;
Map? courses;
DynamicMajorModel.fromJson(Map<String, dynamic> json) {
archive = json['archive'] != null
@ -444,6 +446,7 @@ class DynamicMajorModel {
none =
json['none'] != null ? DynamicNoneModel.fromJson(json['none']) : null;
type = json['type'];
courses = json['courses'] ?? {};
}
}

View File

@ -8,7 +8,9 @@ class FollowUpModel {
List<UpItem>? upList;
FollowUpModel.fromJson(Map<String, dynamic> json) {
liveUsers = LiveUsers.fromJson(json['live_users']);
liveUsers = json['live_users'] != null
? LiveUsers.fromJson(json['live_users'])
: null;
upList = json['up_list'] != null
? json['up_list'].map<UpItem>((e) => UpItem.fromJson(e)).toList()
: [];

View File

@ -4,12 +4,14 @@ class LatestDataModel {
this.tagName,
this.createdAt,
this.assets,
this.body,
});
String? url;
String? tagName;
String? createdAt;
List? assets;
String? body;
LatestDataModel.fromJson(Map<String, dynamic> json) {
url = json['url'];
@ -17,6 +19,7 @@ class LatestDataModel {
createdAt = json['created_at'];
assets =
json['assets'].map<AssetItem>((e) => AssetItem.fromJson(e)).toList();
body = json['body'];
}
}

View File

@ -1,3 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class SearchSuggestModel {
SearchSuggestModel({
this.tag,
@ -19,32 +22,74 @@ class SearchSuggestItem {
SearchSuggestItem({
this.value,
this.term,
this.name,
this.spid,
this.textRich,
});
String? value;
String? term;
List? name;
int? spid;
Widget? textRich;
SearchSuggestItem.fromJson(Map<String, dynamic> json, String inputTerm) {
value = json['value'];
term = json['term'];
String reg = '<em class="suggest_high_light">$inputTerm</em>';
try {
if (json['name'].indexOf(inputTerm) != -1) {
String str = json['name'].replaceAll(reg, '^');
List arr = str.split('^');
arr.insert(arr.length - 1, inputTerm);
name = arr;
} else {
name = ['', '', json['term']];
}
} catch (err) {
name = ['', '', json['term']];
}
spid = json['spid'];
textRich = highlightText(json['name']);
}
}
Widget highlightText(String str) {
// 创建正则表达式,匹配 <em class="suggest_high_light">...</em> 格式的文本
RegExp regex = RegExp(r'<em class="suggest_high_light">(.*?)<\/em>');
// 用于存储每个匹配项的列表
List<InlineSpan> children = [];
// 获取所有匹配项
Iterable<Match> matches = regex.allMatches(str);
// 当前索引位置
int currentIndex = 0;
// 遍历每个匹配项
for (var match in matches) {
// 获取当前匹配项之前的普通文本部分
String normalText = str.substring(currentIndex, match.start);
// 获取需要高亮显示的文本部分
String highlightedText = match.group(1)!;
// 如果普通文本部分不为空,则将其添加到 children 列表中
if (normalText.isNotEmpty) {
children.add(TextSpan(
text: normalText,
style: DefaultTextStyle.of(Get.context!).style,
));
}
// 将需要高亮显示的文本部分添加到 children 列表中,并设置相应样式
children.add(TextSpan(
text: highlightedText,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(Get.context!).colorScheme.primary),
));
// 更新当前索引位置
currentIndex = match.end;
}
// 如果当前索引位置小于文本长度,表示还有剩余的普通文本部分
if (currentIndex < str.length) {
String remainingText = str.substring(currentIndex);
// 将剩余的普通文本部分添加到 children 列表中
children.add(TextSpan(
text: remainingText,
style: DefaultTextStyle.of(Get.context!).style,
));
}
// 使用 Text.rich 创建包含高亮显示的富文本小部件,并返回
return Text.rich(TextSpan(children: children));
}

View File

@ -121,7 +121,7 @@ class HisListItem {
viewAt = json['view_at'];
progress = json['progress'];
badge = json['badge'];
showTitle = json['show_title'];
showTitle = json['show_title'] == '' ? null : json['show_title'];
duration = json['duration'];
current = json['current'];
total = json['total'];

View File

@ -43,7 +43,7 @@ class UserInfoData {
@HiveField(5)
int? mobileVerified;
@HiveField(6)
int? money;
double? money;
@HiveField(7)
int? moral;
@HiveField(8)
@ -88,7 +88,7 @@ class UserInfoData {
: LevelInfo();
mid = json['mid'];
mobileVerified = json['mobile_verified'];
money = json['money'];
money = json['money'] is int ? json['money'].toDouble() : json['money'];
moral = json['moral'];
official = json['official'];
officialVerify = json['officialVerify'];
@ -130,6 +130,7 @@ class LevelInfo {
currentLevel = json['current_level'];
currentMin = json['current_min'];
currentExp = json['current_exp'];
nextExp = json['next_exp'];
nextExp =
json['current_level'] == 6 ? json['current_exp'] : json['next_exp'];
}
}

View File

@ -23,7 +23,7 @@ class UserInfoDataAdapter extends TypeAdapter<UserInfoData> {
levelInfo: fields[3] as LevelInfo?,
mid: fields[4] as int?,
mobileVerified: fields[5] as int?,
money: fields[6] as int?,
money: fields[6] as double?,
moral: fields[7] as int?,
official: (fields[8] as Map?)?.cast<dynamic, dynamic>(),
officialVerify: (fields[9] as Map?)?.cast<dynamic, dynamic>(),