2021-08-25 00:47:01 -04:00
|
|
|
import 'package:flutter/material.dart';
|
2023-01-19 02:27:51 -05:00
|
|
|
import 'package:flutter/services.dart';
|
2021-10-01 00:10:50 -04:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
2022-08-31 14:11:45 -04:00
|
|
|
import 'package:frosty/screens/home/home_store.dart';
|
2022-01-04 02:58:02 -05:00
|
|
|
import 'package:frosty/screens/home/search/search.dart';
|
2022-08-31 14:11:45 -04:00
|
|
|
import 'package:frosty/screens/home/stream_list/stream_list_store.dart';
|
|
|
|
|
import 'package:frosty/screens/home/stream_list/streams_list.dart';
|
|
|
|
|
import 'package:frosty/screens/home/top/top.dart';
|
2022-01-04 02:58:02 -05:00
|
|
|
import 'package:frosty/screens/settings/settings.dart';
|
2022-08-31 14:11:45 -04:00
|
|
|
import 'package:frosty/screens/settings/stores/auth_store.dart';
|
2022-01-04 02:58:02 -05:00
|
|
|
import 'package:frosty/screens/settings/stores/settings_store.dart';
|
2024-08-13 00:41:06 -07:00
|
|
|
import 'package:frosty/screens/settings/widgets/release_notes.dart';
|
2023-10-22 18:38:32 -04:00
|
|
|
import 'package:frosty/widgets/profile_picture.dart';
|
2024-08-13 00:41:06 -07:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2021-10-05 03:17:38 -04:00
|
|
|
import 'package:provider/provider.dart';
|
2024-08-13 00:41:06 -07:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2021-11-14 23:18:43 -05:00
|
|
|
|
2022-01-25 22:06:01 -05:00
|
|
|
class Home extends StatefulWidget {
|
2023-10-28 18:13:23 -04:00
|
|
|
const Home({super.key});
|
2021-08-25 00:47:01 -04:00
|
|
|
|
|
|
|
|
@override
|
2022-01-25 22:06:01 -05:00
|
|
|
State<Home> createState() => _HomeState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _HomeState extends State<Home> {
|
|
|
|
|
late final _authStore = context.read<AuthStore>();
|
2021-12-28 03:14:08 -05:00
|
|
|
|
2022-01-25 22:06:01 -05:00
|
|
|
late final _homeStore = HomeStore(authStore: _authStore);
|
|
|
|
|
|
2024-08-13 00:41:06 -07:00
|
|
|
Future<void> checkAndShowReleaseNotes() async {
|
|
|
|
|
final packageInfo = await PackageInfo.fromPlatform();
|
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
|
|
final currentVersion = packageInfo.version;
|
|
|
|
|
final storedVersion = prefs.getString('last_shown_version');
|
|
|
|
|
|
|
|
|
|
if (storedVersion == null || storedVersion != currentVersion) {
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (context) => const ReleaseNotes()),
|
2024-08-13 18:36:03 -07:00
|
|
|
).then((_) => prefs.setString('last_shown_version', currentVersion));
|
2024-08-13 00:41:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
checkAndShowReleaseNotes();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 22:06:01 -05:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2023-01-19 02:27:51 -05:00
|
|
|
SystemChrome.setPreferredOrientations([]);
|
|
|
|
|
|
2023-10-22 18:38:32 -04:00
|
|
|
final isLoggedIn = _authStore.isLoggedIn && _authStore.user.details != null;
|
|
|
|
|
|
2022-01-19 15:37:20 -05:00
|
|
|
return GestureDetector(
|
2022-01-19 17:36:31 -05:00
|
|
|
onTap: FocusScope.of(context).unfocus,
|
2022-01-19 15:37:20 -05:00
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: false,
|
|
|
|
|
title: Observer(
|
|
|
|
|
builder: (_) {
|
|
|
|
|
final titles = [
|
2022-09-06 12:04:31 -04:00
|
|
|
if (_authStore.isLoggedIn) 'Following',
|
2022-01-19 15:37:20 -05:00
|
|
|
'Top',
|
|
|
|
|
'Search',
|
|
|
|
|
];
|
2022-01-16 18:21:36 -05:00
|
|
|
|
2022-03-30 19:29:51 -04:00
|
|
|
return Text(titles[_homeStore.selectedIndex]);
|
2022-01-19 15:37:20 -05:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
tooltip: 'Settings',
|
2023-10-22 18:38:32 -04:00
|
|
|
icon: isLoggedIn
|
|
|
|
|
? ProfilePicture(
|
|
|
|
|
userLogin: _authStore.user.details!.login,
|
|
|
|
|
radius: 16,
|
|
|
|
|
)
|
|
|
|
|
: const Icon(Icons.settings_rounded),
|
2022-01-19 15:37:20 -05:00
|
|
|
onPressed: () => Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
2023-04-29 11:34:28 -04:00
|
|
|
builder: (context) =>
|
|
|
|
|
Settings(settingsStore: context.read<SettingsStore>()),
|
2022-01-19 15:37:20 -05:00
|
|
|
),
|
2022-01-03 05:51:43 -05:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
),
|
2022-01-19 15:37:20 -05:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: SafeArea(
|
2023-01-18 05:34:54 -05:00
|
|
|
child: Observer(
|
|
|
|
|
builder: (_) => IndexedStack(
|
|
|
|
|
index: _homeStore.selectedIndex,
|
|
|
|
|
children: [
|
|
|
|
|
if (_authStore.isLoggedIn)
|
|
|
|
|
StreamsList(
|
|
|
|
|
listType: ListType.followed,
|
|
|
|
|
scrollController: _homeStore.followedScrollController,
|
2022-06-29 01:06:33 -04:00
|
|
|
),
|
2023-01-18 05:34:54 -05:00
|
|
|
TopSection(
|
|
|
|
|
homeStore: _homeStore,
|
2022-06-29 01:06:33 -04:00
|
|
|
),
|
2023-01-18 05:34:54 -05:00
|
|
|
Search(
|
|
|
|
|
scrollController: _homeStore.searchScrollController,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2022-01-16 18:21:36 -05:00
|
|
|
),
|
2021-12-30 04:12:49 -05:00
|
|
|
),
|
2022-01-19 15:37:20 -05:00
|
|
|
bottomNavigationBar: Observer(
|
2023-10-22 18:38:32 -04:00
|
|
|
builder: (_) => NavigationBar(
|
|
|
|
|
destinations: [
|
2022-01-25 22:06:01 -05:00
|
|
|
if (_authStore.isLoggedIn)
|
2023-10-22 18:38:32 -04:00
|
|
|
NavigationDestination(
|
2023-01-18 05:34:54 -05:00
|
|
|
icon: _homeStore.selectedIndex == 0
|
|
|
|
|
? const Icon(Icons.favorite_rounded)
|
|
|
|
|
: const Icon(Icons.favorite_border_rounded),
|
2022-09-06 12:04:31 -04:00
|
|
|
label: 'Following',
|
2022-07-02 00:50:58 -04:00
|
|
|
tooltip: 'Followed streams',
|
2022-01-19 15:37:20 -05:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
const NavigationDestination(
|
2023-01-18 05:34:54 -05:00
|
|
|
icon: Icon(Icons.arrow_upward_rounded),
|
2022-01-19 15:37:20 -05:00
|
|
|
label: 'Top',
|
2022-07-02 00:50:58 -04:00
|
|
|
tooltip: 'Top streams and categories',
|
2021-11-14 21:12:57 -05:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
const NavigationDestination(
|
2023-01-18 05:34:54 -05:00
|
|
|
icon: Icon(Icons.search_rounded),
|
2022-01-19 15:37:20 -05:00
|
|
|
label: 'Search',
|
2022-07-02 00:50:58 -04:00
|
|
|
tooltip: 'Search for channels and categories',
|
2022-01-19 15:37:20 -05:00
|
|
|
),
|
|
|
|
|
],
|
2023-10-22 18:38:32 -04:00
|
|
|
selectedIndex: _homeStore.selectedIndex,
|
|
|
|
|
onDestinationSelected: _homeStore.handleTap,
|
2022-01-19 15:37:20 -05:00
|
|
|
),
|
2022-01-16 18:21:36 -05:00
|
|
|
),
|
2021-10-12 02:34:30 -04:00
|
|
|
),
|
2021-08-25 00:47:01 -04:00
|
|
|
);
|
|
|
|
|
}
|
2022-01-25 22:06:01 -05:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_homeStore.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
2021-08-25 00:47:01 -04:00
|
|
|
}
|