Improved navigation

This commit is contained in:
Sylvain Berfini 2023-08-09 13:51:05 +02:00
parent 0cca9f8152
commit 0e7f00cddd
15 changed files with 146 additions and 77 deletions

View file

@ -102,4 +102,9 @@ class CallsFragment : GenericFragment() {
}
}
}
override fun onResume() {
super.onResume()
sharedViewModel.currentlyDisplayedFragment.value = R.id.callsFragment
}
}

View file

@ -33,7 +33,6 @@ import org.linphone.databinding.CallsListFragmentBinding
import org.linphone.ui.MainActivity
import org.linphone.ui.calls.viewmodel.CallsListViewModel
import org.linphone.ui.fragment.GenericFragment
import org.linphone.utils.Event
import org.linphone.utils.setKeyboardInsetListener
class CallsListFragment : GenericFragment() {
@ -71,14 +70,6 @@ class CallsListFragment : GenericFragment() {
listViewModel.bottomNavBarVisible.value = !portraitOrientation || !keyboardVisible
}
binding.setOnConversationsClicked {
sharedViewModel.navigateToConversationsEvent.value = Event(true)
}
binding.setOnContactsClicked {
sharedViewModel.navigateToContactsEvent.value = Event(true)
}
binding.setOnAvatarClickListener {
(requireActivity() as MainActivity).toggleDrawerMenu()
}

View file

@ -56,6 +56,10 @@ class ContactFragment : GenericFragment() {
return binding.root
}
override fun goBack() {
sharedViewModel.closeSlidingPaneEvent.value = Event(true)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -71,7 +75,7 @@ class ContactFragment : GenericFragment() {
viewModel.findContactByRefKey(refKey)
binding.setBackClickListener {
sharedViewModel.closeSlidingPaneEvent.value = Event(true)
goBack()
}
sharedViewModel.isSlidingPaneSlideable.observe(viewLifecycleOwner) { slideable ->

View file

@ -115,4 +115,9 @@ class ContactsFragment : GenericFragment() {
}
}
}
override fun onResume() {
super.onResume()
sharedViewModel.currentlyDisplayedFragment.value = R.id.contactsFragment
}
}

View file

@ -130,17 +130,7 @@ class ContactsListFragment : GenericFragment() {
}
binding.setOnNewContactClicked {
if (findNavController().currentDestination?.id == R.id.contactsListFragment) {
findNavController().navigate(R.id.action_contactsListFragment_to_newContactFragment)
}
}
binding.setOnConversationsClicked {
sharedViewModel.navigateToConversationsEvent.value = Event(true)
}
binding.setOnCallsClicked {
sharedViewModel.navigateToCallsEvent.value = Event(true)
findNavController().navigate(R.id.action_global_newContactFragment)
}
binding.setOnAvatarClickListener {

View file

@ -31,14 +31,6 @@ import org.linphone.ui.fragment.GenericFragment
class NewContactFragment : GenericFragment() {
private lateinit var binding: NewContactFragmentBinding
override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation? {
/*if (findNavController().currentDestination?.id == R.id.contactFragment) {
// Holds fragment in place while created contact fragment slides over it
return AnimationUtils.loadAnimation(activity, R.anim.hold)
}*/
return super.onCreateAnimation(transit, enter, nextAnim)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@ -48,19 +40,17 @@ class NewContactFragment : GenericFragment() {
return binding.root
}
override fun goBack() {
findNavController().popBackStack()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.lifecycleOwner = viewLifecycleOwner
// postponeEnterTransition()
binding.setCancelClickListener {
findNavController().popBackStack()
goBack()
}
/*(view.parent as? ViewGroup)?.doOnPreDraw {
startPostponedEnterTransition()
}*/
}
}

View file

@ -0,0 +1,84 @@
/*
* 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.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import org.linphone.R
import org.linphone.databinding.BottomNavBarBinding
import org.linphone.ui.viewmodel.SharedMainViewModel
import org.linphone.utils.Event
class BottomNavBarFragment : Fragment() {
private lateinit var binding: BottomNavBarBinding
private lateinit var sharedViewModel: SharedMainViewModel
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = BottomNavBarBinding.inflate(layoutInflater)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
sharedViewModel = requireActivity().run {
ViewModelProvider(this)[SharedMainViewModel::class.java]
}
binding.lifecycleOwner = viewLifecycleOwner
binding.setOnContactsClicked {
if (sharedViewModel.currentlyDisplayedFragment.value != R.id.contactsFragment) {
sharedViewModel.navigateToContactsEvent.value = Event(true)
}
}
binding.setOnCallsClicked {
if (sharedViewModel.currentlyDisplayedFragment.value != R.id.callsFragment) {
sharedViewModel.navigateToCallsEvent.value = Event(true)
}
}
binding.setOnConversationsClicked {
if (sharedViewModel.currentlyDisplayedFragment.value != R.id.conversationsFragment) {
sharedViewModel.navigateToConversationsEvent.value = Event(true)
}
}
binding.setOnMeetingsClicked {
// TODO
}
sharedViewModel.currentlyDisplayedFragment.observe(viewLifecycleOwner) {
binding.contactsSelected = it == R.id.contactsFragment
binding.callsSelected = it == R.id.callsFragment
binding.conversationsSelected = it == R.id.conversationsFragment
}
}
}

View file

@ -84,7 +84,7 @@ abstract class GenericFragment : Fragment() {
return this.javaClass.name
}
protected fun goBack() {
protected open fun goBack() {
try {
requireActivity().onBackPressedDispatcher.onBackPressed()
} catch (ise: IllegalStateException) {

View file

@ -38,6 +38,8 @@ class SharedMainViewModel : ViewModel() {
val navigateToContactsEvent = MutableLiveData<Event<Boolean>>()
var currentlyDisplayedFragment = MutableLiveData<Int>()
/* Contacts related */
val showContactEvent = MutableLiveData<Event<String>>()

View file

@ -45,18 +45,16 @@
app:layout_constraintStart_toEndOf="@id/bottom_nav_bar"
app:layout_constraintTop_toBottomOf="@id/top_bar" />
<include
bind:onConversationsClicked="@{onConversationsClicked}"
bind:onContactsClicked="@{onContactsClicked}"
bind:callsSelected="@{true}"
<androidx.fragment.app.FragmentContainerView
android:id="@+id/bottom_nav_bar"
android:visibility="@{viewModel.bottomNavBarVisible ? View.VISIBLE : View.GONE}"
layout="@layout/bottom_nav_bar"
android:name="org.linphone.ui.fragment.BottomNavBarFragment"
android:layout_width="75dp"
android:layout_height="0dp"
android:visibility="@{viewModel.bottomNavBarVisible ? View.VISIBLE : View.GONE}"
bind:layout="@layout/bottom_nav_bar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintBottom_toBottomOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/new_call"

View file

@ -33,18 +33,16 @@
app:constraint_referenced_ids="no_contacts_image, no_contacts_label"
android:visibility="@{viewModel.contactsList.empty ? View.VISIBLE : View.GONE}" />
<include
bind:onConversationsClicked="@{onConversationsClicked}"
bind:onCallsClicked="@{onCallsClicked}"
bind:contactsSelected="@{true}"
<androidx.fragment.app.FragmentContainerView
android:id="@+id/bottom_nav_bar"
android:visibility="@{viewModel.bottomNavBarVisible ? View.VISIBLE : View.GONE}"
layout="@layout/bottom_nav_bar"
android:name="org.linphone.ui.fragment.BottomNavBarFragment"
android:layout_width="75dp"
android:layout_height="0dp"
android:visibility="@{viewModel.bottomNavBarVisible ? View.VISIBLE : View.GONE}"
bind:layout="@layout/bottom_nav_bar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintBottom_toBottomOf="parent" />
<include
android:id="@+id/top_bar"

View file

@ -40,18 +40,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/top_bar" />
<include
bind:onConversationsClicked="@{onConversationsClicked}"
bind:onContactsClicked="@{onContactsClicked}"
bind:callsSelected="@{true}"
<androidx.fragment.app.FragmentContainerView
android:id="@+id/bottom_nav_bar"
android:visibility="@{viewModel.bottomNavBarVisible ? View.VISIBLE : View.GONE}"
layout="@layout/bottom_nav_bar"
android:name="org.linphone.ui.fragment.BottomNavBarFragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="@{viewModel.bottomNavBarVisible ? View.VISIBLE : View.GONE}"
bind:layout="@layout/bottom_nav_bar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintBottom_toBottomOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/new_call"

View file

@ -133,18 +133,16 @@
app:layout_constraintTop_toBottomOf="@id/all_contacts_label"
app:layout_constraintBottom_toTopOf="@id/bottom_nav_bar" />
<include
bind:onConversationsClicked="@{onConversationsClicked}"
bind:onCallsClicked="@{onCallsClicked}"
bind:contactsSelected="@{true}"
<androidx.fragment.app.FragmentContainerView
android:id="@+id/bottom_nav_bar"
android:visibility="@{viewModel.bottomNavBarVisible ? View.VISIBLE : View.GONE}"
layout="@layout/bottom_nav_bar"
android:name="org.linphone.ui.fragment.BottomNavBarFragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="@{viewModel.bottomNavBarVisible ? View.VISIBLE : View.GONE}"
bind:layout="@layout/bottom_nav_bar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintBottom_toBottomOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/new_contact"

View file

@ -11,12 +11,6 @@
android:name="org.linphone.ui.contacts.fragment.ContactsListFragment"
android:label="ContactsListFragment"
tools:layout="@layout/contacts_list_fragment">
<action
android:id="@+id/action_contactsListFragment_to_newContactFragment"
app:destination="@id/newContactFragment"
app:enterAnim="@anim/slide_in"
app:launchSingleTop="true"
app:popExitAnim="@anim/slide_out" />
</fragment>
<fragment
@ -24,4 +18,10 @@
android:name="org.linphone.ui.contacts.fragment.NewContactFragment"
android:label="NewContactFragment"
tools:layout="@layout/new_contact_fragment"/>
<action
android:id="@+id/action_global_newContactFragment"
app:destination="@id/newContactFragment"
app:enterAnim="@anim/slide_in"
app:popExitAnim="@anim/slide_out"
app:launchSingleTop="true" />
</navigation>

View file

@ -14,8 +14,8 @@
android:id="@+id/action_conversationsFragment_to_newConversationFragment"
app:destination="@id/newConversationFragment"
app:enterAnim="@anim/slide_in"
app:launchSingleTop="true"
app:popExitAnim="@anim/slide_out" />
app:popExitAnim="@anim/slide_out"
app:launchSingleTop="true" />
<action
android:id="@+id/action_conversationsFragment_to_conversationFragment"
app:destination="@id/conversationFragment"
@ -24,9 +24,9 @@
<action
android:id="@+id/action_conversationsFragment_to_contactsFragment"
app:destination="@id/contactsFragment"
app:launchSingleTop="true"
app:popUpTo="@id/contactsFragment"
app:popUpToInclusive="true" />
app:popUpToInclusive="true"
app:launchSingleTop="true" />
<action
android:id="@+id/action_conversationsFragment_to_callsFragment"
app:destination="@id/callsFragment" />
@ -68,7 +68,10 @@
app:destination="@id/conversationsFragment" />
<action
android:id="@+id/action_contactsFragment_to_callsFragment"
app:destination="@id/callsFragment" />
app:destination="@id/callsFragment"
app:popUpTo="@id/callsFragment"
app:popUpToInclusive="true"
app:launchSingleTop="true"/>
</fragment>
<fragment
@ -78,7 +81,10 @@
tools:layout="@layout/calls_fragment">
<action
android:id="@+id/action_callsFragment_to_contactsFragment"
app:destination="@id/contactsFragment" />
app:destination="@id/contactsFragment"
app:popUpTo="@id/contactsFragment"
app:popUpToInclusive="true"
app:launchSingleTop="true" />
<action
android:id="@+id/action_callsFragment_to_conversationsFragment"
app:destination="@id/conversationsFragment" />