diff options
Diffstat (limited to 'src/distractionless/core.cljd')
-rw-r--r-- | src/distractionless/core.cljd | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/src/distractionless/core.cljd b/src/distractionless/core.cljd index e3a39b9..d12e10f 100644 --- a/src/distractionless/core.cljd +++ b/src/distractionless/core.cljd @@ -4,6 +4,7 @@ ["package:path_provider/path_provider.dart" :as path-provider] [distractionless.config :as dconfig] ["dart:io" :as io] + [clojure.string :as cstr] [distractionless.ui.constants :as duconstants] [distractionless.ui.apps :as duapps])) @@ -19,37 +20,45 @@ :watch [apps (atom '()) :as *apps query (atom "") :as *query data-dir (await (path-provider/getApplicationDocumentsDirectory)) - _ (atom 0) :as reloader] + _ (atom 0) :as reloader + show-all-apps? (atom false) :as *show-all-apps?] :managed [_ (duapps/load-installed-apps! *apps) ; loads apps on app startup config-file (io/File. (str (.-path data-dir) "/config.edn")) _ (dconfig/init-config! config-file nil) ; Init config on app startup + search-bar-controller (m/TextEditingController.) _ (m/AppLifecycleListener .onShow #(do (dconfig/init-config! config-file nil) (duapps/load-installed-apps! *apps) - (reset! *query ""))) - page-controller (m/PageController.)] - :let [root-container-padding (m/EdgeInsets.only - .top 50)] - (m/PageView. - .controller page-controller - .onPageChanged (fn [_] (reset! *query "")) - .children [(let [favourites (get (dconfig/read-from-file config-file) "favourites")] - (m/Container - .padding root-container-padding - .child (m/Column - .children [(m/Expanded - .child (duapps/apps-list (filter #(.contains favourites (.-packageName %)) apps) nil config-file ctx reloader)) - (m/Text "Wische nach links, um alle Apps anzuzeigen" - .style duconstants/text-style)]))) - (m/Container - .padding root-container-padding - .child (m/Column - .children [(m/Text "Alle Apps" - .style duconstants/title-style) - (m/SearchBar - .onChanged (fn [new-val] - (reset! *query new-val) - nil) - .hintText "Suche" - .backgroundColor (#/(.resolveWith m/Color?) m/MaterialStateProperty (fn [^Set _states] duconstants/search-bar-color))) - (m/Expanded - .child (duapps/apps-list apps query config-file ctx reloader))]))]))) + (reset! *query "") + (.clear search-bar-controller)))] + :let [favourites (get (dconfig/read-from-file config-file) "favourites")] + (m/Container + .padding (m/EdgeInsets.only + .top 50) + .child (m/Column + .children [(m/SearchBar + .onChanged (fn [new-val] + (reset! *query new-val) + nil) + .hintText "Suche" + .controller search-bar-controller + .backgroundColor (#/(.resolveWith m/Color?) m/MaterialStateProperty (fn [^Set _states] duconstants/background-color)) + .trailing (when-not (cstr/blank? query) + [(m/IconButton .icon (m/Icon m/Icons.clear_rounded) + .color duconstants/text-color + .onPressed #(do (reset! *query "") + (.clear search-bar-controller)) + .iconSize 30.0)])) + (m/CheckboxListTile + .title (m/Text "Alle Apps anzeigen" + .style duconstants/text-style) + .value show-all-apps? + .onChanged #(reset! *show-all-apps? %) + .activeColor duconstants/checkbox-active-color) + (m/Expanded + .child (duapps/apps-list (filter (cond + (not (cstr/blank? query)) #(cstr/includes? + (cstr/lower-case (.-name %)) + (cstr/lower-case query)) + show-all-apps? (fn [_] true) + :else #(.contains favourites (.-packageName %))) apps) + config-file ctx reloader))])))) |