             [neko.threading :refer [on-ui]])
   (:import [android.widget CursorAdapter TextView LinearLayout]
            android.graphics.Color
+           [android.os SystemClock Handler]
            java.util.Calendar
            [android.app Activity DialogFragment]
            android.view.View

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

(defrecord Task [date name duration date-index])


                          (into [] (map-indexed (fn [i ele] (apply ->Task (concat [(first sorted-map-data)] ele [i]))) (second sorted-map-data))))
                        lst)))

(defn create-update-timer-method [event-timer-view start-time time-swap ]
  (defn update-timer-method []
    (let [time-in-millis (- (SystemClock/uptimeMillis) start-time)
          final-time (+ time-swap time-in-millis)
          total-seconds (mod final-time 1000)
          minutes (quot total-seconds 1000)
          seconds (mod total-seconds 60)
          milliseconds (mod final-time 1000)]
      (config event-timer-view :text (str "" minutes ":" (format "%02d" seconds) ":" (format "%02d" milliseconds))))))

;myHandler.postDelayed(this, 0);

(defn make-date-adapter []
  (adapters/ref-adapter
    (fn [_]
      [:linear-layout {:id-holder   true
                       :orientation :vertical}
       [:text-view {:id ::date-tv}]
       [:linear-layout {:id ::event-ll
                        :id-holder true
                        :orientation :horizontal}
        [:text-view {:id ::event-tv}]
        [:text-view {:id ::time-tv}]
        [:button {:id ::event-btn
                  :text  "start",
                  ;:on-click
                  }]
        ]])
    (fn [_ view _ task]
      (let [date-text-view (find-view view ::date-tv)
            event-linear-layout-view (find-view view ::event-ll)
            event-text-view (find-view event-linear-layout-view ::event-tv)
            event-timer-view (find-view event-linear-layout-view ::time-tv)
            event-button-view (find-view event-linear-layout-view ::event-btn)
            my-handler (Handler.)]
        ;symptom of mutability
        (config date-text-view :visibility (if (= (:date-index task) 0) View/VISIBLE View/GONE))
        (config date-text-view :text (str (:date task)))

        (config event-button-view :on-click (fn [_] (.postDelayed my-handler (create-update-timer-method event-timer-view 0 0) 0)))
        (config event-text-view :text (str (:name task) " " (:duration task) " " (:date-index task)))))
    listing
    sorted-map-array-to-array-task))

