Skip to content

Commit

Permalink
feat: 详情页扩展显示
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Aug 12, 2023
1 parent 9fab8c0 commit 47d8c51
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 115 deletions.
12 changes: 8 additions & 4 deletions lib/pages/detail/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:miru_app/pages/watch/view.dart';
import 'package:miru_app/router/router.dart';
import 'package:miru_app/utils/database.dart';
import 'package:miru_app/utils/extension.dart';
import 'package:miru_app/utils/extension_runtime.dart';
import 'package:miru_app/utils/i18n.dart';
import 'package:miru_app/widgets/messenger.dart';

Expand All @@ -26,19 +27,23 @@ class DetailPageController extends GetxController {

ScrollController scrollController = ScrollController();

final isFavorite = false.obs;
final RxBool isFavorite = false.obs;
final Rx<ExtensionDetail?> data = Rx(null);
final Rx<History?> history = Rx(null);
final RxString error = ''.obs;
final RxBool isLoading = true.obs;
final RxInt selectEpGroup = 0.obs;
final Rx<ExtensionType> type = ExtensionType.bangumi.obs;
final Rx<TMDBDetail?> tmdb = Rx(null);
final Rx<ExtensionRuntime?> runtime = Rx(null);
ExtensionType get type =>
runtime.value?.extension.type ?? ExtensionType.bangumi;
Extension? get extension => runtime.value?.extension;

ExtensionDetail? get detail => data.value;
set detail(ExtensionDetail? value) => data.value = value;
TMDBDetail? get tmdbDetail => tmdb.value;
set tmdbDetail(TMDBDetail? value) => tmdb.value = value;

String get backgorund {
String bg = '';
if (tmdbDetail != null && tmdbDetail!.backdrop != null) {
Expand All @@ -63,8 +68,7 @@ class DetailPageController extends GetxController {
await refreshFavorite();
try {
// 获取扩展类型
final runtime = ExtensionUtils.extensions[package];
type.value = runtime!.extension.type;
runtime.value = ExtensionUtils.extensions[package];
_miruDetail = await DatabaseUtils.getMiruDetail(package, url);
_tmdbID = _miruDetail?.tmdbID ?? -1;
await getDetail();
Expand Down
197 changes: 101 additions & 96 deletions lib/pages/detail/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:miru_app/pages/detail/widgets/detail_appbar_flexible_space.dart'
import 'package:miru_app/pages/detail/widgets/detail_appbar_title.dart';
import 'package:miru_app/pages/detail/widgets/detail_background_color.dart';
import 'package:miru_app/pages/detail/widgets/detail_episodes.dart';
import 'package:miru_app/pages/detail/widgets/detail_extension_tile.dart';
import 'package:miru_app/pages/detail/widgets/detail_favorite_button.dart';
import 'package:miru_app/pages/detail/widgets/detail_overview.dart';
import 'package:miru_app/utils/extension.dart';
Expand Down Expand Up @@ -73,7 +74,7 @@ class _DetailPageState extends State<DetailPage> {
return Scaffold(
body: Obx(() {
late String episodesString;
if (c.type.value == ExtensionType.bangumi) {
if (c.type == ExtensionType.bangumi) {
episodesString = 'video.episodes'.i18n;
} else {
episodesString = 'reader.chapters'.i18n;
Expand Down Expand Up @@ -105,7 +106,7 @@ class _DetailPageState extends State<DetailPage> {
tabs: [
Tab(text: episodesString),
Tab(text: 'detail.overview'.i18n),
if (c.type.value == ExtensionType.bangumi)
if (c.type == ExtensionType.bangumi)
Tab(text: 'detail.cast'.i18n),
],
),
Expand Down Expand Up @@ -250,14 +251,9 @@ class _DetailPageState extends State<DetailPage> {
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Container(
constraints: const BoxConstraints(
maxHeight: 100,
),
child: SelectableText(c.detail!.desc ?? ''),
),
const SizedBox(height: 16),
const SizedBox(height: 20),
const DetailExtensionTile(),
const SizedBox(height: 20),
Row(
children: [
// 收藏按钮
Expand Down Expand Up @@ -304,121 +300,130 @@ class _DetailPageState extends State<DetailPage> {
c.tmdbDetail!.images.isEmpty) {
return const SizedBox();
}
return CardTile(
title: 'tmdb.backdrops'.i18n,
child: SizedBox(
height: 300,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
final image = c.tmdbDetail!.images[index];
final url = TmdbApi.getImageUrl(image);
if (url == null) {
return const SizedBox();
}
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
),
clipBehavior: Clip.antiAlias,
margin: const EdgeInsets.only(right: 8),
child: CacheNetWorkImage(
url,
height: 200,
),
);
},
itemCount: c.tmdbDetail!.images.length,
return fluent.Padding(
padding: const EdgeInsets.only(bottom: 16),
child: CardTile(
title: 'tmdb.backdrops'.i18n,
child: SizedBox(
height: 300,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
final image = c.tmdbDetail!.images[index];
final url = TmdbApi.getImageUrl(image);
if (url == null) {
return const SizedBox();
}
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
),
clipBehavior: Clip.antiAlias,
margin: const EdgeInsets.only(right: 8),
child: CacheNetWorkImage(
url,
height: 200,
),
);
},
itemCount: c.tmdbDetail!.images.length,
),
),
),
);
},
),
const SizedBox(height: 16),
Obx(
() {
if (c.tmdbDetail == null ||
c.tmdbDetail!.casts.isEmpty) {
return const SizedBox();
}
return CardTile(
title: 'detail.cast'.i18n,
child: SizedBox(
height: 150,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
final cast = c.tmdbDetail!.casts[index];
String? url;
if (cast.profilePath != null) {
url = TmdbApi.getImageUrl(cast.profilePath!);
}
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
launchUrl(
Uri.parse(
"https://www.themoviedb.org/person/${cast.id}}",
),
);
},
child: Container(
padding: const EdgeInsets.only(right: 16),
width: 170,
child: Column(
children: [
Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
return fluent.Padding(
padding: const EdgeInsets.only(bottom: 16),
child: CardTile(
title: 'detail.cast'.i18n,
child: SizedBox(
height: 150,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
final cast = c.tmdbDetail!.casts[index];
String? url;
if (cast.profilePath != null) {
url =
TmdbApi.getImageUrl(cast.profilePath!);
}
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
launchUrl(
Uri.parse(
"https://www.themoviedb.org/person/${cast.id}}",
),
);
},
child: Container(
padding:
const EdgeInsets.only(right: 16),
width: 170,
child: Column(
children: [
Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
),
clipBehavior: Clip.antiAlias,
child: CacheNetWorkImage(
url ?? '',
width: 100,
height: 100,
),
),
clipBehavior: Clip.antiAlias,
child: CacheNetWorkImage(
url ?? '',
width: 100,
height: 100,
const SizedBox(height: 8),
Text(
cast.name,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 8),
Text(
cast.name,
style: const TextStyle(
fontWeight: FontWeight.bold,
Text(
cast.character,
overflow: TextOverflow.ellipsis,
),
),
Text(
cast.character,
overflow: TextOverflow.ellipsis,
),
],
],
),
),
),
),
);
},
itemCount: c.tmdbDetail!.casts.length,
);
},
itemCount: c.tmdbDetail!.casts.length,
),
),
),
);
},
),
const SizedBox(height: 16),
Obx(
() {
if (c.tmdbDetail == null ||
c.tmdbDetail!.overview == null) {
if (c.detail?.desc == null) {
return const SizedBox();
}
return CardTile(
title: "detail.overview".i18n,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: SelectableText(c.tmdbDetail!.overview ?? ''),
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: CardTile(
title: "detail.overview".i18n,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: SelectableText(
c.tmdbDetail?.overview ?? c.detail?.desc ?? '',
),
),
),
);
},
),
const SizedBox(height: 16),
Obx(
() {
if (c.tmdbDetail == null) {
Expand Down
9 changes: 2 additions & 7 deletions lib/pages/detail/widgets/detail_appbar_flexible_space.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:miru_app/pages/detail/controller.dart';
import 'package:miru_app/pages/detail/widgets/detail_continue_play.dart';
import 'package:miru_app/pages/detail/widgets/detail_extension_tile.dart';
import 'package:miru_app/pages/detail/widgets/detail_favorite_button.dart';
import 'package:miru_app/widgets/cache_network_image.dart';

Expand Down Expand Up @@ -75,7 +76,6 @@ class _DetailAppbarflexibleSpaceState extends State<DetailAppbarflexibleSpace> {
),
),
),
// flex 左边封面右边标题
Positioned(
left: 20,
bottom: 105,
Expand Down Expand Up @@ -110,12 +110,7 @@ class _DetailAppbarflexibleSpaceState extends State<DetailAppbarflexibleSpace> {
style: Get.theme.textTheme.titleLarge,
),
const SizedBox(height: 10),
Text(
c.isLoading.value ? "" : c.data.value!.desc ?? '',
softWrap: true,
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
const DetailExtensionTile(),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/detail/widgets/detail_continue_play.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class _DetailContinuePlayState extends State<DetailContinuePlay> {
return Obx(() {
late String noEpisodesString;
late String watchNowString;
if (c.type.value == ExtensionType.bangumi) {
if (c.type == ExtensionType.bangumi) {
noEpisodesString = 'video.no-episodes'.i18n;
watchNowString = 'video.watch-now'.i18n;
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/detail/widgets/detail_episodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class _DetailEpisodesState extends State<DetailEpisodes> {

Widget _buildDesktopEpisodes(BuildContext context) {
late String episodesString;
if (c.type.value == ExtensionType.bangumi) {
if (c.type == ExtensionType.bangumi) {
episodesString = 'video.episodes'.i18n;
} else {
episodesString = 'reader.chapters'.i18n;
Expand Down
Loading

0 comments on commit 47d8c51

Please sign in to comment.