From ef29e1cde2265dfd26a276e6e75b5733981fefa7 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 6 Jun 2025 19:01:26 +0200 Subject: Replace countdown before starting specific apps with arithemtic tasks --- src/distractionless/ui/apps.cljd | 43 ++++++++++++++++++++++--------- src/distractionless/ui/apps/settings.cljd | 36 +++++++++++++------------- 2 files changed, 49 insertions(+), 30 deletions(-) (limited to 'src/distractionless/ui') 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))))))) -- cgit v1.2.3