aboutsummaryrefslogtreecommitdiff
path: root/src/distractionless/ui
diff options
context:
space:
mode:
authorTim <contact@bytim.eu>2025-06-06 19:01:26 +0200
committerTim <contact@bytim.eu>2025-06-06 19:01:26 +0200
commitef29e1cde2265dfd26a276e6e75b5733981fefa7 (patch)
tree0596518302383c1178f98d2f9d0fb92af273dbe1 /src/distractionless/ui
parentaca895de6901c01a7eeacaacc1d7f226d7c5e84e (diff)
downloaddistractionless-ef29e1cde2265dfd26a276e6e75b5733981fefa7.tar.xz
distractionless-ef29e1cde2265dfd26a276e6e75b5733981fefa7.zip
Replace countdown before starting specific apps with arithemtic tasksHEADmaster
Diffstat (limited to 'src/distractionless/ui')
-rw-r--r--src/distractionless/ui/apps.cljd43
-rw-r--r--src/distractionless/ui/apps/settings.cljd36
2 files changed, 49 insertions, 30 deletions
diff --git a/src/distractionless/ui/apps.cljd b/src/distractionless/ui/apps.cljd
index 8e06f07..6ca05dd 100644
--- a/src/distractionless/ui/apps.cljd
+++ b/src/distractionless/ui/apps.cljd
@@ -1,35 +1,54 @@
(ns distractionless.ui.apps
- (:require ["package:flutter/material.dart" :as m]
+ (:require [cljd.flutter :as f]
+ ["package:flutter/material.dart" :as m]
["package:flutter/widgets.dart" :as widgets]
["package:installed_apps/installed_apps.dart" :as apps]
+ [distractionless.config :as dconfig]
+ [distractionless.arithmetic-tasks :as darithmetic-tasks]
[distractionless.ui.constants :as duconstants]
[distractionless.ui.apps.settings :as duasettings]
["dart:async" :as async]))
-(defn start-app [app config-file *app-in-queue]
- (async/Future.delayed (Duration.
- .seconds (duasettings/countdown-setting-value app config-file))
- (fn []
- (reset! *app-in-queue nil)
- (await (apps/InstalledApps.startApp (.-packageName app))))))
+(defn start-app [app config-file ctx]
+ (if (.contains (get (dconfig/read-from-file config-file) "arithmetic-tasks")
+ (.-packageName app))
+ (let [task (darithmetic-tasks/gen-task)]
+ (m/showDialog
+ .context ctx
+ .builder (f/build (m/Dialog
+ .backgroundColor duconstants/background-color
+ .child (m/Column
+ .mainAxisSize m/MainAxisSize.min
+ .children [(m/Text (str "Was ergibt "
+ (first (:numbers task)) " "
+ (darithmetic-tasks/type->str (:type task)) " "
+ (second (:numbers task)) "?"))
+ (m/TextField
+ .keyboardType m/TextInputType.number
+ .onSubmitted (fn [new-val]
+ (when (darithmetic-tasks/test-result? task
+ (int/tryParse new-val))
+ (m/Navigator.pop ctx)
+ (await (apps/InstalledApps.startApp (.-packageName app))))
+ nil))])))))
+ (await (apps/InstalledApps.startApp (.-packageName app)))))
(defn load-installed-apps! [a]
(reset! a (await (apps/InstalledApps.getInstalledApps false true))))
-(defn- render-app [app config-file ctx reloader *app-in-queue]
+(defn- render-app [app config-file ctx reloader]
(m/ListTile
.title (m/Text (.-name app)
.style duconstants/text-style)
.leading (widgets/Image.memory (.-icon app)
.height 30.0)
.onTap (fn []
- (reset! *app-in-queue app)
- (start-app app config-file *app-in-queue)
+ (start-app app config-file ctx)
nil)
.onLongPress #(duasettings/open app config-file ctx reloader)))
-(defn apps-list [apps config-file ctx reloader *app-in-queue]
+(defn apps-list [apps config-file ctx reloader]
(m/ListView
.padding m/EdgeInsets.zero
.children (for [app apps]
- (render-app app config-file ctx reloader *app-in-queue))))
+ (render-app app config-file ctx reloader))))
diff --git a/src/distractionless/ui/apps/settings.cljd b/src/distractionless/ui/apps/settings.cljd
index bf786b8..0c06543 100644
--- a/src/distractionless/ui/apps/settings.cljd
+++ b/src/distractionless/ui/apps/settings.cljd
@@ -32,23 +32,23 @@
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- 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
@@ -65,5 +65,5 @@
.child (m/Column
.children (list (header app ctx)
(favourite-setting app config-file reloader)
- (countdown-setting app config-file reloader)
+ (arithmetic-task-setting app config-file reloader)
(open-in-system-settings app)))))))