2023-11-05 19:32:59 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2023-11-06 10:38:26 +01:00
|
|
|
import 'package:release_schedule/api/movie_api.dart';
|
|
|
|
import 'package:release_schedule/api/wikidata_movie_api.dart';
|
2024-01-08 14:30:32 +01:00
|
|
|
import 'package:release_schedule/model/movie.dart';
|
2023-11-06 10:38:26 +01:00
|
|
|
import 'package:release_schedule/model/movie_manager.dart';
|
2023-11-08 14:43:59 +01:00
|
|
|
import 'package:release_schedule/view/movie_manager_list.dart';
|
2023-11-05 19:32:59 +01:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2023-11-06 10:38:26 +01:00
|
|
|
title: 'Movie Schedule',
|
|
|
|
themeMode: ThemeMode.dark,
|
|
|
|
darkTheme: ThemeData.dark(useMaterial3: true),
|
2023-11-05 19:32:59 +01:00
|
|
|
theme: ThemeData(
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
|
|
useMaterial3: true,
|
|
|
|
),
|
2023-11-08 14:43:59 +01:00
|
|
|
home: HomePage(movieManager),
|
2023-11-05 19:32:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-06 10:38:26 +01:00
|
|
|
class HomePage extends StatelessWidget {
|
|
|
|
final MovieApi api = WikidataMovieApi();
|
2023-11-08 14:43:59 +01:00
|
|
|
final MovieManager manager;
|
2023-11-05 19:32:59 +01:00
|
|
|
|
2023-11-08 14:43:59 +01:00
|
|
|
HomePage(this.manager, {super.key});
|
2023-11-05 19:32:59 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2023-11-08 14:59:23 +01:00
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text("Release Schedule"),
|
2024-01-08 14:30:32 +01:00
|
|
|
actions: [HamburgerMenu(manager)],
|
2023-11-08 14:59:23 +01:00
|
|
|
),
|
2024-01-08 12:57:36 +01:00
|
|
|
body: DefaultTabController(
|
|
|
|
length: 2,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TabBarView(
|
|
|
|
children: [
|
|
|
|
Scaffold(
|
2024-01-08 14:30:32 +01:00
|
|
|
body: MovieManagerList(
|
|
|
|
manager,
|
2024-01-08 14:57:03 +01:00
|
|
|
// Only show movies that are bookmarked or have a release date with at least month precision and at least one title
|
2024-01-08 14:30:32 +01:00
|
|
|
filter: (movie) =>
|
2024-01-08 14:57:03 +01:00
|
|
|
movie.bookmarked ||
|
|
|
|
(movie.releaseDate.precision >= DatePrecision.month &&
|
|
|
|
(movie.titles?.length ?? 0) >= 1),
|
2024-01-08 14:30:32 +01:00
|
|
|
),
|
2024-01-08 12:57:36 +01:00
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
child: const Icon(Icons.refresh),
|
|
|
|
onPressed: () => manager.loadUpcomingMovies(),
|
|
|
|
),
|
|
|
|
),
|
2024-01-08 14:57:03 +01:00
|
|
|
MovieManagerList(
|
|
|
|
manager,
|
|
|
|
filter: (movie) => movie.bookmarked,
|
|
|
|
)
|
2024-01-08 12:57:36 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const TabBar(tabs: [
|
|
|
|
Tab(icon: Icon(Icons.list), child: Text("Upcoming")),
|
|
|
|
Tab(icon: Icon(Icons.bookmark), child: Text("Bookmarked")),
|
|
|
|
]),
|
|
|
|
],
|
|
|
|
),
|
2023-11-05 19:32:59 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-01-08 14:30:32 +01:00
|
|
|
|
|
|
|
class HamburgerMenu extends StatelessWidget {
|
|
|
|
final MovieManager manager;
|
|
|
|
const HamburgerMenu(this.manager, {super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return PopupMenuButton(
|
|
|
|
icon: const Icon(Icons.menu),
|
|
|
|
itemBuilder: (context) {
|
|
|
|
return [
|
|
|
|
PopupMenuItem(
|
|
|
|
child: const Text("Remove all not bookmarked"),
|
|
|
|
onTap: () =>
|
|
|
|
manager.removeMoviesWhere((movie) => !movie.bookmarked),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
child: const Text("Remove all"),
|
|
|
|
onTap: () => manager.removeMoviesWhere((movie) => true),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|