aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2020-06-03 22:21:34 +0530
committerAkshay Nair <phenax5@gmail.com>2020-06-03 22:21:34 +0530
commit620f9ea0516d951e1d21793a5bb22e05a5c56949 (patch)
treeb9178704ffa1c60ce350b7ea0096220e1ad407d7
parent008f625c89e0bb930dbb4b92c502e3a273b27807 (diff)
downloaddaft-launcher-620f9ea0516d951e1d21793a5bb22e05a5c56949.tar.gz
daft-launcher-620f9ea0516d951e1d21793a5bb22e05a5c56949.zip
Adds a simple add to favorites action storing to shard prefs
-rw-r--r--.flutter-plugins-dependencies2
-rw-r--r--lib/data/favorites.dart43
-rw-r--r--lib/main.dart2
-rw-r--r--lib/pages/Apps.dart15
4 files changed, 54 insertions, 8 deletions
diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies
index c793bfa..a556131 100644
--- a/.flutter-plugins-dependencies
+++ b/.flutter-plugins-dependencies
@@ -1 +1 @@
-{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.4.3/","dependencies":[]}],"android":[{"name":"android_intent","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.7+2/","dependencies":[]},{"name":"device_apps","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/device_apps-1.0.9/","dependencies":[]},{"name":"shared_preferences","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.4.3/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"android_intent","dependencies":[]},{"name":"device_apps","dependencies":[]},{"name":"shared_preferences","dependencies":[]}],"date_created":"2020-06-03 19:31:00.053777","version":"1.19.0-2.0.pre.214"} \ No newline at end of file
+{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.4.3/","dependencies":[]}],"android":[{"name":"android_intent","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.7+2/","dependencies":[]},{"name":"device_apps","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/device_apps-1.0.9/","dependencies":[]},{"name":"shared_preferences","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.4.3/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"android_intent","dependencies":[]},{"name":"device_apps","dependencies":[]},{"name":"shared_preferences","dependencies":[]}],"date_created":"2020-06-03 21:55:48.530304","version":"1.19.0-2.0.pre.214"} \ No newline at end of file
diff --git a/lib/data/favorites.dart b/lib/data/favorites.dart
new file mode 100644
index 0000000..aad98ee
--- /dev/null
+++ b/lib/data/favorites.dart
@@ -0,0 +1,43 @@
+import 'package:shared_preferences/shared_preferences.dart';
+import 'package:device_apps/device_apps.dart';
+import 'dart:async';
+
+const String FAVORITES = 'favorites';
+const String SEPERATOR = ',';
+
+StreamController<List<Application>> favorites_$ = StreamController<List<Application>>.broadcast();
+
+Future<List<Application>> getFavorites() async {
+ final prefs = await SharedPreferences.getInstance();
+
+ String rawFavoritesList = prefs.getString(FAVORITES);
+ List<String> packageNames = rawFavoritesList?.split(SEPERATOR) ?? <String>[];
+
+ return Future.wait(packageNames.map((String pkg) => DeviceApps.getApp(pkg)));
+}
+
+void initFavorites() async {
+ List<Application> fs = await getFavorites();
+ favorites_$.add(fs);
+}
+
+Stream<List<Application>> getFavorites$() {
+ return favorites_$.stream;
+}
+
+void setFavorites(List<Application> favs) async {
+ final prefs = await SharedPreferences.getInstance();
+
+ String rawFavoritesList = favs.map((Application app) => app.packageName).join(SEPERATOR);
+
+ prefs.setString(FAVORITES, rawFavoritesList);
+
+ favorites_$.add(await getFavorites());
+}
+
+void addToFavorites(Application app) async {
+ List<Application> fs = await getFavorites();
+ fs.add(app);
+ await setFavorites(fs);
+}
+
diff --git a/lib/main.dart b/lib/main.dart
index d98a1b1..a7800da 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -36,7 +36,7 @@ class MyAppState extends StreamState<MyApp> {
ThemeData getDarkTheme() {
Color fg = Color(0xFFD8DEE9);
return ThemeData(
- backgroundColor: Color(0xFF0F1215),
+ backgroundColor: Color(0xFF1F2225),
scaffoldBackgroundColor: Color(0xFF0F1215),
accentColor: fg,
primaryColor: Color(0xFF5E81AC),
diff --git a/lib/pages/Apps.dart b/lib/pages/Apps.dart
index 3b0845f..7049799 100644
--- a/lib/pages/Apps.dart
+++ b/lib/pages/Apps.dart
@@ -5,6 +5,8 @@ import 'package:android_intent/android_intent.dart';
import '../components/FixedContainer.dart';
import '../components/SearchableAppList.dart';
+import '../data/favorites.dart';
+
class Option extends StatelessWidget {
void Function() onTap;
Widget child;
@@ -44,18 +46,19 @@ class AppsView extends StatelessWidget {
}
Widget buildOptionsMenu(BuildContext ctx, Application app) {
+ ThemeData theme = Theme.of(ctx);
+
return Dialog(
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12.0),
- ),
child: Container(
decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(20.0),
+ color: theme.backgroundColor,
),
- height: 300.0,
- width: 300.0,
+ height: 170.0,
child: ListView(
children: [
+ Option(child: Text('Add to favorites'), onTap: () async {
+ await addToFavorites(app);
+ }),
Option(child: Text('App Settings'), onTap: () async {
await AndroidIntent(
action: 'action_application_details_settings',