blob: 2036da63a782caf75802e00487245eb1a60ba1e8 (
plain)
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
|
(ns distractionless.core
(:require ["package:flutter/material.dart" :as m]
[cljd.flutter :as f]
["package:path_provider/path_provider.dart" :as path-provider]
[distractionless.config :as dconfig]
["dart:io" :as io]
[distractionless.ui.constants :as duconstants]
[distractionless.ui.apps :as duapps]))
(defn ^dynamic main []
(f/run
(m/MaterialApp
.theme (m/ThemeData .primarySwatch m.Colors/pink))
.home
(m/Scaffold .backgroundColor duconstants/background-color)
.body
:context ctx
:watch [apps (atom '()) :as *apps
query (atom "") :as *query
data-dir (await (path-provider/getApplicationDocumentsDirectory))
_ (atom 0) :as reloader]
:managed [_ (duapps/load-installed-apps! *apps) ; loads apps on app startup
config-file (io/File. (str (.-path data-dir) "/config.edn"))
_ (dconfig/init-config! config-file nil) ; Init config on app startup
_ (m/AppLifecycleListener .onShow #(do (dconfig/init-config! config-file nil)
(duapps/load-installed-apps! *apps)))
page-controller (m/PageController.)]
:let [root-container-padding (m/EdgeInsets.only
.top 50)]
(m/PageView.
.controller page-controller
.children [(let [favourites (get (dconfig/read-from-file config-file) "favourites")]
(m/Container
.padding root-container-padding
.child (m/Column
.children [(m/Expanded
.child (duapps/apps-list (filter #(.contains favourites (.-packageName %)) apps) nil config-file ctx reloader))
(m/Text "Wische nach links, um alle Apps anzuzeigen"
.style duconstants/text-style)])))
(m/Container
.padding root-container-padding
.child (m/Column
.children [(m/Text "Alle Apps"
.style duconstants/title-style)
(m/SearchBar
.onChanged (fn [new-val]
(reset! *query new-val)
nil)
.hintText "Suche"
.backgroundColor (#/(.resolveWith m/Color?) m/MaterialStateProperty (fn [^Set _states] duconstants/search-bar-color)))
(m/Expanded
.child (duapps/apps-list apps query config-file ctx reloader))]))])))
|