Skip to content

Commit b2b740b

Browse files
finish styling, pending moving to quo2 and polish functionality
1 parent 8dbcad9 commit b2b740b

File tree

3 files changed

+59
-110
lines changed

3 files changed

+59
-110
lines changed

src/quo2/components/record_audio/soundtrack/view.cljs

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
(def ^:private thumb-dark (js/require "../resources/images/icons2/12x12/thumb-dark.png"))
1111

1212
(defn soundtrack
13-
[{:keys [audio-current-time-ms player-ref seeking-audio?]}]
13+
[{:keys [audio-current-time-ms player-ref style seeking-audio?]}]
1414
[:f>
1515
(fn []
1616
(let [audio-duration-ms (audio/get-player-duration @player-ref)]
1717
[:<>
1818
[slider/slider
1919
{:test-ID "soundtrack"
20-
:style (style/player-slider-container)
20+
:style (merge
21+
(style/player-slider-container)
22+
(or style {}))
2123
:minimum-value 0
2224
:maximum-value audio-duration-ms
2325
:value @audio-current-time-ms

src/status_im/ui/screens/chat/message/audio.cljs

+38-84
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,6 @@
2020
(defonce current-active-state-ref-ref (atom nil))
2121
(defonce progress-timer (atom nil))
2222

23-
(defn start-stop-progress-timer
24-
[{:keys [state-ref progress-ref progress-anim]} start?]
25-
(when @progress-timer
26-
(utils/clear-interval @progress-timer)
27-
(when-not start?
28-
(reset! progress-timer nil)))
29-
(when start?
30-
(when @progress-timer
31-
(utils/clear-interval @progress-timer))
32-
(reset! progress-timer
33-
(utils/set-interval
34-
#(when (and @state-ref (not (:slider-seeking @state-ref)))
35-
(let [ct (audio/get-player-current-time @player-ref)]
36-
(reset! progress-ref ct)
37-
(when ct
38-
(anim/start (anim/timing progress-anim
39-
{:toValue @progress-ref
40-
:duration 100
41-
:easing (.-linear ^js anim/easing)
42-
:useNativeDriver true})))))
43-
100))))
44-
4523
(defn update-state
4624
[{:keys [state-ref progress-ref progress-anim message-id seek-to-ms audio-duration-ms
4725
slider-new-state-seeking? unloaded? error]}]
@@ -90,16 +68,7 @@
9068

9169
; update progress UI on slider release
9270
(when (and (some? slider-new-state-seeking?) (not slider-new-state-seeking?) (some? seek-to-ms))
93-
(reset! (:progress-ref new-state) seek-to-ms))
94-
95-
; update progres anim value to follow the slider
96-
(when (and slider-seeking (some? seek-to-ms))
97-
(anim/set-value (:progress-anim new-state) seek-to-ms))
98-
99-
; on unload, reset values
100-
(when unloaded?
101-
(reset! (:progress-ref new-state) 0)
102-
(anim/set-value (:progress-anim new-state) 0))))
71+
(reset! (:progress-ref new-state) seek-to-ms))))
10372

10473
(defn destroy-player
10574
[{:keys [message-id reloading?]}]
@@ -162,32 +131,32 @@
162131
(update-state params)))))
163132

164133
(defn play-pause
165-
[{:keys [message-id state-ref] :as params} audio]
134+
[{:keys [message-id state-ref] :as params} audio seeking-audio?]
166135
(if (not= message-id @current-player-message-id)
167136
;; player has audio from another message, we need to reload
168137
(reload-player params
169138
audio
170139
;; on-success: audio is loaded, do we have an existing value to seek to?
171-
#(if-some [seek-time (:seek-to-ms @state-ref)]
172-
;; check seek time against real audio duration and play
173-
(let [checked-seek-time (min (audio/get-player-duration @player-ref) seek-time)]
174-
(seek params
175-
checked-seek-time
176-
true
177-
(fn [] (play-pause params audio))))
178-
179-
;; nothing to seek to, play
180-
(play-pause params audio)))
140+
(fn []
141+
(reset! seeking-audio? false)
142+
(if-some [seek-time (:seek-to-ms @state-ref)]
143+
;; check seek time against real audio duration and play
144+
(let [checked-seek-time (min (audio/get-player-duration @player-ref) seek-time)]
145+
(seek params
146+
checked-seek-time
147+
true
148+
(fn [] (play-pause params audio))))
149+
150+
;; nothing to seek to, play
151+
(play-pause params audio))))
181152

182153
;; loaded audio corresponds to current message we can play
183154
(when @player-ref
184155
(audio/toggle-playpause-player
185156
@player-ref
186157
#(do
187-
(start-stop-progress-timer params true)
188158
(update-state params))
189159
#(do
190-
(start-stop-progress-timer params false)
191160
(update-state params))
192161
#(update-state (merge params {:error (:message %)}))))))
193162

@@ -199,64 +168,49 @@
199168
[quo/icon
200169
(case (:general @state-ref)
201170
:preparing :i/loading
202-
:playing :i/play-audio
203-
:i/pause-audio)
171+
:playing :i/pause-audio
172+
:i/play-audio)
204173
{:size 20
205174
:accessibility-label :play-pause-audio-message-button
206175
:color colors/white}]])
207176

208177
(defview message-content
209178
[{:keys [audio audio-duration-ms message-id]}]
210-
(letsubs [state (reagent/atom nil)
211-
progress (reagent/atom 0)
212-
progress-anim (anim/create-value 0)
213-
width [:dimensions/window-width]]
179+
(letsubs [state (reagent/atom nil)
180+
progress (reagent/atom 0)
181+
seeking-audio? (reagent/atom false)]
214182
{:component-did-mount (fn []
215183
(update-state {:state-ref state
216184
:audio-duration-ms audio-duration-ms
217185
:message-id message-id
218186
:unloaded? true
219-
:progress-ref progress
220-
:progress-anim progress-anim}))
187+
:progress-ref progress}))
221188
:component-will-unmount (fn []
222189
(destroy-player {:state-ref state :message-id message-id})
223190
(when (= @current-player-message-id message-id)
224191
(reset! current-active-state-ref-ref nil)
225192
(reset! current-player-message-id nil))
226193
(reset! state nil))}
227194

228-
(let [base-params {:state-ref state
229-
:message-id message-id
230-
:progress-ref progress
231-
:progress-anim progress-anim}]
195+
(let [base-params {:state-ref state
196+
:message-id message-id
197+
:progress-ref progress}]
232198
(if (= (:general @state) :error)
233199
[react/text
234200
{:style {:typography :main-medium
235201
:margin-bottom 16}} (:error-msg @state)]
236-
[react/view {:style {:width 295
237-
:height 56
238-
:border-radius 12
239-
:border-width 1
240-
:padding 12
241-
:align-items :center
242-
:border-color (colors/theme-colors colors/neutral-20 colors/neutral-80)
243-
:background-color (colors/theme-colors colors/neutral-5 colors/neutral-80-opa-40)}}
244-
[react/view style/play-pause-slider-container
245-
[play-pause-button state #(play-pause base-params audio)]
246-
[react/view style/slider-container
247-
[quo/soundtrack
248-
{:audio-current-time-ms (:progress-ref base-params)
249-
:player-ref player-ref
250-
:seeking-audio? (:slider-seeking @state)}]]]
251-
252-
[react/view style/times-container
253-
[quo/text {:style (style/timestamp)
254-
:accessibility-label :audio-duration-label
255-
:weight :regular
256-
:size :paragraph-1}
257-
(let [time (cond
258-
(or (:slider-seeking @state) (> (:seek-to-ms @state) 0)) (:seek-to-ms @state)
259-
(#{:playing :paused :seeking} (:general @state)) @progress
260-
:else (:duration @state))
261-
s (quot time 1000)]
262-
(gstring/format "%02d:%02d" (quot s 60) (mod s 60)))]]]))))
202+
[react/view {:style (style/container)}
203+
[play-pause-button state #(play-pause base-params audio seeking-audio?)]
204+
[quo/soundtrack
205+
{:style style/slider-container
206+
:audio-current-time-ms progress
207+
:player-ref player-ref
208+
:seeking-audio? seeking-audio?}]
209+
[quo/text
210+
{:style style/timestamp
211+
:accessibility-label :audio-duration-label
212+
:weight :medium
213+
:size :paragraph-2}
214+
(let [duration-ms (:duration @state)
215+
duration-secs (quot duration-ms 1000)]
216+
(gstring/format "%02d:%02d" (quot duration-secs 60) (mod duration-secs 60)))]]))))

src/status_im/ui/screens/chat/styles/message/audio.cljs

+17-24
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,27 @@
66
[quo2.theme :as theme]))
77

88
(defn container
9-
[window-width]
10-
{:width (* window-width 0.60)
11-
:flex-direction :column
12-
:justify-content :space-between})
9+
[]
10+
{:width 295
11+
:height 56
12+
:border-radius 12
13+
:border-width 1
14+
:padding 12
15+
:flex-direction :row
16+
:align-items :center
17+
:justify-content :space-between
18+
:border-color (colors/theme-colors colors/neutral-20 colors/neutral-80)
19+
:background-color (colors/theme-colors colors/neutral-5 colors/neutral-80-opa-40)})
1320

1421
(def play-pause-slider-container
1522
{:flex-direction :row
1623
:align-items :center})
1724

1825
(def slider-container
19-
{:flex-direction :column
20-
:align-items :stretch
21-
:flex-grow 1})
22-
23-
(defn slider
24-
[]
25-
{:style (merge {:margin-left 12
26-
:height 34}
27-
(when platform/ios? {:margin-bottom 4}))
28-
:thumb-tint-color colors-old/white
29-
:minimum-track-tint-color colors-old/white
30-
:maximum-track-tint-color colors-old/white-transparent})
26+
{:position :absolute
27+
:left 60
28+
:right 71
29+
:bottom nil})
3130

3231
(defn play-pause-container
3332
[]
@@ -38,11 +37,5 @@
3837
:align-items :center
3938
:justify-content :center})
4039

41-
(def times-container
42-
{:flex-direction :row
43-
:justify-content :space-between})
44-
45-
(defn timestamp
46-
[]
47-
(merge (message.style/audio-message-timestamp-text)
48-
{:margin-left 40}))
40+
(def timestamp
41+
{:margin-left 4})

0 commit comments

Comments
 (0)