Skip to content

Commit

Permalink
Add Apps Page
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 committed Jan 16, 2024
1 parent 4e55b2d commit f410fce
Show file tree
Hide file tree
Showing 13 changed files with 451 additions and 113 deletions.
133 changes: 133 additions & 0 deletions lib/app/(public)/apps_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import 'package:asp/asp.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:yuno/app/core/services/game_service.dart';
import 'package:yuno/app/interactor/actions/apps_action.dart';

import '../../injector.dart';
import '../interactor/atoms/app_atom.dart';
import '../interactor/atoms/config_atom.dart';

class AppsPage extends StatefulWidget {
const AppsPage({super.key});

@override
State<AppsPage> createState() => _AppsPageState();
}

class _AppsPageState extends State<AppsPage> with WidgetsBindingObserver {
late RxDisposer _disposer;

@override
void initState() {
super.initState();

final gamepadService = injector.get<GameService>();
_disposer = rxObserver(() => gamepadService.state, effect: (state) {
if (gameConfigState.value.swapABXY && state == GamepadButton.buttonA) {
Navigator.of(context).pop();
} else if (state == GamepadButton.buttonB) {
Navigator.of(context).pop();
}
});

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
fetchApps();
});

WidgetsBinding.instance.addObserver(this);
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
fetchApps();
}
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_disposer();
super.dispose();
}

@override
Widget build(BuildContext context) {
final size = MediaQuery.sizeOf(context);
const itemWidth = 100.0;
const padding = 17.0;
var crossAxisCount = ((size.width - (padding * 2)) / itemWidth).floor();
if (crossAxisCount < 2) {
crossAxisCount = 2;
}

return RxBuilder(
builder: (_) {
final apps = appsState.value;

return Scaffold(
appBar: AppBar(
title: const Text('Apps'),
actions: const [
IconButton(
icon: Icon(Icons.settings),
onPressed: openConfiguration,
),
],
),
body: GridView.builder(
addAutomaticKeepAlives: true,
padding: const EdgeInsets.only(
bottom: 12,
left: padding,
right: padding,
),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
childAspectRatio: 1 / 1,
),
itemCount: apps.length,
itemBuilder: (context, index) {
final app = apps.elementAt(index);

return Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: InkWell(
onTap: () {
openApp(app);
},
onLongPress: () {
openAppSettings(app);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
const Gap(5),
SizedBox(
width: 48,
height: 48,
child: Image.memory(
app.icon,
),
),
const Gap(8),
Text(
app.name,
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
);
},
),
);
},
);
}
}
184 changes: 91 additions & 93 deletions lib/app/(public)/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:yuno/routes.dart';

import '../core/assets/sounds.dart' as sounds;
import '../core/widgets/animated_menu_leading.dart';
import '../core/widgets/animated_search.dart';
import '../core/widgets/animated_title_app_bart.dart';
import '../core/widgets/background/background.dart';
import '../core/widgets/card_tile/card_tile.dart';
Expand All @@ -38,6 +39,7 @@ Route routeBuilder(BuildContext context, RouteSettings settings) {

class HomePage extends StatefulWidget {
final Animation<double> transitionAnimation;

const HomePage({super.key, required this.transitionAnimation});

@override
Expand All @@ -51,7 +53,8 @@ class _HomePageState extends State<HomePage> {
var title = 'Home';
final scrollController = AutoScrollController();
final menuScrollController = AutoScrollController();
List<Game> get games => gamesByCategoryState;

List<Game> get games => filteredGamesState;
DateTime? _lastOpenGameAt;
var hasRailsExtanded = false;
Timer? _timer;
Expand Down Expand Up @@ -150,8 +153,9 @@ class _HomePageState extends State<HomePage> {
Routefly.push(routePaths.config);
}

void openApps() {
void openApps() async {
resetConfig();
Routefly.push(routePaths.apps);
}

void switchRail() {
Expand Down Expand Up @@ -275,106 +279,100 @@ class _HomePageState extends State<HomePage> {
type: config.backgroundType,
color: colorScheme.primaryContainer,
),
FocusScope(
canRequestFocus: false,
child: Scaffold(
Scaffold(
backgroundColor: Colors.transparent,
appBar: AnimatedTitleAppBar(
surfaceTintColor: colorScheme.surfaceTint,
backgroundColor: Colors.transparent,
appBar: AnimatedTitleAppBar(
surfaceTintColor: colorScheme.surfaceTint,
backgroundColor: Colors.transparent,
leading: IconButton(
icon: AnimatedMenuLeading(
isCloseMenu: hasRailsExtanded,
icon: AnimatedIcons.menu_close,
),
onPressed: switchRail,
leading: IconButton(
icon: AnimatedMenuLeading(
isCloseMenu: hasRailsExtanded,
icon: AnimatedIcons.menu_close,
),
title: title,
actions: [
IconButton(
icon: const Icon(Icons.search),
onPressed: () {
// Routefly.push(routePaths.search);
},
),
],
onPressed: switchRail,
),
body: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SingleChildScrollView(
controller: menuScrollController,
child: IntrinsicHeight(
child: NavigationRail(
backgroundColor: Colors.transparent,
indicatorColor: colorScheme.surfaceVariant,
extended: hasRailsExtanded,
onDestinationSelected: (value) {
handlerDestinationSelect(value);
},
destinations: [
for (var i = 0;
i < availableCategoriesState.length;
i++)
NavigationRailDestination(
icon: AutoScrollTag(
controller: menuScrollController,
index: i,
key: ValueKey(i),
child: SvgPicture.asset(
availableCategoriesState[i].image,
width: 28,
),
title: title,
actions: [
AnimatedSearch(onChanged: (value) {
gameSearchState.value = value;
}),
],
),
body: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SingleChildScrollView(
controller: menuScrollController,
child: IntrinsicHeight(
child: NavigationRail(
backgroundColor: Colors.transparent,
indicatorColor: colorScheme.surfaceVariant,
extended: hasRailsExtanded,
onDestinationSelected: (value) {
handlerDestinationSelect(value);
},
destinations: [
for (var i = 0;
i < availableCategoriesState.length;
i++)
NavigationRailDestination(
icon: AutoScrollTag(
controller: menuScrollController,
index: i,
key: ValueKey(i),
child: SvgPicture.asset(
availableCategoriesState[i].image,
width: 28,
),
label: Text(availableCategoriesState[i].name),
),
],
selectedIndex: selectedDestinationIndex,
),
label: Text(availableCategoriesState[i].name),
),
],
selectedIndex: selectedDestinationIndex,
),
),
Expanded(
child: GridView.builder(
controller: scrollController,
addAutomaticKeepAlives: true,
padding: const EdgeInsets.only(bottom: 120),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
childAspectRatio: 3 / 5,
),
itemCount: games.length,
itemBuilder: (context, index) {
return AutoScrollTag(
index: index,
key: ValueKey(index),
controller: scrollController,
child: CardTile(
game: games[index],
colorSelect: colorScheme.primary,
transitionAnimation: widget.transitionAnimation,
selected: selectedItemIndex == index,
onTap: () {
if (index == selectedItemIndex) {
openGame();
} else {
handlerSelect(index);
}
},
index: index,
gamesLength: games.length,
),
);
},
),
Expanded(
child: GridView.builder(
controller: scrollController,
addAutomaticKeepAlives: true,
padding: const EdgeInsets.only(bottom: 120),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
childAspectRatio: 3 / 5,
),
itemCount: games.length,
itemBuilder: (context, index) {
return AutoScrollTag(
index: index,
key: ValueKey(index),
controller: scrollController,
child: CardTile(
game: games[index],
colorSelect: colorScheme.primary,
transitionAnimation: widget.transitionAnimation,
selected: selectedItemIndex == index,
onTap: () {
if (index == selectedItemIndex) {
openGame();
} else {
handlerSelect(index);
}
},
index: index,
gamesLength: games.length,
),
);
},
),
],
),
bottomNavigationBar: NavigationCommand(
colorScheme: colorScheme,
onApps: openApps,
onSettings: openSettings,
onPlay: openGame,
),
),
],
),
bottomNavigationBar: NavigationCommand(
colorScheme: colorScheme,
onApps: openApps,
onSettings: openSettings,
onPlay: openGame,
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'package:yuno/routes.dart';

import '../core/assets/sounds.dart' as sounds;
import '../core/assets/static.dart' as img;
import '../interactor/actions/game_action.dart';
import '../interactor/actions/apps_action.dart' as apps;
import '../interactor/actions/game_action.dart' as game;

class AppPage extends StatefulWidget {
const AppPage({super.key});
Expand All @@ -21,7 +22,8 @@ class _AppPageState extends State<AppPage> {
void didChangeDependencies() {
super.didChangeDependencies();
Future.wait([
firstInitialization(context),
apps.fetchApps(),
game.firstInitialization(context),
img.precacheCache(context),
sounds.precacheCache(),
Future.delayed(const Duration(seconds: 2)),
Expand Down
Loading

0 comments on commit f410fce

Please sign in to comment.