summaryrefslogtreecommitdiff
path: root/src/clojure/io/cons/carddav_sync/sync_service.clj
blob: 192eacb1b09d880633048d7f36c787a11114f021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns io.cons.carddav_sync.sync_service
  (:use io.cons.carddav_sync.log)
  (:require io.cons.carddav_sync.sync_adapter)
  (:import io.cons.carddav_sync.sync_adapter)
  (:gen-class
   :extends android.app.Service
   :exposes-methods {onCreate superOnCreate
                     onDestroy superOnDestroy}
   :state state
   :init init))

(defn -init
  []
  [[] (atom nil)])

(defn -onCreate
  [this]
  (.superOnCreate this)
  (log-i "Service created")
  (swap! (.state this)
         #(when-not % (sync_adapter. (.getApplicationContext this) true))))

(defn -onDestroy
  [this]
  (.superOnDestroy this)
  (log-i "Service destroyed"))

(defn -onBind
  [this intent]
  (.getSyncAdapterBinder @(.state this)))