Merge pull request #65 from status-im/my-profile

My profile view

Former-commit-id: 8c386f2175
This commit is contained in:
Jarrad 2016-05-12 11:54:02 +02:00
commit 9a4c349b06
17 changed files with 289 additions and 131 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

View File

@ -15,7 +15,7 @@
[syng-im.components.chats.new-group :refer [new-group]] [syng-im.components.chats.new-group :refer [new-group]]
[syng-im.components.chat.new-participants :refer [new-participants]] [syng-im.components.chat.new-participants :refer [new-participants]]
[syng-im.components.chat.remove-participants :refer [remove-participants]] [syng-im.components.chat.remove-participants :refer [remove-participants]]
[syng-im.components.profile :refer [profile]] [syng-im.components.profile :refer [profile my-profile]]
[syng-im.utils.logging :as log] [syng-im.utils.logging :as log]
[syng-im.utils.utils :refer [toast]] [syng-im.utils.utils :refer [toast]]
[syng-im.navigation :as nav] [syng-im.navigation :as nav]
@ -48,7 +48,8 @@
:new-group [new-group] :new-group [new-group]
:contact-list [contact-list] :contact-list [contact-list]
:chat [chat] :chat [chat]
:profile [profile])))) :profile [profile]
:my-profile [my-profile]))))
(defn init [] (defn init []
(dispatch-sync [:initialize-db]) (dispatch-sync [:initialize-db])

View File

@ -7,7 +7,6 @@
icon icon
navigator navigator
touchable-highlight touchable-highlight
toolbar-android
list-view list-view
list-item list-item
android?]] android?]]
@ -18,6 +17,7 @@
[syng-im.utils.listview :refer [to-datasource [syng-im.utils.listview :refer [to-datasource
to-datasource2]] to-datasource2]]
[syng-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [syng-im.components.invertible-scroll-view :refer [invertible-scroll-view]]
[syng-im.components.toolbar :refer [toolbar]]
[syng-im.components.chat.chat-message :refer [chat-message]] [syng-im.components.chat.chat-message :refer [chat-message]]
[syng-im.components.chat.chat-message-new :refer [chat-message-new]])) [syng-im.components.chat.chat-message-new :refer [chat-message-new]]))
@ -81,20 +81,39 @@
[view nil]] [view nil]]
items]) items])
(defn action-view [{:keys [icon-style handler title subtitle] (defn action-view [{:keys [icon-style custom-icon handler title subtitle]
icon-name :icon}] icon-name :icon}]
[touchable-highlight {:on-press (fn [] [touchable-highlight {:on-press (fn []
(dispatch [:set-show-actions false]) (dispatch [:set-show-actions false])
(handler))} (when handler
(handler)))}
[view st/action-icon-row [view st/action-icon-row
[view st/action-icon-view [view st/action-icon-view
[icon icon-name icon-style]] (or custom-icon
[icon icon-name icon-style])]
[view st/action-view [view st/action-view
[text {:style st/action-title} title] [text {:style st/action-title} title]
(when-let [subtitle subtitle] (when-let [subtitle subtitle]
[text {:style st/action-subtitle} [text {:style st/action-subtitle}
subtitle])]]]) subtitle])]]])
(defn menu-item-contact-photo [{:keys [photo-path]}]
[image {:source (if (s/blank? photo-path)
res/user-no-photo
{:uri photo-path})
:style st/menu-item-profile-contact-photo}])
(defn menu-item-contact-online [{:keys [online]}]
(when online
[view st/menu-item-profile-online-view
[view st/menu-item-profile-online-dot-left]
[view st/menu-item-profile-online-dot-right]]))
(defn menu-item-icon-profile []
[view st/icon-view
[menu-item-contact-photo {}]
[menu-item-contact-online {:online true}]])
(defn actions-list-view [] (defn actions-list-view []
(let [{:keys [group-chat chat-id]} (let [{:keys [group-chat chat-id]}
(subscribe [:chat-properties [:group-chat :chat-id]])] (subscribe [:chat-properties [:group-chat :chat-id]])]
@ -125,10 +144,31 @@
:height 13} :height 13}
:handler (fn [])}] :handler (fn [])}]
[{:title "Profile" [{:title "Profile"
:custom-icon [menu-item-icon-profile]
:icon :menu_group :icon :menu_group
:icon-style {:width 25 :icon-style {:width 25
:height 19} :height 19}
:handler #(dispatch [:show-profile @chat-id])}])] :handler #(dispatch [:show-profile @chat-id])}
{:title "Search chat"
:subtitle "!not implemented"
:icon :search_gray_copy
:icon-style {:width 17
:height 17}
:handler nil #_#(dispatch
[:show-remove-participants navigator])}
{:title "Notifications and sounds"
:subtitle "!not implemented"
:icon :muted
:icon-style {:width 18
:height 21}
:handler nil #_#(dispatch [:leave-group-chat
navigator])}
{:title "Settings"
:subtitle "!not implemented"
:icon :settings
:icon-style {:width 20
:height 13}
:handler (fn [])}])]
[view st/actions-wrapper [view st/actions-wrapper
[view st/actions-separator] [view st/actions-separator]
[view st/actions-view [view st/actions-view
@ -139,16 +179,11 @@
[overlay {:on-click-outside #(dispatch [:set-show-actions false])} [overlay {:on-click-outside #(dispatch [:set-show-actions false])}
[actions-list-view]]) [actions-list-view]])
(defn toolbar [] (defn toolbar-content []
(let [{:keys [group-chat name contacts]} (let [{:keys [group-chat name contacts]}
(subscribe [:chat-properties [:group-chat :name :contacts]]) (subscribe [:chat-properties [:group-chat :name :contacts]])
show-actions (subscribe [:show-actions])] show-actions (subscribe [:show-actions])]
(fn [] (fn []
[view st/toolbar-view
(when (not @show-actions)
[touchable-highlight {:on-press #(dispatch [:navigate-back])}
[view st/icon-view
[icon :back st/back-icon]]])
[view (st/chat-name-view @show-actions) [view (st/chat-name-view @show-actions)
[text {:style st/chat-name-text} [text {:style st/chat-name-text}
(or @name "Chat name")] (or @name "Chat name")]
@ -162,7 +197,11 @@
" members" " members"
" member") " member")
", " cnt " active"))]] ", " cnt " active"))]]
[text {:style st/last-activity} "Active a minute ago"])] [text {:style st/last-activity} "Active a minute ago"])])))
(defn toolbar-action []
(let [show-actions (subscribe [:show-actions])]
(fn []
(if @show-actions (if @show-actions
[touchable-highlight [touchable-highlight
{:on-press #(dispatch [:set-show-actions false])} {:on-press #(dispatch [:set-show-actions false])}
@ -172,7 +211,16 @@
{:on-press #(dispatch [:set-show-actions true])} {:on-press #(dispatch [:set-show-actions true])}
[view st/icon-view [view st/icon-view
[chat-photo {}] [chat-photo {}]
[contact-online {:online true}]]])]))) [contact-online {:online true}]]]))))
(defn chat-toolbar []
(let [{:keys [group-chat name contacts]}
(subscribe [:chat-properties [:group-chat :name :contacts]])
show-actions (subscribe [:show-actions])]
(fn []
[toolbar {:hide-nav? @show-actions
:custom-content [toolbar-content]
:custom-action [toolbar-action]}])))
(defn messages-view [group-chat] (defn messages-view [group-chat]
(let [messages (subscribe [:chat :messages]) (let [messages (subscribe [:chat :messages])
@ -191,7 +239,7 @@
show-actions-atom (subscribe [:show-actions])] show-actions-atom (subscribe [:show-actions])]
(fn [] (fn []
[view st/chat-view [view st/chat-view
[toolbar] [chat-toolbar]
[messages-view @group-chat] [messages-view @group-chat]
(when @group-chat [typing-all]) (when @group-chat [typing-all])
(when is-active [chat-message-new]) (when is-active [chat-message-new])

View File

@ -167,3 +167,34 @@
(def overlay-highlight (def overlay-highlight
{:flex 1}) {:flex 1})
;;----- Menu item Profile ----------------
(def menu-item-profile-contact-photo
{:marginTop 13
:marginLeft 16
:borderRadius 50
:width 24
:height 24})
(def menu-item-profile-online-view
{:position :absolute
:top 26
:left 29
:width 15
:height 15
:borderRadius 50
:backgroundColor online-color
:borderWidth 2
:borderColor color-white})
(def menu-item-profile-online-dot
{:position :absolute
:top 4
:width 3
:height 3
:borderRadius 50
:backgroundColor color-white})
(def menu-item-profile-online-dot-left (merge menu-item-profile-online-dot {:left 1.7}))
(def menu-item-profile-online-dot-right (merge menu-item-profile-online-dot {:left 6.3}))

View File

@ -25,6 +25,7 @@
[]))) [])))
(defn title-content [showSearch] (defn title-content [showSearch]
[view st/discovery-toolbar-content
(if showSearch (if showSearch
[text-input {:underlineColorAndroid "transparent" [text-input {:underlineColorAndroid "transparent"
:style st/discovery-search-input :style st/discovery-search-input
@ -35,7 +36,7 @@
hashtags (get-hashtags search)] hashtags (get-hashtags search)]
(dispatch [:broadcast-status search hashtags])))}] (dispatch [:broadcast-status search hashtags])))}]
[view [view
[text {:style st/discovery-title} "Discover"]])) [text {:style st/discovery-title} "Discover"]])])
(defn create-fake-discovery [] (defn create-fake-discovery []
(let [number (rand-int 999)] (let [number (rand-int 999)]
@ -61,7 +62,7 @@
:height 12}} :height 12}}
:handler create-fake-discovery} :handler create-fake-discovery}
:title "Add Participants" :title "Add Participants"
:content (title-content @showSearch) :custom-content [title-content @showSearch]
:action {:image {:source {:uri "icon_search"} :action {:image {:source {:uri "icon_search"}
:style {:width 17 :style {:width 17
:height 17}} :height 17}}

View File

@ -24,6 +24,11 @@
;; discovery.cljs ;; discovery.cljs
(def discovery-toolbar-content
{:flex 1
:alignItems :center
:justifyContent :center})
(def discovery-search-input (def discovery-search-input
{:flex 1 {:flex 1
:marginLeft 18 :marginLeft 18

View File

@ -36,16 +36,18 @@
name]]) name]])
(defn drawer-menu [navigator] (defn drawer-menu [navigator]
(let [username (subscribe [:username])]
(fn [navigator]
[view st/drawer-menu [view st/drawer-menu
[view st/user-photo-container [view st/user-photo-container
[user-photo {}]] [user-photo {}]]
[view st/name-container [view st/name-container
[text {:style st/name-text} [text {:style st/name-text}
"Status"]] @username]]
[view st/menu-items-container [view st/menu-items-container
[menu-item {:name "Profile" [menu-item {:name "Profile"
:handler (fn [] :handler (fn []
(dispatch [:show-profile navigator]))}] (dispatch [:show-my-profile]))}]
[menu-item {:name "Settings" [menu-item {:name "Settings"
:handler (fn [] :handler (fn []
;; TODO not implemented ;; TODO not implemented
@ -68,10 +70,10 @@
;; TODO not implemented ;; TODO not implemented
)} )}
[text {:style st/switch-users-text} [text {:style st/switch-users-text}
"Switch users"]]]]) "Switch users"]]]])))
(defn drawer-view [{:keys [navigator]} items] (defn drawer-view [{:keys [navigator]} items]
[drawer-layout-android {:drawerWidth 300 [drawer-layout-android {:drawerWidth 260
:drawerPosition js/React.DrawerLayoutAndroid.positions.Left :drawerPosition js/React.DrawerLayoutAndroid.positions.Left
:render-navigation-view #(r/as-element [drawer-menu navigator]) :render-navigation-view #(r/as-element [drawer-menu navigator])
:ref (fn [drawer] :ref (fn [drawer]

View File

@ -41,10 +41,10 @@
(let [contact (subscribe [:contact])] (let [contact (subscribe [:contact])]
(fn [] (fn []
[scroll-view {:style st/profile} [scroll-view {:style st/profile}
[touchable-highlight {:style st/profile-back-button-touchable [touchable-highlight {:style st/back-btn-touchable
:on-press #(dispatch [:navigate-back])} :on-press #(dispatch [:navigate-back])}
[view st/profile-back-button-container [view st/back-btn-container
[icon :back st/profile-back-button-icon]]] [icon :back st/back-btn-icon]]]
[view st/status-block [view st/status-block
[view st/user-photo-container [view st/user-photo-container
[user-photo {}] [user-photo {}]
@ -74,3 +74,36 @@
[touchable-opacity {} [touchable-opacity {}
[text {:style st/report-user-text} [text {:style st/report-user-text}
"REPORT USER"]]]]]))) "REPORT USER"]]]]])))
(defn my-profile []
(let [username (subscribe [:username])
phone-number (subscribe [:phone-number])
email (subscribe [:email])
status (subscribe [:status])]
(fn []
[scroll-view {:style st/profile}
[touchable-highlight {:style st/back-btn-touchable
:on-press #(dispatch [:navigate-back])}
[view st/back-btn-container
[icon :back st/back-btn-icon]]]
[touchable-highlight {:style st/actions-btn-touchable
:on-press (fn []
;; TODO not implemented
)}
[view st/actions-btn-container
[icon :dots st/actions-btn-icon]]]
[view st/status-block
[view st/user-photo-container
[user-photo {}]
[user-online {:online true}]]
[text {:style st/user-name}
@username]
[text {:style st/status}
@status]]
[view st/profile-properties-container
[profile-property-view {:name "Username"
:value @username}]
[profile-property-view {:name "Phone number"
:value @phone-number}]
[profile-property-view {:name "Email"
:value @email}]]])))

View File

@ -68,19 +68,33 @@
:backgroundColor color-white :backgroundColor color-white
:flexDirection :column}) :flexDirection :column})
(def profile-back-button-touchable (def back-btn-touchable
{:position :absolute}) {:position :absolute})
(def profile-back-button-container (def back-btn-container
{:width 56 {:width 56
:height 56}) :height 56})
(def profile-back-button-icon (def back-btn-icon
{:marginTop 21 {:marginTop 21
:marginLeft 23 :marginLeft 23
:width 8 :width 8
:height 14}) :height 14})
(def actions-btn-touchable
{:position :absolute
:right 0})
(def actions-btn-container
{:width 56
:height 56
:alignItems :center
:justifyContent :center})
(def actions-btn-icon
{:width 4
:height 16})
(def status-block (def status-block
{:alignSelf :center {:alignSelf :center
:alignItems :center :alignItems :center

View File

@ -17,12 +17,14 @@
[syng-im.utils.listview :refer [to-realm-datasource]] [syng-im.utils.listview :refer [to-realm-datasource]]
[reagent.core :as r])) [reagent.core :as r]))
(defn toolbar [{:keys [navigator title nav-action action background-color content style]}] (defn toolbar [{:keys [navigator title nav-action hide-nav? action custom-action
background-color custom-content style]}]
(let [style (merge {:flexDirection "row" (let [style (merge {:flexDirection "row"
:backgroundColor (or background-color toolbar-background1) :backgroundColor (or background-color toolbar-background1)
:height 56 :height 56
:elevation 2} style)] :elevation 2} style)]
[view {:style style} [view {:style style}
(when (not hide-nav?)
(if nav-action (if nav-action
[touchable-highlight {:on-press (:handler nav-action)} [touchable-highlight {:on-press (:handler nav-action)}
[view {:width 56 [view {:width 56
@ -37,12 +39,8 @@
:style {:marginTop 21 :style {:marginTop 21
:marginLeft 23 :marginLeft 23
:width 8 :width 8
:height 14}}]]]) :height 14}}]]]))
(if content (or custom-content
[view {:style {:flex 1
:alignItems "center"
:justifyContent "center"}}
content]
[view {:style {:flex 1 [view {:style {:flex 1
:alignItems "center" :alignItems "center"
:justifyContent "center"}} :justifyContent "center"}}
@ -51,10 +49,12 @@
:fontSize 16 :fontSize 16
:fontFamily font}} :fontFamily font}}
title]]) title]])
custom-action
(when action
[touchable-highlight {:on-press (:handler action)} [touchable-highlight {:on-press (:handler action)}
[view {:width 56 [view {:width 56
:height 56 :height 56
:alignItems "center" :alignItems "center"
:justifyContent "center"} :justifyContent "center"}
[image (:image action)]]]])) [image (:image action)]]])]))

View File

@ -7,8 +7,7 @@
(def default-view :chat-list) (def default-view :chat-list)
;; initial state of app-db ;; initial state of app-db
(def app-db {:greeting "Hello Clojure in iOS and Android!" (def app-db {:identity-password "replace-me-with-user-entered-password"
:identity-password "replace-me-with-user-entered-password"
:identity "me" :identity "me"
:contacts [] :contacts []
:current-chat-id "console" :current-chat-id "console"
@ -22,7 +21,11 @@
:signed-up false :signed-up false
:view-id default-view :view-id default-view
:navigation-stack (list default-view) :navigation-stack (list default-view)
:name "My Name" ;; TODO fix hardcoded values
:username "My Name"
:phone-number "3147984309"
:email "myemail@gmail.com"
:status "Hi, this is my status"
:current-tag nil}) :current-tag nil})
(def protocol-initialized-path [:protocol-initialized]) (def protocol-initialized-path [:protocol-initialized])

View File

@ -457,6 +457,12 @@
(dispatch [:navigate-to :profile]) (dispatch [:navigate-to :profile])
db))) db)))
(register-handler :show-my-profile
(fn [db [action]]
(log/debug action)
(dispatch [:navigate-to :my-profile])
db))
;; -- Chats -------------------------------------------------------------- ;; -- Chats --------------------------------------------------------------
(register-handler :show-chat (register-handler :show-chat

View File

@ -94,11 +94,25 @@
;; -- User data -------------------------------------------------------------- ;; -- User data --------------------------------------------------------------
;; (register-sub (register-sub :username
;; :get-user-phone-number (fn [db _]
;; (fn [db _] (reaction
;; (reaction (get @db :username))))
;; (get @db :user-phone-number))))
(register-sub :phone-number
(fn [db _]
(reaction
(get @db :phone-number))))
(register-sub :email
(fn [db _]
(reaction
(get @db :email))))
(register-sub :status
(fn [db _]
(reaction
(get @db :status))))
(register-sub (register-sub
:get-user-identity :get-user-identity