Moved lambdas arguments out of parenthesis

This commit is contained in:
Sylvain Berfini 2022-01-28 16:49:00 +01:00
parent 81884dd218
commit a0ebeb1fea
47 changed files with 1238 additions and 1350 deletions

View file

@ -79,66 +79,62 @@ class AccountLoginFragment : AbstractPhoneFragment<AssistantAccountLoginFragment
}
viewModel.goToSmsValidationEvent.observe(
viewLifecycleOwner,
{
it.consume {
val args = Bundle()
args.putBoolean("IsLogin", true)
args.putString("PhoneNumber", viewModel.accountCreator.phoneNumber)
navigateToPhoneAccountValidation(args)
}
viewLifecycleOwner
) {
it.consume {
val args = Bundle()
args.putBoolean("IsLogin", true)
args.putString("PhoneNumber", viewModel.accountCreator.phoneNumber)
navigateToPhoneAccountValidation(args)
}
)
}
viewModel.leaveAssistantEvent.observe(
viewLifecycleOwner,
{
it.consume {
coreContext.contactsManager.updateLocalContacts()
viewLifecycleOwner
) {
it.consume {
coreContext.contactsManager.updateLocalContacts()
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
requireActivity().finish()
}
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
requireActivity().finish()
}
}
)
}
viewModel.invalidCredentialsEvent.observe(
viewLifecycleOwner,
{
it.consume {
val dialogViewModel =
DialogViewModel(getString(R.string.assistant_error_invalid_credentials))
val dialog: Dialog = DialogUtils.getDialog(requireContext(), dialogViewModel)
viewLifecycleOwner
) {
it.consume {
val dialogViewModel =
DialogViewModel(getString(R.string.assistant_error_invalid_credentials))
val dialog: Dialog = DialogUtils.getDialog(requireContext(), dialogViewModel)
dialogViewModel.showCancelButton {
viewModel.removeInvalidProxyConfig()
dialog.dismiss()
}
dialogViewModel.showDeleteButton(
{
viewModel.continueEvenIfInvalidCredentials()
dialog.dismiss()
},
getString(R.string.assistant_continue_even_if_credentials_invalid)
)
dialog.show()
dialogViewModel.showCancelButton {
viewModel.removeInvalidProxyConfig()
dialog.dismiss()
}
dialogViewModel.showDeleteButton(
{
viewModel.continueEvenIfInvalidCredentials()
dialog.dismiss()
},
getString(R.string.assistant_continue_even_if_credentials_invalid)
)
dialog.show()
}
)
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
viewLifecycleOwner
) {
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
)
}
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
checkPermissions()

View file

@ -48,13 +48,12 @@ class EchoCancellerCalibrationFragment : GenericFragment<AssistantEchoCancellerC
binding.viewModel = viewModel
viewModel.echoCalibrationTerminated.observe(
viewLifecycleOwner,
{
it.consume {
requireActivity().finish()
}
viewLifecycleOwner
) {
it.consume {
requireActivity().finish()
}
)
}
if (!PermissionHelper.required(requireContext()).hasRecordAudioPermission()) {
Log.i("[Echo Canceller Calibration] Asking for RECORD_AUDIO permission")

View file

@ -50,21 +50,19 @@ class EmailAccountCreationFragment : GenericFragment<AssistantEmailAccountCreati
binding.viewModel = viewModel
viewModel.goToEmailValidationEvent.observe(
viewLifecycleOwner,
{
it.consume {
navigateToEmailAccountValidation()
}
viewLifecycleOwner
) {
it.consume {
navigateToEmailAccountValidation()
}
)
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
viewLifecycleOwner
) {
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
)
}
}
}

View file

@ -49,27 +49,25 @@ class EmailAccountValidationFragment : GenericFragment<AssistantEmailAccountVali
binding.viewModel = viewModel
viewModel.leaveAssistantEvent.observe(
viewLifecycleOwner,
{
it.consume {
coreContext.contactsManager.updateLocalContacts()
viewLifecycleOwner
) {
it.consume {
coreContext.contactsManager.updateLocalContacts()
val args = Bundle()
args.putBoolean("AllowSkip", true)
args.putString("Username", viewModel.accountCreator.username)
args.putString("Password", viewModel.accountCreator.password)
navigateToAccountLinking(args)
}
val args = Bundle()
args.putBoolean("AllowSkip", true)
args.putString("Username", viewModel.accountCreator.username)
args.putString("Password", viewModel.accountCreator.password)
navigateToAccountLinking(args)
}
)
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
viewLifecycleOwner
) {
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
)
}
}
}

View file

@ -54,52 +54,50 @@ class GenericAccountLoginFragment : GenericFragment<AssistantGenericAccountLogin
binding.viewModel = viewModel
viewModel.leaveAssistantEvent.observe(
viewLifecycleOwner,
{
it.consume {
coreContext.contactsManager.updateLocalContacts()
viewLifecycleOwner
) {
it.consume {
coreContext.contactsManager.updateLocalContacts()
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
requireActivity().finish()
}
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
requireActivity().finish()
}
}
)
}
viewModel.invalidCredentialsEvent.observe(
viewLifecycleOwner,
{
it.consume {
val dialogViewModel = DialogViewModel(getString(R.string.assistant_error_invalid_credentials))
val dialog: Dialog = DialogUtils.getDialog(requireContext(), dialogViewModel)
viewLifecycleOwner
) {
it.consume {
val dialogViewModel =
DialogViewModel(getString(R.string.assistant_error_invalid_credentials))
val dialog: Dialog = DialogUtils.getDialog(requireContext(), dialogViewModel)
dialogViewModel.showCancelButton {
viewModel.removeInvalidProxyConfig()
dialog.dismiss()
}
dialogViewModel.showDeleteButton(
{
viewModel.continueEvenIfInvalidCredentials()
dialog.dismiss()
},
getString(R.string.assistant_continue_even_if_credentials_invalid)
)
dialog.show()
dialogViewModel.showCancelButton {
viewModel.removeInvalidProxyConfig()
dialog.dismiss()
}
dialogViewModel.showDeleteButton(
{
viewModel.continueEvenIfInvalidCredentials()
dialog.dismiss()
},
getString(R.string.assistant_continue_even_if_credentials_invalid)
)
dialog.show()
}
)
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
viewLifecycleOwner
) {
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
)
}
}
}

View file

@ -62,25 +62,23 @@ class PhoneAccountCreationFragment :
}
viewModel.goToSmsValidationEvent.observe(
viewLifecycleOwner,
{
it.consume {
val args = Bundle()
args.putBoolean("IsCreation", true)
args.putString("PhoneNumber", viewModel.accountCreator.phoneNumber)
navigateToPhoneAccountValidation(args)
}
viewLifecycleOwner
) {
it.consume {
val args = Bundle()
args.putBoolean("IsCreation", true)
args.putString("PhoneNumber", viewModel.accountCreator.phoneNumber)
navigateToPhoneAccountValidation(args)
}
)
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
viewLifecycleOwner
) {
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
)
}
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
checkPermissions()

View file

@ -73,38 +73,35 @@ class PhoneAccountLinkingFragment : AbstractPhoneFragment<AssistantPhoneAccountL
}
viewModel.goToSmsValidationEvent.observe(
viewLifecycleOwner,
{
it.consume {
val args = Bundle()
args.putBoolean("IsLinking", true)
args.putString("PhoneNumber", viewModel.accountCreator.phoneNumber)
navigateToPhoneAccountValidation(args)
}
viewLifecycleOwner
) {
it.consume {
val args = Bundle()
args.putBoolean("IsLinking", true)
args.putString("PhoneNumber", viewModel.accountCreator.phoneNumber)
navigateToPhoneAccountValidation(args)
}
)
}
viewModel.leaveAssistantEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (LinphoneApplication.coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
requireActivity().finish()
}
viewLifecycleOwner
) {
it.consume {
if (LinphoneApplication.coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
requireActivity().finish()
}
}
)
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
viewLifecycleOwner
) {
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
)
}
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
checkPermissions()

View file

@ -59,37 +59,38 @@ class PhoneAccountValidationFragment : GenericFragment<AssistantPhoneAccountVali
viewModel.isLinking.value = arguments?.getBoolean("IsLinking", false)
viewModel.leaveAssistantEvent.observe(
viewLifecycleOwner,
{
it.consume {
when {
viewModel.isLogin.value == true || viewModel.isCreation.value == true -> {
coreContext.contactsManager.updateLocalContacts()
viewLifecycleOwner
) {
it.consume {
when {
viewModel.isLogin.value == true || viewModel.isCreation.value == true -> {
coreContext.contactsManager.updateLocalContacts()
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
requireActivity().finish()
}
}
viewModel.isLinking.value == true -> {
val args = Bundle()
args.putString("Identity", "sip:${viewModel.accountCreator.username}@${viewModel.accountCreator.domain}")
navigateToAccountSettings(args)
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
requireActivity().finish()
}
}
viewModel.isLinking.value == true -> {
val args = Bundle()
args.putString(
"Identity",
"sip:${viewModel.accountCreator.username}@${viewModel.accountCreator.domain}"
)
navigateToAccountSettings(args)
}
}
}
)
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
viewLifecycleOwner
) {
it.consume { message ->
(requireActivity() as AssistantActivity).showSnackBar(message)
}
)
}
val clipboard = requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
clipboard.addPrimaryClipChangedListener {

View file

@ -56,14 +56,13 @@ class QrCodeFragment : GenericFragment<AssistantQrCodeFragmentBinding>() {
binding.viewModel = viewModel
viewModel.qrCodeFoundEvent.observe(
viewLifecycleOwner,
{
it.consume { url ->
sharedViewModel.remoteProvisioningUrl.value = url
findNavController().navigateUp()
}
viewLifecycleOwner
) {
it.consume { url ->
sharedViewModel.remoteProvisioningUrl.value = url
findNavController().navigateUp()
}
)
}
viewModel.setBackCamera()
if (!PermissionHelper.required(requireContext()).hasCameraPermission()) {

View file

@ -55,22 +55,21 @@ class RemoteProvisioningFragment : GenericFragment<AssistantRemoteProvisioningFr
}
viewModel.fetchSuccessfulEvent.observe(
viewLifecycleOwner,
{
it.consume { success ->
if (success) {
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
requireActivity().finish()
}
viewLifecycleOwner
) {
it.consume { success ->
if (success) {
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()
} else {
val activity = requireActivity() as AssistantActivity
activity.showSnackBar(R.string.assistant_remote_provisioning_failure)
requireActivity().finish()
}
} else {
val activity = requireActivity() as AssistantActivity
activity.showSnackBar(R.string.assistant_remote_provisioning_failure)
}
}
)
}
viewModel.urlToFetch.value = sharedViewModel.remoteProvisioningUrl.value ?: coreContext.core.provisioningUri
}

View file

@ -73,11 +73,10 @@ class WelcomeFragment : GenericFragment<AssistantWelcomeFragmentBinding>() {
}
viewModel.termsAndPrivacyAccepted.observe(
viewLifecycleOwner,
{
if (it) corePreferences.readAndAgreeTermsAndPrivacy = true
}
)
viewLifecycleOwner
) {
if (it) corePreferences.readAndAgreeTermsAndPrivacy = true
}
setUpTermsAndPrivacyLinks()
}

View file

@ -61,40 +61,36 @@ class CallActivity : ProximitySensorActivity() {
sharedViewModel = ViewModelProvider(this)[SharedCallViewModel::class.java]
sharedViewModel.toggleDrawerEvent.observe(
this,
{
it.consume {
if (binding.statsMenu.isDrawerOpen(Gravity.LEFT)) {
binding.statsMenu.closeDrawer(binding.sideMenuContent, true)
} else {
binding.statsMenu.openDrawer(binding.sideMenuContent, true)
}
this
) {
it.consume {
if (binding.statsMenu.isDrawerOpen(Gravity.LEFT)) {
binding.statsMenu.closeDrawer(binding.sideMenuContent, true)
} else {
binding.statsMenu.openDrawer(binding.sideMenuContent, true)
}
}
)
}
sharedViewModel.resetHiddenInterfaceTimerInVideoCallEvent.observe(
this,
{
it.consume {
viewModel.showMomentarily()
}
this
) {
it.consume {
viewModel.showMomentarily()
}
)
}
viewModel.proximitySensorEnabled.observe(
this,
{
enableProximitySensor(it)
}
)
this
) {
enableProximitySensor(it)
}
viewModel.videoEnabled.observe(
this,
{
updateConstraintSetDependingOnFoldingState()
}
)
this
) {
updateConstraintSetDependingOnFoldingState()
}
}
override fun onLayoutChanges(foldingFeature: FoldingFeature?) {

View file

@ -79,24 +79,22 @@ class IncomingCallActivity : GenericActivity() {
binding.viewModel = viewModel
viewModel.callEndedEvent.observe(
this,
{
it.consume {
Log.i("[Incoming Call Activity] Call ended, finish activity")
finish()
}
this
) {
it.consume {
Log.i("[Incoming Call Activity] Call ended, finish activity")
finish()
}
)
}
viewModel.earlyMediaVideoEnabled.observe(
this,
{
if (it) {
Log.i("[Incoming Call Activity] Early media video being received, set native window id")
coreContext.core.nativeVideoWindowId = binding.remoteVideoSurface
}
this
) {
if (it) {
Log.i("[Incoming Call Activity] Early media video being received, set native window id")
coreContext.core.nativeVideoWindowId = binding.remoteVideoSurface
}
)
}
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
val keyguardLocked = keyguardManager.isKeyguardLocked

View file

@ -80,64 +80,58 @@ class OutgoingCallActivity : ProximitySensorActivity() {
binding.controlsViewModel = controlsViewModel
viewModel.callEndedEvent.observe(
this,
{
it.consume {
Log.i("[Outgoing Call Activity] Call ended, finish activity")
finish()
}
this
) {
it.consume {
Log.i("[Outgoing Call Activity] Call ended, finish activity")
finish()
}
)
}
viewModel.callConnectedEvent.observe(
this,
{
it.consume {
Log.i("[Outgoing Call Activity] Call connected, finish activity")
finish()
}
this
) {
it.consume {
Log.i("[Outgoing Call Activity] Call connected, finish activity")
finish()
}
)
}
controlsViewModel.isSpeakerSelected.observe(
this,
{
enableProximitySensor(!it)
}
)
this
) {
enableProximitySensor(!it)
}
controlsViewModel.askAudioRecordPermissionEvent.observe(
this,
{
it.consume { permission ->
requestPermissions(arrayOf(permission), 0)
}
this
) {
it.consume { permission ->
requestPermissions(arrayOf(permission), 0)
}
)
}
controlsViewModel.askCameraPermissionEvent.observe(
this,
{
it.consume { permission ->
requestPermissions(arrayOf(permission), 0)
}
this
) {
it.consume { permission ->
requestPermissions(arrayOf(permission), 0)
}
)
}
controlsViewModel.toggleNumpadEvent.observe(
this,
{
it.consume { open ->
if (this::numpadAnimator.isInitialized) {
if (open) {
numpadAnimator.start()
} else {
numpadAnimator.reverse()
}
this
) {
it.consume { open ->
if (this::numpadAnimator.isInitialized) {
if (open) {
numpadAnimator.start()
} else {
numpadAnimator.reverse()
}
}
}
)
}
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
checkPermissions()

View file

@ -88,140 +88,129 @@ class ControlsFragment : GenericFragment<CallControlsFragmentBinding>() {
binding.conferenceViewModel = conferenceViewModel
callsViewModel.currentCallViewModel.observe(
viewLifecycleOwner,
{
if (it != null) {
binding.activeCallTimer.base =
SystemClock.elapsedRealtime() - (1000 * it.call.duration) // Linphone timestamps are in seconds
binding.activeCallTimer.start()
}
viewLifecycleOwner
) {
if (it != null) {
binding.activeCallTimer.base =
SystemClock.elapsedRealtime() - (1000 * it.call.duration) // Linphone timestamps are in seconds
binding.activeCallTimer.start()
}
)
}
callsViewModel.noMoreCallEvent.observe(
viewLifecycleOwner,
{
it.consume {
requireActivity().finish()
}
viewLifecycleOwner
) {
it.consume {
requireActivity().finish()
}
)
}
callsViewModel.askWriteExternalStoragePermissionEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (!PermissionHelper.get().hasWriteExternalStoragePermission()) {
Log.i("[Controls Fragment] Asking for WRITE_EXTERNAL_STORAGE permission")
requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 2)
}
viewLifecycleOwner
) {
it.consume {
if (!PermissionHelper.get().hasWriteExternalStoragePermission()) {
Log.i("[Controls Fragment] Asking for WRITE_EXTERNAL_STORAGE permission")
requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 2)
}
}
)
}
callsViewModel.callUpdateEvent.observe(
viewLifecycleOwner,
{
it.consume { call ->
if (call.state == Call.State.StreamsRunning) {
dialog?.dismiss()
} else if (call.state == Call.State.UpdatedByRemote) {
if (coreContext.core.isVideoCaptureEnabled || coreContext.core.isVideoDisplayEnabled) {
if (call.currentParams.isVideoEnabled != call.remoteParams?.isVideoEnabled) {
showCallVideoUpdateDialog(call)
}
} else {
Log.w("[Controls Fragment] Video display & capture are disabled, don't show video dialog")
viewLifecycleOwner
) {
it.consume { call ->
if (call.state == Call.State.StreamsRunning) {
dialog?.dismiss()
} else if (call.state == Call.State.UpdatedByRemote) {
if (coreContext.core.isVideoCaptureEnabled || coreContext.core.isVideoDisplayEnabled) {
if (call.currentParams.isVideoEnabled != call.remoteParams?.isVideoEnabled) {
showCallVideoUpdateDialog(call)
}
} else {
Log.w("[Controls Fragment] Video display & capture are disabled, don't show video dialog")
}
}
}
)
}
controlsViewModel.chatClickedEvent.observe(
viewLifecycleOwner,
{
it.consume {
val intent = Intent()
intent.setClass(requireContext(), MainActivity::class.java)
intent.putExtra("Chat", true)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
viewLifecycleOwner
) {
it.consume {
val intent = Intent()
intent.setClass(requireContext(), MainActivity::class.java)
intent.putExtra("Chat", true)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
)
}
controlsViewModel.addCallClickedEvent.observe(
viewLifecycleOwner,
{
it.consume {
val intent = Intent()
intent.setClass(requireContext(), MainActivity::class.java)
intent.putExtra("Dialer", true)
intent.putExtra("Transfer", false)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
viewLifecycleOwner
) {
it.consume {
val intent = Intent()
intent.setClass(requireContext(), MainActivity::class.java)
intent.putExtra("Dialer", true)
intent.putExtra("Transfer", false)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
)
}
controlsViewModel.transferCallClickedEvent.observe(
viewLifecycleOwner,
{
it.consume {
val intent = Intent()
intent.setClass(requireContext(), MainActivity::class.java)
intent.putExtra("Dialer", true)
intent.putExtra("Transfer", true)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
viewLifecycleOwner
) {
it.consume {
val intent = Intent()
intent.setClass(requireContext(), MainActivity::class.java)
intent.putExtra("Dialer", true)
intent.putExtra("Transfer", true)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
)
}
controlsViewModel.askAudioRecordPermissionEvent.observe(
viewLifecycleOwner,
{
it.consume { permission ->
Log.i("[Controls Fragment] Asking for $permission permission")
requestPermissions(arrayOf(permission), 0)
}
viewLifecycleOwner
) {
it.consume { permission ->
Log.i("[Controls Fragment] Asking for $permission permission")
requestPermissions(arrayOf(permission), 0)
}
)
}
controlsViewModel.askCameraPermissionEvent.observe(
viewLifecycleOwner,
{
it.consume { permission ->
Log.i("[Controls Fragment] Asking for $permission permission")
requestPermissions(arrayOf(permission), 1)
}
viewLifecycleOwner
) {
it.consume { permission ->
Log.i("[Controls Fragment] Asking for $permission permission")
requestPermissions(arrayOf(permission), 1)
}
)
}
controlsViewModel.toggleNumpadEvent.observe(
viewLifecycleOwner,
{
it.consume { open ->
if (this::numpadAnimator.isInitialized) {
if (open) {
numpadAnimator.start()
} else {
numpadAnimator.reverse()
}
viewLifecycleOwner
) {
it.consume { open ->
if (this::numpadAnimator.isInitialized) {
if (open) {
numpadAnimator.start()
} else {
numpadAnimator.reverse()
}
}
}
)
}
controlsViewModel.somethingClickedEvent.observe(
viewLifecycleOwner,
{
it.consume {
sharedViewModel.resetHiddenInterfaceTimerInVideoCallEvent.value = Event(true)
}
viewLifecycleOwner
) {
it.consume {
sharedViewModel.resetHiddenInterfaceTimerInVideoCallEvent.value = Event(true)
}
)
}
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
checkPermissions()

View file

@ -64,15 +64,14 @@ class StatusFragment : GenericFragment<CallStatusFragmentBinding>() {
}
viewModel.showZrtpDialogEvent.observe(
viewLifecycleOwner,
{
it.consume { call ->
if (call.state == Call.State.Connected || call.state == Call.State.StreamsRunning) {
showZrtpDialog(call)
}
viewLifecycleOwner
) {
it.consume { call ->
if (call.state == Call.State.Connected || call.state == Call.State.StreamsRunning) {
showZrtpDialog(call)
}
}
)
}
}
override fun onCreate(savedInstanceState: Bundle?) {

View file

@ -122,35 +122,36 @@ class ChatBubbleActivity : GenericActivity() {
adapter.disableContextMenu()
adapter.openContentEvent.observe(
this,
{
it.consume { content ->
if (content.isFileEncrypted) {
Toast.makeText(this, R.string.chat_bubble_cant_open_enrypted_file, Toast.LENGTH_LONG).show()
} else {
FileUtils.openFileInThirdPartyApp(this, content.filePath.orEmpty(), true)
}
this
) {
it.consume { content ->
if (content.isFileEncrypted) {
Toast.makeText(
this,
R.string.chat_bubble_cant_open_enrypted_file,
Toast.LENGTH_LONG
).show()
} else {
FileUtils.openFileInThirdPartyApp(this, content.filePath.orEmpty(), true)
}
}
)
}
val layoutManager = LinearLayoutManager(this)
layoutManager.stackFromEnd = true
binding.chatMessagesList.layoutManager = layoutManager
listViewModel.events.observe(
this,
{ events ->
adapter.submitList(events)
}
)
this
) { events ->
adapter.submitList(events)
}
chatSendingViewModel.textToSend.observe(
this,
{
chatSendingViewModel.onTextToSendChanged(it)
}
)
this
) {
chatSendingViewModel.onTextToSendChanged(it)
}
binding.setOpenAppClickListener {
coreContext.notificationsManager.currentlyDisplayedChatRoomAddress = null

View file

@ -125,26 +125,24 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
binding.callOverlayViewModel = callOverlayViewModel
sharedViewModel.toggleDrawerEvent.observe(
this,
{
it.consume {
if (binding.sideMenu.isDrawerOpen(Gravity.LEFT)) {
binding.sideMenu.closeDrawer(binding.sideMenuContent, true)
} else {
binding.sideMenu.openDrawer(binding.sideMenuContent, true)
}
this
) {
it.consume {
if (binding.sideMenu.isDrawerOpen(Gravity.LEFT)) {
binding.sideMenu.closeDrawer(binding.sideMenuContent, true)
} else {
binding.sideMenu.openDrawer(binding.sideMenuContent, true)
}
}
)
}
coreContext.callErrorMessageResourceId.observe(
this,
{
it.consume { message ->
showSnackBar(message)
}
this
) {
it.consume { message ->
showSnackBar(message)
}
)
}
if (coreContext.core.accountList.isEmpty()) {
if (corePreferences.firstStart) {
@ -251,7 +249,7 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
tabsFragment.visibility = if (tabsFragmentVisible1 && tabsFragmentVisible2) View.VISIBLE else View.GONE
}
fun View.hideKeyboard() {
private fun View.hideKeyboard() {
val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(windowToken, 0)
}

View file

@ -211,11 +211,10 @@ class ChatMessagesListAdapter(
// This is for item selection through ListTopBarFragment
selectionListViewModel = selectionViewModel
selectionViewModel.isEditionEnabled.observe(
viewLifecycleOwner,
{
position = bindingAdapterPosition
}
)
viewLifecycleOwner
) {
position = bindingAdapterPosition
}
setClickListener {
if (selectionViewModel.isEditionEnabled.value == true) {
@ -416,11 +415,10 @@ class ChatMessagesListAdapter(
// This is for item selection through ListTopBarFragment
selectionListViewModel = selectionViewModel
selectionViewModel.isEditionEnabled.observe(
viewLifecycleOwner,
{
position = bindingAdapterPosition
}
)
viewLifecycleOwner
) {
position = bindingAdapterPosition
}
binding.setClickListener {
if (selectionViewModel.isEditionEnabled.value == true) {

View file

@ -73,11 +73,10 @@ class ChatRoomsListAdapter(
// This is for item selection through ListTopBarFragment
selectionListViewModel = selectionViewModel
selectionViewModel.isEditionEnabled.observe(
viewLifecycleOwner,
{
position = bindingAdapterPosition
}
)
viewLifecycleOwner
) {
position = bindingAdapterPosition
}
forwardPending = isForwardPending

View file

@ -93,62 +93,55 @@ class ChatRoomCreationFragment : SecureFragment<ChatRoomCreationFragmentBinding>
}
viewModel.contactsList.observe(
viewLifecycleOwner,
{
adapter.submitList(it)
}
)
viewLifecycleOwner
) {
adapter.submitList(it)
}
viewModel.isEncrypted.observe(
viewLifecycleOwner,
{
adapter.updateSecurity(it)
}
)
viewLifecycleOwner
) {
adapter.updateSecurity(it)
}
viewModel.sipContactsSelected.observe(
viewLifecycleOwner,
{
viewModel.updateContactsList()
}
)
viewLifecycleOwner
) {
viewModel.updateContactsList()
}
viewModel.selectedAddresses.observe(
viewLifecycleOwner,
{
adapter.updateSelectedAddresses(it)
}
)
viewLifecycleOwner
) {
adapter.updateSelectedAddresses(it)
}
viewModel.chatRoomCreatedEvent.observe(
viewLifecycleOwner,
{
it.consume { chatRoom ->
sharedViewModel.selectedChatRoom.value = chatRoom
navigateToChatRoom(AppUtils.createBundleWithSharedTextAndFiles(sharedViewModel))
}
viewLifecycleOwner
) {
it.consume { chatRoom ->
sharedViewModel.selectedChatRoom.value = chatRoom
navigateToChatRoom(AppUtils.createBundleWithSharedTextAndFiles(sharedViewModel))
}
)
}
viewModel.filter.observe(
viewLifecycleOwner,
{
viewModel.applyFilter()
}
)
viewLifecycleOwner
) {
viewModel.applyFilter()
}
adapter.selectedContact.observe(
viewLifecycleOwner,
{
it.consume { searchResult ->
if (createGroup) {
viewModel.toggleSelectionForSearchResult(searchResult)
} else {
viewModel.createOneToOneChat(searchResult)
}
viewLifecycleOwner
) {
it.consume { searchResult ->
if (createGroup) {
viewModel.toggleSelectionForSearchResult(searchResult)
} else {
viewModel.createOneToOneChat(searchResult)
}
}
)
}
addParticipantsFromSharedViewModel()
@ -160,13 +153,12 @@ class ChatRoomCreationFragment : SecureFragment<ChatRoomCreationFragmentBinding>
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
viewLifecycleOwner
) {
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
)
}
if (!PermissionHelper.get().hasReadContactsPermission()) {
Log.i("[Chat Room Creation] Asking for READ_CONTACTS permission")

View file

@ -294,193 +294,191 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
binding.chatMessagesList.addOnScrollListener(chatScrollListener)
chatSendingViewModel.textToSend.observe(
viewLifecycleOwner,
{
chatSendingViewModel.onTextToSendChanged(it)
}
)
viewLifecycleOwner
) {
chatSendingViewModel.onTextToSendChanged(it)
}
chatSendingViewModel.requestRecordAudioPermissionEvent.observe(
viewLifecycleOwner,
{
it.consume {
Log.i("[Chat Room] Asking for RECORD_AUDIO permission")
requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 2)
}
viewLifecycleOwner
) {
it.consume {
Log.i("[Chat Room] Asking for RECORD_AUDIO permission")
requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 2)
}
)
}
listViewModel.events.observe(
viewLifecycleOwner,
{ events ->
adapter.setUnreadMessageCount(viewModel.chatRoom.unreadMessagesCount, viewModel.isUserScrollingUp.value == true)
adapter.submitList(events)
}
)
viewLifecycleOwner
) { events ->
adapter.setUnreadMessageCount(
viewModel.chatRoom.unreadMessagesCount,
viewModel.isUserScrollingUp.value == true
)
adapter.submitList(events)
}
listViewModel.messageUpdatedEvent.observe(
viewLifecycleOwner,
{
it.consume { position ->
adapter.notifyItemChanged(position)
}
viewLifecycleOwner
) {
it.consume { position ->
adapter.notifyItemChanged(position)
}
)
}
listViewModel.requestWriteExternalStoragePermissionEvent.observe(
viewLifecycleOwner,
{
it.consume {
requestPermissions(arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
}
viewLifecycleOwner
) {
it.consume {
requestPermissions(arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
}
)
}
adapter.deleteMessageEvent.observe(
viewLifecycleOwner,
{
it.consume { chatMessage ->
listViewModel.deleteMessage(chatMessage)
viewModel.updateLastMessageToDisplay()
}
viewLifecycleOwner
) {
it.consume { chatMessage ->
listViewModel.deleteMessage(chatMessage)
viewModel.updateLastMessageToDisplay()
}
)
}
adapter.resendMessageEvent.observe(
viewLifecycleOwner,
{
it.consume { chatMessage ->
listViewModel.resendMessage(chatMessage)
}
viewLifecycleOwner
) {
it.consume { chatMessage ->
listViewModel.resendMessage(chatMessage)
}
)
}
adapter.forwardMessageEvent.observe(
viewLifecycleOwner,
{
it.consume { chatMessage ->
// Remove observer before setting the message to forward
// as we don't want to forward it in this chat room
sharedViewModel.messageToForwardEvent.removeObservers(viewLifecycleOwner)
sharedViewModel.messageToForwardEvent.value = Event(chatMessage)
sharedViewModel.isPendingMessageForward.value = true
viewLifecycleOwner
) {
it.consume { chatMessage ->
// Remove observer before setting the message to forward
// as we don't want to forward it in this chat room
sharedViewModel.messageToForwardEvent.removeObservers(viewLifecycleOwner)
sharedViewModel.messageToForwardEvent.value = Event(chatMessage)
sharedViewModel.isPendingMessageForward.value = true
if (sharedViewModel.isSlidingPaneSlideable.value == true) {
Log.i("[Chat Room] Forwarding message, going to chat rooms list")
sharedViewModel.closeSlidingPaneEvent.value = Event(true)
} else {
navigateToEmptyChatRoom()
}
if (sharedViewModel.isSlidingPaneSlideable.value == true) {
Log.i("[Chat Room] Forwarding message, going to chat rooms list")
sharedViewModel.closeSlidingPaneEvent.value = Event(true)
} else {
navigateToEmptyChatRoom()
}
}
)
}
adapter.replyMessageEvent.observe(
viewLifecycleOwner,
{
it.consume { chatMessage ->
chatSendingViewModel.pendingChatMessageToReplyTo.value?.destroy()
chatSendingViewModel.pendingChatMessageToReplyTo.value = ChatMessageData(chatMessage)
chatSendingViewModel.isPendingAnswer.value = true
}
viewLifecycleOwner
) {
it.consume { chatMessage ->
chatSendingViewModel.pendingChatMessageToReplyTo.value?.destroy()
chatSendingViewModel.pendingChatMessageToReplyTo.value =
ChatMessageData(chatMessage)
chatSendingViewModel.isPendingAnswer.value = true
}
)
}
adapter.showImdnForMessageEvent.observe(
viewLifecycleOwner,
{
it.consume { chatMessage ->
val args = Bundle()
args.putString("MessageId", chatMessage.messageId)
navigateToImdn(args)
}
viewLifecycleOwner
) {
it.consume { chatMessage ->
val args = Bundle()
args.putString("MessageId", chatMessage.messageId)
navigateToImdn(args)
}
)
}
adapter.addSipUriToContactEvent.observe(
viewLifecycleOwner,
{
it.consume { sipUri ->
Log.i("[Chat Room] Going to contacts list with SIP URI to add: $sipUri")
sharedViewModel.updateContactsAnimationsBasedOnDestination.value = Event(R.id.masterChatRoomsFragment)
navigateToContacts(sipUri)
}
viewLifecycleOwner
) {
it.consume { sipUri ->
Log.i("[Chat Room] Going to contacts list with SIP URI to add: $sipUri")
sharedViewModel.updateContactsAnimationsBasedOnDestination.value =
Event(R.id.masterChatRoomsFragment)
navigateToContacts(sipUri)
}
)
}
adapter.openContentEvent.observe(
viewLifecycleOwner,
{
it.consume { content ->
val path = content.filePath.orEmpty()
viewLifecycleOwner
) {
it.consume { content ->
val path = content.filePath.orEmpty()
if (!File(path).exists()) {
(requireActivity() as MainActivity).showSnackBar(R.string.chat_room_file_not_found)
} else {
Log.i("[Chat Message] Opening file: $path")
sharedViewModel.contentToOpen.value = content
if (!File(path).exists()) {
(requireActivity() as MainActivity).showSnackBar(R.string.chat_room_file_not_found)
} else {
Log.i("[Chat Message] Opening file: $path")
sharedViewModel.contentToOpen.value = content
if (corePreferences.useInAppFileViewerForNonEncryptedFiles || content.isFileEncrypted) {
val preventScreenshots =
viewModel.chatRoom.currentParams.isEncryptionEnabled
when {
FileUtils.isExtensionImage(path) -> navigateToImageFileViewer(
preventScreenshots
)
FileUtils.isExtensionVideo(path) -> navigateToVideoFileViewer(
preventScreenshots
)
FileUtils.isExtensionAudio(path) -> navigateToAudioFileViewer(
preventScreenshots
)
FileUtils.isExtensionPdf(path) -> navigateToPdfFileViewer(
preventScreenshots
)
FileUtils.isPlainTextFile(path) -> navigateToTextFileViewer(
preventScreenshots
)
else -> {
if (content.isFileEncrypted) {
Log.w("[Chat Message] File is encrypted and can't be opened in one of our viewers...")
showDialogForUserConsentBeforeExportingFileInThirdPartyApp(content)
} else if (!FileUtils.openFileInThirdPartyApp(requireActivity(), path)) {
showDialogToSuggestOpeningFileAsText()
}
if (corePreferences.useInAppFileViewerForNonEncryptedFiles || content.isFileEncrypted) {
val preventScreenshots =
viewModel.chatRoom.currentParams.isEncryptionEnabled
when {
FileUtils.isExtensionImage(path) -> navigateToImageFileViewer(
preventScreenshots
)
FileUtils.isExtensionVideo(path) -> navigateToVideoFileViewer(
preventScreenshots
)
FileUtils.isExtensionAudio(path) -> navigateToAudioFileViewer(
preventScreenshots
)
FileUtils.isExtensionPdf(path) -> navigateToPdfFileViewer(
preventScreenshots
)
FileUtils.isPlainTextFile(path) -> navigateToTextFileViewer(
preventScreenshots
)
else -> {
if (content.isFileEncrypted) {
Log.w("[Chat Message] File is encrypted and can't be opened in one of our viewers...")
showDialogForUserConsentBeforeExportingFileInThirdPartyApp(
content
)
} else if (!FileUtils.openFileInThirdPartyApp(
requireActivity(),
path
)
) {
showDialogToSuggestOpeningFileAsText()
}
}
} else {
if (!FileUtils.openFileInThirdPartyApp(requireActivity(), path)) {
showDialogToSuggestOpeningFileAsText()
}
}
} else {
if (!FileUtils.openFileInThirdPartyApp(requireActivity(), path)) {
showDialogToSuggestOpeningFileAsText()
}
}
}
}
)
}
adapter.scrollToChatMessageEvent.observe(
viewLifecycleOwner,
{
it.consume { chatMessage ->
val events = listViewModel.events.value.orEmpty()
val eventLog = events.find { eventLog ->
if (eventLog.eventLog.type == EventLog.Type.ConferenceChatMessage) {
(eventLog.data as ChatMessageData).chatMessage.messageId == chatMessage.messageId
} else false
}
val index = events.indexOf(eventLog)
try {
if (corePreferences.enableAnimations) {
binding.chatMessagesList.smoothScrollToPosition(index)
} else {
binding.chatMessagesList.scrollToPosition(index)
}
} catch (iae: IllegalArgumentException) {
Log.e("[Chat Room] Can't scroll to position $index")
viewLifecycleOwner
) {
it.consume { chatMessage ->
val events = listViewModel.events.value.orEmpty()
val eventLog = events.find { eventLog ->
if (eventLog.eventLog.type == EventLog.Type.ConferenceChatMessage) {
(eventLog.data as ChatMessageData).chatMessage.messageId == chatMessage.messageId
} else false
}
val index = events.indexOf(eventLog)
try {
if (corePreferences.enableAnimations) {
binding.chatMessagesList.smoothScrollToPosition(index)
} else {
binding.chatMessagesList.scrollToPosition(index)
}
} catch (iae: IllegalArgumentException) {
Log.e("[Chat Room] Can't scroll to position $index")
}
}
)
}
binding.setBackClickListener {
goBack()
@ -571,33 +569,31 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
}
sharedViewModel.richContentUri.observe(
viewLifecycleOwner,
{
it.consume { uri ->
Log.i("[Chat] Found rich content URI: $uri")
lifecycleScope.launch {
withContext(Dispatchers.Main) {
val path = FileUtils.getFilePath(requireContext(), uri)
Log.i("[Chat] Rich content URI: $uri matching path is: $path")
if (path != null) {
chatSendingViewModel.addAttachment(path)
}
viewLifecycleOwner
) {
it.consume { uri ->
Log.i("[Chat] Found rich content URI: $uri")
lifecycleScope.launch {
withContext(Dispatchers.Main) {
val path = FileUtils.getFilePath(requireContext(), uri)
Log.i("[Chat] Rich content URI: $uri matching path is: $path")
if (path != null) {
chatSendingViewModel.addAttachment(path)
}
}
}
}
)
}
sharedViewModel.messageToForwardEvent.observe(
viewLifecycleOwner,
{
it.consume { chatMessage ->
Log.i("[Chat Room] Found message to transfer")
showForwardConfirmationDialog(chatMessage)
sharedViewModel.isPendingMessageForward.value = false
}
viewLifecycleOwner
) {
it.consume { chatMessage ->
Log.i("[Chat Room] Found message to transfer")
showForwardConfirmationDialog(chatMessage)
sharedViewModel.isPendingMessageForward.value = false
}
)
}
binding.stubbedMessageToReplyTo.setOnInflateListener { _, inflated ->
Log.i("[Chat Room] Replying to message layout inflated")

View file

@ -84,36 +84,32 @@ class GroupInfoFragment : SecureFragment<ChatRoomGroupInfoFragmentBinding>() {
binding.participants.addItemDecoration(AppUtils.getDividerDecoration(requireContext(), layoutManager))
viewModel.participants.observe(
viewLifecycleOwner,
{
adapter.submitList(it)
}
)
viewLifecycleOwner
) {
adapter.submitList(it)
}
viewModel.isMeAdmin.observe(
viewLifecycleOwner,
{ isMeAdmin ->
adapter.showAdminControls(isMeAdmin && chatRoom != null)
}
)
viewLifecycleOwner
) { isMeAdmin ->
adapter.showAdminControls(isMeAdmin && chatRoom != null)
}
viewModel.meAdminChangedEvent.observe(
viewLifecycleOwner,
{
it.consume { isMeAdmin ->
showMeAdminStateChanged(isMeAdmin)
}
viewLifecycleOwner
) {
it.consume { isMeAdmin ->
showMeAdminStateChanged(isMeAdmin)
}
)
}
adapter.participantRemovedEvent.observe(
viewLifecycleOwner,
{
it.consume { participant ->
viewModel.removeParticipant(participant)
}
viewLifecycleOwner
) {
it.consume { participant ->
viewModel.removeParticipant(participant)
}
)
}
addParticipantsFromSharedViewModel()
@ -122,22 +118,20 @@ class GroupInfoFragment : SecureFragment<ChatRoomGroupInfoFragmentBinding>() {
}
viewModel.createdChatRoomEvent.observe(
viewLifecycleOwner,
{
it.consume { chatRoom ->
goToChatRoom(chatRoom, true)
}
viewLifecycleOwner
) {
it.consume { chatRoom ->
goToChatRoom(chatRoom, true)
}
)
}
viewModel.updatedChatRoomEvent.observe(
viewLifecycleOwner,
{
it.consume { chatRoom ->
goToChatRoom(chatRoom, false)
}
viewLifecycleOwner
) {
it.consume { chatRoom ->
goToChatRoom(chatRoom, false)
}
)
}
binding.setNextClickListener {
if (viewModel.chatRoom != null) {
@ -182,13 +176,12 @@ class GroupInfoFragment : SecureFragment<ChatRoomGroupInfoFragmentBinding>() {
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
viewLifecycleOwner
) {
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
)
}
}
private fun addParticipantsFromSharedViewModel() {

View file

@ -98,11 +98,10 @@ class ImdnFragment : SecureFragment<ChatRoomImdnFragmentBinding>() {
binding.participantsList.addItemDecoration(headerItemDecoration)
viewModel.participants.observe(
viewLifecycleOwner,
{
adapter.submitList(it)
}
)
viewLifecycleOwner
) {
adapter.submitList(it)
}
binding.setBackClickListener {
goBack()

View file

@ -113,40 +113,38 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
// Chat room loading can take some time, so wait until it is ready before opening the pane
sharedViewModel.chatRoomFragmentOpenedEvent.observe(
viewLifecycleOwner,
{
it.consume {
binding.slidingPane.openPane()
}
viewLifecycleOwner
) {
it.consume {
binding.slidingPane.openPane()
}
)
}
sharedViewModel.closeSlidingPaneEvent.observe(
viewLifecycleOwner,
{
it.consume {
(requireActivity() as MainActivity).hideKeyboard()
if (!binding.slidingPane.closePane()) {
goBack()
}
viewLifecycleOwner
) {
it.consume {
(requireActivity() as MainActivity).hideKeyboard()
if (!binding.slidingPane.closePane()) {
goBack()
}
}
)
}
sharedViewModel.layoutChangedEvent.observe(
viewLifecycleOwner,
{
it.consume {
sharedViewModel.isSlidingPaneSlideable.value = binding.slidingPane.isSlideable
if (binding.slidingPane.isSlideable) {
val navHostFragment = childFragmentManager.findFragmentById(R.id.chat_nav_container) as NavHostFragment
if (navHostFragment.navController.currentDestination?.id == R.id.emptyChatFragment) {
Log.i("[Chat] Foldable device has been folded, closing side pane with empty fragment")
binding.slidingPane.closePane()
}
viewLifecycleOwner
) {
it.consume {
sharedViewModel.isSlidingPaneSlideable.value = binding.slidingPane.isSlideable
if (binding.slidingPane.isSlideable) {
val navHostFragment =
childFragmentManager.findFragmentById(R.id.chat_nav_container) as NavHostFragment
if (navHostFragment.navController.currentDestination?.id == R.id.emptyChatFragment) {
Log.i("[Chat] Foldable device has been folded, closing side pane with empty fragment")
binding.slidingPane.closePane()
}
}
}
)
}
binding.slidingPane.lockMode = SlidingPaneLayout.LOCK_MODE_LOCKED
/* End of shared view model & sliding pane related */
@ -216,50 +214,47 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
binding.chatList.addItemDecoration(AppUtils.getDividerDecoration(requireContext(), layoutManager))
listViewModel.chatRooms.observe(
viewLifecycleOwner,
{ chatRooms ->
adapter.submitList(chatRooms)
}
)
viewLifecycleOwner
) { chatRooms ->
adapter.submitList(chatRooms)
}
listViewModel.contactsUpdatedEvent.observe(
viewLifecycleOwner,
{
it.consume {
adapter.notifyDataSetChanged()
}
viewLifecycleOwner
) {
it.consume {
adapter.notifyDataSetChanged()
}
)
}
adapter.selectedChatRoomEvent.observe(
viewLifecycleOwner,
{
it.consume { chatRoom ->
if ((requireActivity() as GenericActivity).isDestructionPending) {
Log.w("[Chat] Activity is pending destruction, don't start navigating now!")
sharedViewModel.destructionPendingChatRoom = chatRoom
} else {
if (chatRoom.peerAddress.asStringUriOnly() == coreContext.notificationsManager.currentlyDisplayedChatRoomAddress) {
if (!binding.slidingPane.isOpen) {
Log.w("[Chat] Chat room is displayed but sliding pane is closed...")
if (!binding.slidingPane.openPane()) {
Log.e("[Chat] Tried to open pane to workaround already displayed chat room issue, failed!")
}
} else {
Log.w("[Chat] This chat room is already displayed!")
viewLifecycleOwner
) {
it.consume { chatRoom ->
if ((requireActivity() as GenericActivity).isDestructionPending) {
Log.w("[Chat] Activity is pending destruction, don't start navigating now!")
sharedViewModel.destructionPendingChatRoom = chatRoom
} else {
if (chatRoom.peerAddress.asStringUriOnly() == coreContext.notificationsManager.currentlyDisplayedChatRoomAddress) {
if (!binding.slidingPane.isOpen) {
Log.w("[Chat] Chat room is displayed but sliding pane is closed...")
if (!binding.slidingPane.openPane()) {
Log.e("[Chat] Tried to open pane to workaround already displayed chat room issue, failed!")
}
} else {
sharedViewModel.selectedChatRoom.value = chatRoom
navigateToChatRoom(
AppUtils.createBundleWithSharedTextAndFiles(
sharedViewModel
)
)
Log.w("[Chat] This chat room is already displayed!")
}
} else {
sharedViewModel.selectedChatRoom.value = chatRoom
navigateToChatRoom(
AppUtils.createBundleWithSharedTextAndFiles(
sharedViewModel
)
)
}
}
}
)
}
binding.setEditClickListener {
listSelectionViewModel.isEditionEnabled.value = true
@ -313,56 +308,52 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
}
} else {
sharedViewModel.textToShare.observe(
viewLifecycleOwner,
{
if (it.isNotEmpty()) {
Log.i("[Chat] Found text to share")
// val activity = requireActivity() as MainActivity
// activity.showSnackBar(R.string.chat_room_toast_choose_for_sharing)
listViewModel.textSharingPending.value = true
clearDisplayedChatRoom()
} else {
if (sharedViewModel.filesToShare.value.isNullOrEmpty()) {
listViewModel.textSharingPending.value = false
}
viewLifecycleOwner
) {
if (it.isNotEmpty()) {
Log.i("[Chat] Found text to share")
// val activity = requireActivity() as MainActivity
// activity.showSnackBar(R.string.chat_room_toast_choose_for_sharing)
listViewModel.textSharingPending.value = true
clearDisplayedChatRoom()
} else {
if (sharedViewModel.filesToShare.value.isNullOrEmpty()) {
listViewModel.textSharingPending.value = false
}
}
)
}
sharedViewModel.filesToShare.observe(
viewLifecycleOwner,
{
if (it.isNotEmpty()) {
Log.i("[Chat] Found ${it.size} files to share")
// val activity = requireActivity() as MainActivity
// activity.showSnackBar(R.string.chat_room_toast_choose_for_sharing)
listViewModel.fileSharingPending.value = true
clearDisplayedChatRoom()
} else {
if (sharedViewModel.textToShare.value.isNullOrEmpty()) {
listViewModel.fileSharingPending.value = false
}
viewLifecycleOwner
) {
if (it.isNotEmpty()) {
Log.i("[Chat] Found ${it.size} files to share")
// val activity = requireActivity() as MainActivity
// activity.showSnackBar(R.string.chat_room_toast_choose_for_sharing)
listViewModel.fileSharingPending.value = true
clearDisplayedChatRoom()
} else {
if (sharedViewModel.textToShare.value.isNullOrEmpty()) {
listViewModel.fileSharingPending.value = false
}
}
)
}
sharedViewModel.isPendingMessageForward.observe(
viewLifecycleOwner,
{
listViewModel.forwardPending.value = it
adapter.forwardPending(it)
if (it) {
Log.i("[Chat] Found chat message to transfer")
}
viewLifecycleOwner
) {
listViewModel.forwardPending.value = it
adapter.forwardPending(it)
if (it) {
Log.i("[Chat] Found chat message to transfer")
}
)
}
listViewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
viewLifecycleOwner
) {
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
)
}
}
}

View file

@ -71,11 +71,10 @@ class ContactsListAdapter(
// This is for item selection through ListTopBarFragment
selectionListViewModel = selectionViewModel
selectionViewModel.isEditionEnabled.observe(
viewLifecycleOwner,
{
position = bindingAdapterPosition
}
)
viewLifecycleOwner
) {
position = bindingAdapterPosition
}
setClickListener {
if (selectionViewModel.isEditionEnabled.value == true) {

View file

@ -83,47 +83,50 @@ class DetailContactFragment : GenericFragment<ContactDetailFragmentBinding>() {
binding.viewModel = viewModel
viewModel.sendSmsToEvent.observe(
viewLifecycleOwner,
{
it.consume { number ->
sendSms(number)
}
viewLifecycleOwner
) {
it.consume { number ->
sendSms(number)
}
)
}
viewModel.startCallToEvent.observe(
viewLifecycleOwner,
{
it.consume { address ->
if (coreContext.core.callsNb > 0) {
Log.i("[Contact] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}")
sharedViewModel.updateContactsAnimationsBasedOnDestination.value = Event(R.id.dialerFragment)
sharedViewModel.updateDialerAnimationsBasedOnDestination.value = Event(R.id.masterContactsFragment)
viewLifecycleOwner
) {
it.consume { address ->
if (coreContext.core.callsNb > 0) {
Log.i("[Contact] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}")
sharedViewModel.updateContactsAnimationsBasedOnDestination.value =
Event(R.id.dialerFragment)
sharedViewModel.updateDialerAnimationsBasedOnDestination.value =
Event(R.id.masterContactsFragment)
val args = Bundle()
args.putString("URI", address.asStringUriOnly())
args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer)
args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it
navigateToDialer(args)
} else {
coreContext.startCall(address)
}
val args = Bundle()
args.putString("URI", address.asStringUriOnly())
args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer)
args.putBoolean(
"SkipAutoCallStart",
true
) // If auto start call setting is enabled, ignore it
navigateToDialer(args)
} else {
coreContext.startCall(address)
}
}
)
}
viewModel.chatRoomCreatedEvent.observe(
viewLifecycleOwner,
{
it.consume { chatRoom ->
sharedViewModel.updateContactsAnimationsBasedOnDestination.value = Event(R.id.masterChatRoomsFragment)
val args = Bundle()
args.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly())
args.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly())
navigateToChatRoom(args)
}
viewLifecycleOwner
) {
it.consume { chatRoom ->
sharedViewModel.updateContactsAnimationsBasedOnDestination.value =
Event(R.id.masterChatRoomsFragment)
val args = Bundle()
args.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly())
args.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly())
navigateToChatRoom(args)
}
)
}
binding.setBackClickListener {
goBack()
@ -138,13 +141,12 @@ class DetailContactFragment : GenericFragment<ContactDetailFragmentBinding>() {
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
viewLifecycleOwner
) {
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
)
}
view.doOnPreDraw {
// Notifies fragment is ready to be drawn

View file

@ -85,59 +85,58 @@ class MasterContactsFragment : MasterFragment<ContactMasterFragmentBinding, Cont
useMaterialSharedAxisXForwardAnimation = false
sharedViewModel.updateContactsAnimationsBasedOnDestination.observe(
viewLifecycleOwner,
{
it.consume { id ->
val forward = when (id) {
R.id.dialerFragment, R.id.masterChatRoomsFragment -> false
else -> true
}
if (corePreferences.enableAnimations) {
val portraitOrientation = resources.configuration.orientation != Configuration.ORIENTATION_LANDSCAPE
val axis = if (portraitOrientation) MaterialSharedAxis.X else MaterialSharedAxis.Y
enterTransition = MaterialSharedAxis(axis, forward)
reenterTransition = MaterialSharedAxis(axis, forward)
returnTransition = MaterialSharedAxis(axis, !forward)
exitTransition = MaterialSharedAxis(axis, !forward)
}
viewLifecycleOwner
) {
it.consume { id ->
val forward = when (id) {
R.id.dialerFragment, R.id.masterChatRoomsFragment -> false
else -> true
}
if (corePreferences.enableAnimations) {
val portraitOrientation =
resources.configuration.orientation != Configuration.ORIENTATION_LANDSCAPE
val axis =
if (portraitOrientation) MaterialSharedAxis.X else MaterialSharedAxis.Y
enterTransition = MaterialSharedAxis(axis, forward)
reenterTransition = MaterialSharedAxis(axis, forward)
returnTransition = MaterialSharedAxis(axis, !forward)
exitTransition = MaterialSharedAxis(axis, !forward)
}
}
)
}
sharedViewModel.contactFragmentOpenedEvent.observe(
viewLifecycleOwner,
{
it.consume {
binding.slidingPane.openPane()
}
viewLifecycleOwner
) {
it.consume {
binding.slidingPane.openPane()
}
)
}
sharedViewModel.closeSlidingPaneEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (!binding.slidingPane.closePane()) {
goBack()
}
viewLifecycleOwner
) {
it.consume {
if (!binding.slidingPane.closePane()) {
goBack()
}
}
)
}
sharedViewModel.layoutChangedEvent.observe(
viewLifecycleOwner,
{
it.consume {
sharedViewModel.isSlidingPaneSlideable.value = binding.slidingPane.isSlideable
if (binding.slidingPane.isSlideable) {
val navHostFragment = childFragmentManager.findFragmentById(R.id.contacts_nav_container) as NavHostFragment
if (navHostFragment.navController.currentDestination?.id == R.id.emptyContactFragment) {
Log.i("[Contacts] Foldable device has been folded, closing side pane with empty fragment")
binding.slidingPane.closePane()
}
viewLifecycleOwner
) {
it.consume {
sharedViewModel.isSlidingPaneSlideable.value = binding.slidingPane.isSlideable
if (binding.slidingPane.isSlideable) {
val navHostFragment =
childFragmentManager.findFragmentById(R.id.contacts_nav_container) as NavHostFragment
if (navHostFragment.navController.currentDestination?.id == R.id.emptyContactFragment) {
Log.i("[Contacts] Foldable device has been folded, closing side pane with empty fragment")
binding.slidingPane.closePane()
}
}
}
)
}
binding.slidingPane.lockMode = SlidingPaneLayout.LOCK_MODE_LOCKED
/* End of shared view model & sliding pane related */
@ -208,38 +207,36 @@ class MasterContactsFragment : MasterFragment<ContactMasterFragmentBinding, Cont
binding.contactsList.addItemDecoration(headerItemDecoration)
adapter.selectedContactEvent.observe(
viewLifecycleOwner,
{
it.consume { contact ->
Log.i("[Contacts] Selected item in list changed: $contact")
sharedViewModel.selectedContact.value = contact
viewLifecycleOwner
) {
it.consume { contact ->
Log.i("[Contacts] Selected item in list changed: $contact")
sharedViewModel.selectedContact.value = contact
if (editOnClick) {
navigateToContactEditor(sipUriToAdd, binding.slidingPane)
editOnClick = false
sipUriToAdd = null
} else {
navigateToContact()
}
if (editOnClick) {
navigateToContactEditor(sipUriToAdd, binding.slidingPane)
editOnClick = false
sipUriToAdd = null
} else {
navigateToContact()
}
}
)
}
listViewModel.contactsList.observe(
viewLifecycleOwner,
{
val id = contactIdToDisplay
if (id != null) {
val contact = coreContext.contactsManager.findContactById(id)
if (contact != null) {
contactIdToDisplay = null
Log.i("[Contacts] Found matching contact $contact after callback")
adapter.selectedContactEvent.value = Event(contact)
}
viewLifecycleOwner
) {
val id = contactIdToDisplay
if (id != null) {
val contact = coreContext.contactsManager.findContactById(id)
if (contact != null) {
contactIdToDisplay = null
Log.i("[Contacts] Found matching contact $contact after callback")
adapter.selectedContactEvent.value = Event(contact)
}
adapter.submitList(it)
}
)
adapter.submitList(it)
}
binding.setAllContactsToggleClickListener {
listViewModel.sipContactsSelected.value = false
@ -249,18 +246,16 @@ class MasterContactsFragment : MasterFragment<ContactMasterFragmentBinding, Cont
}
listViewModel.sipContactsSelected.observe(
viewLifecycleOwner,
{
listViewModel.updateContactsList()
}
)
viewLifecycleOwner
) {
listViewModel.updateContactsList()
}
listViewModel.filter.observe(
viewLifecycleOwner,
{
listViewModel.updateContactsList()
}
)
viewLifecycleOwner
) {
listViewModel.updateContactsList()
}
binding.setNewContactClickListener {
// Remove any previously selected contact

View file

@ -77,24 +77,25 @@ class DialerFragment : SecureFragment<DialerFragmentBinding>() {
useMaterialSharedAxisXForwardAnimation = false
sharedViewModel.updateDialerAnimationsBasedOnDestination.observe(
viewLifecycleOwner,
{
it.consume { id ->
val forward = when (id) {
R.id.masterChatRoomsFragment -> false
else -> true
}
if (corePreferences.enableAnimations) {
val portraitOrientation = resources.configuration.orientation != Configuration.ORIENTATION_LANDSCAPE
val axis = if (portraitOrientation) MaterialSharedAxis.X else MaterialSharedAxis.Y
enterTransition = MaterialSharedAxis(axis, forward)
reenterTransition = MaterialSharedAxis(axis, forward)
returnTransition = MaterialSharedAxis(axis, !forward)
exitTransition = MaterialSharedAxis(axis, !forward)
}
viewLifecycleOwner
) {
it.consume { id ->
val forward = when (id) {
R.id.masterChatRoomsFragment -> false
else -> true
}
if (corePreferences.enableAnimations) {
val portraitOrientation =
resources.configuration.orientation != Configuration.ORIENTATION_LANDSCAPE
val axis =
if (portraitOrientation) MaterialSharedAxis.X else MaterialSharedAxis.Y
enterTransition = MaterialSharedAxis(axis, forward)
reenterTransition = MaterialSharedAxis(axis, forward)
returnTransition = MaterialSharedAxis(axis, !forward)
exitTransition = MaterialSharedAxis(axis, !forward)
}
}
)
}
binding.setNewContactClickListener {
sharedViewModel.updateDialerAnimationsBasedOnDestination.value = Event(R.id.masterContactsFragment)
@ -111,43 +112,40 @@ class DialerFragment : SecureFragment<DialerFragmentBinding>() {
}
viewModel.enteredUri.observe(
viewLifecycleOwner,
{
if (it == corePreferences.debugPopupCode) {
displayDebugPopup()
viewModel.enteredUri.value = ""
}
viewLifecycleOwner
) {
if (it == corePreferences.debugPopupCode) {
displayDebugPopup()
viewModel.enteredUri.value = ""
}
)
}
viewModel.uploadFinishedEvent.observe(
viewLifecycleOwner,
{
it.consume { url ->
// To prevent being trigger when using the Send Logs button in About page
if (uploadLogsInitiatedByUs) {
val clipboard =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Logs url", url)
clipboard.setPrimaryClip(clip)
viewLifecycleOwner
) {
it.consume { url ->
// To prevent being trigger when using the Send Logs button in About page
if (uploadLogsInitiatedByUs) {
val clipboard =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Logs url", url)
clipboard.setPrimaryClip(clip)
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.logs_url_copied_to_clipboard)
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.logs_url_copied_to_clipboard)
AppUtils.shareUploadedLogsUrl(activity, url)
}
AppUtils.shareUploadedLogsUrl(activity, url)
}
}
)
}
viewModel.updateAvailableEvent.observe(
viewLifecycleOwner,
{
it.consume { url ->
displayNewVersionAvailableDialog(url)
}
viewLifecycleOwner
) {
it.consume { url ->
displayNewVersionAvailableDialog(url)
}
)
}
if (corePreferences.firstStart) {
Log.w("[Dialer] First start detected, wait for assistant to be finished to check for update & request permissions")

View file

@ -139,7 +139,7 @@ class TopBarFragment : GenericFragment<FileViewerTopBarFragmentBinding>() {
Log.w("[File Viewer] Media store file path is empty, media store export failed?")
val filePath = content.plainFilePath.orEmpty()
plainFilePath = if (filePath.isEmpty()) content.filePath.orEmpty() else filePath
plainFilePath = filePath.ifEmpty { content.filePath.orEmpty() }
Log.i("[File Viewer] Plain file path is: $plainFilePath")
if (plainFilePath.isNotEmpty()) {
if (!FileUtils.openFileInThirdPartyApp(requireActivity(), plainFilePath)) {

View file

@ -56,56 +56,55 @@ abstract class MasterFragment<T : ViewDataBinding, U : SelectionListAdapter<*, *
listSelectionViewModel = ViewModelProvider(this)[ListTopBarViewModel::class.java]
listSelectionViewModel.isEditionEnabled.observe(
viewLifecycleOwner,
{
if (!it) listSelectionViewModel.onUnSelectAll()
}
)
viewLifecycleOwner
) {
if (!it) listSelectionViewModel.onUnSelectAll()
}
listSelectionViewModel.selectAllEvent.observe(
viewLifecycleOwner,
{
it.consume {
listSelectionViewModel.onSelectAll(getItemCount() - 1)
}
viewLifecycleOwner
) {
it.consume {
listSelectionViewModel.onSelectAll(getItemCount() - 1)
}
)
}
listSelectionViewModel.unSelectAllEvent.observe(
viewLifecycleOwner,
{
it.consume {
listSelectionViewModel.onUnSelectAll()
}
viewLifecycleOwner
) {
it.consume {
listSelectionViewModel.onUnSelectAll()
}
)
}
listSelectionViewModel.deleteSelectionEvent.observe(
viewLifecycleOwner,
{
it.consume {
val confirmationDialog = AppUtils.getStringWithPlural(dialogConfirmationMessageBeforeRemoval, listSelectionViewModel.selectedItems.value.orEmpty().size)
val viewModel = DialogViewModel(confirmationDialog)
val dialog: Dialog = DialogUtils.getDialog(requireContext(), viewModel)
viewLifecycleOwner
) {
it.consume {
val confirmationDialog = AppUtils.getStringWithPlural(
dialogConfirmationMessageBeforeRemoval,
listSelectionViewModel.selectedItems.value.orEmpty().size
)
val viewModel = DialogViewModel(confirmationDialog)
val dialog: Dialog = DialogUtils.getDialog(requireContext(), viewModel)
viewModel.showCancelButton {
viewModel.showCancelButton {
dialog.dismiss()
listSelectionViewModel.isEditionEnabled.value = false
}
viewModel.showDeleteButton(
{
delete()
dialog.dismiss()
listSelectionViewModel.isEditionEnabled.value = false
}
},
getString(R.string.dialog_delete)
)
viewModel.showDeleteButton(
{
delete()
dialog.dismiss()
listSelectionViewModel.isEditionEnabled.value = false
},
getString(R.string.dialog_delete)
)
dialog.show()
}
dialog.show()
}
)
}
}
private fun delete() {

View file

@ -51,15 +51,14 @@ class StatusFragment : GenericFragment<StatusFragmentBinding>() {
}
sharedViewModel.accountRemoved.observe(
viewLifecycleOwner,
{
Log.i("[Status Fragment] An account was removed, update default account state")
val defaultAccount = coreContext.core.defaultAccount
if (defaultAccount != null) {
viewModel.updateDefaultAccountRegistrationStatus(defaultAccount.state)
}
viewLifecycleOwner
) {
Log.i("[Status Fragment] An account was removed, update default account state")
val defaultAccount = coreContext.core.defaultAccount
if (defaultAccount != null) {
viewModel.updateDefaultAccountRegistrationStatus(defaultAccount.state)
}
)
}
binding.setMenuClickListener {
sharedViewModel.toggleDrawerEvent.value = Event(true)

View file

@ -73,11 +73,10 @@ class CallLogsListAdapter(
// This is for item selection through ListTopBarFragment
selectionListViewModel = selectionViewModel
selectionViewModel.isEditionEnabled.observe(
viewLifecycleOwner,
{
position = bindingAdapterPosition
}
)
viewLifecycleOwner
) {
position = bindingAdapterPosition
}
setClickListener {
if (selectionViewModel.isEditionEnabled.value == true) {

View file

@ -99,50 +99,48 @@ class DetailCallLogFragment : GenericFragment<HistoryDetailFragmentBinding>() {
}
viewModel.startCallEvent.observe(
viewLifecycleOwner,
{
it.consume { callLog ->
val address = callLog.remoteAddress
if (coreContext.core.callsNb > 0) {
Log.i("[History] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}")
sharedViewModel.updateDialerAnimationsBasedOnDestination.value = Event(R.id.masterCallLogsFragment)
viewLifecycleOwner
) {
it.consume { callLog ->
val address = callLog.remoteAddress
if (coreContext.core.callsNb > 0) {
Log.i("[History] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}")
sharedViewModel.updateDialerAnimationsBasedOnDestination.value =
Event(R.id.masterCallLogsFragment)
val args = Bundle()
args.putString("URI", address.asStringUriOnly())
args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer)
args.putBoolean(
"SkipAutoCallStart",
true
) // If auto start call setting is enabled, ignore it
navigateToDialer(args)
} else {
val localAddress = callLog.localAddress
coreContext.startCall(address, localAddress = localAddress)
}
val args = Bundle()
args.putString("URI", address.asStringUriOnly())
args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer)
args.putBoolean(
"SkipAutoCallStart",
true
) // If auto start call setting is enabled, ignore it
navigateToDialer(args)
} else {
val localAddress = callLog.localAddress
coreContext.startCall(address, localAddress = localAddress)
}
}
)
}
viewModel.chatRoomCreatedEvent.observe(
viewLifecycleOwner,
{
it.consume { chatRoom ->
val args = Bundle()
args.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly())
args.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly())
navigateToChatRoom(args)
}
viewLifecycleOwner
) {
it.consume { chatRoom ->
val args = Bundle()
args.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly())
args.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly())
navigateToChatRoom(args)
}
)
}
viewModel.onErrorEvent.observe(
viewLifecycleOwner,
{
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
viewLifecycleOwner
) {
it.consume { messageResourceId ->
(activity as MainActivity).showSnackBar(messageResourceId)
}
)
}
}
override fun goBack() {

View file

@ -101,30 +101,29 @@ class MasterCallLogsFragment : MasterFragment<HistoryMasterFragmentBinding, Call
view.doOnPreDraw { sharedViewModel.isSlidingPaneSlideable.value = binding.slidingPane.isSlideable }
sharedViewModel.closeSlidingPaneEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (!binding.slidingPane.closePane()) {
goBack()
}
viewLifecycleOwner
) {
it.consume {
if (!binding.slidingPane.closePane()) {
goBack()
}
}
)
}
sharedViewModel.layoutChangedEvent.observe(
viewLifecycleOwner,
{
it.consume {
sharedViewModel.isSlidingPaneSlideable.value = binding.slidingPane.isSlideable
if (binding.slidingPane.isSlideable) {
val navHostFragment = childFragmentManager.findFragmentById(R.id.history_nav_container) as NavHostFragment
if (navHostFragment.navController.currentDestination?.id == R.id.emptyCallHistoryFragment) {
Log.i("[History] Foldable device has been folded, closing side pane with empty fragment")
binding.slidingPane.closePane()
}
viewLifecycleOwner
) {
it.consume {
sharedViewModel.isSlidingPaneSlideable.value = binding.slidingPane.isSlideable
if (binding.slidingPane.isSlideable) {
val navHostFragment =
childFragmentManager.findFragmentById(R.id.history_nav_container) as NavHostFragment
if (navHostFragment.navController.currentDestination?.id == R.id.emptyCallHistoryFragment) {
Log.i("[History] Foldable device has been folded, closing side pane with empty fragment")
binding.slidingPane.closePane()
}
}
}
)
}
binding.slidingPane.lockMode = SlidingPaneLayout.LOCK_MODE_LOCKED
/* End of shared view model & sliding pane related */
@ -193,73 +192,71 @@ class MasterCallLogsFragment : MasterFragment<HistoryMasterFragmentBinding, Call
binding.callLogsList.addItemDecoration(headerItemDecoration)
listViewModel.callLogs.observe(
viewLifecycleOwner,
{ callLogs ->
if (listViewModel.missedCallLogsSelected.value == false) {
adapter.submitList(callLogs)
}
viewLifecycleOwner
) { callLogs ->
if (listViewModel.missedCallLogsSelected.value == false) {
adapter.submitList(callLogs)
}
)
}
listViewModel.missedCallLogs.observe(
viewLifecycleOwner,
{ callLogs ->
if (listViewModel.missedCallLogsSelected.value == true) {
adapter.submitList(callLogs)
}
viewLifecycleOwner
) { callLogs ->
if (listViewModel.missedCallLogsSelected.value == true) {
adapter.submitList(callLogs)
}
)
}
listViewModel.missedCallLogsSelected.observe(
viewLifecycleOwner,
{
if (it) {
adapter.submitList(listViewModel.missedCallLogs.value)
} else {
adapter.submitList(listViewModel.callLogs.value)
}
viewLifecycleOwner
) {
if (it) {
adapter.submitList(listViewModel.missedCallLogs.value)
} else {
adapter.submitList(listViewModel.callLogs.value)
}
)
}
listViewModel.contactsUpdatedEvent.observe(
viewLifecycleOwner,
{
it.consume {
adapter.notifyDataSetChanged()
}
viewLifecycleOwner
) {
it.consume {
adapter.notifyDataSetChanged()
}
)
}
adapter.selectedCallLogEvent.observe(
viewLifecycleOwner,
{
it.consume { callLog ->
sharedViewModel.selectedCallLogGroup.value = callLog
navigateToCallHistory(binding.slidingPane)
}
viewLifecycleOwner
) {
it.consume { callLog ->
sharedViewModel.selectedCallLogGroup.value = callLog
navigateToCallHistory(binding.slidingPane)
}
)
}
adapter.startCallToEvent.observe(
viewLifecycleOwner,
{
it.consume { callLogGroup ->
val remoteAddress = callLogGroup.lastCallLog.remoteAddress
if (coreContext.core.callsNb > 0) {
Log.i("[History] Starting dialer with pre-filled URI ${remoteAddress.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}")
sharedViewModel.updateDialerAnimationsBasedOnDestination.value = Event(R.id.masterCallLogsFragment)
val args = Bundle()
args.putString("URI", remoteAddress.asStringUriOnly())
args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer)
args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it
navigateToDialer(args)
} else {
val localAddress = callLogGroup.lastCallLog.localAddress
coreContext.startCall(remoteAddress, localAddress = localAddress)
}
viewLifecycleOwner
) {
it.consume { callLogGroup ->
val remoteAddress = callLogGroup.lastCallLog.remoteAddress
if (coreContext.core.callsNb > 0) {
Log.i("[History] Starting dialer with pre-filled URI ${remoteAddress.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}")
sharedViewModel.updateDialerAnimationsBasedOnDestination.value =
Event(R.id.masterCallLogsFragment)
val args = Bundle()
args.putString("URI", remoteAddress.asStringUriOnly())
args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer)
args.putBoolean(
"SkipAutoCallStart",
true
) // If auto start call setting is enabled, ignore it
navigateToDialer(args)
} else {
val localAddress = callLogGroup.lastCallLog.localAddress
coreContext.startCall(remoteAddress, localAddress = localAddress)
}
}
)
}
binding.setAllCallLogsToggleClickListener {
listViewModel.missedCallLogsSelected.value = false

View file

@ -22,7 +22,6 @@ package org.linphone.activities.main.history.viewmodels
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import java.util.*
import kotlin.collections.ArrayList
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences

View file

@ -69,11 +69,10 @@ class RecordingsFragment : MasterFragment<RecordingsFragmentBinding, RecordingsL
binding.recordingsList.addItemDecoration(headerItemDecoration)
viewModel.recordingsList.observe(
viewLifecycleOwner,
{ recordings ->
adapter.submitList(recordings)
}
)
viewLifecycleOwner
) { recordings ->
adapter.submitList(recordings)
}
binding.setBackClickListener { goBack() }

View file

@ -63,32 +63,30 @@ class AccountSettingsFragment : GenericSettingFragment<SettingsAccountFragmentBi
binding.setBackClickListener { goBack() }
viewModel.linkPhoneNumberEvent.observe(
viewLifecycleOwner,
{
it.consume {
val authInfo = viewModel.account.findAuthInfo()
if (authInfo == null) {
Log.e("[Account Settings] Failed to find auth info for account ${viewModel.account}")
} else {
val args = Bundle()
args.putString("Username", authInfo.username)
args.putString("Password", authInfo.password)
args.putString("HA1", authInfo.ha1)
navigateToPhoneLinking(args)
}
viewLifecycleOwner
) {
it.consume {
val authInfo = viewModel.account.findAuthInfo()
if (authInfo == null) {
Log.e("[Account Settings] Failed to find auth info for account ${viewModel.account}")
} else {
val args = Bundle()
args.putString("Username", authInfo.username)
args.putString("Password", authInfo.password)
args.putString("HA1", authInfo.ha1)
navigateToPhoneLinking(args)
}
}
)
}
viewModel.accountRemovedEvent.observe(
viewLifecycleOwner,
{
it.consume {
sharedViewModel.accountRemoved.value = true
goBack()
}
viewLifecycleOwner
) {
it.consume {
sharedViewModel.accountRemoved.value = true
goBack()
}
)
}
view.doOnPreDraw {
// Notifies fragment is ready to be drawn

View file

@ -55,103 +55,96 @@ class AdvancedSettingsFragment : GenericSettingFragment<SettingsAdvancedFragment
binding.setBackClickListener { goBack() }
viewModel.uploadFinishedEvent.observe(
viewLifecycleOwner,
{
it.consume { url ->
val clipboard =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Logs url", url)
clipboard.setPrimaryClip(clip)
viewLifecycleOwner
) {
it.consume { url ->
val clipboard =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Logs url", url)
clipboard.setPrimaryClip(clip)
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.logs_url_copied_to_clipboard)
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.logs_url_copied_to_clipboard)
AppUtils.shareUploadedLogsUrl(activity, url)
}
AppUtils.shareUploadedLogsUrl(activity, url)
}
)
}
viewModel.uploadErrorEvent.observe(
viewLifecycleOwner,
{
it.consume {
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.logs_upload_failure)
}
viewLifecycleOwner
) {
it.consume {
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.logs_upload_failure)
}
)
}
viewModel.resetCompleteEvent.observe(
viewLifecycleOwner,
{
it.consume {
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.logs_reset_complete)
}
viewLifecycleOwner
) {
it.consume {
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.logs_reset_complete)
}
)
}
viewModel.setNightModeEvent.observe(
viewLifecycleOwner,
{
it.consume { value ->
AppCompatDelegate.setDefaultNightMode(
when (value) {
0 -> AppCompatDelegate.MODE_NIGHT_NO
1 -> AppCompatDelegate.MODE_NIGHT_YES
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
}
viewLifecycleOwner
) {
it.consume { value ->
AppCompatDelegate.setDefaultNightMode(
when (value) {
0 -> AppCompatDelegate.MODE_NIGHT_NO
1 -> AppCompatDelegate.MODE_NIGHT_YES
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
}
)
}
viewModel.backgroundModeEnabled.value = !DeviceUtils.isAppUserRestricted(requireContext())
viewModel.goToBatterySettingsEvent.observe(
viewLifecycleOwner,
{
it.consume {
try {
val intent = Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS")
startActivity(intent)
} catch (anfe: ActivityNotFoundException) {
Log.e("[Advanced Settings] ActivityNotFound exception: ", anfe)
}
viewLifecycleOwner
) {
it.consume {
try {
val intent = Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS")
startActivity(intent)
} catch (anfe: ActivityNotFoundException) {
Log.e("[Advanced Settings] ActivityNotFound exception: ", anfe)
}
}
)
}
viewModel.powerManagerSettingsVisibility.value = PowerManagerUtils.getDevicePowerManagerIntent(requireContext()) != null
viewModel.goToPowerManagerSettingsEvent.observe(
viewLifecycleOwner,
{
it.consume {
val intent = PowerManagerUtils.getDevicePowerManagerIntent(requireActivity())
if (intent != null) {
try {
startActivity(intent)
} catch (se: SecurityException) {
Log.e("[Advanced Settings] Security exception: ", se)
}
viewLifecycleOwner
) {
it.consume {
val intent = PowerManagerUtils.getDevicePowerManagerIntent(requireActivity())
if (intent != null) {
try {
startActivity(intent)
} catch (se: SecurityException) {
Log.e("[Advanced Settings] Security exception: ", se)
}
}
}
)
}
viewModel.goToAndroidSettingsEvent.observe(
viewLifecycleOwner,
{
it.consume {
val intent = Intent()
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.data = Uri.parse("package:${requireContext().packageName}")
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
ContextCompat.startActivity(requireContext(), intent, null)
}
viewLifecycleOwner
) {
it.consume {
val intent = Intent()
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.data = Uri.parse("package:${requireContext().packageName}")
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
ContextCompat.startActivity(requireContext(), intent, null)
}
)
}
}
override fun goBack() {

View file

@ -54,24 +54,22 @@ class AudioSettingsFragment : GenericSettingFragment<SettingsAudioFragmentBindin
binding.setBackClickListener { goBack() }
viewModel.askAudioRecordPermissionForEchoCancellerCalibrationEvent.observe(
viewLifecycleOwner,
{
it.consume {
Log.i("[Audio Settings] Asking for RECORD_AUDIO permission for echo canceller calibration")
requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 1)
}
viewLifecycleOwner
) {
it.consume {
Log.i("[Audio Settings] Asking for RECORD_AUDIO permission for echo canceller calibration")
requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 1)
}
)
}
viewModel.askAudioRecordPermissionForEchoTesterEvent.observe(
viewLifecycleOwner,
{
it.consume {
Log.i("[Audio Settings] Asking for RECORD_AUDIO permission for echo tester")
requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 2)
}
viewLifecycleOwner
) {
it.consume {
Log.i("[Audio Settings] Asking for RECORD_AUDIO permission for echo tester")
requestPermissions(arrayOf(android.Manifest.permission.RECORD_AUDIO), 2)
}
)
}
initAudioCodecsList()

View file

@ -55,76 +55,75 @@ class CallSettingsFragment : GenericSettingFragment<SettingsCallFragmentBinding>
binding.setBackClickListener { goBack() }
viewModel.systemWideOverlayEnabledEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (!Compatibility.canDrawOverlay(requireContext())) {
val intent = Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse("package:${requireContext().packageName}"))
startActivityForResult(intent, 0)
}
viewLifecycleOwner
) {
it.consume {
if (!Compatibility.canDrawOverlay(requireContext())) {
val intent = Intent(
"android.settings.action.MANAGE_OVERLAY_PERMISSION",
Uri.parse("package:${requireContext().packageName}")
)
startActivityForResult(intent, 0)
}
}
)
}
viewModel.goToAndroidNotificationSettingsEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (Build.VERSION.SDK_INT >= Version.API26_O_80) {
val i = Intent()
i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS
i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
i.putExtra(
Settings.EXTRA_CHANNEL_ID,
getString(R.string.notification_channel_service_id)
)
i.addCategory(Intent.CATEGORY_DEFAULT)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
startActivity(i)
}
viewLifecycleOwner
) {
it.consume {
if (Build.VERSION.SDK_INT >= Version.API26_O_80) {
val i = Intent()
i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS
i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
i.putExtra(
Settings.EXTRA_CHANNEL_ID,
getString(R.string.notification_channel_service_id)
)
i.addCategory(Intent.CATEGORY_DEFAULT)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
startActivity(i)
}
}
)
}
viewModel.enableTelecomManagerEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (!Compatibility.hasTelecomManagerPermissions(requireContext())) {
Compatibility.requestTelecomManagerPermissions(requireActivity(), 1)
} else if (!TelecomHelper.exists()) {
corePreferences.useTelecomManager = true
Log.w("[Telecom Helper] Doesn't exists yet, creating it")
TelecomHelper.create(requireContext())
updateTelecomManagerAccount()
}
viewLifecycleOwner
) {
it.consume {
if (!Compatibility.hasTelecomManagerPermissions(requireContext())) {
Compatibility.requestTelecomManagerPermissions(requireActivity(), 1)
} else if (!TelecomHelper.exists()) {
corePreferences.useTelecomManager = true
Log.w("[Telecom Helper] Doesn't exists yet, creating it")
TelecomHelper.create(requireContext())
updateTelecomManagerAccount()
}
}
)
}
viewModel.goToAndroidNotificationSettingsEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (Build.VERSION.SDK_INT >= Version.API26_O_80) {
val i = Intent()
i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS
i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
i.putExtra(
Settings.EXTRA_CHANNEL_ID,
getString(R.string.notification_channel_service_id)
)
i.addCategory(Intent.CATEGORY_DEFAULT)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
startActivity(i)
}
viewLifecycleOwner
) {
it.consume {
if (Build.VERSION.SDK_INT >= Version.API26_O_80) {
val i = Intent()
i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS
i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
i.putExtra(
Settings.EXTRA_CHANNEL_ID,
getString(R.string.notification_channel_service_id)
)
i.addCategory(Intent.CATEGORY_DEFAULT)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
startActivity(i)
}
}
)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

View file

@ -50,39 +50,37 @@ class ChatSettingsFragment : GenericSettingFragment<SettingsChatFragmentBinding>
binding.setBackClickListener { goBack() }
viewModel.launcherShortcutsEvent.observe(
viewLifecycleOwner,
{
it.consume { newValue ->
if (newValue) {
Compatibility.createShortcutsToChatRooms(requireContext())
} else {
Compatibility.removeShortcuts(requireContext())
}
viewLifecycleOwner
) {
it.consume { newValue ->
if (newValue) {
Compatibility.createShortcutsToChatRooms(requireContext())
} else {
Compatibility.removeShortcuts(requireContext())
}
}
)
}
viewModel.goToAndroidNotificationSettingsEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (Build.VERSION.SDK_INT >= Version.API26_O_80) {
val i = Intent()
i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS
i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
i.putExtra(
Settings.EXTRA_CHANNEL_ID,
getString(R.string.notification_channel_chat_id)
)
i.addCategory(Intent.CATEGORY_DEFAULT)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
startActivity(i)
}
viewLifecycleOwner
) {
it.consume {
if (Build.VERSION.SDK_INT >= Version.API26_O_80) {
val i = Intent()
i.action = Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS
i.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
i.putExtra(
Settings.EXTRA_CHANNEL_ID,
getString(R.string.notification_channel_chat_id)
)
i.addCategory(Intent.CATEGORY_DEFAULT)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
startActivity(i)
}
}
)
}
}
override fun goBack() {

View file

@ -51,30 +51,28 @@ class ContactsSettingsFragment : GenericSettingFragment<SettingsContactsFragment
binding.setBackClickListener { goBack() }
viewModel.launcherShortcutsEvent.observe(
viewLifecycleOwner,
{
it.consume { newValue ->
if (newValue) {
Compatibility.createShortcutsToContacts(requireContext())
} else {
Compatibility.removeShortcuts(requireContext())
if (corePreferences.chatRoomShortcuts) {
Compatibility.createShortcutsToChatRooms(requireContext())
}
viewLifecycleOwner
) {
it.consume { newValue ->
if (newValue) {
Compatibility.createShortcutsToContacts(requireContext())
} else {
Compatibility.removeShortcuts(requireContext())
if (corePreferences.chatRoomShortcuts) {
Compatibility.createShortcutsToChatRooms(requireContext())
}
}
}
)
}
viewModel.askWriteContactsPermissionForPresenceStorageEvent.observe(
viewLifecycleOwner,
{
it.consume {
Log.i("[Contacts Settings] Asking for WRITE_CONTACTS permission to be able to store presence")
requestPermissions(arrayOf(android.Manifest.permission.WRITE_CONTACTS), 1)
}
viewLifecycleOwner
) {
it.consume {
Log.i("[Contacts Settings] Asking for WRITE_CONTACTS permission to be able to store presence")
requestPermissions(arrayOf(android.Manifest.permission.WRITE_CONTACTS), 1)
}
)
}
if (!PermissionHelper.required(requireContext()).hasReadContactsPermission()) {
Log.i("[Contacts Settings] Asking for READ_CONTACTS permission")

View file

@ -69,39 +69,37 @@ class SettingsFragment : SecureFragment<SettingsFragmentBinding>() {
// Account settings loading can take some time, so wait until it is ready before opening the pane
sharedViewModel.accountSettingsFragmentOpenedEvent.observe(
viewLifecycleOwner,
{
it.consume {
binding.slidingPane.openPane()
}
viewLifecycleOwner
) {
it.consume {
binding.slidingPane.openPane()
}
)
}
sharedViewModel.closeSlidingPaneEvent.observe(
viewLifecycleOwner,
{
it.consume {
if (!binding.slidingPane.closePane()) {
goBack()
}
viewLifecycleOwner
) {
it.consume {
if (!binding.slidingPane.closePane()) {
goBack()
}
}
)
}
sharedViewModel.layoutChangedEvent.observe(
viewLifecycleOwner,
{
it.consume {
sharedViewModel.isSlidingPaneSlideable.value = binding.slidingPane.isSlideable
if (binding.slidingPane.isSlideable) {
val navHostFragment = childFragmentManager.findFragmentById(R.id.settings_nav_container) as NavHostFragment
if (navHostFragment.navController.currentDestination?.id == R.id.emptySettingsFragment) {
Log.i("[Settings] Foldable device has been folded, closing side pane with empty fragment")
binding.slidingPane.closePane()
}
viewLifecycleOwner
) {
it.consume {
sharedViewModel.isSlidingPaneSlideable.value = binding.slidingPane.isSlideable
if (binding.slidingPane.isSlideable) {
val navHostFragment =
childFragmentManager.findFragmentById(R.id.settings_nav_container) as NavHostFragment
if (navHostFragment.navController.currentDestination?.id == R.id.emptySettingsFragment) {
Log.i("[Settings] Foldable device has been folded, closing side pane with empty fragment")
binding.slidingPane.closePane()
}
}
}
)
}
binding.slidingPane.lockMode = SlidingPaneLayout.LOCK_MODE_LOCKED
/* End of shared view model & sliding pane related */
@ -112,12 +110,11 @@ class SettingsFragment : SecureFragment<SettingsFragmentBinding>() {
binding.setBackClickListener { goBack() }
sharedViewModel.accountRemoved.observe(
viewLifecycleOwner,
{
Log.i("[Settings] Account removed, update accounts list")
viewModel.updateAccountsList()
}
)
viewLifecycleOwner
) {
Log.i("[Settings] Account removed, update accounts list")
viewModel.updateAccountsList()
}
val identity = arguments?.getString("Identity")
if (identity != null) {

View file

@ -33,7 +33,7 @@ class TelephonyListener(private val telephonyManager: TelephonyManager) : PhoneS
private fun runOnUiThreadExecutor(): Executor {
val handler = Handler(Looper.getMainLooper())
return Executor() {
return Executor {
handler.post(it)
}
}

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/tools">
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View"/>

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/tools">
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View"/>