starwisp.scm 36.9 KB
Newer Older
Dave Griffiths's avatar
Dave Griffiths committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
;; Starwisp Copyright (C) 2013 Dave Griffiths
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; strings


;; colours
21
(msg "starting up....")
Dave Griffiths's avatar
Dave Griffiths committed
22
23

(define trans-col (list 0 0 0 0))
24
25
(define colour-one (list 0 0 255 100))
(define colour-two (list  127 127 255 100))
Dave Griffiths's avatar
Dave Griffiths committed
26
27
28
29

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; persistent database

30
(define db "/sdcard/symbai/local-symbai.db")
Dave Griffiths's avatar
Dave Griffiths committed
31
32
33
34
35
36
37
38
39
40
(db-open db)
(setup db "local")
(setup db "sync")
(setup db "stream")

(insert-entity-if-not-exists
 db "local" "app-settings" "null" 1
 (list
  (ktv "user-id" "varchar" "No name yet...")))

Dave Griffiths's avatar
Dave Griffiths committed
41
(define entity-types (list "village"))
42

Dave Griffiths's avatar
Dave Griffiths committed
43
;;(display (db-all db "local" "app-settings"))(newline)
Dave Griffiths's avatar
Dave Griffiths committed
44

Dave Griffiths's avatar
Dave Griffiths committed
45
46
47
48
(define tribes-list '(khasi other))
(define subtribe-list '(khynriam pnar bhoi war other))
(define education-list   '(illiterate literate primary middle high secondary university))
(define married-list '(ever-married currently-married currently-single seperated))
Dave Griffiths's avatar
Dave Griffiths committed
49
50
51
52

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; user interface abstraction

53
54
55
56
57
;;;;;;;;;;;;; i18n ;;;;;;;;;;;;;;;;;;;;;;


(define i18n-text
  (list
Dave Griffiths's avatar
Dave Griffiths committed
58
   (list 'test-num (list "1.0000000" "1.0000000" "1.0000000"))
59
60
61
62
63
64
   (list 'test-text (list "I am test text" "I am test text" "I am test text"))
   (list 'one (list "one"))
   (list 'two (list "two"))
   (list 'three (list "three"))
   (list 'village (list "Village"))
   (list 'household (list "Household"))
65
   (list 'households (list "Households"))
66
   (list 'individual (list "Individual"))
67
   (list 'individuals (list "Individuals"))
68

69
   (list 'add-item-to-list (list "+"))
70
   (list 'default-village-name (list "New village"))
Dave Griffiths's avatar
Dave Griffiths committed
71

72
73
74
75
76
77
   (list 'title (list "Symbai" "Symbai" "Symbai"))
   (list 'sync (list "Sync" "Sync" "Sync"))
   (list 'languages (list "Choose language" "Choose language" "Choose language"))
   (list 'english (list "English" "English" "English"))
   (list 'khasi (list "Khasi" "Khasi" "Khasi"))
   (list 'hindi (list "Hindi" "Hindi" "Hindi"))
Dave Griffiths's avatar
Dave Griffiths committed
78
   (list 'user-id (list "Your user ID" "User ID" "User ID"))
79
80
   (list 'ok (list "Ok" "Ok" "Ok"))
   (list 'cancel (list "Cancel" "Cancel" "Cancel"))
Dave Griffiths's avatar
Dave Griffiths committed
81
   (list 'villages (list "Villages" "Villages" "Villages"))
82
83
84
85
   (list 'list-empty (list "List empty"))
   (list 'delete (list "Delete"))
   (list 'delete-are-you-sure (list "Are you sure you want to delete this?"))
   (list 'save-are-you-sure (list "Are you sure you want to save changes?"))
Dave Griffiths's avatar
Dave Griffiths committed
86

87
88
89
90
91
92
93
94
95
96
97
   ;; sync
   (list 'sync-all (list "Sync me!"))
   (list 'sync-syncall (list "Sync everything"))
   (list 'export-data (list "Exporting data"))
   (list 'sync-download (list "Download main DB"))
   (list 'sync-export (list "Email main DB"))
   (list 'email-local (list "Email local DB"))
   (list 'debug (list "Debug"))
   (list 'sync-back (list "Back"))
   (list 'sync-prof (list "Profile"))

Dave Griffiths's avatar
Dave Griffiths committed
98
   ;; village screen
99
   (list 'village-name (list "Village name" "Village name" "Village name"))
Dave Griffiths's avatar
Dave Griffiths committed
100
101
102
103
104
105
106
   (list 'block (list "Block" "Block" "Block"))
   (list 'district (list "District" "District" "District"))
   (list 'car (list "Accessible by car"))
   (list 'household-list (list "Household list"))
   (list 'amenities (list "Amenities"))
   (list 'school (list "School"))
   (list 'present (list "Present"))
Dave Griffiths's avatar
Dave Griffiths committed
107
   (list 'closest-access (list "Closest place of access"))
Dave Griffiths's avatar
Dave Griffiths committed
108
109
   (list 'house-gps (list "GPS"))
   (list 'toilet-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
110
111
112
113
114
115
116
117
118
119
   (list 'school (list "School"))
   (list 'hospital (list "Hospital/Health care centre"))
   (list 'post-office (list "Post Office"))
   (list 'railway-station (list "Railway station"))
   (list 'state-bus-service (list "Inter-state bus service"))
   (list 'district-bus-service (list "Inter-village/district bus service"))
   (list 'panchayat (list "Village Panchayat Office"))
   (list 'NGO (list "Presence of NGO's working with them"))
   (list 'market (list "Market"))

120
   ;; household
Dave Griffiths's avatar
Dave Griffiths committed
121
122
   (list 'household-name (list "Household name"))
   (list 'default-household-name (list "A household"))
123
124
125
126
127
128
129
130
131
132
133
   (list 'location (list "House location"))
   (list 'elevation (list "Elevation"))
   (list 'toilet-location (list "Toilet location"))
   (list 'children (list "Children"))
   (list 'male (list "Male"))
   (list 'female (list "Female"))
   (list 'num-pots (list "Number of pots"))
   (list 'adults (list "Adults"))
   (list 'add-individual (list "Add individual"))

   ;; individual
Dave Griffiths's avatar
Dave Griffiths committed
134
135
136
   (list 'default-individual-name (list "A person"))
   (list 'default-family-name (list "A family"))
   (list 'default-photo-id (list "???"))
Dave Griffiths's avatar
Dave Griffiths committed
137
138
139
140
141
142
143
144
145
146
   (list 'name-display (list "Name"))
   (list 'photo-id-display (list "Photo ID"))
   (list 'family-display (list "Family"))
   (list 'details-button (list "Details"))
   (list 'family-button (list "Family"))
   (list 'migration-button (list "Migration"))
   (list 'income-button (list "Income"))
   (list 'geneaology-button (list "Geneaology"))
   (list 'social-button (list "Social"))
   (list 'agreement-button (list "Agreement"))
147
148
149

   ;; details
   (list 'change-photo (list "Change photo"))
Dave Griffiths's avatar
Dave Griffiths committed
150
151
152
   (list 'details-name (list "Name"))
   (list 'details-photo-id (list "Photo ID"))
   (list 'details-family (list "Family"))
153
154
   (list 'tribe (list "Tribe"))
   (list 'sub-tribe (list "Sub tribe"))
Dave Griffiths's avatar
Dave Griffiths committed
155
156
157
158
159
   (list 'khasi (list "Khasi"))
   (list 'khynriam (list "Khynriam"))
   (list 'pnar (list "Pnar"))
   (list 'bhoi (list "Bhoi"))
   (list 'war (list "War"))
160
161
162
163
   (list 'other (list "Other"))
   (list 'age (list "Age"))
   (list 'gender (list "Gender"))
   (list 'education (list "Education"))
Dave Griffiths's avatar
Dave Griffiths committed
164
165
166
167
168
169
170
171
   (list 'illiterate (list "Illiterate"))
   (list 'literate (list "Literate"))
   (list 'primary (list "Primary 1-5"))
   (list 'middle (list "Middle 6-8"))
   (list 'high (list "High 9-10"))
   (list 'secondary (list "Higher Secondary"))
   (list 'university (list "University"))

172
173
174
175
176
177
178
179
180
181
182

   ;; family
   (list 'spouse (list "Spouse"))
   (list 'head-of-house (list "Head of house"))
   (list 'marital-status (list "Marital status"))
   (list 'ever-married (list "Ever married"))
   (list 'currently-married (list "Currently married"))
   (list 'currently-single (list "Currently single"))
   (list 'seperated (list "Seperated/divorced"))
   (list 'times-married (list "How many times married"))
   (list 'change-spouse (list "Change/add spouse"))
Dave Griffiths's avatar
Dave Griffiths committed
183
184
185
186
   (list 'children-living (list "Living"))
   (list 'children-dead (list "Dead"))
   (list 'children-together (list "Living together"))
   (list 'children-apart (list "Living apart"))
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
   (list 'residence-after-marriage (list "Residence after marriage"))
   (list 'birthplace (list "Birthplace"))
   (list 'spouse-village (list "Spouses natal village"))
   (list 'num-siblings (list "Number of living siblings of the same sex born from same mother"))
   (list 'birth-order (list "Birth order amoung currently living same sex siblings born from same mother"))

   ;; migration
   (list 'length-time (list "Length of time lived in this village (years)"))
   (list 'place-of-birth (list "Place of birth"))
   (list 'num-residence-changes (list "Number of time place of residence changed since birth"))
   (list 'village-visits-month (list "Number of times you have visited another village in the last month"))
   (list 'village-visits-year (list "Number of times you have visited another village in the last year (i.e. betwen last summer and this summer)"))

   ;; income
   (list 'occupation (list "Occupation"))
   (list 'occupation (list "Occupation"))
   (list 'agriculture (list "Agriculture"))
   (list 'gathering (list "Gathering"))
   (list 'labour (list "Labour"))
   (list 'cows (list "Cows"))
   (list 'fishing (list "Fishing"))
Dave Griffiths's avatar
Dave Griffiths committed
208
209
210
211
212
   (list 'num-people-in-house (list "People living in house"))
   (list 'contribute (list "Contribute to family earnings?"))
   (list 'own-land (list "Own land?"))
   (list 'rent-land (list "Rent out your land?"))
   (list 'hire-land (list "Hire land?"))
213
214
215
216
217
218
219
220
221
222
223
   (list 'crops (list "Crops"))
   (list 'crop (list "Crop"))
   (list 'unit (list "Unit"))
   (list 'quantity (list "Quantity"))
   (list 'used-or-eaten (list "Used/Eaten"))
   (list 'sold (list "Sold"))
   (list 'seed (list "Seed (hybrid/local)"))
   (list 'house-type (list "House type"))
   (list 'concrete (list "Concrete"))
   (list 'tin (list "Tin"))
   (list 'thatched (list "Thatched"))
Dave Griffiths's avatar
Dave Griffiths committed
224
225
   (list 'loan (list "Outstanding loans"))
   (list 'earning (list "One day's earnings"))
226
227
228
229
   (list 'in-the-home (list "In the home"))
   (list 'radio (list "Radio"))
   (list 'tv (list "TV"))
   (list 'mobile (list "Mobile phone"))
Dave Griffiths's avatar
Dave Griffiths committed
230
231
   (list 'visit-market (list "Tribal market visits"))
   (list 'town-sell (list "Town or city visits"))
232
233
234
235
236
237
238
239
240

   ;; geneaology

   (list 'mother (list "Mother"))
   (list 'father (list "Father"))
   (list 'change-mother (list "Change mother"))
   (list 'change-father (list "Change father"))
   (list 'alive (list "Alive"))
   (list 'sex (list "Sex"))
241
242
   ))

Dave Griffiths's avatar
Dave Griffiths committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;

(define (debug! txt)
  (set-current! 'debug-text (string-append txt "\n" (get-current 'debug-text ""))))

(define (update-debug)
  (update-widget 'debug-text-view (get-id "sync-debug") 'text
                 (get-current 'debug-text "")))

(define (debug-timer-cb)
  (append
   (cond
    ((get-current 'sync-on #f)
     (set-current! 'upload 0)
     (set-current! 'download 0)
     (connect-to-net
      (lambda ()
Dave Griffiths's avatar
Dave Griffiths committed
262
        (msg "connected, going in...")
Dave Griffiths's avatar
Dave Griffiths committed
263
264
265
266
267
268
        (append
         (list (toast "sync-cb"))
         (upload-dirty db)
         (suck-new db "sync")))))
    (else '()))
   (list
Dave Griffiths's avatar
Dave Griffiths committed
269
    (delayed "debug-timer" (+ 10000 (random 5000)) debug-timer-cb)
Dave Griffiths's avatar
Dave Griffiths committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
    (update-debug))))


(define pf-length 20) ;; minutes...

(define (timer-cb)
  (set-current!
   'timer-seconds
   (- (get-current 'timer-seconds 59) 1))
  (append
   (cond
    ((< (get-current 'timer-seconds 59) 0)
     (set-current! 'timer-minutes (- (get-current 'timer-minutes pf-length) 1))
     (set-current! 'timer-seconds 59)
     (cond ((< (get-current 'timer-minutes pf-length) 1)
            (list
             (alert-dialog
              "pup-focal-end"
              "Pup focal time is up, have you finished?"
              (lambda (v)
                (cond
                 ((eqv? v 1)
                  (list (finish-activity 1)))
                 (else
                  (set-current! 'timer-minutes 1)
                  (list)))))))
           (else
            (list (replace-fragment (get-id "pf-top") "pf-scan1")))))
    (else '()))
   (list
    (delayed "timer" 1000 timer-cb)
    (update-widget
     'text-view (get-id "pf-timer-time-minutes") 'text
     (string-append (number->string (get-current 'timer-minutes pf-length))))
    (update-widget
     'text-view (get-id "pf-timer-time") 'text
     (string-append (number->string (get-current 'timer-seconds 59))))
    )))


(define (force-pause)
  (list
   (delayed "timer" 1000 (lambda () '()))
   (update-widget 'toggle-button (get-id "pf-pause") 'checked 1)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; fragments

(define-fragment-list

  (fragment
321
322
   "top"
   (horiz
Dave Griffiths's avatar
Dave Griffiths committed
323
    (image-view 0 "face" (layout 48 64 -1 'centre 0))
324
    (text-view (make-id "title") "" 30
325
326
327
328
               (layout 'fill-parent 'fill-parent 0.25 'centre 10))

    (linear-layout
     0 'vertical
Dave Griffiths's avatar
Dave Griffiths committed
329
     (layout 'fill-parent 'wrap-content 0.75 'centre 0)
330
331
332
333
     (list 0 0 0 0)

     (list
      (text-view (make-id "") 'name 20
Dave Griffiths's avatar
Dave Griffiths committed
334
                 (layout 'fill-parent 'wrap-content 1 'centre 0))
335
      (text-view (make-id "") 'photo-id 20
Dave Griffiths's avatar
Dave Griffiths committed
336
                 (layout 'fill-parent 'wrap-content 1 'centre 0)))))
Dave Griffiths's avatar
Dave Griffiths committed
337
338
339
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
340
341
342
     (list
      (update-widget 'text-view (get-id "title") 'text
                     (get-current 'activity-title "Title not set"))))
Dave Griffiths's avatar
Dave Griffiths committed
343
344
345
346
347
348
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))


349
350
351
352
  (fragment
   "bottom"
   (linear-layout
    0 'horizontal
Dave Griffiths's avatar
Dave Griffiths committed
353
    (layout 'fill-parent 'fill-parent 1 'centre 0)
354
355
    (list 0 0 0 0)
    (list
356
357
358
359
360
361
     (mbutton-scale
      'ok
      (lambda ()
        (list
         (alert-dialog
          "ok-check"
362
          (mtext-lookup 'save-are-you-sure)
363
364
365
366
367
368
369
370
          (lambda (v)
            (cond
             ((eqv? v 1)
              (entity-update-values!)
              (list (finish-activity 1)))
             (else
              (list))))))))
     (mbutton-scale 'cancel (lambda () (list (finish-activity 1))))))
371
372
373
374
375
376
377
378
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))
Dave Griffiths's avatar
Dave Griffiths committed
379
380
381
382
383
384


  )

(msg "one")

Dave Griffiths's avatar
Dave Griffiths committed
385
386
387
388
(define (build-activity . contents)
  (vert-fill
   (relative
    '(("parent-top"))
389
    colour-one ;;(list 100 100 255 127)
Dave Griffiths's avatar
Dave Griffiths committed
390
391
392
393
394
395
396
397
398
    (build-fragment "top" (make-id "top") fillwrap))

   (scroll-view-vert
    0 (layout 'fill-parent 'fill-parent 1 'centre 0)
    (list
     (apply vert-fill contents)))

   (relative
    '(("parent-bottom"))
399
    colour-one
Dave Griffiths's avatar
Dave Griffiths committed
400
401
402
403
    (vert
     (spacer 5)
     (build-fragment "bottom" (make-id "bottom") fillwrap)))))

Dave Griffiths's avatar
Dave Griffiths committed
404
405
406
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; activities

407
(define photo-code 999)
Dave Griffiths's avatar
Dave Griffiths committed
408
409
410
411
412

(define-activity-list

  (activity
   "main"
413
414
415
416
   (build-activity
    (mtitle 'title)
    (horiz
     (medit-text 'user-id "normal" (lambda () (list)))
417
     (mbutton-scale 'sync (lambda () (list (start-activity "sync" 0 "")))))
418
419

    (mspinner 'languages (list 'english 'khasi 'hindi) (lambda (c) (list)))
420
    (mbutton 'find-individual (lambda () (list (start-activity "individual-chooser" 0 ""))))
421
    (build-list-widget
Dave Griffiths's avatar
Dave Griffiths committed
422
     db "sync" 'villages "village" "village" (lambda () #f)
423
424
425
426
     (list
      (ktv "name" "varchar" (mtext-lookup 'default-village-name))
      (ktv "block" "varchar" "")
      (ktv "district" "varchar" "test")
Dave Griffiths's avatar
Dave Griffiths committed
427
      (ktv "car" "int" 0))))
428

429
   (lambda (activity arg)
430
     (set-current! 'activity-title "Main screen")
431
432
     (activity-layout activity))
   (lambda (activity arg)
Dave Griffiths's avatar
Dave Griffiths committed
433
434
435
436
437
438
439
     (list
      (gps-start "gps" (lambda (loc)
                         (set-current! 'location loc)
                         (list (toast (string-append
                                       (number->string (car loc)) ", "
                                       (number->string (cadr loc)))))))
      (update-list-widget db "sync" "village" "village" #f)))
440
441
442
443
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
444
445
446
447
448
449
450
451
452
   (lambda (activity requestcode resultcode)
     (cond
      ((eqv? requestcode photo-code)
       (msg "camera returned" resultcode)
       (list (update-widget
              'image-view (get-id "image")
              'external-image (string-append dirname "photo.jpg"))))
      (else
       '()))))
453
454
455
456


  (activity
   "village"
Dave Griffiths's avatar
Dave Griffiths committed
457
458
459
   (let ((place-widgets
          (lambda (id shade)
            (horiz-colour
460
             (if shade colour-one colour-two)
Dave Griffiths's avatar
Dave Griffiths committed
461
462
463
             (mtoggle-button-scale id (lambda (v) '()))
             (medit-text-scale 'closest-access "normal" (lambda (v) '()))
             (vert
Dave Griffiths's avatar
Dave Griffiths committed
464
              (mbutton-scale 'gps (lambda ()  '()))
465
466
              (mtext-small 'test-num)
              (mtext-small 'test-num))))))
Dave Griffiths's avatar
Dave Griffiths committed
467
468
     (build-activity
      (horiz
Dave Griffiths's avatar
Dave Griffiths committed
469
470
       (medit-text 'village-name "normal" (lambda (v) (entity-add-value! "name" "varchar" v) '()))
       (medit-text 'block "normal" (lambda (v) (entity-add-value! "block" "varchar" v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
471
      (horiz
Dave Griffiths's avatar
Dave Griffiths committed
472
473
       (medit-text 'district "normal" (lambda (v) (entity-add-value! "district" "varchar" v) '()))
       (mtoggle-button-scale 'car (lambda (v) (entity-add-value! "car" "int" v) '())))
474

Dave Griffiths's avatar
Dave Griffiths committed
475
476
477
478
      (mbutton 'household-list
               (lambda ()
                 (list (start-activity "household-list" 0
                                       (get-current 'village #f)))))
479

Dave Griffiths's avatar
Dave Griffiths committed
480
481
482
483
484
485
486
487
488
      (mtitle 'amenities)
      (place-widgets 'school #t)
      (place-widgets 'hospital #f)
      (place-widgets 'post-office #t)
      (place-widgets 'railway-station #f)
      (place-widgets 'state-bus-service #t)
      (place-widgets 'district-bus-service #f)
      (place-widgets 'panchayat #t)
      (place-widgets 'NGO #f)
489
490
      (place-widgets 'market #t)
      (delete-button)))
Dave Griffiths's avatar
Dave Griffiths committed
491
   (lambda (activity arg)
492
     (set-current! 'activity-title "Village")
Dave Griffiths's avatar
Dave Griffiths committed
493
494
     (activity-layout activity))
   (lambda (activity arg)
495
     (entity-init! db "sync" "village" (get-entity-by-unique db "sync" arg))
496
     (set-current! 'village arg)
497
498
499
500
     (list
      (mupdate 'edit-text 'village-name "name")
      (mupdate 'edit-text 'block "block")
      (mupdate 'edit-text 'district "district")
Dave Griffiths's avatar
Dave Griffiths committed
501
      (mupdate 'toggle-button 'car "car")))
Dave Griffiths's avatar
Dave Griffiths committed
502
503
504
505
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
Dave Griffiths's avatar
Dave Griffiths committed
506
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
507

Dave Griffiths's avatar
Dave Griffiths committed
508
509
510
511

  (activity
   "household-list"
   (build-activity
512
    (build-list-widget
Dave Griffiths's avatar
Dave Griffiths committed
513
     db "sync" 'households "household" "household" (lambda () (get-current 'village #f))
514
515
516
517
518
519
     (list
      (ktv "name" "varchar" (mtext-lookup 'default-household-name))
      (ktv "num-pots" "int" 0)
      (ktv "house-lat" "real" 0) ;; get from current location?
      (ktv "house-lon" "real" 0)
      (ktv "toilet-lat" "real" 0)
Dave Griffiths's avatar
Dave Griffiths committed
520
      (ktv "toilet-lon" "real" 0))))
Dave Griffiths's avatar
Dave Griffiths committed
521
   (lambda (activity arg)
522
     (set-current! 'activity-title "Household List")
Dave Griffiths's avatar
Dave Griffiths committed
523
     (activity-layout activity))
524
   (lambda (activity arg)
Dave Griffiths's avatar
Dave Griffiths committed
525
     (msg "rebuilding household list with" arg)
Dave Griffiths's avatar
Dave Griffiths committed
526
527
     (list (update-list-widget
            db "sync" "household" "household" arg)))
Dave Griffiths's avatar
Dave Griffiths committed
528
529
530
531
532
533
534
535
536
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "household"
   (build-activity
537
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
538
539
     (medit-text 'household-name "normal" (lambda (v) (entity-add-value! "name" "varchar" v) '()))
     (medit-text 'num-pots "numeric" (lambda (v) (entity-add-value! "num-pots" "int" v) '())))
540
541
    (horiz
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
542
543
544
545
      (mtext 'location)
      (mbutton 'house-gps (lambda () (do-gps 'house "house")))
      (mtext-small 'house-lat)
      (mtext-small 'house-lon))
546
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
547
548
549
550
551
      (mtext 'toilet-location)
      (mbutton 'toilet-gps (lambda () (do-gps 'toilet "toilet")))
      (mtext-small 'toilet-lat)
      (mtext-small 'toilet-lon)))

552
553

    (build-list-widget
Dave Griffiths's avatar
Dave Griffiths committed
554
555
     db "sync" 'individuals "individual" "individual"
     (lambda () (get-current 'household #f))
556
     (list
Dave Griffiths's avatar
Dave Griffiths committed
557
      (ktv "name" "varchar" (mtext-lookup 'default-individual-name))
558
      (ktv "family" "varchar" (mtext-lookup 'default-family-name))
Dave Griffiths's avatar
Dave Griffiths committed
559
560
561
562
563
      (ktv "photo-id" "varchar" (mtext-lookup 'default-photo-id))
      (ktv "photo" "file" "none")
      (ktv "tribe" "varchar" "none")
      (ktv "subtribe" "varchar" "none")
      (ktv "age" "int" 0)
564
      (ktv "gender" "varchar" "Female")
Dave Griffiths's avatar
Dave Griffiths committed
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
      (ktv "education" "varchar" "none")
      (ktv "head-of-house" "varchar" "none")
      (ktv "marital-status" "varchar" "none")
      (ktv "times-married" "int" 0)
      (ktv "id-spouse" "varchar" "none")
      (ktv "children-living" "int" 0)
      (ktv "children-dead" "int" 0)
      (ktv "children-together" "int" 0)
      (ktv "children-apart" "int" 0)
      (ktv "residence-after-marriage" "varchar" "none")
      (ktv "num-siblings" "int" 0)
      (ktv "birth-order" "int" 0)
      (ktv "length-time" "int" 0)
      (ktv "place-of-birth" "varchar" "none")
      (ktv "num-residence-changes" "int" 0)
      (ktv "village-visits-month" "int" 0)
      (ktv "village-visits-year" "int" 0)
      (ktv "occupation" "varchar" "none")
      (ktv "contribute" "int" 0)
      (ktv "own-land" "int" 0)
      (ktv "rent-land" "int" 0)
      (ktv "hire-land" "int" 0)
      (ktv "house-type" "varchar" "none")
      (ktv "loan" "int" 0)
      (ktv "earning" "int" 0)
      (ktv "radio" "int" 0)
      (ktv "tv" "int" 0)
      (ktv "mobile" "int" 0)
      (ktv "visit-market" "int" 0)
      (ktv "town-sell" "int" 0)
      ))

Dave Griffiths's avatar
Dave Griffiths committed
597
    (delete-button))
Dave Griffiths's avatar
Dave Griffiths committed
598
   (lambda (activity arg)
599
     (set-current! 'activity-title "Household")
Dave Griffiths's avatar
Dave Griffiths committed
600
     (activity-layout activity))
601
602
603
   (lambda (activity arg)
     (entity-init! db "sync" "household" (get-entity-by-unique db "sync" arg))
     (set-current! 'household arg)
Dave Griffiths's avatar
Dave Griffiths committed
604
605
606
607
608
609
610
     (append
      (list
       (update-list-widget db "sync" "individual" "individual" arg)
       (mupdate 'edit-text 'household-name "name")
       (mupdate 'edit-text 'num-pots "num-pots"))
      (mupdate-gps 'house "house")
      (mupdate-gps 'toilet "toilet")))
611

Dave Griffiths's avatar
Dave Griffiths committed
612
613
614
615
616
617
618
619
620
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "individual"
   (build-activity
621
622
623
    (horiz
     (image-view (make-id "photo") "face" (layout 240 320 -1 'centre 10))
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
624
      (mtext 'name-display)
625
      (spacer 20)
Dave Griffiths's avatar
Dave Griffiths committed
626
      (mtext 'family-display)
627
      (spacer 20)
Dave Griffiths's avatar
Dave Griffiths committed
628
      (mtext 'photo-id-display)))
629
    (mbutton 'agreement-button (lambda () (list (start-activity "agreement" 0 ""))))
630
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
631
632
     (mbutton-scale 'details-button (lambda () (list (start-activity "details" 0 ""))))
     (mbutton-scale 'family-button (lambda () (list (start-activity "family" 0 "")))))
633
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
634
635
     (mbutton-scale 'migration-button (lambda () (list (start-activity "migration" 0 ""))))
     (mbutton-scale 'income-button (lambda () (list (start-activity "income" 0 "")))))
636
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
637
638
     (mbutton-scale 'geneaology-button (lambda () (list (start-activity "geneaology" 0 ""))))
     (mbutton-scale 'social-button (lambda () (list (start-activity "social" 0 "")))))
639
    (spacer 20)
Dave Griffiths's avatar
Dave Griffiths committed
640
    (delete-button))
641

Dave Griffiths's avatar
Dave Griffiths committed
642
   (lambda (activity arg)
643
     (set-current! 'activity-title "Individual")
Dave Griffiths's avatar
Dave Griffiths committed
644
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
645
646
647
648
   (lambda (activity arg)
     (entity-init! db "sync" "individual" (get-entity-by-unique db "sync" arg))
     (set-current! 'individual arg)
     (list
Dave Griffiths's avatar
Dave Griffiths committed
649
650
651
      (mupdate 'text-view 'name-display "name")
      (mupdate 'text-view 'family-display "family")
      (mupdate 'text-view 'photo-id-display "photo-id")
652
      (mupdate 'image-view 'photo "photo")))
Dave Griffiths's avatar
Dave Griffiths committed
653
654
655
656
657
658
659
660
661
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "details"
   (build-activity
662
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
663

664
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
665
      (image-view (make-id "photo") "face" (layout 240 320 -1 'centre 10))
666
667
668
      (mbutton
       'change-photo
       (lambda ()
Dave Griffiths's avatar
Dave Griffiths committed
669
670
671
672
         (list
          (take-photo (string-append dirname "files/" (entity-get-value "unique_id") "-face.jpg") photo-code))
         )))

673
     (vert
674
675
676
      (medit-text 'details-name "normal" (lambda (v) (entity-add-value! "name" "varchar" v) '()))
      (medit-text 'details-family "normal" (lambda (v) (entity-add-value! "family" "varchar" v) '()))
      (medit-text 'details-photo-id "normal" (lambda (v) (entity-add-value! "photo-id" "varchar" v) '()))))
Dave Griffiths's avatar
Dave Griffiths committed
677
678
    (mspinner-other 'tribe tribes-list (lambda (v) (msg "tribe now:" v) (entity-add-value! "tribe" "varchar" v) '()))
    (mspinner-other 'sub-tribe subtribe-list (lambda (v) (entity-add-value! "subtribe" "varchar" v) '()))
679
    (horiz
680
681
     (medit-text 'age "numeric" (lambda (v) (entity-add-value! "age" "int" v) '()))
     (mspinner 'gender '(male female) (lambda (v) (entity-add-value! "gender" "varchar" v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
682
     (mspinner 'education education-list (lambda (v) (entity-add-value! "education" "varchar" v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
683
684
    )
   (lambda (activity arg)
685
     (set-current! 'activity-title "Individual details")
Dave Griffiths's avatar
Dave Griffiths committed
686
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
687
688
689
690
691
   (lambda (activity arg)
     (list
      (mupdate 'edit-text 'details-name "name")
      (mupdate 'edit-text 'details-family "family")
      (mupdate 'edit-text 'details-photo-id "photo-id")
692
      (mupdate 'image-view 'photo "photo")
Dave Griffiths's avatar
Dave Griffiths committed
693
694
      (mupdate-spinner-other 'tribe "tribe" tribes-list)
      (mupdate-spinner-other 'sub-tribe "subtribe" subtribe-list)
695
696
      (mupdate 'edit-text 'age "age")
      (mupdate-spinner 'gender "gender" '(male female))
Dave Griffiths's avatar
Dave Griffiths committed
697
      (mupdate-spinner 'education "education" education-list)
Dave Griffiths's avatar
Dave Griffiths committed
698
      ))
Dave Griffiths's avatar
Dave Griffiths committed
699
700
701
702
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
Dave Griffiths's avatar
Dave Griffiths committed
703
704
705
706
707
708
709
   (lambda (activity requestcode resultcode)
     (msg "back from camera")
     (cond
      ((eqv? requestcode photo-code)
       ;; todo: means we save when the camera happens
       ;; need to do this before init is called again in on-start,
       ;; which happens next
710
711
712
713
714
       (let ((unique-id (entity-get-value "unique_id")))
         (entity-add-value! "photo" "file" (string-append unique-id "-face.jpg"))
         (entity-update-values!)
         ;; need to reset the individual from the db now (as update reset it)
         (entity-init! db "sync" "individual" (get-entity-by-unique db "sync" unique-id)))
Dave Griffiths's avatar
Dave Griffiths committed
715
716
717
718
       (list
        (mupdate 'image-view 'photo "photo")))
      (else
       '()))))
Dave Griffiths's avatar
Dave Griffiths committed
719
720
721
722

  (activity
   "family"
   (build-activity
723
724
    (horiz
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
725
726
727
      (mspinner 'head-of-house '(male female) (lambda (v) (entity-add-value! "head-of-house" "varchar" v) '()))
      (mspinner 'marital-status married-list (lambda (v) (entity-add-value! "marital-status" "varchar" v) '()))
      (medit-text 'times-married "numeric" (lambda (v) (entity-add-value! "times-married" "int" v) '())))
728
729
730
731
732
733
734
     (vert
      (mtitle 'spouse)
      (image-view (make-id "spouse-image") "face" (layout 240 320 -1 'centre 0))
      (mbutton 'change-spouse (lambda () '()))))

    (mtitle 'children)
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
735
736
     (medit-text 'children-living "numeric" (lambda (v) (entity-add-value! "children-living" "int" v) '()))
     (medit-text 'children-dead "numeric" (lambda (v) (entity-add-value! "children-dead" "int" v) '())))
737
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
738
739
     (medit-text 'children-together "numeric" (lambda (v) (entity-add-value! "children-together" "int" v) '()))
     (medit-text 'children-apart "numeric" (lambda (v) (entity-add-value! "children-apart" "int" v) '())))
740
    (mspinner-other 'residence-after-marriage '(birthplace spouse-village) (lambda (v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
741
742
    (medit-text 'num-siblings "numeric" (lambda (v) (entity-add-value! "num-siblings" "int" v) '()))
    (medit-text 'birth-order "numeric" (lambda (v) (entity-add-value! "birth-order" "int" v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
743
   (lambda (activity arg)
744
     (set-current! 'activity-title "Individual family")
Dave Griffiths's avatar
Dave Griffiths committed
745
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
746
747
748
749
750
751
752
753
754
755
756
757
758
   (lambda (activity arg)
     (list
      (mupdate-spinner 'head-of-house "head-of-house" '(male female))
      (mupdate-spinner 'marital-status "marital-status" married-list)
      (mupdate 'edit-text 'times-married "times-married")
      ;;(mupdate 'id-spouse "id-spouse")
      (mupdate 'edit-text 'children-living "children-living")
      (mupdate 'edit-text 'children-dead "children-dead")
      (mupdate 'edit-text 'children-together "children-together")
      (mupdate 'edit-text 'children-apart "children-apart")
      (mupdate-spinner 'residence-after-marriage "residence-after-marriage" '(birthplace spouse-village))
      (mupdate 'edit-text 'num-siblings "num-siblings")
      (mupdate 'edit-text 'birth-order "birth-order")))
Dave Griffiths's avatar
Dave Griffiths committed
759
760
761
762
763
764
765
766
767
768
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))


  (activity
   "migration"
   (build-activity
Dave Griffiths's avatar
Dave Griffiths committed
769
770
771
772
773
    (medit-text 'length-time "numeric" (lambda (v) (entity-add-value! "length-time" "int" v) '()))
    (medit-text 'place-of-birth "normal" (lambda (v) (entity-add-value! "place-of-birth" "varchar" v) '()))
    (medit-text 'num-residence-changes "numeric" (lambda (v) (entity-add-value! "num-residence-changes" "int" v) '()))
    (medit-text 'village-visits-month "numeric" (lambda (v) (entity-add-value! "village-visits-month" "int" v) '()))
    (medit-text 'village-visits-year "numeric" (lambda (v) (entity-add-value! "village-visits-year" "int" v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
774
775
    )
   (lambda (activity arg)
776
     (set-current! 'activity-title "Individual migration")
Dave Griffiths's avatar
Dave Griffiths committed
777
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
778
779
780
781
782
783
784
   (lambda (activity arg)
     (list
      (mupdate 'edit-text 'length-time "length-time")
      (mupdate 'edit-text 'place-of-birth "place-of-birth")
      (mupdate 'edit-text 'num-residence-changes "num-residence-changes")
      (mupdate 'edit-text 'village-visits-month "village-visits-month")
      (mupdate 'edit-text 'village-visits-year "village-visits-year")))
Dave Griffiths's avatar
Dave Griffiths committed
785
786
787
788
789
790
791
792
793
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "income"
   (build-activity
Dave Griffiths's avatar
Dave Griffiths committed
794
795
    (mspinner 'occupation '(agriculture gathering labour cows fishing other)
              (lambda (v) (entity-add-value! "occupation" "varchar" v) '()))
796
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
797
798
     (mtoggle-button-scale 'contribute (lambda (v) (entity-add-value! "contribute" "int" v) '()))
     (mtoggle-button-scale 'own-land (lambda (v) (entity-add-value! "own-land" "int" v) '())))
799
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
800
801
     (mtoggle-button-scale 'rent-land (lambda (v) (entity-add-value! "rent-land" "int" v) '()))
     (mtoggle-button-scale 'hire-land (lambda (v) (entity-add-value! "hire-land" "int" v) '())))
802
    (mtitle 'crops)
Dave Griffiths's avatar
Dave Griffiths committed
803
804
805
806
    ;; todo ->
    ;;    (horiz
    ;;     (mtext-scale 'crop) (mtext-scale 'unit) (mtext-scale 'quantity)
    ;;     (mtext-scale 'used-or-eaten) (mtext-scale 'sold) (mtext-scale 'seed))
807
808
    (mspinner-other 'house-type '(concrete tin thatched) (lambda (v) '()))
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
809
810
     (medit-text 'loan "numeric" (lambda (v) (entity-add-value! "loan" "int" v) '()))
     (medit-text 'earning "numeric" (lambda (v) (entity-add-value! "earning" "int" v) '())))
811
812
    (mtext 'in-the-home)
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
813
814
815
     (mtoggle-button-scale 'radio (lambda (v) (entity-add-value! "radio" "int" v) '()))
     (mtoggle-button-scale 'tv (lambda (v) (entity-add-value! "tv" "int" v) '()))
     (mtoggle-button-scale 'mobile (lambda (v) (entity-add-value! "mobile" "int" v) '())))
816
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
817
818
     (medit-text 'visit-market "numeric" (lambda (v) (entity-add-value! "visit-market" "int" v) '()))
     (medit-text 'town-sell "numeric" (lambda (v) (entity-add-value! "town-sell" "int" v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
819
820
    )
   (lambda (activity arg)
821
     (set-current! 'activity-title "Individual income")
Dave Griffiths's avatar
Dave Griffiths committed
822
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
   (lambda (activity arg)
     (list
      (mupdate-spinner 'occupation "occupation" '(agriculture gathering labour cows fishing other))
      (mupdate 'toggle-button 'contribute "contribute")
      (mupdate 'toggle-button 'own-land "own-land")
      (mupdate 'toggle-button 'rent-land "rent-land")
      (mupdate 'toggle-button 'hire-land "hire-land")
      (mupdate-spinner-other 'house-type "house-type" '(concrete tin thatched))
      (mupdate 'edit-text 'loan "loan")
      (mupdate 'edit-text 'earning "earning")
      (mupdate 'toggle-button 'radio "radio")
      (mupdate 'toggle-button 'tv "tv")
      (mupdate 'toggle-button 'mobile "mobile")
      (mupdate 'edit-text 'visit-market "visit-market")
      (mupdate 'edit-text 'town-sell "town-sell")))
Dave Griffiths's avatar
Dave Griffiths committed
838
839
840
841
842
843
844
845
846
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "geneaology"
   (build-activity
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
    (horiz
     (vert
      (mtitle 'mother)
      (image-view (make-id "image") "face" (layout 240 320 -1 'centre 0))
      (mbutton 'change-mother (lambda () '())))
     (vert
      (mtitle 'father)
      (image-view (make-id "image") "face" (layout 240 320 -1 'centre 0))
      (mbutton 'change-father (lambda () '()))))
    (mtitle 'children)
    (horiz
     (medit-text 'name "normal" (lambda (v) '()))
     (mtoggle-button-scale 'alive (lambda (v) '()))
     (mspinner 'sex '(female male) (lambda (v) '()))
     (medit-text 'age "numeric" (lambda (v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
862
863
    )
   (lambda (activity arg)
864
     (set-current! 'activity-title "Individual geneaology")
Dave Griffiths's avatar
Dave Griffiths committed
865
866
867
868
869
870
871
872
873
874
875
876
877
     (activity-layout activity))
   (lambda (activity arg) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "social"
   (build-activity
    )
   (lambda (activity arg)
878
     (set-current! 'activity-title "Individual social network")
Dave Griffiths's avatar
Dave Griffiths committed
879
880
881
882
883
884
885
886
887
888
889
890
891
     (activity-layout activity))
   (lambda (activity arg) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "agreement"
   (build-activity
    )
   (lambda (activity arg)
892
     (set-current! 'activity-title "Individual agreement")
Dave Griffiths's avatar
Dave Griffiths committed
893
894
895
896
897
898
899
900
901
902
903
     (activity-layout activity))
   (lambda (activity arg) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "individual-chooser"
   (build-activity
904
905
906
907
908
909
910
    (vert
     (linear-layout
      (make-id "choose-pics") 'vertical
      (layout 'fill-parent 'wrap-content 0.75 'centre 0)
      (list 0 0 0 0)
      (list))
     (mtext 'filter-stuff))
Dave Griffiths's avatar
Dave Griffiths committed
911
912
    )
   (lambda (activity arg)
913
     (set-current! 'activity-title "Individual chooser")
Dave Griffiths's avatar
Dave Griffiths committed
914
     (activity-layout activity))
915
916
917
918
919
920
921
922
923
924
925
926
927
928
   (lambda (activity arg)
     (list
      (update-widget
       'linear-layout (get-id "choose-pics") 'contents
       (map
        (lambda (e)
          (msg (ktv-get e "gender"))
          (let ((gender (ktv-get e "gender")))
            (text-view
             (make-id (string-append "chooser-" (ktv-get e "unique_id")))
             (string-append (ktv-get e "unique_id") ": " (if (null? gender) "not set" gender))
             30 (layout 'wrap-content 'wrap-content 1 'centre 5))))
        (db-filter db "sync" "individual"
                   (list (make-filter "gender" "varchar" "=" "female")))))))
Dave Griffiths's avatar
Dave Griffiths committed
929
930
931
932
933
934
935
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))


936
937
938
  (activity
   "sync"
   (vert
939
940
941
    (text-view (make-id "sync-title") "Sync database" 40 fillwrap)
    (mtext 'sync-dirty "...")
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
942
     (mtoggle-button-scale 'sync-all (lambda (v) (set-current! 'sync-on v) '()))
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
     (mbutton-scale 'sync-syncall
               (lambda ()
                 (let ((r (append
                           (spit db "sync" (dirty-and-all-entities db "sync"))
                           (spit db "stream" (dirty-and-all-entities db "stream")))))
                   (cons (toast "Uploading data...") r)))))
    (mtitle 'export-data)
    (horiz
     (mbutton-scale 'sync-download
               (lambda ()
                 (debug! (string-append "Downloading whole db"))
                 (append
                 (foldl
                  (lambda (e r)
                    (debug! (string-append "Downloading /sdcard/symbai/" e ".csv"))
                    (cons
                     (http-download
                      (string-append "getting-" e)
                      (string-append url "fn=entity-csv&table=stream&type=" e)
                      (string-append "/sdcard/mongoose/" e ".csv"))
                     r))
                  (list
                   (http-download
                    "getting-db"
                    "http://192.168.2.1:8889/symbai.db"
                    (string-append "/sdcard/symbai/symbai.db"))
                   )
                  entity-types)
                 (list))))
     (mbutton-scale 'sync-export
               (lambda ()
                 (debug! "Sending mail")
                 (list
                  (send-mail
                   ""
                   "From Symbai" "Please find attached your mongoose data"
                   (cons
                    "/sdcard/symbai/symbai.db"
                    (map
                     (lambda (e)
                       (string-append "/sdcard/symbai/" e ".csv"))
                     entity-types))))))
     (mbutton-scale 'email-local
               (lambda ()
                 (debug! "Sending mail")
                 (list
                  (send-mail
                   ""
                   "From symbai" "Please find attached your local data"
                   (list "/sdcard/symbai/local-symbai.db")))))
     )
    (spacer 10)
    (mtitle 'debug)
    (scroll-view-vert
     0 (layout 'fill-parent 200 1 'left 0)
     (list
      (vert
       (debug-text-view (make-id "sync-debug") "..." 15 (layout 'fill-parent 400 1 'left 0)))))
    (spacer 10)
    (horiz
     (mbutton-scale 'sync-back (lambda () (list (finish-activity 1))))
     (mbutton-scale 'sync-prof (lambda () (prof-print) (list))))
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
    )

   (lambda (activity arg)
     (activity-layout activity))
   (lambda (activity arg)
     (set-current! 'sync-on #f)
     (append
      (debug-timer-cb)
      (list
       (update-widget 'debug-text-view (get-id "sync-debug") 'text (get-current 'debug-text ""))
1015
       (update-widget 'text-view (get-id "sync-dirty") 'text (build-dirty db))
1016
1017
1018
1019
1020
1021
       )))
   (lambda (activity) '())
   (lambda (activity) (list (delayed "debug-timer" 1000 (lambda () '()))))
   (lambda (activity) (list (delayed "debug-timer" 1000 (lambda () '()))))
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
1022

Dave Griffiths's avatar
Dave Griffiths committed
1023
1024


1025
1026
1027



Dave Griffiths's avatar
Dave Griffiths committed
1028
  )