Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia
import androidx.appcompat.view.ContextThemeWrapper
import androidx.cardview.widget.CardView
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -213,9 +214,7 @@ import java.util.Date
import java.util.Locale
import java.util.concurrent.ExecutionException
import javax.inject.Inject
import kotlin.collections.set
import kotlin.math.roundToInt
import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia

@AutoInjector(NextcloudTalkApplication::class)
class ChatActivity :
Expand Down Expand Up @@ -347,8 +346,6 @@ class ChatActivity :
}
}

private lateinit var messageInputFragment: MessageInputFragment

val typingParticipants = HashMap<String, TypingParticipant>()

var callStarted = false
Expand Down Expand Up @@ -425,9 +422,9 @@ class ChatActivity :
roomToken
)

messageInputFragment = getMessageInputFragment()
messageInputViewModel = ViewModelProvider(this, viewModelFactory)[MessageInputViewModel::class.java]
messageInputViewModel.setData(chatViewModel.getChatRepository())
val internalId = conversationUser!!.id.toString() + "@" + roomToken
messageInputViewModel.setData(chatViewModel.getChatRepository(), internalId)

binding.progressBar.visibility = View.VISIBLE

Expand All @@ -444,15 +441,6 @@ class ChatActivity :
}
}

private fun getMessageInputFragment(): MessageInputFragment {
val internalId = conversationUser!!.id.toString() + "@" + roomToken
return MessageInputFragment().apply {
arguments = Bundle().apply {
putString(CONVERSATION_INTERNAL_ID, internalId)
}
}
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
val extras: Bundle? = intent.extras
Expand Down Expand Up @@ -506,10 +494,15 @@ class ChatActivity :
}

override fun onSaveInstanceState(outState: Bundle) {
chatViewModel.handleOrientationChange()
chatViewModel.handleSavedInstance()
super.onSaveInstanceState(outState)
}

override fun onRestoreInstanceState(savedInstanceState: Bundle) {
chatViewModel.handleRestoreInstance()
super.onRestoreInstanceState(savedInstanceState)
}

override fun onStop() {
super.onStop()
active = false
Expand Down Expand Up @@ -583,9 +576,13 @@ class ChatActivity :
chatApiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))
participantPermissions = ParticipantPermissions(spreedCapabilities, currentConversation!!)

supportFragmentManager.commit {
setReorderingAllowed(true) // optimizes out redundant replace operations
replace(R.id.fragment_container_activity_chat, messageInputFragment)
if (chatViewModel.getVoiceRecordingLocked.value != true) {
supportFragmentManager.commit {
setReorderingAllowed(true) // optimizes out redundant replace operations
messageInputViewModel.messageInputFragment?.let {
replace(R.id.fragment_container_activity_chat, it)
}
}
}

joinRoomWithPassword()
Expand Down Expand Up @@ -962,7 +959,9 @@ class ChatActivity :
} else {
supportFragmentManager.commit {
setReorderingAllowed(true)
replace(R.id.fragment_container_activity_chat, getMessageInputFragment())
messageInputViewModel.messageInputFragment?.let {
replace(R.id.fragment_container_activity_chat, it)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MediaRecorderManager : LifecycleAwareManager {
}

var currentVoiceRecordFile: String = ""
private var lockRecording = false

enum class MediaRecorderState {
INITIAL,
Expand Down Expand Up @@ -166,6 +167,12 @@ class MediaRecorderManager : LifecycleAwareManager {
}

override fun handleOnStop() {
stop()
if (!lockRecording) {
stop()
}
}

fun lockRecording(shouldLock: Boolean) {
lockRecording = shouldLock
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,13 @@ class ChatViewModel @Inject constructor(
audioFocusRequestManager.audioFocusRequest(request, callback)
}

fun handleOrientationChange() {
fun handleSavedInstance() {
_getCapabilitiesViewState.value = GetCapabilitiesStartState
mediaRecorderManager.lockRecording(true)
}

fun handleRestoreInstance() {
mediaRecorderManager.lockRecording(false)
}

fun getMessageById(url: String, conversationModel: ConversationModel, messageId: Long): Flow<ChatMessage> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
package com.nextcloud.talk.chat.viewmodels

import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.nextcloud.talk.chat.ChatActivity.Companion.CONVERSATION_INTERNAL_ID
import com.nextcloud.talk.chat.MessageInputFragment
import com.nextcloud.talk.chat.data.ChatMessageRepository
import com.nextcloud.talk.chat.data.io.AudioFocusRequestManager
import com.nextcloud.talk.chat.data.io.AudioRecorderManager
Expand Down Expand Up @@ -45,9 +48,17 @@ class MessageInputViewModel @Inject constructor(
lateinit var chatRepository: ChatMessageRepository
lateinit var currentLifeCycleFlag: LifeCycleFlag
val disposableSet = mutableSetOf<Disposable>()
var messageInputFragment: MessageInputFragment? = null

fun setData(chatMessageRepository: ChatMessageRepository) {
fun setData(chatMessageRepository: ChatMessageRepository, internalId: String) {
chatRepository = chatMessageRepository
if (messageInputFragment == null) {
messageInputFragment = MessageInputFragment().apply {
arguments = Bundle().apply {
putString(CONVERSATION_INTERNAL_ID, internalId)
}
}
}
}

override fun onResume(owner: LifecycleOwner) {
Expand Down
Loading