import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import '../../model/video/watch_record_model.dart';
|
import '../../ui/video/video_detail.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';
|
|
void main() {
|
runApp(MyApp());
|
}
|
|
class MyApp extends StatelessWidget {
|
// This widget is the root of your application.
|
@override
|
Widget build(BuildContext context) {
|
return MaterialApp(
|
title: '视频收藏',
|
theme: ThemeData(primaryColor: const Color(0xFFF5F5F5)),
|
home: VideoScanRecordPage(title: ''),
|
);
|
}
|
}
|
|
class VideoScanRecordPage extends StatefulWidget {
|
VideoScanRecordPage({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
|
_VideoScanRecordPageState createState() => _VideoScanRecordPageState();
|
}
|
|
class _VideoScanRecordPageState extends State<VideoScanRecordPage>
|
with SingleTickerProviderStateMixin {
|
bool editMode = false;
|
Set<String> selectedSet = {};
|
|
final MyRefreshController _refreshController =
|
MyRefreshController(initialRefresh: false);
|
List<WatchRecordModel> recordList = [];
|
|
int page = 1;
|
int toalCount = 0;
|
|
@override
|
void initState() {
|
super.initState();
|
loadWatchRecord(1);
|
}
|
|
Future loadWatchRecord(int _page) async {
|
page = _page;
|
List<WatchRecordModel> temp = await DBManager.listWatchRecord(page, 20);
|
int count = await DBManager.countWatchRecord();
|
setState(() {
|
toalCount = count;
|
});
|
if (page == 1) {
|
setState(() {
|
recordList = temp;
|
});
|
} else {
|
setState(() {
|
recordList.addAll(temp);
|
});
|
}
|
|
_refreshController.refreshCompleted();
|
if (count >= recordList.length) {
|
_refreshController.loadNoData();
|
} else {
|
_refreshController.loadComplete();
|
}
|
if (toalCount == 0) {
|
_refreshController.dataEmpty!();
|
}
|
}
|
|
void deleteRecord() async {
|
if (selectedSet.isEmpty) {
|
return;
|
}
|
await DBManager.deleteWatchRecord(selectedSet.toList());
|
setState(() {
|
selectedSet.clear();
|
});
|
loadWatchRecord(1).then((value) {
|
if (recordList.isEmpty) {
|
setState(() {
|
editMode = false;
|
});
|
_refreshController.setEditMode!(false);
|
}
|
});
|
}
|
|
Widget getListView() {
|
return ListView.builder(
|
padding: const EdgeInsets.only(top: 10),
|
itemBuilder: (BuildContext context, int index) {
|
return getItem(index);
|
},
|
itemCount: recordList.length,
|
);
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: Colors.white,
|
body: Column(
|
children: [
|
TopNavBar(
|
title: "观看记录",
|
rightIcon: recordList.isNotEmpty
|
? const Icon(
|
Icons.format_list_bulleted,
|
size: 25,
|
color: Color(0xFF202020),
|
)
|
: null,
|
rightClick: () {
|
setState(() {
|
editMode = !editMode;
|
_refreshController.setEditMode!(editMode);
|
if (!editMode) {
|
selectedSet.clear();
|
} else {}
|
});
|
},
|
),
|
Container(
|
height: DimenUtil.getOnePixel(context),
|
color: const Color(0xFFDBDBDB),
|
),
|
Expanded(
|
child: RefreshListView(
|
content: getListView(),
|
refreshController: _refreshController,
|
refresh: () {
|
loadWatchRecord(1);
|
},
|
loadMore: () {
|
loadWatchRecord(page + 1);
|
},
|
)),
|
editMode && recordList.isNotEmpty
|
? Container(
|
padding: const EdgeInsets.fromLTRB(28, 10, 28, 10),
|
decoration: const BoxDecoration(
|
color: Colors.white,
|
border: Border(
|
top: BorderSide(
|
color: Color(0xFFDBDBDB), width: 0.5))),
|
child: Row(
|
children: [
|
Expanded(
|
child: MyOutlineButton(
|
recordList.length == selectedSet.length ? "反选" : "全选",
|
8,
|
height: 34,
|
fontSize: 16,
|
color: const Color(0xFFdbdbdb),
|
textColor: const Color(0xFF202020),
|
onClick: () {
|
if (recordList.length == selectedSet.length) {
|
setState(() {
|
selectedSet.clear();
|
});
|
} else {
|
Set<String> list = recordList
|
.map((e) => e.id.toString())
|
.toSet();
|
setState(() {
|
selectedSet = list;
|
});
|
}
|
},
|
)),
|
Container(
|
width: 20,
|
),
|
Expanded(
|
child: MyFillButton(
|
selectedSet.isNotEmpty
|
? ("删除(${selectedSet.length})")
|
: "删除",
|
8,
|
height: 34,
|
fontSize: 16,
|
onClick: () {
|
deleteRecord();
|
},
|
)),
|
],
|
),
|
)
|
: Container()
|
],
|
));
|
}
|
|
Widget getItem(index) {
|
return Container(
|
alignment: Alignment.centerLeft,
|
margin: const EdgeInsets.fromLTRB(10, 8, 10, 8),
|
height: 80,
|
child: InkWell(
|
child: Row(
|
children: [
|
Stack(
|
alignment: Alignment.center,
|
children: [
|
ClipRRect(
|
borderRadius: BorderRadius.circular(6),
|
child: VideoImage(
|
VideoUtil.getHPicture(recordList[index].video!),
|
height: 80,
|
width: 80 * 1.68,
|
)),
|
(editMode
|
? Image.asset(
|
selectedSet.contains("${recordList[index].id}")
|
? "assets/imgs/video/icon_check_true.png"
|
: "assets/imgs/video/icon_check_false.png",
|
width: 35,
|
)
|
: Container())
|
],
|
),
|
Container(
|
width: 10,
|
),
|
Expanded(
|
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
Text(
|
recordList[index].video!.name!,
|
maxLines: 2,
|
overflow: TextOverflow.ellipsis,
|
style:
|
const TextStyle(color: Color(0xFF232323), fontSize: 15),
|
),
|
Text(
|
recordList[index].video!.tag ?? "",
|
maxLines: 1,
|
overflow: TextOverflow.ellipsis,
|
style:
|
const TextStyle(color: Color(0xFFB8AFB5), fontSize: 12),
|
),
|
Expanded(child: Container()),
|
Text(
|
_getPositionDesc(recordList[index]),
|
style:
|
const TextStyle(color: Color(0xFFB8AFB5), fontSize: 12),
|
)
|
],
|
))
|
],
|
),
|
onTap: () {
|
if (!editMode) {
|
//跳转详情
|
NavigatorUtil.navigateToNextPage(context, VideoDetailPage(position:recordList[index].position! ,videoInfo:recordList[index].video ,), (data) {
|
|
|
});
|
|
|
return;
|
}
|
print("check: index-$index");
|
setState(() {
|
if (selectedSet.contains("${recordList[index].id}")) {
|
selectedSet.remove("${recordList[index].id}");
|
} else {
|
selectedSet.add("${recordList[index].id}");
|
}
|
});
|
},
|
));
|
}
|
|
String _getPositionDesc(WatchRecordModel record) {
|
if (record.video!.tag != null && record.video!.tag!.contains("集")) {
|
return "观看至${record.position! + 1}集";
|
} else {
|
return "";
|
}
|
}
|
}
|