1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:device_apps/device_apps.dart';
import 'package:android_intent/android_intent.dart';
import 'package:flutter/services.dart';
import 'pages/Home.dart';
import 'pages/Apps.dart';
import 'components/AppContextMenu.dart';
import 'data/config.dart';
import 'data/favorites.dart';
import 'data/applications.dart';
import 'helpers/StreamState.dart';
void main() {
runApp(MyApp());
}
class MyAppState extends StreamState<MyApp> {
// State
final config = StreamStateValue<Config>(
stream$: getConfig$(),
value: Config(),
);
final favoriteApps = StreamStateValue<List<Application>>(
stream$: getFavorites$(),
value: [],
);
final applications = StreamStateValue<List<Application>>(
stream$: getApplications$(),
value: [],
);
final dateTime = StreamStateValue<DateTime>(
stream$: Stream.periodic(Duration(seconds: 1), (_x) => DateTime.now()).asBroadcastStream(),
value: DateTime.now(),
);
FocusNode searchFieldFocus = FocusNode();
void initState() {
super.initState();
initStateValue(config);
refreshConfig();
initStateValue(favoriteApps);
refreshFavorites();
initStateValue(applications);
refreshApplications();
initStateValue(dateTime);
}
void dispose() {
searchFieldFocus.dispose();
super.dispose();
}
void openApp(Application app) {
DeviceApps.openApp(app.packageName);
}
void openOptionsMenu(BuildContext ctx, Application app) {
var isFavorite = -1 != favoriteApps.value.indexWhere((a) => a.packageName == app.packageName);
showDialog(context: ctx, builder: (BuildContext ctx) => AppContextMenu(app: app, isFavorite: isFavorite));
}
ThemeData getLightTheme() {
return ThemeData(brightness: Brightness.light);
}
ThemeData getDarkTheme() {
Color fg = Color(0xFFD8DEE9);
return ThemeData(
backgroundColor: Color(0xFF1F2225),
scaffoldBackgroundColor: Color(0xFF0F1215),
accentColor: fg,
primaryColor: Color(0xFF5E81AC),
textTheme: TextTheme(
headline1: TextStyle(color: fg),
headline2: TextStyle(color: fg),
headline3: TextStyle(color: fg),
headline4: TextStyle(color: fg),
headline5: TextStyle(color: fg),
headline6: TextStyle(color: fg),
subtitle1: TextStyle(color: fg),
subtitle2: TextStyle(color: fg),
bodyText1: TextStyle(color: fg),
bodyText2: TextStyle(color: fg),
button: TextStyle(color: fg),
caption: TextStyle(color: fg),
overline: TextStyle(color: fg),
),
);
}
// This widget is the root of your application.
@override
Widget build(BuildContext ctx) {
return MaterialApp(
title: 'owyn launcher',
theme: getLightTheme(),
darkTheme: getDarkTheme(),
themeMode: config.value.isDarkMode() ? ThemeMode.dark : ThemeMode.light,
home: Scaffold(
body: WillPopScope(
onWillPop: () => Future.value(false),
child: PageView(
controller: PageController(keepPage: true),
onPageChanged: (x) {
if (x == 1) {
searchFieldFocus.requestFocus();
} else {
searchFieldFocus.unfocus();
//SystemChannels.textInput.invokeMethod('TextInput.hide');
}
},
children: [
HomeView(
dateTime: dateTime.value,
favoriteApps: favoriteApps.value,
openApp: openApp,
openOptionsMenu: openOptionsMenu,
),
AppsView(
appList: applications.value,
openApp: openApp,
openOptionsMenu: openOptionsMenu,
searchFieldFocus: searchFieldFocus,
),
],
),
),
),
);
}
}
class MyApp extends StatefulWidget {
MyAppState createState() => MyAppState();
}
|