Skip to content

Commit

Permalink
feat(gebura): update library detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Nov 30, 2024
1 parent f1b1ccc commit 72ce074
Show file tree
Hide file tree
Showing 23 changed files with 1,212 additions and 304 deletions.
60 changes: 55 additions & 5 deletions lib/bloc/gebura/gebura_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
final appInsts = await _repo.loadLocalAppInsts();
final appInstsMap =
Map.fromEntries(appInsts.map((e) => MapEntry(e.uuid, e)));
appInstsMap.addAll(state.libraryAppInsts);
emit(GeburaLoadAppInstsState(
state.copyWith(
libraryAppInsts: appInstsMap,
Expand All @@ -210,7 +209,6 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
final launchers = await _repo.loadLocalAppInstLaunchers();
final launchersMap =
Map.fromEntries(launchers.map((e) => MapEntry(e.uuid, e)));
launchersMap.addAll(state.libraryAppInstLaunchers);
emit(GeburaLoadAppInstLaunchersState(
state.copyWith(
libraryAppInstLaunchers: launchersMap,
Expand Down Expand Up @@ -960,18 +958,70 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
// return resp.getData();
// }
//
Future<String?> updateLocalApp(LocalApp app) async {
try {
await _repo.updateLocalApp(app);
add(GeburaRefreshLibraryListEvent());
return null;
} catch (e) {
return e.toString();
}
}

Future<String?> addLocalAppInst(LocalAppInst appInst) async {
try {
await _repo.addLocalAppInst(appInst);
add(GeburaLoadAppInstsEvent());
return null;
} catch (e) {
return e.toString();
}
}

Future<String?> updateLocalAppInst(LocalAppInst appInst) async {
try {
await _repo.updateLocalAppInst(appInst);
add(GeburaLoadAppInstsEvent());
return null;
} catch (e) {
return e.toString();
}
}

Future<String?> addLocalAppInstLauncher(
LocalAppInstLauncher appInstLauncher) async {
try {
await _repo.addLocalAppInstLauncher(appInstLauncher);
add(GeburaLoadAppInstLaunchersEvent());
return null;
} catch (e) {
return e.toString();
}
}

Future<String?> updateLocalAppInstLauncher(
LocalAppInstLauncher appInstLauncher) async {
try {
await _repo.updateLocalAppInstLauncher(appInstLauncher);
add(GeburaLoadAppInstLaunchersEvent());
return null;
} catch (e) {
return e.toString();
}
}

Future<void> showSteamAppDetails(String steamAppID) async {
await launchUrlString('steam://nav/games/details/$steamAppID');
}

Future<bool> saveLocalCommonAppLibraryFolder(CommonAppScan setting) async {
Future<String?> saveLocalCommonAppLibraryFolder(CommonAppScan setting) async {
try {
await _repo.addLocalCommonLibraryFolder(_toDaoCommonAppScan(setting));
add(GeburaScanLocalLibraryEvent(refreshCommon: [setting.uuid]));
} catch (e) {
return false;
return e.toString();
}
return true;
return null;
}

Future<CommonAppScan?> getLocalCommonAppLibraryFolder(String uuid) async {
Expand Down
4 changes: 4 additions & 0 deletions lib/repo/gebura/gebura_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class GeburaRepo {
return _dao.addLocalAppInst(inst);
}

Future<void> updateLocalAppInst(LocalAppInst inst) async {
await _dao.updateLocalAppInst(inst);
}

Future<List<LocalAppInst>> loadLocalAppInsts({String? appUUID}) async {
return _dao.loadLocalAppInsts(appUUID: appUUID);
}
Expand Down
52 changes: 38 additions & 14 deletions lib/route.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:dao/dao.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -429,8 +430,7 @@ class GeburaLibraryRoute extends GoRouteData {
}

enum GeburaLibrarySettingsActions {
commonAppScanResult,
steamAppScanResult,
appScanResult,
}

class GeburaLibrarySettingsRoute extends GoRouteData {
Expand All @@ -442,51 +442,75 @@ class GeburaLibrarySettingsRoute extends GoRouteData {
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
final actions = {
GeburaLibrarySettingsActions.commonAppScanResult:
GeburaAppScanResultPanel(
GeburaLibrarySettingsActions.appScanResult: GeburaAppScanResultPanel(
uuid: $extra is String ? $extra! as String : '',
),
// GeburaLibrarySettingsActions.steamAppScanResult:
// GeburaSteamAppScanResultPanel(
// folder: $extra is String ? $extra! as String : '',
// ),
};
return NoTransitionPage(
child: GeburaRoute.rootWidget(
child: ModuleFramePage(
leftPart: const GeburaNav(
function: GeburaFunctions.librarySettings,
),
middlePart: const GeburaLibrarySettings(),
middlePart: const GeburaLibrarySettingsPage(),
rightPart: actions[action] ?? Container(),
),
),
);
}
}

enum GeburaLibraryDetailActions { assignApp }
enum GeburaLibraryDetailActions {
assignApp,
appEdit,
appInstAdd,
appInstEdit,
appInstLauncherAdd,
appInstLauncherEdit,
}

class GeburaLibraryDetailRoute extends GoRouteData {
const GeburaLibraryDetailRoute(this.uuid, {this.action});
const GeburaLibraryDetailRoute(this.uuid, {this.action, this.$extra});

final GeburaLibraryDetailActions? action;
final String uuid;
final dynamic $extra;

@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
final actions = {
GeburaLibraryDetailActions.assignApp: const GeburaAssignAppPanel(),
GeburaLibraryDetailActions.appEdit: GeburaLibraryDetailAppPanel(
uuid: uuid,
),
GeburaLibraryDetailActions.appInstAdd: GeburaLibraryDetailAppInstAddPanel(
uuid: uuid,
),
GeburaLibraryDetailActions.appInstEdit:
GeburaLibraryDetailAppInstEditPanel(
initialValue: $extra is LocalAppInst ? $extra! as LocalAppInst : null,
),
GeburaLibraryDetailActions.appInstLauncherAdd:
GeburaLibraryDetailAppInstLauncherAddPanel(
uuid: uuid,
inst: $extra is LocalAppInst ? $extra! as LocalAppInst : null,
),
GeburaLibraryDetailActions.appInstLauncherEdit:
GeburaLibraryDetailAppInstLauncherEditPanel(
launcher: $extra is LocalAppInstLauncher
? $extra! as LocalAppInstLauncher
: null,
),
};
return NoTransitionPage(
child: GeburaRoute.rootWidget(
child: ModuleFramePage(
leftPart: GeburaNav(
function: GeburaFunctions.library,
selectedItem: uuid ?? '',
selectedItem: uuid,
),
middlePart: GeburaLibraryDetailPage(uuid: uuid ?? ''),
rightPart: actions[action],
middlePart: GeburaLibraryDetailPage(uuid: uuid),
rightPart: actions[action] ?? Container(),
),
),
);
Expand Down
19 changes: 13 additions & 6 deletions lib/route.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions lib/view/layout/bootstrap_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ class BootstrapContainer extends StatelessWidget {
required this.children,
this.alignment = Alignment.center,
this.fill = BootstrapSteps.undefined,
this.useWrap = false,
});

final List<Widget> children;
final AlignmentGeometry alignment;
final BootstrapSteps fill;
final bool useWrap;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -74,10 +76,14 @@ class BootstrapContainer extends StatelessWidget {
maxWidth: maxWidth,
),
width: maxWidth,
child: Row(
mainAxisSize: MainAxisSize.min,
children: children,
),
child: useWrap
? Wrap(
children: children,
)
: Row(
mainAxisSize: MainAxisSize.min,
children: children,
),
),
),
);
Expand Down
12 changes: 6 additions & 6 deletions lib/view/pages/gebura/gebura_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class GeburaAppCoverImage extends StatelessWidget {
Widget build(BuildContext context) {
return BlocBuilder<GeburaBloc, GeburaState>(
builder: (context, state) {
if (path != null) {
if (path != null && path!.isNotEmpty) {
return ExtendedImage.file(
io.File(path!),
);
} else if (url != null) {
} else if (url != null && url!.isNotEmpty) {
return ExtendedImage.network(
url!,
height: 200,
Expand Down Expand Up @@ -58,12 +58,12 @@ class GeburaAppIconImage extends StatelessWidget {
final String? path;

DecorationImage? _buildImage(BuildContext context) {
if (path != null) {
if (path != null && path!.isNotEmpty) {
return DecorationImage(
image: ExtendedFileImageProvider(io.File(path!)),
fit: BoxFit.scaleDown,
);
} else if (url != null) {
} else if (url != null && url!.isNotEmpty) {
return DecorationImage(
image: ExtendedNetworkImageProvider(url!),
fit: BoxFit.scaleDown,
Expand Down Expand Up @@ -101,12 +101,12 @@ class GeburaAppBackgroundImage extends StatelessWidget {
final String? path;

DecorationImage? _buildImage(BuildContext context) {
if (path != null) {
if (path != null && path!.isNotEmpty) {
return DecorationImage(
image: ExtendedFileImageProvider(io.File(path!)),
fit: BoxFit.cover,
);
} else if (url != null) {
} else if (url != null && url!.isNotEmpty) {
return DecorationImage(
image: ExtendedNetworkImageProvider(url!),
fit: BoxFit.cover,
Expand Down
Loading

0 comments on commit 72ce074

Please sign in to comment.