Skip to content

Commit

Permalink
feat: Episode list mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Sep 5, 2023
1 parent 029aa64 commit 9c3066b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
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/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

0 comments on commit 9c3066b

Please sign in to comment.