import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import '../../api/video_api.dart';
|
import '../../model/video/video_model.dart';
|
import '../../model/video/watch_record_model.dart';
|
import '../../ui/widget/button.dart';
|
import '../../ui/widget/refresh_listview.dart';
|
import '../../ui/widget/video_item.dart';
|
import '../../utils/db_manager.dart';
|
import '../../utils/video/video_util.dart';
|
import '../../api/http.dart';
|
import '../../ui/common/browser.dart';
|
import '../../ui/widget/dialog.dart';
|
import '../../ui/widget/nav.dart';
|
import '../../utils/cache_util.dart';
|
import '../../utils/config_util.dart';
|
import '../../utils/event_bus_util.dart';
|
import '../../utils/pageutils.dart';
|
import '../../utils/push_util.dart';
|
import '../../utils/setting_util.dart';
|
import '../../utils/string_util.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../utils/ui_utils.dart';
|
import '../../utils/user_util.dart';
|
import 'package:package_info/package_info.dart';
|
|
class VideoAttentionPage extends StatefulWidget {
|
VideoAttentionPage({Key? key, required this.title}) : super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final String title;
|
|
@override
|
_VideoAttentionPageState createState() => _VideoAttentionPageState();
|
}
|
|
class _VideoAttentionPageState extends State<VideoAttentionPage>
|
with SingleTickerProviderStateMixin {
|
final MyRefreshController _refreshController = MyRefreshController();
|
List<VideoInfoModel> videoList = [];
|
|
int page = 1;
|
int toalCount = 0;
|
|
@override
|
void initState() {
|
super.initState();
|
}
|
|
void loadVideoList(int _page) async {
|
page = _page;
|
Map<String, dynamic>? result =
|
await VideoApiUtil.getAttentionVideoList(context, page);
|
if (result == null) {
|
if (page == 1) {
|
_refreshController.apiError!();
|
}
|
return;
|
}
|
|
if (result["IsPost"] != "true") {
|
return;
|
}
|
|
List<dynamic> list = result["Data"]["data"];
|
List<VideoInfoModel> temList = [];
|
list.forEach((element) {
|
temList.add(VideoInfoModel.fromJson(element["VideoInfo"]));
|
});
|
|
int count = int.parse(result["Data"]["count"]);
|
setState(() {
|
toalCount = count;
|
});
|
if (page == 1) {
|
setState(() {
|
videoList = temList;
|
});
|
} else {
|
setState(() {
|
videoList.addAll(temList);
|
});
|
}
|
|
_refreshController.refreshCompleted();
|
if (count >= videoList.length) {
|
_refreshController.loadNoData();
|
} else {
|
_refreshController.loadComplete();
|
}
|
if (videoList.isEmpty) {
|
_refreshController.dataEmpty!();
|
}
|
}
|
|
void deleteVideo(index) async {
|
Map<String, dynamic>? result =
|
await VideoApiUtil.cancelAttentionVideo(context, videoList[index].id!);
|
if (result == null) {
|
return;
|
}
|
if (result["IsPost"] == "true") {
|
setState(() {
|
videoList.removeAt(index);
|
});
|
ToastUtil.toast("删除成功", context);
|
if (videoList.isEmpty) {
|
loadVideoList(1);
|
}
|
} else {
|
ToastUtil.toast(result["Error"], context);
|
}
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: Colors.white,
|
body: Column(
|
children: [
|
TopNavBar(
|
title: "我的追剧",
|
),
|
Container(
|
height: DimenUtil.getOnePixel(context),
|
color: const Color(0xFFDBDBDB),
|
),
|
Expanded(
|
child: RefreshListView(
|
content: ListView.builder(
|
padding: const EdgeInsets.only(top: 10),
|
itemBuilder: (BuildContext context, int index) {
|
return getItem(index);
|
},
|
itemCount: videoList.length,
|
),
|
refreshController: _refreshController,
|
refresh: () {
|
loadVideoList(1);
|
},
|
loadMore: () {
|
loadVideoList(page + 1);
|
},
|
)),
|
],
|
));
|
}
|
|
Widget getItem(index) {
|
return Container(
|
alignment: Alignment.centerLeft,
|
margin: const EdgeInsets.fromLTRB(10, 8, 10, 8),
|
height: 80,
|
child: Stack(
|
children: [
|
InkWell(
|
onTap: () {
|
jumpVideoDetail(context, videoList[index], false);
|
},
|
child: Row(
|
children: [
|
ClipRRect(
|
borderRadius: BorderRadius.circular(6),
|
child: VideoImage(
|
VideoUtil.getHPicture(videoList[index]),
|
fit: BoxFit.cover,
|
height: 80,
|
width: 80 * 1.68,
|
)),
|
Container(
|
width: 10,
|
),
|
Expanded(
|
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
Text(
|
videoList[index].name!,
|
maxLines: 2,
|
overflow: TextOverflow.ellipsis,
|
style: const TextStyle(
|
color: Color(0xFF232323), fontSize: 15),
|
),
|
Text(
|
videoList[index].tag!,
|
maxLines: 1,
|
overflow: TextOverflow.ellipsis,
|
style: const TextStyle(
|
color: Color(0xFFB8AFB5), fontSize: 12),
|
),
|
Expanded(child: Container()),
|
const Text(
|
"",
|
style:
|
TextStyle(color: Color(0xFFB8AFB5), fontSize: 12),
|
)
|
],
|
))
|
],
|
)),
|
Positioned(
|
width: 60,
|
right: 10,
|
top: 0,
|
bottom: 0,
|
child: Container(
|
alignment: Alignment.centerRight,
|
child: MyFillButton(
|
"取消追剧",
|
5,
|
onClick: () {
|
deleteVideo(index);
|
},
|
)))
|
],
|
));
|
}
|
}
|