 (ns com.davidykay.helloclojure.main
+  (:require [neko.log :as log])
   (:use [neko.activity :only [defactivity set-content-view!]]
         [neko.threading :only [on-ui]]
         [neko.ui :only [make-ui config]]
-        )
+        [clojure.string :only [join]])
   (:import (java.util Calendar)
+           (android.view View)
            (android.app Activity)
            (android.app DatePickerDialog DatePickerDialog$OnDateSetListener)
            (android.app DialogFragment)))
 
-(def listing (atom ""))
+(def listing (atom (sorted-map)))
 
 (declare ^android.widget.LinearLayout mylayout)
 (declare update-ui)
+
+(defn format-events [events]
+  (->> (map (fn [[location event]]
+              (format "%s - %s\n" location event))
+            events)
+       (join "                      ")))
+
+(defn format-listing [lst]
+  (->> (map (fn [[date events]]
+               (format "%s - %s" date (format-events events)))
+             lst)
+       join))
+
 
 (defn set-elmt [elmt s]
   (on-ui (config (elmt (.getTag mylayout)) :text s)))

        (DatePickerDialog. activity this year month day)))
     (onDateSet [view year month day]
       (set-elmt ::date
         (format "%02d/%02d/%02d" year (inc month) day)))))

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

(defn main-layout [activity]
  [:linear-layout {:orientation :vertical,

  (str (.getText (elmt (.getTag mylayout)))))

(defn add-event []
  (let [date-key (try
                   (read-string (get-elmt ::date))
                   (catch RuntimeException e "Date string is empty!"))]
    (log/d "add-event. date-key: " date-key)
    (log/d "add-event. Current val of listing: " @listing)
    (when (number? date-key)
      (swap! listing update-in [date-key] (fnil conj []) [(get-elmt ::location) (get-elmt ::name)])
      (update-ui))))

(defn date-picker [activity]
  (proxy [DialogFragment DatePickerDialog$OnDateSetListener] []
