(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 countdown-setting-value [app config-file] (get-in (dconfig/read-from-file config-file) ["countdowns" (.-packageName app)] 0)) (defn- countdown-setting [app config-file reloader] (m/Row .children [(m/Text "Countdown, bevor App öffnet (in Sekunden): " .style duconstants/text-style) (m/Expanded .child (m/TextFormField .keyboardType m/TextInputType.number .initialValue (str (countdown-setting-value app config-file)) .onChanged (fn [new-val] (dconfig/update-config! config-file #(update % "countdowns" conj [(.-packageName app) (or (int/tryParse new-val) 0)]) reloader))))])) (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) (countdown-setting app config-file reloader) (open-in-system-settings app)))))))