aboutsummaryrefslogtreecommitdiff
path: root/src/distractionless/ui/apps/settings.cljd
blob: c6d1c67d3ac564671ac60d0fb2a0daea2c10fff6 (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
(ns distractionless.ui.apps.settings
  (:require ["package:flutter/material.dart" :as m]
            [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 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)))))))