mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Properly close any sliding pane child fragment when default account changes
This commit is contained in:
parent
c8b1231322
commit
bf089193d4
14 changed files with 91 additions and 68 deletions
|
|
@ -85,17 +85,6 @@ class ConversationsListFragment : AbstractTopBarFragment() {
|
|||
"$TAG Default account changed, updating avatar in top bar & re-computing conversations"
|
||||
)
|
||||
listViewModel.applyFilter()
|
||||
|
||||
val slidingPane = binding.slidingPaneLayout
|
||||
if (slidingPane.isOpen) {
|
||||
if (slidingPane.isSlideable) {
|
||||
Log.i("$TAG Default account changed, closing sliding pane")
|
||||
slidingPane.close()
|
||||
} else {
|
||||
Log.i("$TAG Default account changed, going back to empty fragment")
|
||||
// TODO: clear displayed conversation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation? {
|
||||
|
|
|
|||
|
|
@ -102,9 +102,10 @@ class StartConversationFragment : GenericAddressPickerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
sharedViewModel.defaultAccountChangedEvent.observe(viewLifecycleOwner) {
|
||||
// Do not consume it!
|
||||
viewModel.updateGroupChatButtonVisibility()
|
||||
viewModel.defaultAccountChangedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
viewModel.updateGroupChatButtonVisibility()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,6 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
|
|||
}
|
||||
showGreenToastEvent.postValue(Event(Pair(message, R.drawable.user_circle)))
|
||||
|
||||
// TODO FIXME: list doesn't have the changes...
|
||||
computeParticipantsList()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,17 +69,6 @@ class ContactsListFragment : AbstractTopBarFragment() {
|
|||
"$TAG Default account changed, updating avatar in top bar & refreshing contacts list"
|
||||
)
|
||||
listViewModel.applyCurrentDefaultAccountFilter()
|
||||
|
||||
val slidingPane = binding.slidingPaneLayout
|
||||
if (slidingPane.isOpen) {
|
||||
if (slidingPane.isSlideable) {
|
||||
Log.i("$TAG Default account changed, closing sliding pane")
|
||||
slidingPane.close()
|
||||
} else {
|
||||
Log.i("$TAG Default account changed, going back to empty fragment")
|
||||
// TODO: clear displayed contact
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation? {
|
||||
|
|
|
|||
|
|
@ -149,6 +149,12 @@ abstract class AbstractTopBarFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
viewModel.defaultAccountChangedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
onDefaultAccountChanged()
|
||||
}
|
||||
}
|
||||
|
||||
sharedViewModel.currentlyDisplayedFragment.observe(viewLifecycleOwner) {
|
||||
viewModel.contactsSelected.value = it == R.id.contactsListFragment
|
||||
viewModel.callsSelected.value = it == R.id.historyListFragment
|
||||
|
|
@ -161,13 +167,6 @@ abstract class AbstractTopBarFragment : GenericFragment() {
|
|||
viewModel.resetMissedCallsCount()
|
||||
}
|
||||
}
|
||||
|
||||
sharedViewModel.defaultAccountChangedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
Log.i("$TAG Default account changed")
|
||||
onDefaultAccountChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun initBottomNavBar(navBar: View) {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ import org.linphone.ui.main.MainActivity
|
|||
import org.linphone.ui.main.settings.fragment.AccountProfileFragmentDirections
|
||||
import org.linphone.ui.main.viewmodel.DrawerMenuViewModel
|
||||
import org.linphone.ui.welcome.WelcomeActivity
|
||||
import org.linphone.utils.Event
|
||||
|
||||
@UiThread
|
||||
class DrawerMenuFragment : GenericFragment() {
|
||||
|
|
@ -119,7 +118,6 @@ class DrawerMenuFragment : GenericFragment() {
|
|||
Log.w(
|
||||
"$TAG Default account has changed, now is [$identity], closing side menu in 500ms"
|
||||
)
|
||||
sharedViewModel.defaultAccountChangedEvent.value = Event(true)
|
||||
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,10 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.ui.main.viewmodel.DefaultAccountChangedViewModel
|
||||
|
||||
@UiThread
|
||||
abstract class SlidingPaneChildFragment : GenericFragment() {
|
||||
|
|
@ -32,6 +34,8 @@ abstract class SlidingPaneChildFragment : GenericFragment() {
|
|||
private const val TAG = "[Sliding Pane Child Fragment]"
|
||||
}
|
||||
|
||||
private lateinit var defaultAccountChangedViewModel: DefaultAccountChangedViewModel
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(false) {
|
||||
override fun handleOnBackPressed() {
|
||||
Log.d("$TAG ${getFragmentRealClassName()} handleOnBackPressed")
|
||||
|
|
@ -65,6 +69,14 @@ abstract class SlidingPaneChildFragment : GenericFragment() {
|
|||
onBackPressedCallback
|
||||
)
|
||||
|
||||
defaultAccountChangedViewModel = ViewModelProvider(this)[DefaultAccountChangedViewModel::class.java]
|
||||
defaultAccountChangedViewModel.defaultAccountChangedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
Log.i("$TAG Default account changed, leaving fragment")
|
||||
goBack()
|
||||
}
|
||||
}
|
||||
|
||||
sharedViewModel.isSlidingPaneSlideable.observe(viewLifecycleOwner) { slideable ->
|
||||
val enabled = backPressedCallBackEnabled(slideable)
|
||||
onBackPressedCallback.isEnabled = enabled
|
||||
|
|
|
|||
|
|
@ -70,17 +70,6 @@ class HistoryListFragment : AbstractTopBarFragment() {
|
|||
"$TAG Default account changed, updating avatar in top bar & re-computing call logs"
|
||||
)
|
||||
listViewModel.applyFilter()
|
||||
|
||||
val slidingPane = binding.slidingPaneLayout
|
||||
if (slidingPane.isOpen) {
|
||||
if (slidingPane.isSlideable) {
|
||||
Log.i("$TAG Default account changed, closing sliding pane")
|
||||
slidingPane.close()
|
||||
} else {
|
||||
Log.i("$TAG Default account changed, going back to empty fragment")
|
||||
// TODO: clear displayed call log
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation? {
|
||||
|
|
|
|||
|
|
@ -128,16 +128,17 @@ class StartCallFragment : GenericAddressPickerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
viewModel.defaultAccountChangedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
viewModel.updateGroupCallButtonVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
binding.root.setKeyboardInsetListener { keyboardVisible ->
|
||||
if (keyboardVisible) {
|
||||
viewModel.isNumpadVisible.value = false
|
||||
}
|
||||
}
|
||||
|
||||
sharedViewModel.defaultAccountChangedEvent.observe(viewLifecycleOwner) {
|
||||
// Do not consume it!
|
||||
viewModel.updateGroupCallButtonVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
|
|||
|
|
@ -60,17 +60,6 @@ class MeetingsListFragment : AbstractTopBarFragment() {
|
|||
"$TAG Default account changed, updating avatar in top bar & re-computing meetings list"
|
||||
)
|
||||
listViewModel.applyFilter()
|
||||
|
||||
val slidingPane = binding.slidingPaneLayout
|
||||
if (slidingPane.isOpen) {
|
||||
if (slidingPane.isSlideable) {
|
||||
Log.i("$TAG Default account changed, closing sliding pane")
|
||||
slidingPane.close()
|
||||
} else {
|
||||
Log.i("$TAG Default account changed, going back to empty fragment")
|
||||
// TODO: clear displayed conference
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation? {
|
||||
|
|
|
|||
|
|
@ -89,6 +89,10 @@ open class AbstractTopBarViewModel @UiThread constructor() : ViewModel() {
|
|||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val defaultAccountChangedEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
protected var currentFilter = ""
|
||||
|
||||
private val coreListener = object : CoreListenerStub() {
|
||||
|
|
@ -132,6 +136,8 @@ open class AbstractTopBarViewModel @UiThread constructor() : ViewModel() {
|
|||
account.postValue(AccountModel(defaultAccount))
|
||||
}
|
||||
|
||||
defaultAccountChangedEvent.postValue(Event(true))
|
||||
|
||||
updateUnreadMessagesCount()
|
||||
updateMissedCallsCount()
|
||||
updateAvailableMenus()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ package org.linphone.ui.main.viewmodel
|
|||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import java.text.Collator
|
||||
import java.util.Locale
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
|
|
@ -38,7 +37,7 @@ import org.linphone.ui.main.model.SelectedAddressModel
|
|||
import org.linphone.ui.main.model.isInSecureMode
|
||||
import org.linphone.utils.AppUtils
|
||||
|
||||
abstract class AddressSelectionViewModel @UiThread constructor() : ViewModel() {
|
||||
abstract class AddressSelectionViewModel @UiThread constructor() : DefaultAccountChangedViewModel() {
|
||||
companion object {
|
||||
private const val TAG = "[Address Selection ViewModel]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-android
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.linphone.ui.main.viewmodel
|
||||
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.Account
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
import org.linphone.utils.Event
|
||||
|
||||
open class DefaultAccountChangedViewModel : ViewModel() {
|
||||
val defaultAccountChangedEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
private val coreListener = object : CoreListenerStub() {
|
||||
@WorkerThread
|
||||
override fun onDefaultAccountChanged(core: Core, account: Account?) {
|
||||
defaultAccountChangedEvent.postValue(Event(true))
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
core.addListener(coreListener)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
core.removeListener(coreListener)
|
||||
}
|
||||
|
||||
super.onCleared()
|
||||
}
|
||||
}
|
||||
|
|
@ -67,10 +67,6 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
|
|||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
val defaultAccountChangedEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val refreshDrawerMenuAccountsListEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue