feat: 推荐数据缓存
This commit is contained in:
@ -1,5 +1,8 @@
|
|||||||
import 'dart:developer';
|
import 'package:hive/hive.dart';
|
||||||
|
|
||||||
|
part 'result.g.dart';
|
||||||
|
|
||||||
|
@HiveType(typeId: 0)
|
||||||
class RecVideoItemAppModel {
|
class RecVideoItemAppModel {
|
||||||
RecVideoItemAppModel({
|
RecVideoItemAppModel({
|
||||||
this.id,
|
this.id,
|
||||||
@ -24,27 +27,47 @@ class RecVideoItemAppModel {
|
|||||||
this.adInfo,
|
this.adInfo,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@HiveField(0)
|
||||||
int? id;
|
int? id;
|
||||||
|
@HiveField(1)
|
||||||
int? aid;
|
int? aid;
|
||||||
|
@HiveField(2)
|
||||||
String? bvid;
|
String? bvid;
|
||||||
|
@HiveField(3)
|
||||||
int? cid;
|
int? cid;
|
||||||
|
@HiveField(4)
|
||||||
String? pic;
|
String? pic;
|
||||||
Stat? stat;
|
@HiveField(5)
|
||||||
|
RcmdStat? stat;
|
||||||
|
@HiveField(6)
|
||||||
String? duration;
|
String? duration;
|
||||||
|
@HiveField(7)
|
||||||
String? title;
|
String? title;
|
||||||
|
@HiveField(8)
|
||||||
int? isFollowed;
|
int? isFollowed;
|
||||||
Owner? owner;
|
@HiveField(9)
|
||||||
|
RcmdOwner? owner;
|
||||||
|
@HiveField(10)
|
||||||
RcmdReason? rcmdReason;
|
RcmdReason? rcmdReason;
|
||||||
|
@HiveField(11)
|
||||||
String? goto;
|
String? goto;
|
||||||
|
@HiveField(12)
|
||||||
int? param;
|
int? param;
|
||||||
|
@HiveField(13)
|
||||||
String? uri;
|
String? uri;
|
||||||
|
@HiveField(14)
|
||||||
String? talkBack;
|
String? talkBack;
|
||||||
// 番剧
|
// 番剧
|
||||||
|
@HiveField(15)
|
||||||
String? bangumiView;
|
String? bangumiView;
|
||||||
|
@HiveField(16)
|
||||||
String? bangumiFollow;
|
String? bangumiFollow;
|
||||||
|
@HiveField(17)
|
||||||
String? bangumiBadge;
|
String? bangumiBadge;
|
||||||
|
|
||||||
|
@HiveField(18)
|
||||||
String? cardType;
|
String? cardType;
|
||||||
|
@HiveField(19)
|
||||||
Map? adInfo;
|
Map? adInfo;
|
||||||
|
|
||||||
RecVideoItemAppModel.fromJson(Map<String, dynamic> json) {
|
RecVideoItemAppModel.fromJson(Map<String, dynamic> json) {
|
||||||
@ -52,13 +75,14 @@ class RecVideoItemAppModel {
|
|||||||
? json['player_args']['aid']
|
? json['player_args']['aid']
|
||||||
: int.parse(json['param'] ?? '-1');
|
: int.parse(json['param'] ?? '-1');
|
||||||
aid = json['player_args'] != null ? json['player_args']['aid'] : -1;
|
aid = json['player_args'] != null ? json['player_args']['aid'] : -1;
|
||||||
|
bvid = null;
|
||||||
cid = json['player_args'] != null ? json['player_args']['cid'] : -1;
|
cid = json['player_args'] != null ? json['player_args']['cid'] : -1;
|
||||||
pic = json['cover'];
|
pic = json['cover'];
|
||||||
stat = Stat.fromJson(json);
|
stat = RcmdStat.fromJson(json);
|
||||||
duration = json['cover_right_text'];
|
duration = json['cover_right_text'];
|
||||||
title = json['title'];
|
title = json['title'];
|
||||||
isFollowed = 0;
|
isFollowed = 0;
|
||||||
owner = Owner.fromJson(json);
|
owner = RcmdOwner.fromJson(json);
|
||||||
rcmdReason = json['rcmd_reason_style'] != null
|
rcmdReason = json['rcmd_reason_style'] != null
|
||||||
? RcmdReason.fromJson(json['rcmd_reason_style'])
|
? RcmdReason.fromJson(json['rcmd_reason_style'])
|
||||||
: null;
|
: null;
|
||||||
@ -78,32 +102,36 @@ class RecVideoItemAppModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Stat {
|
@HiveType(typeId: 1)
|
||||||
Stat({
|
class RcmdStat {
|
||||||
|
RcmdStat({
|
||||||
this.view,
|
this.view,
|
||||||
this.like,
|
this.like,
|
||||||
this.danmu,
|
this.danmu,
|
||||||
});
|
});
|
||||||
|
@HiveField(0)
|
||||||
String? view;
|
String? view;
|
||||||
|
@HiveField(1)
|
||||||
String? like;
|
String? like;
|
||||||
|
@HiveField(2)
|
||||||
String? danmu;
|
String? danmu;
|
||||||
|
|
||||||
Stat.fromJson(Map<String, dynamic> json) {
|
RcmdStat.fromJson(Map<String, dynamic> json) {
|
||||||
view = json["cover_left_text_1"];
|
view = json["cover_left_text_1"];
|
||||||
danmu = json['cover_left_text_2'];
|
danmu = json['cover_left_text_2'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Owner {
|
@HiveType(typeId: 2)
|
||||||
Owner({this.name});
|
class RcmdOwner {
|
||||||
|
RcmdOwner({this.name, this.mid});
|
||||||
|
|
||||||
|
@HiveField(0)
|
||||||
String? name;
|
String? name;
|
||||||
|
@HiveField(1)
|
||||||
int? mid;
|
int? mid;
|
||||||
|
|
||||||
Owner.fromJson(Map<String, dynamic> json) {
|
RcmdOwner.fromJson(Map<String, dynamic> json) {
|
||||||
if (json['goto'] == 'bangumi') {
|
|
||||||
log(json.toString());
|
|
||||||
}
|
|
||||||
name = json['goto'] == 'av'
|
name = json['goto'] == 'av'
|
||||||
? json['args']['up_name']
|
? json['args']['up_name']
|
||||||
: json['desc_button'] != null
|
: json['desc_button'] != null
|
||||||
@ -113,11 +141,13 @@ class Owner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HiveType(typeId: 8)
|
||||||
class RcmdReason {
|
class RcmdReason {
|
||||||
RcmdReason({
|
RcmdReason({
|
||||||
this.content,
|
this.content,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@HiveField(0)
|
||||||
String? content;
|
String? content;
|
||||||
|
|
||||||
RcmdReason.fromJson(Map<String, dynamic> json) {
|
RcmdReason.fromJson(Map<String, dynamic> json) {
|
||||||
|
209
lib/models/home/rcmd/result.g.dart
Normal file
209
lib/models/home/rcmd/result.g.dart
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'result.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// TypeAdapterGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class RecVideoItemAppModelAdapter extends TypeAdapter<RecVideoItemAppModel> {
|
||||||
|
@override
|
||||||
|
final int typeId = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
RecVideoItemAppModel read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return RecVideoItemAppModel(
|
||||||
|
id: fields[0] as int?,
|
||||||
|
aid: fields[1] as int?,
|
||||||
|
bvid: fields[2] as String?,
|
||||||
|
cid: fields[3] as int?,
|
||||||
|
pic: fields[4] as String?,
|
||||||
|
stat: fields[5] as RcmdStat?,
|
||||||
|
duration: fields[6] as String?,
|
||||||
|
title: fields[7] as String?,
|
||||||
|
isFollowed: fields[8] as int?,
|
||||||
|
owner: fields[9] as RcmdOwner?,
|
||||||
|
rcmdReason: fields[10] as RcmdReason?,
|
||||||
|
goto: fields[11] as String?,
|
||||||
|
param: fields[12] as int?,
|
||||||
|
uri: fields[13] as String?,
|
||||||
|
talkBack: fields[14] as String?,
|
||||||
|
bangumiView: fields[15] as String?,
|
||||||
|
bangumiFollow: fields[16] as String?,
|
||||||
|
bangumiBadge: fields[17] as String?,
|
||||||
|
cardType: fields[18] as String?,
|
||||||
|
adInfo: (fields[19] as Map?)?.cast<dynamic, dynamic>(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, RecVideoItemAppModel obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(20)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.id)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.aid)
|
||||||
|
..writeByte(2)
|
||||||
|
..write(obj.bvid)
|
||||||
|
..writeByte(3)
|
||||||
|
..write(obj.cid)
|
||||||
|
..writeByte(4)
|
||||||
|
..write(obj.pic)
|
||||||
|
..writeByte(5)
|
||||||
|
..write(obj.stat)
|
||||||
|
..writeByte(6)
|
||||||
|
..write(obj.duration)
|
||||||
|
..writeByte(7)
|
||||||
|
..write(obj.title)
|
||||||
|
..writeByte(8)
|
||||||
|
..write(obj.isFollowed)
|
||||||
|
..writeByte(9)
|
||||||
|
..write(obj.owner)
|
||||||
|
..writeByte(10)
|
||||||
|
..write(obj.rcmdReason)
|
||||||
|
..writeByte(11)
|
||||||
|
..write(obj.goto)
|
||||||
|
..writeByte(12)
|
||||||
|
..write(obj.param)
|
||||||
|
..writeByte(13)
|
||||||
|
..write(obj.uri)
|
||||||
|
..writeByte(14)
|
||||||
|
..write(obj.talkBack)
|
||||||
|
..writeByte(15)
|
||||||
|
..write(obj.bangumiView)
|
||||||
|
..writeByte(16)
|
||||||
|
..write(obj.bangumiFollow)
|
||||||
|
..writeByte(17)
|
||||||
|
..write(obj.bangumiBadge)
|
||||||
|
..writeByte(18)
|
||||||
|
..write(obj.cardType)
|
||||||
|
..writeByte(19)
|
||||||
|
..write(obj.adInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is RecVideoItemAppModelAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RcmdStatAdapter extends TypeAdapter<RcmdStat> {
|
||||||
|
@override
|
||||||
|
final int typeId = 1;
|
||||||
|
|
||||||
|
@override
|
||||||
|
RcmdStat read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return RcmdStat(
|
||||||
|
view: fields[0] as String?,
|
||||||
|
like: fields[1] as String?,
|
||||||
|
danmu: fields[2] as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, RcmdStat obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(3)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.view)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.like)
|
||||||
|
..writeByte(2)
|
||||||
|
..write(obj.danmu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is RcmdStatAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RcmdOwnerAdapter extends TypeAdapter<RcmdOwner> {
|
||||||
|
@override
|
||||||
|
final int typeId = 2;
|
||||||
|
|
||||||
|
@override
|
||||||
|
RcmdOwner read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return RcmdOwner(
|
||||||
|
name: fields[0] as String?,
|
||||||
|
mid: fields[1] as int?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, RcmdOwner obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(2)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.name)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.mid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is RcmdOwnerAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RcmdReasonAdapter extends TypeAdapter<RcmdReason> {
|
||||||
|
@override
|
||||||
|
final int typeId = 8;
|
||||||
|
|
||||||
|
@override
|
||||||
|
RcmdReason read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return RcmdReason(
|
||||||
|
content: fields[0] as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, RcmdReason obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(1)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is RcmdReasonAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
@ -17,14 +17,14 @@ class RcmdController extends GetxController {
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
// if (recVideo.get('cacheList') != null &&
|
if (recVideo.get('cacheList') != null &&
|
||||||
// recVideo.get('cacheList').isNotEmpty) {
|
recVideo.get('cacheList').isNotEmpty) {
|
||||||
// List<RecVideoItemModel> list = [];
|
List<RecVideoItemAppModel> list = [];
|
||||||
// for (var i in recVideo.get('cacheList')) {
|
for (var i in recVideo.get('cacheList')) {
|
||||||
// list.add(i);
|
list.add(i);
|
||||||
// }
|
}
|
||||||
// videoList.value = list;
|
videoList.value = list;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取推荐
|
// 获取推荐
|
||||||
@ -47,7 +47,7 @@ class RcmdController extends GetxController {
|
|||||||
} else if (type == 'onLoad') {
|
} else if (type == 'onLoad') {
|
||||||
videoList.addAll(res['data']);
|
videoList.addAll(res['data']);
|
||||||
}
|
}
|
||||||
// recVideo.put('cacheList', res['data']);
|
recVideo.put('cacheList', res['data']);
|
||||||
_currentPage += 1;
|
_currentPage += 1;
|
||||||
}
|
}
|
||||||
isLoadingMore = false;
|
isLoadingMore = false;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// import 'package:hive/hive.dart';
|
// import 'package:hive/hive.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:pilipala/models/home/rcmd/result.dart';
|
||||||
import 'package:pilipala/models/model_owner.dart';
|
import 'package:pilipala/models/model_owner.dart';
|
||||||
import 'package:pilipala/models/model_rec_video_item.dart';
|
|
||||||
import 'package:pilipala/models/search/hot.dart';
|
import 'package:pilipala/models/search/hot.dart';
|
||||||
import 'package:pilipala/models/user/info.dart';
|
import 'package:pilipala/models/user/info.dart';
|
||||||
|
|
||||||
@ -38,9 +38,10 @@ class GStrorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static regAdapter() {
|
static regAdapter() {
|
||||||
Hive.registerAdapter(RecVideoItemModelAdapter());
|
Hive.registerAdapter(RecVideoItemAppModelAdapter());
|
||||||
Hive.registerAdapter(RcmdReasonAdapter());
|
Hive.registerAdapter(RcmdReasonAdapter());
|
||||||
Hive.registerAdapter(StatAdapter());
|
Hive.registerAdapter(RcmdStatAdapter());
|
||||||
|
Hive.registerAdapter(RcmdOwnerAdapter());
|
||||||
Hive.registerAdapter(OwnerAdapter());
|
Hive.registerAdapter(OwnerAdapter());
|
||||||
Hive.registerAdapter(UserInfoDataAdapter());
|
Hive.registerAdapter(UserInfoDataAdapter());
|
||||||
Hive.registerAdapter(LevelInfoAdapter());
|
Hive.registerAdapter(LevelInfoAdapter());
|
||||||
|
Reference in New Issue
Block a user