Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calendar trable #8

Open
Macj opened this issue May 8, 2014 · 4 comments
Open

calendar trable #8

Macj opened this issue May 8, 2014 · 4 comments

Comments

@Macj
Copy link

Macj commented May 8, 2014

Hi! When I add a calendar functionality, my app start to
dies. When I click on a Event date button app shut down.

@krisc
Copy link
Owner

krisc commented May 9, 2014

Can you clarify what you mean by 'calendar functionality'? Do you mean the DatePickerDialog?

@Macj
Copy link
Author

Macj commented May 9, 2014

Yes, I mean the DatePickerDialog.
After i add
(:import (java.util Calendar)
(android.app DatePickerDialog DatePickerDialog$OnDateSetListener)
(android.app DialogFragment)))

and

(declare date-picker)
(declare show-picker)

(defn date-picker [activity](proxy [DialogFragment DatePickerDialog$OnDateSetListener] []
%28onCreateDialog [savedInstanceState]
%28let [c %28Calendar/getInstance%29
year %28.get c Calendar/YEAR%29
month %28.get c Calendar/MONTH%29
day %28.get c Calendar/DAY_OF_MONTH%29]
%28DatePickerDialog. activity this year month day%29%29%29
%28onDateSet [view year month day]
%28on-ui %28.setText %28::date %28.getTag mylayout%29%29
%28str year
%28format "%02d" %28inc month))
(format "%02d" day)))))))

(defn show-picker [activity dp](. dp show %28. activity getFragmentManager%29))

My app ends with the error after loading part and wright before starts.

My code looks like yours:

(ns org.stuff.events.main
(:use [neko.activity :only [defactivity set-content-view!]]
[neko.threading :only [on-ui]]
[neko.ui :only [make-ui]]
[neko.application :only [defapplication]]
[clojure.string :only [join]])
(:import (java.util Calendar)
(android.view View)
(android.app Activity)
(android.app DatePickerDialog DatePickerDialog$OnDateSetListener)
(android.app DialogFragment)))

(declare android.widget.LinearLayout mylayout)
(declare add-event)
(declare date-picker)
(declare show-picker)

(defn mt-listing [](atom %28sorted-map%29))
(def listing (mt-listing))

(defn format-events [events](->> %28map %28fn [[location event]]
%28format "%s - %sn" location event))
events)
(join " ")))

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

(defn main-layout [activity]
[:linear-layout {:orientation :vertical,
:id-holder :true,
:def `mylayout}
[:edit-text {:hint "Event name",
:id ::name}]
[:edit-text {:hint "Event location",
:id ::location}]
[:linear-layout {:orientation :horizontal}
[:text-view {:hint "Event date",
:id ::date}]
[:button {:text "...",
:on-click (fn [_](show-picker activity
%28date-picker activity%29))}]]
[:button {:text "+ Event",
:on-click (fn _)}]
[:text-view {:text (format-listing @Listing),
:id ::listing}]])

(defn get-elmt [elmt](str %28.getText %28elmt %28.getTag mylayout%29%29%29))

(defn set-elmt [elmt s](on-ui %28.setText %28elmt %28.getTag mylayout%29%29 s%29))

(defn update-ui [](set-elmt ::listing %28format-listing @Listing%29)
(set-elmt ::location "")
(set-elmt ::name "")
(set-elmt ::date ""))

(defn add-event [](let [date-key %28try
%28read-string %28get-elmt ::date%29%29
%28catch RuntimeException e))]
(when (number? date-key)
(swap! listing update-in [date-key](fnil conj []) [(get-elmt ::location) (get-elmt ::name)])
(update-ui))))

(defactivity org.stuff.events.MyActivity
:def a
:on-create
(fn [this bundle](on-ui
%28set-content-view! this
%28make-ui %28main-layout this%29%29%29)
(on-ui
(set-elmt ::listing @Listing))))

(defn date-picker [activity](proxy [DialogFragment DatePickerDialog$OnDateSetListener] []
%28onCreateDialog [savedInstanceState]
%28let [c %28Calendar/getInstance%29
year %28.get c Calendar/YEAR%29
month %28.get c Calendar/MONTH%29
day %28.get c Calendar/DAY_OF_MONTH%29]
%28DatePickerDialog. activity this year month day%29%29%29
%28onDateSet [view year month day]
%28on-ui %28.setText %28::date %28.getTag mylayout%29%29
%28str year
%28format "%02d" %28inc month))
(format "%02d" day)))))))

(defn show-picker [activity dp](. dp show %28. activity getFragmentManager%29))


can you help my?

9 ÍÁÑ 2014, × 20:47, Kris Calabio [email protected] ÎÁÐÉÓÁÌ(Á):

the DatePickerDialog

@krisc
Copy link
Owner

krisc commented May 9, 2014

Do the versions of the software stack match mine? If you're using newest version, they may cause problems. I know, my tutorial may be out of date. I haven't checked if my code works with the latest versions, but I will do so when I find the time. Until then, maybe you can post the output from adb logcat

@krisc
Copy link
Owner

krisc commented May 22, 2014

Macj, I finally found the time to update my tutorial. It works with the newest stable versions at least on my machine. I made a one breaking change, namely the listing atom no longer calls a constructor.

I'm not exactly sure what caused your problem, but a running app crashing and losing your REPL is not too uncommon due to the fragility of current tools. If your code looks exactly like mine, try running lein droid doall at the command line to rebuild the app and re-establish the REPL connection. Let me know if that fixes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants