<commit_before>(ns com.example.gt.metime.main
  (:require [neko.activity :refer [defactivity set-content-view!]]
            [neko.debug :refer [*a]]
            [neko.ui :refer [config]]
            [neko.log :as log]
            [clojure.string :refer [join]]
            [neko.find-view :refer [find-view]]
            [neko.threading :refer [on-ui]])
  (:import android.widget.TextView
           (java.util Calendar)
           (android.app Activity)
           (android.app DatePickerDialog DatePickerDialog$OnDateSetListener)
           (android.app TimePickerDialog TimePickerDialog$OnTimeSetListener)
           (android.app DialogFragment)))

(declare add-event)
(declare date-picker)
(declare time-picker)

(defn show-picker [activity dp picker-type]
  (. dp show (. activity getFragmentManager) picker-type))

(def listing (atom (sorted-map)))

(defn format-events [events]
  (->> (map (fn [[event]]
    (format "%s\n" event))
    events)
  (join "                      ")))

(defn format-listing [lst]
  (->> (map (fn [[date events]]
      (format "%s - %s" date (format-events events)))
    lst)
  join))

(defn main-layout [activity]
  [:linear-layout {:orientation :vertical}
    [:edit-text {
      :hint "Event name",
      :id ::name}]
    [:linear-layout {:orientation :horizontal}
      [:text-view {
        :hint "Goal (Time)",
        :id ::time}]
      [:button {
        :text "...",
        :on-click (fn [_] (show-picker activity
          (time-picker activity), "timePicker"))}]]
    [:linear-layout {:orientation :horizontal}
      [:text-view {
        :hint "Event date",
        :id ::date}]
      [:button {
        :text "...",
        :on-click (fn [_] (show-picker activity
          (date-picker activity) "datePicker"))}]]
    [:button {
      :text "+ Event",
      :on-click (fn [_] (add-event activity))}]
    [:text-view {
      :text (format-listing @listing)
      :id ::listing}]])

(defn get-elmt [activity elmt]
  (str (.getText ^TextView (find-view activity elmt))))

(defn set-elmt [activity elmt s]
  (on-ui (config (find-view activity elmt) :text s)))

(defn update-ui [activity]
  (set-elmt activity ::listing (format-listing @listing))
  (set-elmt activity ::name ""))

(defn add-event [activity]
  (let [date-key (try
      (read-string (get-elmt activity ::date))
      (catch RuntimeException e "Date string is empty!"))]
    (when (number? date-key)
      (swap! listing update-in [date-key] (fnil conj [])
        [(get-elmt activity ::name)])
      (update-ui activity))))

(defn date-picker [activity]
  (proxy [DialogFragment DatePickerDialog$OnDateSetListener] []
    (onCreateDialog [savedInstanceState]
      (let [c (Calendar/getInstance)
        year (.get c Calendar/YEAR)
        month (.get c Calendar/MONTH)
        day (.get c Calendar/DAY_OF_MONTH)]
        (DatePickerDialog. activity this year month day)))
    (onDateSet [view year month day]
      (set-elmt activity ::date
        (format "%d%02d%02d" year (inc month) day)))))

(defn time-picker [activity]
  (proxy [DialogFragment TimePickerDialog$OnTimeSetListener] []
    (onCreateDialog [savedInstanceState]
      (TimePickerDialog. activity this 0 0 true))
    (onTimeSet [view hourOfDay minute]
      (set-elmt activity ::time
        (format "%02d:%02d" hourOfDay minute)))))

(defactivity com.example.gt.metime.MainActivity
  :key :main

  (onCreate [this bundle]
    (.superOnCreate this bundle)
    (on-ui
      (set-content-view! (*a) (main-layout (*a)))
      (set-elmt (*a) ::listing (format-listing @listing)))
    ))<commit_msg>added a list view... with dummy data<commit_after>(ns com.example.gt.metime.main
  (:require [neko.activity :refer [defactivity set-content-view!]]
            [neko.debug :refer [*a]]
            [neko.ui :refer [config]]
            [neko.log :as log]
            [neko.ui.adapters :as adapters]
            [clojure.string :refer [join]]
            [neko.find-view :refer [find-view]]
            [neko.threading :refer [on-ui]])
  (:import [android.widget CursorAdapter TextView]
           android.graphics.Color
           java.util.Calendar
           android.app.Activity
           [android.app DatePickerDialog DatePickerDialog$OnDateSetListener]
           [android.app TimePickerDialog TimePickerDialog$OnTimeSetListener]
           android.app.DialogFragment))

(declare add-event)
(declare date-picker)
(declare time-picker)

(defn show-picker [activity picker picker-type]
  (. picker show (. activity getFragmentManager) picker-type))

(def listing (atom (sorted-map)))

(defn format-events [events]
  (->> (map (fn [[time-key event]]
      (format "%s - %s\n" time-key event))
      events)
    (join "                      ")))

(defn format-listing [lst]
  (->> (map (fn [[date events]]
      (format "%s - %s" date (format-events events)))
    lst)
    join))

(def alphabet
  (atom {:type :phonetic
         :letters ["alpha" "bravo" "charlie" "delta"]}))

(defn make-adapter []
  (adapters/ref-adapter
    (fn [_]
      [:linear-layout {:id-holder true}
       [:text-view {:id         ::caption-tv}]
       ])
    (fn [position view _ data]
      (let [tv (find-view view ::caption-tv)]
        (config tv :text (str position ". " data))

        ))
    alphabet
    :letters
    ))

(defn main-layout [activity]
  [:linear-layout {:orientation :vertical}
    [:edit-text {
      :hint "Event name",
      :id ::name}]
    [:linear-layout {:orientation :horizontal}
      [:text-view {
        :hint "Goal (Time)",
        :id ::time}]
      [:button {
        :text "...",
        :on-click (fn [_] (show-picker activity
          (time-picker activity), "timePicker"))}]]
    [:linear-layout {:orientation :horizontal}
      [:text-view {
        :hint "Event date",
        :id ::date}]
      [:button {
        :text "...",
        :on-click (fn [_] (show-picker activity
          (date-picker activity) "datePicker"))}]]
    [:button {
      :text "+ Event",
      :on-click (fn [_] (add-event activity))}]
    [:text-view {
      :text (format-listing @listing)
      :id ::listing}]
    [:list-view {
      :id ::listings
      :draw-selector-on-top true
      :adapter (make-adapter)
      ;:on-item-click (fn [_] (show-picker activity
      ;  (date-picker activity) "timerActivity"))

                 }]
   ])

(defn get-elmt [activity elmt]
  (str (.getText ^TextView (find-view activity elmt))))

(defn set-elmt-text [activity elmt s]
  (on-ui (config (find-view activity elmt) :text s)))

;(defn update-listings [activity]
;  (on-ui (config (find-view activity ::listings) :adapter (timer-adapter activity @listing))))

(defn update-ui [activity]
  (set-elmt-text activity ::listing (format-listing @listing))
  (set-elmt-text activity ::name "")
  (swap! alphabet update-in [:letters] conj "echo")
  )

(defn add-event [activity]
  (let [
      date-key (try
        (read-string (get-elmt activity ::date))
        (catch RuntimeException e "Date string is empty!"))
      time-key (try
        (read-string (get-elmt activity ::time))
        (catch RuntimeException e "Time string is empty!"))]
    (when (number? date-key)
      (swap! listing update-in [date-key] (fnil conj [])
        [(get-elmt activity ::name) time-key])
      (update-ui activity))))

(defn date-picker [activity]
  (proxy [DialogFragment DatePickerDialog$OnDateSetListener] []
    (onCreateDialog [savedInstanceState]
      (let [c (Calendar/getInstance)
        year (.get c Calendar/YEAR)
        month (.get c Calendar/MONTH)
        day (.get c Calendar/DAY_OF_MONTH)]
        (DatePickerDialog. activity this year month day)))
    (onDateSet [view year month day]
      (set-elmt-text activity ::date
        (format "%d%02d%02d" year (inc month) day)))))

(defn time-picker [activity]
  (proxy [DialogFragment TimePickerDialog$OnTimeSetListener] []
    (onCreateDialog [savedInstanceState]
      (TimePickerDialog. activity this 0 0 true))
    (onTimeSet [view hourOfDay minute]
      (set-elmt-text activity ::time
        (format "%d"  (+ (* hourOfDay 60) minute))))))

(defactivity com.example.gt.metime.MainActivity
  :key :main

  (onCreate [this bundle]
    (.superOnCreate this bundle)
    (on-ui
      (set-content-view! (*a) (main-layout (*a)))
      (swap! alphabet update-in [:letters] conj "echo")
      )
    ))
{'fraction_non_alphanumeric': 0.1549092657132556, 'fraction_numerical': 0.0021632015382766494, 'mean_word_length': 2.6404199475065617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '241136', 'n_tokens_mistral': 2758, 'n_tokens_neox': 2635, 'n_words': 693}