2023-11-05 19:32:59 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2024-01-09 16:32:53 +01:00
|
|
|
import 'package:release_schedule/model/dates.dart';
|
2024-01-08 21:48:13 +01:00
|
|
|
import 'package:release_schedule/model/live_search.dart';
|
2023-11-06 10:38:26 +01:00
|
|
|
import 'package:release_schedule/model/movie_manager.dart';
|
2024-01-09 14:48:36 +01:00
|
|
|
import 'package:release_schedule/view/movie_item.dart';
|
2023-11-08 14:43:59 +01:00
|
|
|
import 'package:release_schedule/view/movie_manager_list.dart';
|
2024-01-08 21:58:18 +01:00
|
|
|
import 'package:release_schedule/view/swipe_transition.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,
|
2024-01-09 19:17:59 +01:00
|
|
|
darkTheme: ThemeData.dark(
|
|
|
|
useMaterial3: true,
|
|
|
|
).copyWith(
|
|
|
|
colorScheme: ColorScheme.fromSeed(
|
|
|
|
seedColor: Colors.deepOrange,
|
|
|
|
brightness: Brightness.dark,
|
|
|
|
),
|
|
|
|
),
|
2023-11-05 19:32:59 +01:00
|
|
|
theme: ThemeData(
|
2024-01-09 19:17:59 +01:00
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
|
2023-11-05 19:32:59 +01:00
|
|
|
useMaterial3: true,
|
|
|
|
),
|
2023-11-08 14:43:59 +01:00
|
|
|
home: HomePage(movieManager),
|
2023-11-05 19:32:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 21:48:13 +01:00
|
|
|
class HomePage extends StatefulWidget {
|
2023-11-08 14:43:59 +01:00
|
|
|
final MovieManager manager;
|
2023-11-05 19:32:59 +01:00
|
|
|
|
2024-01-08 21:58:18 +01:00
|
|
|
const HomePage(this.manager, {super.key});
|
2023-11-05 19:32:59 +01:00
|
|
|
|
2024-01-08 21:48:13 +01:00
|
|
|
@override
|
|
|
|
State<HomePage> createState() => _HomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomePageState extends State<HomePage>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
late AnimationController _controller;
|
|
|
|
late LiveSearch liveSearch;
|
2024-01-09 12:47:42 +01:00
|
|
|
late TextEditingController _searchController;
|
2024-01-08 21:48:13 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_controller = AnimationController(
|
|
|
|
vsync: this, // the SingleTickerProviderStateMixin
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
);
|
2024-01-09 12:47:42 +01:00
|
|
|
_searchController = TextEditingController();
|
2024-01-08 21:48:13 +01:00
|
|
|
liveSearch = LiveSearch(widget.manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_controller.dispose();
|
2024-01-09 12:47:42 +01:00
|
|
|
_searchController.dispose();
|
2024-01-08 21:48:13 +01:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
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(
|
2024-01-09 16:32:53 +01:00
|
|
|
elevation: 1,
|
2024-01-09 12:47:42 +01:00
|
|
|
title: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
controller: _searchController,
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
hintText: "Search",
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
if (value.isEmpty) {
|
|
|
|
_controller.reverse();
|
|
|
|
} else {
|
|
|
|
_controller.forward();
|
|
|
|
}
|
|
|
|
liveSearch.updateSearch(value);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
AnimatedBuilder(
|
|
|
|
animation: _controller,
|
|
|
|
builder: (context, child) {
|
|
|
|
if (liveSearch.searchTerm.isEmpty) return Container();
|
|
|
|
return IconButton(
|
|
|
|
icon: const Icon(Icons.clear),
|
|
|
|
onPressed: () {
|
|
|
|
_searchController.clear();
|
|
|
|
liveSearch.updateSearch("");
|
|
|
|
_controller.reverse();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2024-01-08 21:48:13 +01:00
|
|
|
),
|
|
|
|
actions: [HamburgerMenu(widget.manager)],
|
2023-11-08 14:59:23 +01:00
|
|
|
),
|
2024-01-08 21:48:13 +01:00
|
|
|
body: SwipeTransition(
|
|
|
|
animation: _controller,
|
|
|
|
first: OverviewPage(manager: widget.manager),
|
|
|
|
second: SearchResultPage(liveSearch: liveSearch),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SearchResultPage extends StatelessWidget {
|
|
|
|
const SearchResultPage({
|
|
|
|
super.key,
|
|
|
|
required this.liveSearch,
|
|
|
|
});
|
|
|
|
|
|
|
|
final LiveSearch liveSearch;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return AnimatedBuilder(
|
|
|
|
animation: liveSearch,
|
|
|
|
builder: (context, child) {
|
2024-01-09 14:48:36 +01:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
liveSearch.loading ? const LinearProgressIndicator() : Container(),
|
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: liveSearch.searchResults.length,
|
|
|
|
itemBuilder: (context, index) => MovieItem(
|
|
|
|
liveSearch.searchResults[index],
|
|
|
|
showReleaseDate: true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2024-01-08 21:48:13 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class OverviewPage extends StatelessWidget {
|
|
|
|
const OverviewPage({
|
|
|
|
super.key,
|
|
|
|
required this.manager,
|
|
|
|
});
|
|
|
|
|
|
|
|
final MovieManager manager;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return DefaultTabController(
|
|
|
|
length: 2,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2024-01-09 16:32:53 +01:00
|
|
|
const TabBar(
|
|
|
|
tabs: [
|
|
|
|
Tab(icon: Icon(Icons.list), child: Text("Upcoming")),
|
|
|
|
Tab(icon: Icon(Icons.bookmark), child: Text("Bookmarked")),
|
|
|
|
],
|
|
|
|
),
|
2024-01-08 21:48:13 +01:00
|
|
|
Expanded(
|
|
|
|
child: TabBarView(
|
|
|
|
children: [
|
|
|
|
Scaffold(
|
|
|
|
body: MovieManagerList(
|
2024-01-08 14:57:03 +01:00
|
|
|
manager,
|
2024-01-08 21:48:13 +01:00
|
|
|
// Only show movies that are bookmarked or have a release date with at least month precision and at least one title
|
|
|
|
filter: (movie) =>
|
|
|
|
movie.bookmarked ||
|
2024-01-09 14:48:36 +01:00
|
|
|
(movie.releaseDate.dateWithPrecision.precision >=
|
|
|
|
DatePrecision.month &&
|
2024-01-08 21:48:13 +01:00
|
|
|
(movie.titles?.length ?? 0) >= 1),
|
|
|
|
),
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
child: const Icon(Icons.refresh),
|
|
|
|
onPressed: () async {
|
|
|
|
var scaffold = ScaffoldMessenger.of(context);
|
|
|
|
try {
|
|
|
|
await manager.loadUpcomingMovies();
|
|
|
|
} catch (e) {
|
|
|
|
scaffold.showSnackBar(
|
|
|
|
const SnackBar(
|
|
|
|
content: Text("Failed to load upcoming movies"),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
MovieManagerList(
|
|
|
|
manager,
|
|
|
|
filter: (movie) => movie.bookmarked,
|
|
|
|
)
|
|
|
|
],
|
2024-01-08 12:57:36 +01:00
|
|
|
),
|
2024-01-08 21:48:13 +01:00
|
|
|
),
|
|
|
|
],
|
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 [
|
2024-01-08 21:48:13 +01:00
|
|
|
PopupMenuItem(
|
|
|
|
child: const Text("Remove irrelevant"),
|
|
|
|
onTap: () => manager.removeMoviesWhere((movie) =>
|
|
|
|
!movie.bookmarked &&
|
|
|
|
!(movie.releaseDates?.any((date) =>
|
2024-01-09 14:48:36 +01:00
|
|
|
date.dateWithPrecision.precision >=
|
|
|
|
DatePrecision.month &&
|
|
|
|
date.dateWithPrecision.date.isAfter(DateTime.now()
|
2024-01-08 21:48:13 +01:00
|
|
|
.subtract(const Duration(days: 30)))) ??
|
|
|
|
false)),
|
|
|
|
),
|
2024-01-08 14:30:32 +01:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|