admin
2022-03-31 02f1c9fd2c594323f772f8e8f0f2187a285c1749
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
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);
                      },
                    )))
          ],
        ));
  }
}