Last active
August 29, 2015 14:04
-
-
Save mfikes/29108e92515f607a43bb to your computer and use it in GitHub Desktop.
FRC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns classroom-checkout.users-master-view-controller | |
(:require [fikesfarm.ios.interop :refer [TableViewDataSource TableViewDelegate FetchedResultsControllerDelegate fetched-results-change-type' table-view-row-animations]] | |
[classroom-checkout.user-detail-view-controller :refer [user]] | |
[classroom-checkout.database :refer [database-manager create-user!]]) | |
(:require-macros [fikesfarm.ios.util :refer [reify]])) | |
(def view-controller (atom nil)) | |
(def table-view (atom nil)) | |
(def edit-bar-button-item (atom nil)) | |
(def add-bar-button-item (atom nil)) | |
(def fetched-results-controller (atom nil)) | |
(defn setup-fetched-results-controller-delegate [] | |
(set! (.-cljsDelegate @fetched-results-controller) | |
(reify FetchedResultsControllerDelegate | |
(did-change-object-at-index-path-for-change-type-new-index-path | |
[_ _ section row change-type new-section new-row] | |
(println "did-change-object-at-index-path-for-change-type-new-index-path") | |
(case (fetched-results-change-type' change-type) | |
:fetched-results-change-insert (.insertRowInSectionWithRowAnimation @table-view new-row new-section (:table-view-row-animation-fade table-view-row-animations)) | |
:fetched-results-change-delete (.deleteRowInSectionWithRowAnimation @table-view row section (:table-view-row-animation-fade table-view-row-animations)) | |
:fetched-results-change-update (.reloadData @table-view) | |
:fetched-results-change-move (do | |
(.deleteRowInSectionWithRowAnimation @table-view row section (:table-view-row-animation-fade table-view-row-animations)) | |
(.insertRowInSectionWithRowAnimation @table-view new-row new-section (:table-view-row-animation-fade table-view-row-animations))))) | |
(did-change-section-at-index-for-change-type [_ _ section-index change-type] | |
(println "did-change-section-at-index-for-change-type") | |
(case (fetched-results-change-type' change-type) | |
:fetched-results-change-insert (.insertSectionWithRowAnimation @table-view section-index (:table-view-row-animation-fade table-view-row-animations)) | |
:fetched-results-change-delete (.deleteSectionWithRowAnimation @table-view section-index (:table-view-row-animation-fade table-view-row-animations)))) | |
(will-change-content [_] | |
(println "will-change-content") | |
(.beginUpdates @table-view)) | |
(did-change-content [_] | |
(println "did-change-content") | |
(.endUpdates @table-view))))) | |
(defn setup-table-view-data-source [] | |
(set! (.-dataSource @table-view) | |
(reify TableViewDataSource | |
(number-of-rows-in-section [_ section] | |
(.numberOfObjectsInSection @fetched-results-controller section)) | |
(init-cell-for-row-at-index-path [_ cell section row] | |
(set! (-> cell .-textLabel .-text) | |
(.-name (.objectAtSectionRow @fetched-results-controller section row)))) | |
(number-of-sections [_] | |
(.sectionCount @fetched-results-controller)) | |
(title-for-header-in-section [_ section] | |
(if (zero? section) "Teachers" "Students"))))) | |
(defn setup-table-view-delegate [] | |
(set! (.-delegate @table-view) | |
(reify TableViewDelegate | |
(did-select-row-at-index-path [_ section row] | |
(println "dsr" section row))))) | |
(defn do-add-bar-button-item-action! [] | |
(println "do-add-bar-button-item-action!") | |
(create-user! "Unnamed" false "123456") | |
(println "added another user")) | |
(defn ^:export view-did-load! [view-controller table-view edit-bar-button-item add-bar-button-item] | |
(reset! classroom-checkout.users-master-view-controller/view-controller view-controller) | |
(reset! classroom-checkout.users-master-view-controller/table-view table-view) | |
(reset! classroom-checkout.users-master-view-controller/edit-bar-button-item edit-bar-button-item) | |
(reset! classroom-checkout.users-master-view-controller/add-bar-button-item add-bar-button-item) | |
(reset! fetched-results-controller (.createFetchedResultsController @database-manager)) | |
(setup-fetched-results-controller-delegate) | |
(.performFetch @fetched-results-controller) | |
(setup-table-view-data-source) | |
(setup-table-view-delegate) | |
(.setActionCallback add-bar-button-item do-add-bar-button-item-action!)) | |
(defn ^:export prepare-for-segue! [identifer destination-view-controller] | |
(println "users-vc prepare for segue" identifer) | |
(let [[section row] (.indexPathForSelectedRow @table-view)] | |
(reset! user (.objectAtSectionRow @fetched-results-controller section row)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment