mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
using instance based playback activity listener and updating param name to give more context
This commit is contained in:
parent
6d2dc20ad1
commit
28af0a637f
2 changed files with 17 additions and 17 deletions
|
@ -48,8 +48,6 @@ import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val ROOM_DETAILS_SCREEN_ON_TRACKER = "room_details_screen_on"
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class RoomDetailActivity :
|
class RoomDetailActivity :
|
||||||
VectorBaseActivity<ActivityRoomDetailBinding>(),
|
VectorBaseActivity<ActivityRoomDetailBinding>(),
|
||||||
|
@ -77,6 +75,13 @@ class RoomDetailActivity :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val playbackActivityListener = VoiceMessagePlaybackTracker.ActivityListener { isPlayingOrRecording ->
|
||||||
|
when (isPlayingOrRecording) {
|
||||||
|
true -> keepScreenOn()
|
||||||
|
false -> endKeepScreenOn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getCoordinatorLayout() = views.coordinatorLayout
|
override fun getCoordinatorLayout() = views.coordinatorLayout
|
||||||
|
|
||||||
@Inject lateinit var playbackTracker: VoiceMessagePlaybackTracker
|
@Inject lateinit var playbackTracker: VoiceMessagePlaybackTracker
|
||||||
|
@ -122,12 +127,7 @@ class RoomDetailActivity :
|
||||||
}
|
}
|
||||||
views.drawerLayout.addDrawerListener(drawerListener)
|
views.drawerLayout.addDrawerListener(drawerListener)
|
||||||
|
|
||||||
playbackTracker.trackActivity(ROOM_DETAILS_SCREEN_ON_TRACKER) { isActive ->
|
playbackTracker.trackActivity(playbackActivityListener)
|
||||||
when (isActive) {
|
|
||||||
true -> keepScreenOn()
|
|
||||||
false -> endKeepScreenOn()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRoomLeft(roomLeft: RequireActiveMembershipViewEvents.RoomLeft) {
|
private fun handleRoomLeft(roomLeft: RequireActiveMembershipViewEvents.RoomLeft) {
|
||||||
|
@ -150,7 +150,7 @@ class RoomDetailActivity :
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
supportFragmentManager.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks)
|
supportFragmentManager.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks)
|
||||||
views.drawerLayout.removeDrawerListener(drawerListener)
|
views.drawerLayout.removeDrawerListener(drawerListener)
|
||||||
playbackTracker.unTrackActivity(ROOM_DETAILS_SCREEN_ON_TRACKER)
|
playbackTracker.unTrackActivity(playbackActivityListener)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,15 +26,15 @@ class VoiceMessagePlaybackTracker @Inject constructor() {
|
||||||
|
|
||||||
private val mainHandler = Handler(Looper.getMainLooper())
|
private val mainHandler = Handler(Looper.getMainLooper())
|
||||||
private val listeners = mutableMapOf<String, Listener>()
|
private val listeners = mutableMapOf<String, Listener>()
|
||||||
private val activityListeners = mutableMapOf<String, ActivityListener>()
|
private val activityListeners = mutableListOf<ActivityListener>()
|
||||||
private val states = mutableMapOf<String, Listener.State>()
|
private val states = mutableMapOf<String, Listener.State>()
|
||||||
|
|
||||||
fun trackActivity(key: String, listener: ActivityListener) {
|
fun trackActivity(listener: ActivityListener) {
|
||||||
activityListeners[key] = listener
|
activityListeners.add(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unTrackActivity(id: String) {
|
fun unTrackActivity(listener: ActivityListener) {
|
||||||
activityListeners.remove(id)
|
activityListeners.remove(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun track(id: String, listener: Listener) {
|
fun track(id: String, listener: Listener) {
|
||||||
|
@ -61,10 +61,10 @@ class VoiceMessagePlaybackTracker @Inject constructor() {
|
||||||
*/
|
*/
|
||||||
private fun setState(key: String, state: Listener.State) {
|
private fun setState(key: String, state: Listener.State) {
|
||||||
states[key] = state
|
states[key] = state
|
||||||
val isActive = states.values.any { it is Listener.State.Playing || it is Listener.State.Recording }
|
val isPlayingOrRecording = states.values.any { it is Listener.State.Playing || it is Listener.State.Recording }
|
||||||
mainHandler.post {
|
mainHandler.post {
|
||||||
listeners[key]?.onUpdate(state)
|
listeners[key]?.onUpdate(state)
|
||||||
activityListeners.forEach { it.value.onUpdate(isActive) }
|
activityListeners.forEach { it.onUpdate(isPlayingOrRecording) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +138,6 @@ class VoiceMessagePlaybackTracker @Inject constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun interface ActivityListener {
|
fun interface ActivityListener {
|
||||||
fun onUpdate(isActive: Boolean)
|
fun onUpdate(isPlayingOrRecording: Boolean)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue