Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(UI): episode list mode #60

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/pages/detail/widgets/detail_continue_play.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,19 @@ class _DetailContinuePlayState extends State<DetailContinuePlay> {
children: [
const Icon(fluent.FluentIcons.play),
const SizedBox(width: 5),
Text(
FlutterI18n.translate(
context,
'detail.continue-watching',
translationParams: {
'episode': history.episodeTitle,
},
Container(
constraints: const BoxConstraints(
maxWidth: 150,
),
child: Text(
FlutterI18n.translate(
context,
'detail.continue-watching',
translationParams: {
'episode': history.episodeTitle,
},
),
maxLines: 1,
),
)
],
Expand Down
67 changes: 58 additions & 9 deletions lib/pages/detail/widgets/detail_episodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:get/get.dart';
import 'package:miru_app/models/extension.dart';
import 'package:miru_app/pages/detail/controller.dart';
import 'package:miru_app/pages/detail/widgets/detail_continue_play.dart';
import 'package:miru_app/utils/miru_storage.dart';
import 'package:miru_app/widgets/card_tile.dart';
import 'package:miru_app/utils/i18n.dart';
import 'package:miru_app/widgets/platform_widget.dart';
Expand All @@ -23,6 +24,7 @@ class _DetailEpisodesState extends State<DetailEpisodes> {
List<fluent.ComboBoxItem<int>>? comboBoxItems;
List<DropdownMenuItem<int>>? dropdownItems;
late List<ExtensionEpisodeGroup> episodes = [];
late String listMode = MiruStorage.getSetting(SettingKey.listMode);

Widget _buildAndroidEpisodes(BuildContext context) {
return Column(
Expand Down Expand Up @@ -101,8 +103,23 @@ class _DetailEpisodesState extends State<DetailEpisodes> {
} else {
episodesString = 'reader.chapters'.i18n;
}
return CardTile(

Widget cardTile(Widget child) {
return CardTile(
title: episodesString,
leading: fluent.IconButton(
icon: Icon(
listMode == "grid"
? fluent.FluentIcons.view_list
: fluent.FluentIcons.grid_view_medium,
),
onPressed: () {
setState(() {
listMode == "grid" ? listMode = "list" : listMode = "grid";
MiruStorage.setSetting(SettingKey.listMode, listMode);
});
},
),
trailing: Row(
children: [
const DetailContinuePlay(),
Expand All @@ -118,12 +135,20 @@ class _DetailEpisodesState extends State<DetailEpisodes> {
)
],
),
child: LayoutBuilder(builder: (context, constraints) {
return Container(
constraints: const BoxConstraints(
maxHeight: 500,
),
child: GridView.builder(
child: Container(
constraints: const BoxConstraints(
maxHeight: 500,
),
child: child,
),
);
}

if (listMode == "grid") {
return cardTile(
LayoutBuilder(
builder: (context, constraints) {
return GridView.builder(
shrinkWrap: true,
itemCount: episodes.isEmpty
? 0
Expand All @@ -149,9 +174,33 @@ class _DetailEpisodesState extends State<DetailEpisodes> {
},
);
},
),
);
},
),
);
}

return cardTile(
ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(0),
itemCount:
episodes.isEmpty ? 0 : episodes[c.selectEpGroup.value].urls.length,
itemBuilder: (context, index) {
return fluent.ListTile(
title: Text(episodes[c.selectEpGroup.value].urls[index].name),
onPressed: () {
c.goWatch(
context,
episodes[c.selectEpGroup.value].urls,
index,
c.selectEpGroup.value,
);
},
);
}));
},
),
);
}

@override
Expand Down
2 changes: 2 additions & 0 deletions lib/pages/home/widgets/home_resent_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class _HomeRecentCardState extends State<HomeRecentCard> {
color: Colors.white,
fontSize: 12,
),
maxLines: 1,
),
],
),
Expand Down Expand Up @@ -231,6 +232,7 @@ class _HomeRecentCardState extends State<HomeRecentCard> {
color: Colors.white,
fontSize: 12,
),
maxLines: 1,
),
if (_update.isNotEmpty) ...[
const SizedBox(height: 8),
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/miru_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class MiruStorage {
await _initSetting(SettingKey.theme, 'system');
await _initSetting(SettingKey.enableNSFW, false);
await _initSetting(SettingKey.videoPlayer, 'built-in');
await _initSetting(SettingKey.listMode, "grid");
}

static _initSetting(String key, dynamic value) async {
Expand Down Expand Up @@ -139,4 +140,5 @@ class SettingKey {
static String enableNSFW = 'EnableNSFW';
static String videoPlayer = 'VideoPlayer';
static String databaseVersion = 'DatabaseVersion';
static String listMode = 'ListMode';
}
4 changes: 4 additions & 0 deletions lib/widgets/card_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class CardTile extends StatelessWidget {
required this.title,
required this.child,
this.trailing,
this.leading,
}) : super(key: key);
final String title;
final Widget? leading;
final Widget? trailing;
final Widget child;

Expand All @@ -34,6 +36,8 @@ class CardTile extends StatelessWidget {
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 3),
if (leading != null) leading!,
const Spacer(),
if (trailing != null) trailing!
],
Expand Down