diff options
Diffstat (limited to 'lib/main.dart')
| -rw-r--r-- | lib/main.dart | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/lib/main.dart b/lib/main.dart index 54a02bf..25ea6ee 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,8 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:device_apps/device_apps.dart'; +import 'package:android_intent/android_intent.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'pages/Home.dart'; import 'pages/Apps.dart'; @@ -8,7 +10,6 @@ import 'pages/Apps.dart'; import 'data/config.dart'; import 'data/favorites.dart'; import 'helpers/StreamState.dart'; -import 'package:shared_preferences/shared_preferences.dart'; void main() { runApp(MyApp()); @@ -37,6 +38,49 @@ class MyAppState extends StreamState<MyApp> { initStateValue(dateTime); } + Widget buildOptionsMenu(BuildContext ctx, Application app) { + ThemeData theme = Theme.of(ctx); + + var isFavorite = -1 != favoriteApps.value.indexWhere((a) => a.packageName == app.packageName); + + return Dialog( + child: Container( + decoration: BoxDecoration( + color: theme.backgroundColor, + ), + height: 170.0, + child: ListView( + children: [ + Option(child: Text(isFavorite ? 'Remove from favorites' : 'Add to favorites'), onTap: () async { + await isFavorite ? removeFromFavorites(app) : addToFavorites(app); + }), + Option(child: Text('App Settings'), onTap: () async { + await AndroidIntent( + action: 'action_application_details_settings', + data: 'package:${app.packageName}', + ).launch(); + }), + Option(child: Text('Uninstall'), onTap: () async { + // FIXME: Doesn't work + await AndroidIntent( + action: 'action_delete', + data: 'package:${app.packageName}', + ).launch(); + }), + ], + ), + ), + ); + } + + void openApp(Application app) { + DeviceApps.openApp(app.packageName); + } + + void openOptionsMenu(BuildContext ctx, Application app) { + showDialog(context: ctx, builder: (BuildContext ctx) => buildOptionsMenu(ctx, app)); + } + ThemeData getLightTheme() { return ThemeData(brightness: Brightness.light); } @@ -68,7 +112,7 @@ class MyAppState extends StreamState<MyApp> { // This widget is the root of your application. @override - Widget build(BuildContext context) { + Widget build(BuildContext ctx) { return MaterialApp( title: 'owyn launcher', theme: getLightTheme(), @@ -81,8 +125,13 @@ class MyAppState extends StreamState<MyApp> { HomeView( dateTime: dateTime.value, favoriteApps: favoriteApps.value, + openApp: openApp, + openOptionsMenu: openOptionsMenu, + ), + AppsView( + openApp: openApp, + openOptionsMenu: openOptionsMenu, ), - AppsView(), ], ), ), |
