mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-24 22:17:25 +00:00
feat: update kotlin and add in call view model and more management functions
This commit is contained in:
@@ -14,6 +14,7 @@ import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider
|
||||
import org.thoughtcrime.securesms.crypto.DatabaseSecretProvider
|
||||
import org.thoughtcrime.securesms.database.*
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.webrtc.data.SessionCallDataProvider
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@@ -121,6 +122,10 @@ object DatabaseModule {
|
||||
@Singleton
|
||||
fun provideStorage(@ApplicationContext context: Context, openHelper: SQLCipherOpenHelper) = Storage(context,openHelper)
|
||||
|
||||
// @Provides
|
||||
// @Singleton
|
||||
// fun provideCallDataProvider(storage: Storage) = SessionCallDataProvider(storage)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAttachmentProvider(@ApplicationContext context: Context, openHelper: SQLCipherOpenHelper): MessageDataProvider = DatabaseAttachmentProvider(context, openHelper)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package org.thoughtcrime.securesms.service
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@@ -36,6 +37,10 @@ class WebRtcCallService: Service(), SignalAudioManager.EventListener {
|
||||
|
||||
private const val INVALID_NOTIFICATION_ID = -1
|
||||
|
||||
private var lastNotificationId: Int = INVALID_NOTIFICATION_ID
|
||||
private var lastNotification: Notification? = null
|
||||
|
||||
|
||||
fun update(context: Context, type: Int, callId: UUID) {
|
||||
val intent = Intent(context, WebRtcCallService::class.java)
|
||||
.setAction(ACTION_UPDATE)
|
||||
|
@@ -6,12 +6,32 @@ import org.thoughtcrime.securesms.database.Storage
|
||||
import java.util.concurrent.Executors
|
||||
import javax.inject.Inject
|
||||
|
||||
class CallManager @Inject constructor(
|
||||
private val context: Context,
|
||||
private val storage: Storage,
|
||||
) {
|
||||
class CallManager(private val context: Context,
|
||||
private val storage: Storage) {
|
||||
|
||||
private val serviceExecutor = Executors.newSingleThreadExecutor()
|
||||
private val networkExecutor = Executors.newSingleThreadExecutor()
|
||||
|
||||
|
||||
|
||||
fun networkChange(networkAvailable: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
fun acceptCall() {
|
||||
|
||||
}
|
||||
|
||||
fun declineCall() {
|
||||
|
||||
}
|
||||
|
||||
fun setAudioEnabled(isEnabled: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
fun setVideoEnabled(isEnabled: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.webrtc
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class CallViewModel @Inject constructor(
|
||||
private val callManager: CallManager
|
||||
): ViewModel() {
|
||||
|
||||
sealed class StateEvent {
|
||||
data class AudioEnabled(val isEnabled: Boolean): StateEvent()
|
||||
data class VideoEnabled(val isEnabled: Boolean): StateEvent()
|
||||
}
|
||||
|
||||
private val audioEnabledState = MutableStateFlow(StateEvent.AudioEnabled(true))
|
||||
private val videoEnabledState = MutableStateFlow(StateEvent.VideoEnabled(false))
|
||||
|
||||
// set up listeners for establishing connection toggling video / audio
|
||||
init {
|
||||
audioEnabledState.onEach { (enabled) -> callManager.setAudioEnabled(enabled) }
|
||||
.launchIn(viewModelScope)
|
||||
videoEnabledState.onEach { (enabled) -> callManager.setVideoEnabled(enabled) }
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package org.thoughtcrime.securesms.webrtc
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.telephony.PhoneStateListener
|
||||
import android.telephony.TelephonyManager
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.session.libsignal.utilities.Log
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
class HangUpRtcOnPstnCallAnsweredListener(private val hangupListener: ()->Unit): PhoneStateListener() {
|
||||
|
||||
companion object {
|
||||
private val TAG = Log.tag(HangUpRtcOnPstnCallAnsweredListener::class.java)
|
||||
}
|
||||
|
||||
override fun onCallStateChanged(state: Int, phoneNumber: String?) {
|
||||
super.onCallStateChanged(state, phoneNumber)
|
||||
if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
|
||||
hangupListener()
|
||||
Log.i(TAG, "Device phone call ended Session call.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AndroidEntryPoint
|
||||
class NetworkReceiver: BroadcastReceiver() {
|
||||
|
||||
@Inject
|
||||
lateinit var callManager: CallManager
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
class PowerButtonReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
class ProximityLockRelease: Thread.UncaughtExceptionHandler {
|
||||
override fun uncaughtException(t: Thread, e: Throwable) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package org.thoughtcrime.securesms.webrtc.data
|
||||
|
||||
import org.session.libsession.database.CallDataProvider
|
||||
import org.session.libsession.database.StorageProtocol
|
||||
import javax.inject.Inject
|
||||
|
||||
class SessionCallDataProvider @Inject constructor(private val storage: StorageProtocol): CallDataProvider {
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user