v1.0.1
This commit is contained in:
188
lib/modules/comic/home/recommend/comic_recommend_controller.dart
Normal file
188
lib/modules/comic/home/recommend/comic_recommend_controller.dart
Normal file
@@ -0,0 +1,188 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_dmzj/app/controller/base_controller.dart';
|
||||
import 'package:flutter_dmzj/app/log.dart';
|
||||
import 'package:flutter_dmzj/models/comic/recommend_model.dart';
|
||||
import 'package:flutter_dmzj/modules/comic/home/comic_home_controller.dart';
|
||||
import 'package:flutter_dmzj/requests/comic_request.dart';
|
||||
import 'package:flutter_dmzj/routes/app_navigator.dart';
|
||||
import 'package:flutter_dmzj/services/user_service.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class ComicRecommendController extends BasePageController<ComicRecommendModel> {
|
||||
final ComicRequest request = ComicRequest();
|
||||
StreamSubscription<dynamic>? subLogin;
|
||||
StreamSubscription<dynamic>? subLogout;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
subLogin = UserService.loginedStream.listen((event) {
|
||||
loadSubscribe();
|
||||
});
|
||||
subLogout = UserService.logoutStream.listen((event) {
|
||||
list.removeWhere((x) => x.categoryId == 49);
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ComicRecommendModel>> getData(int page, int pageSize) async {
|
||||
var ls = await request.recommend();
|
||||
|
||||
// ls.insert(
|
||||
// ls.length > 3 ? 2 : 1,
|
||||
// ComicRecommendModel(
|
||||
// categoryId: 50,
|
||||
// title: "随便看看",
|
||||
// sort: 6,
|
||||
// data: [],
|
||||
// ),
|
||||
// );
|
||||
//loadRandom();
|
||||
if (UserService.instance.logined.value) {
|
||||
loadSubscribe();
|
||||
}
|
||||
return ls;
|
||||
}
|
||||
|
||||
// /// 加载随机漫画
|
||||
// Future<void> loadRandom() async {
|
||||
// try {
|
||||
// var result = await request.refreshRecommend(50);
|
||||
// var index = list.indexWhere((x) => x.categoryId == 50);
|
||||
// if (index != -1) {
|
||||
// list[index].data = result;
|
||||
// } else {
|
||||
// list.insert(
|
||||
// list.length > 3 ? 2 : 1,
|
||||
// result,
|
||||
// );
|
||||
// }
|
||||
// } catch (e) {
|
||||
// Log.logPrint(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
/// 刷新国漫
|
||||
Future<void> refreshGuoman() async {
|
||||
try {
|
||||
var index = list.indexWhere((x) => x.categoryId == 111);
|
||||
var result =
|
||||
await request.refreshRecommend(111, size: 6, page: list[index].page);
|
||||
|
||||
if (index != -1) {
|
||||
list[index].data = result;
|
||||
list[index].page++;
|
||||
list.refresh();
|
||||
}
|
||||
} catch (e) {
|
||||
Log.logPrint(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// 刷新近期必看
|
||||
Future<void> refreshRecommend() async {
|
||||
try {
|
||||
var index = list.indexWhere((x) => x.categoryId == 110);
|
||||
|
||||
var result = await request.refreshRecommend(110, page: list[index].page);
|
||||
|
||||
if (index != -1) {
|
||||
list[index].data = result;
|
||||
list[index].page++;
|
||||
list.refresh();
|
||||
}
|
||||
} catch (e) {
|
||||
Log.logPrint(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// 加载订阅
|
||||
void loadSubscribe() async {
|
||||
try {
|
||||
var result = await request.recommendSubscribe();
|
||||
var index = list.indexWhere((x) => x.categoryId == 49);
|
||||
if (index != -1) {
|
||||
list[index] = result;
|
||||
} else {
|
||||
list.insert(1, result);
|
||||
}
|
||||
} catch (e) {
|
||||
Log.logPrint(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// 刷新热门连载
|
||||
Future<void> refreshHot() async {
|
||||
try {
|
||||
var index = list.indexWhere((x) => x.categoryId == 112);
|
||||
var result =
|
||||
await request.refreshRecommend(112, page: list[index].page, size: 6);
|
||||
|
||||
if (index != -1) {
|
||||
list[index].data = result;
|
||||
list[index].page++;
|
||||
list.refresh();
|
||||
}
|
||||
} catch (e) {
|
||||
Log.logPrint(e);
|
||||
}
|
||||
}
|
||||
|
||||
void openDetail(ComicRecommendItemModel item) {
|
||||
//漫画=1
|
||||
if (item.type == null || item.type == 1) {
|
||||
AppNavigator.toComicDetail(
|
||||
item.objId ?? item.id ?? 0,
|
||||
);
|
||||
} else if (item.type == 5) {
|
||||
//专题=5
|
||||
AppNavigator.toSpecialDetail(
|
||||
item.objId ?? 0,
|
||||
);
|
||||
} else if (item.type == 6) {
|
||||
//网页=6
|
||||
AppNavigator.toWebView(item.url ?? "");
|
||||
} else if (item.type == 7) {
|
||||
//新闻=7
|
||||
AppNavigator.toNewsDetail(
|
||||
url: item.url ?? "",
|
||||
newsId: item.objId ?? 0,
|
||||
title: item.title,
|
||||
);
|
||||
} else if (item.type == 8) {
|
||||
//作者=8
|
||||
AppNavigator.toComicAuthorDetail(item.objId ?? 0);
|
||||
} else if (item.type == 13) {
|
||||
//社区=13
|
||||
//直接跳转至网页
|
||||
launchUrlString(
|
||||
"http://m.forum.idmzj.com/thread/detail?tid=${item.objId}",
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
// AppNavigator.toWebView(
|
||||
// "http://m.forum.dmzj.com/thread/detail?tid=${item.objId}",
|
||||
// );
|
||||
} else {
|
||||
SmartDialog.showToast("未知类型,无法跳转");
|
||||
}
|
||||
}
|
||||
|
||||
void toSpecial() {
|
||||
var homeController = Get.find<ComicHomeController>();
|
||||
homeController.tabController.animateTo(4);
|
||||
}
|
||||
|
||||
void toMySubscribe() {
|
||||
AppNavigator.toUserSubscribe();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
subLogin?.cancel();
|
||||
subLogout?.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
372
lib/modules/comic/home/recommend/comic_recommend_view.dart
Normal file
372
lib/modules/comic/home/recommend/comic_recommend_view.dart
Normal file
@@ -0,0 +1,372 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dmzj/app/app_style.dart';
|
||||
import 'package:flutter_dmzj/models/comic/recommend_model.dart';
|
||||
import 'package:flutter_dmzj/modules/comic/home/recommend/comic_recommend_controller.dart';
|
||||
import 'package:flutter_dmzj/widgets/keep_alive_wrapper.dart';
|
||||
import 'package:flutter_dmzj/widgets/net_image.dart';
|
||||
import 'package:flutter_dmzj/widgets/page_list_view.dart';
|
||||
import 'package:flutter_dmzj/widgets/refresh_until_widget.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ComicRecommendView extends StatelessWidget {
|
||||
final ComicRecommendController controller;
|
||||
ComicRecommendView({Key? key})
|
||||
: controller = Get.put(ComicRecommendController()),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return KeepAliveWrapper(
|
||||
child: PageListView(
|
||||
pageController: controller,
|
||||
padding: AppStyle.edgeInsetsH12,
|
||||
firstRefresh: true,
|
||||
loadMore: false,
|
||||
showPageLoadding: true,
|
||||
itemBuilder: (context, i) {
|
||||
var item = controller.list[i];
|
||||
//大图推荐
|
||||
if (item.categoryId == 109) {
|
||||
return buildBanner(item);
|
||||
}
|
||||
//随便看看
|
||||
// if (item.categoryId == 50) {
|
||||
// return buildCard(
|
||||
// context,
|
||||
// child: buildTreeColumnGridView(item.data),
|
||||
// title: item.title.toString(),
|
||||
// action: buildRefresh(onRefresh: controller.loadRandom),
|
||||
// );
|
||||
// }
|
||||
//我的订阅
|
||||
if (item.categoryId == 49) {
|
||||
return buildCard(
|
||||
context,
|
||||
child: buildTreeColumnGridView(item.data),
|
||||
title: item.title.toString(),
|
||||
action: buildShowMore(onTap: controller.toMySubscribe),
|
||||
);
|
||||
}
|
||||
//近期必看\国漫\热门连载\最新上架
|
||||
if (item.categoryId == 110 ||
|
||||
item.categoryId == 111 ||
|
||||
item.categoryId == 112 ||
|
||||
item.categoryId == 56) {
|
||||
Widget? action;
|
||||
//刷新国漫
|
||||
if (item.categoryId == 110) {
|
||||
action = buildRefresh(onRefresh: controller.refreshRecommend);
|
||||
}
|
||||
if (item.categoryId == 111) {
|
||||
action = buildRefresh(onRefresh: controller.refreshGuoman);
|
||||
}
|
||||
if (item.categoryId == 112) {
|
||||
action = buildRefresh(onRefresh: controller.refreshHot);
|
||||
}
|
||||
return buildCard(
|
||||
context,
|
||||
child: buildTreeColumnGridView(item.data),
|
||||
title: item.title.toString(),
|
||||
action: action,
|
||||
);
|
||||
}
|
||||
//火热专题\美漫大事件\条漫
|
||||
if (item.categoryId == 48 ||
|
||||
item.categoryId == 53 ||
|
||||
item.categoryId == 55) {
|
||||
return buildCard(
|
||||
context,
|
||||
child: buildTwoColumnGridView(item.data),
|
||||
title: item.title.toString(),
|
||||
action: item.categoryId == 48
|
||||
? buildShowMore(onTap: controller.toSpecial)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
//大师
|
||||
if (item.categoryId == 51) {
|
||||
return buildCard(
|
||||
context,
|
||||
child: buildAuthorGridView(item.data),
|
||||
title: item.title.toString(),
|
||||
);
|
||||
}
|
||||
return buildCard(
|
||||
context,
|
||||
child: buildTreeColumnGridView(item.data),
|
||||
title: item.title.toString(),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildCard(
|
||||
BuildContext context, {
|
||||
required Widget child,
|
||||
required String title,
|
||||
Widget? action,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: AppStyle.edgeInsetsB8,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: AppStyle.radius8,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16, height: 1.0, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 48,
|
||||
child: action,
|
||||
),
|
||||
],
|
||||
),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildShowMore({required Function() onTap}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: const Row(
|
||||
children: [
|
||||
Text(
|
||||
"查看更多",
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey),
|
||||
),
|
||||
Icon(Icons.chevron_right, size: 18, color: Colors.grey),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildRefresh({required Future Function() onRefresh}) {
|
||||
return RefreshUntilWidget(onRefresh: onRefresh, text: "换一批");
|
||||
}
|
||||
|
||||
Widget buildBanner(ComicRecommendModel item) {
|
||||
return Padding(
|
||||
padding: AppStyle.edgeInsetsB12,
|
||||
child: ClipRRect(
|
||||
borderRadius: AppStyle.radius4,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 75 / 40,
|
||||
child: Swiper(
|
||||
itemWidth: 750,
|
||||
itemHeight: 400,
|
||||
autoplay: true,
|
||||
itemCount: item.data.length,
|
||||
itemBuilder: (_, i) => NetImage(
|
||||
item.data[i].cover,
|
||||
width: 750,
|
||||
height: 400,
|
||||
),
|
||||
onTap: (i) {
|
||||
controller.openDetail(item.data[i]);
|
||||
},
|
||||
pagination: SwiperCustomPagination(
|
||||
builder: (BuildContext context, SwiperPluginConfig config) {
|
||||
return Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 8,
|
||||
right: 12,
|
||||
top: 4,
|
||||
bottom: 4,
|
||||
),
|
||||
//color: Colors.black12,
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.bottomCenter,
|
||||
end: Alignment.topCenter,
|
||||
colors: [
|
||||
Colors.black38,
|
||||
Colors.transparent,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.data[config.activeIndex].title,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14, color: Colors.white),
|
||||
),
|
||||
),
|
||||
AppStyle.hGap8,
|
||||
PageIndicator(
|
||||
controller: config.pageController!,
|
||||
count: config.itemCount,
|
||||
size: 10,
|
||||
layout: PageIndicatorLayout.SCALE,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTreeColumnGridView(List<ComicRecommendItemModel> items) {
|
||||
return MasonryGridView.count(
|
||||
padding: EdgeInsets.zero,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisCount: 3,
|
||||
mainAxisSpacing: 12,
|
||||
crossAxisSpacing: 12,
|
||||
itemCount: items.length,
|
||||
itemBuilder: (_, i) {
|
||||
var item = items[i];
|
||||
return InkWell(
|
||||
onTap: () => controller.openDetail(item),
|
||||
borderRadius: AppStyle.radius4,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: AppStyle.radius4,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 27 / 36,
|
||||
child: NetImage(
|
||||
item.cover,
|
||||
width: 270,
|
||||
height: 360,
|
||||
),
|
||||
),
|
||||
),
|
||||
AppStyle.vGap8,
|
||||
Text(
|
||||
item.title,
|
||||
maxLines: 1,
|
||||
style: const TextStyle(height: 1.2),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
item.subTitle ?? item.status ?? '',
|
||||
maxLines: 1,
|
||||
style: const TextStyle(
|
||||
height: 1.2,
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
AppStyle.vGap8,
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildAuthorGridView(List<ComicRecommendItemModel> items) {
|
||||
return MasonryGridView.count(
|
||||
padding: EdgeInsets.zero,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisCount: 3,
|
||||
mainAxisSpacing: 8,
|
||||
crossAxisSpacing: 8,
|
||||
itemCount: items.length,
|
||||
itemBuilder: (_, i) {
|
||||
var item = items[i];
|
||||
return InkWell(
|
||||
onTap: () => controller.openDetail(item),
|
||||
borderRadius: AppStyle.radius8,
|
||||
child: Padding(
|
||||
padding: AppStyle.edgeInsetsA12,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
NetImage(
|
||||
item.cover,
|
||||
width: 56,
|
||||
height: 56,
|
||||
borderRadius: 32,
|
||||
),
|
||||
Padding(
|
||||
padding: AppStyle.edgeInsetsV8,
|
||||
child: Text(
|
||||
item.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(height: 1.2, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTwoColumnGridView(List<ComicRecommendItemModel> items) {
|
||||
return MasonryGridView.count(
|
||||
padding: EdgeInsets.zero,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisCount: 2,
|
||||
mainAxisSpacing: 12,
|
||||
crossAxisSpacing: 12,
|
||||
itemCount: items.length,
|
||||
itemBuilder: (_, i) {
|
||||
var item = items[i];
|
||||
return InkWell(
|
||||
onTap: () => controller.openDetail(item),
|
||||
borderRadius: AppStyle.radius4,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: AppStyle.radius4,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 32 / 17,
|
||||
child: NetImage(
|
||||
item.cover,
|
||||
width: 320,
|
||||
height: 170,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: AppStyle.edgeInsetsV8,
|
||||
child: Text(
|
||||
item.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(height: 1.2),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user