aboutsummaryrefslogtreecommitdiff
path: root/src/distractionless/ui/apps/settings.cljd
blob: 0c06543186f7998360afb0a34d2fca68f5ace062 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(ns distractionless.ui.apps.settings
  (:require ["package:flutter/material.dart" :as m]
            ["package:installed_apps/installed_apps.dart" :as apps]
            [cljd.flutter :as f]
            [distractionless.ui.constants :as duconstants]
            [distractionless.config :as dconfig]))

(defn- header [app ctx]
  (m/Row
   .mainAxisAlignment m/MainAxisAlignment.spaceBetween
   .children [(m/Text (.-name app)
                      .style duconstants/title-style)
              (m/IconButton .icon (m/Icon m/Icons.clear_rounded)
                            .color duconstants/text-color
                            .onPressed #(m/Navigator.pop ctx)
                            .iconSize 30.0)]))

(defn- favourite-setting [app config-file reloader]
  (m/CheckboxListTile
   .title (m/Text "Favorit"
                  .style duconstants/text-style)
   .value (contains? (get (dconfig/read-from-file config-file) "favourites")
                     (.-packageName app))
   .onChanged (fn [new-val]
                (if new-val
                  (dconfig/update-config! config-file
                                          #(update % "favourites" conj (.-packageName app))
                                          reloader)
                  (dconfig/update-config! config-file
                                          (fn [config]
                                            (update config "favourites" disj (.-packageName app)))
                                          reloader)))
   .activeColor duconstants/checkbox-active-color))

(defn- arithmetic-task-setting [app config-file reloader]
  (prn (get (dconfig/read-from-file config-file) "arithmetic-tasks"))
  (m/CheckboxListTile
   .title (m/Text "Rechenaufgabe lösen zum Öffnen"
                  .style duconstants/text-style)
   .value (.contains (get (dconfig/read-from-file config-file) "arithmetic-tasks")
                     (.-packageName app))
   .onChanged (fn [new-val]
                (if new-val
                  (dconfig/update-config! config-file
                                          #(update % "arithmetic-tasks" conj (.-packageName app))
                                          reloader)
                  (dconfig/update-config! config-file
                                          (fn [config]
                                            (update config "arithmetic-tasks" disj (.-packageName app)))
                                          reloader)))
   .activeColor duconstants/checkbox-active-color))

(defn- open-in-system-settings [app]
  (m/ListTile
   .title (m/Text "In Systemeinstellungen öffnen"
                  .style duconstants/text-style)
   .onTap #(do (apps/InstalledApps.openSettings (.-packageName app)) nil)))

(defn open [app config-file ctx reloader]
  (m/showDialog
   .context ctx
   .builder (f/build :watch [_ reloader]
                     (m/Dialog.fullscreen
                      .backgroundColor duconstants/background-color
                      .child (m/Column
                              .children (list (header app ctx)
                                              (favourite-setting app config-file reloader)
                                              (arithmetic-task-setting app config-file reloader)
                                              (open-in-system-settings app)))))))