mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Started bottom nav bar viewmodel + scroll to top when adding new items to calls history list
This commit is contained in:
parent
60965b767c
commit
09bbe05f08
6 changed files with 112 additions and 64 deletions
|
|
@ -156,6 +156,7 @@ class CallsListFragment : GenericFragment() {
|
|||
|
||||
listViewModel.callLogs.observe(viewLifecycleOwner) {
|
||||
adapter.submitList(it)
|
||||
binding.callsList.scrollToPosition(0)
|
||||
|
||||
(view.parent as? ViewGroup)?.doOnPreDraw {
|
||||
startPostponedEnterTransition()
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ import android.view.ViewGroup
|
|||
import androidx.annotation.UiThread
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.databinding.BottomNavBarBinding
|
||||
import org.linphone.ui.main.viewmodel.BottomNavBarViewModel
|
||||
import org.linphone.ui.main.viewmodel.SharedMainViewModel
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.setKeyboardInsetListener
|
||||
|
|
@ -38,6 +38,8 @@ import org.linphone.utils.setKeyboardInsetListener
|
|||
class BottomNavBarFragment : Fragment() {
|
||||
private lateinit var binding: BottomNavBarBinding
|
||||
|
||||
private lateinit var viewModel: BottomNavBarViewModel
|
||||
|
||||
private lateinit var sharedViewModel: SharedMainViewModel
|
||||
|
||||
override fun onCreateView(
|
||||
|
|
@ -52,12 +54,17 @@ class BottomNavBarFragment : Fragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
viewModel = requireActivity().run {
|
||||
ViewModelProvider(this)[BottomNavBarViewModel::class.java]
|
||||
}
|
||||
binding.viewModel = viewModel
|
||||
|
||||
sharedViewModel = requireActivity().run {
|
||||
ViewModelProvider(this)[SharedMainViewModel::class.java]
|
||||
}
|
||||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
binding.root.setKeyboardInsetListener { keyboardVisible ->
|
||||
val portraitOrientation = resources.configuration.orientation != Configuration.ORIENTATION_LANDSCAPE
|
||||
binding.bottomNavBar.visibility = if (!portraitOrientation || !keyboardVisible) View.VISIBLE else View.GONE
|
||||
|
|
@ -86,12 +93,9 @@ class BottomNavBarFragment : Fragment() {
|
|||
}
|
||||
|
||||
sharedViewModel.currentlyDisplayedFragment.observe(viewLifecycleOwner) {
|
||||
binding.contactsSelected = it == R.id.contactsFragment
|
||||
binding.callsSelected = it == R.id.callsFragment
|
||||
binding.conversationsSelected = it == R.id.conversationsFragment
|
||||
viewModel.contactsSelected.value = it == R.id.contactsFragment
|
||||
viewModel.callsSelected.value = it == R.id.callsFragment
|
||||
viewModel.conversationsSelected.value = it == R.id.conversationsFragment
|
||||
}
|
||||
|
||||
binding.hideConversations = corePreferences.disableChat || true // TODO
|
||||
binding.hideMeetings = true // TODO
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-android
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.linphone.ui.main.viewmodel
|
||||
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.core.Call
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
|
||||
class BottomNavBarViewModel @UiThread constructor() : ViewModel() {
|
||||
companion object {
|
||||
const val TAG = "[Bottom Navigation Bar ViewModel]"
|
||||
}
|
||||
|
||||
val contactsSelected = MutableLiveData<Boolean>()
|
||||
|
||||
val callsSelected = MutableLiveData<Boolean>()
|
||||
|
||||
val conversationsSelected = MutableLiveData<Boolean>()
|
||||
|
||||
val meetingsSelected = MutableLiveData<Boolean>()
|
||||
|
||||
val hideConversations = MutableLiveData<Boolean>()
|
||||
|
||||
val hideMeetings = MutableLiveData<Boolean>()
|
||||
|
||||
private val coreListener = object : CoreListenerStub() {
|
||||
override fun onCallStateChanged(
|
||||
core: Core,
|
||||
call: Call,
|
||||
state: Call.State?,
|
||||
message: String
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
core.addListener(coreListener)
|
||||
}
|
||||
|
||||
hideConversations.value = corePreferences.disableChat || true // TODO
|
||||
hideMeetings.value = true // TODO
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
|
||||
coreContext.postOnCoreThread { core ->
|
||||
core.removeListener(coreListener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,23 +19,8 @@
|
|||
name="onMeetingsClicked"
|
||||
type="View.OnClickListener" />
|
||||
<variable
|
||||
name="contactsSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="callsSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="conversationsSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="meetingsSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="hideConversations"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="hideMeetings"
|
||||
type="Boolean" />
|
||||
name="viewModel"
|
||||
type="org.linphone.ui.main.viewmodel.BottomNavBarViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
|
@ -51,10 +36,10 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:drawableTop="@drawable/contacts"
|
||||
android:drawablePadding="10dp"
|
||||
android:drawableTint="@{contactsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:drawableTint="@{viewModel.contactsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:onClick="@{onContactsClicked}"
|
||||
android:text="Contacts"
|
||||
android:textStyle="@{contactsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
android:textStyle="@{viewModel.contactsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
app:layout_constraintBottom_toTopOf="@id/calls"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
@ -67,10 +52,10 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableTop="@drawable/calls"
|
||||
android:drawableTint="@{callsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:drawableTint="@{viewModel.callsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:drawablePadding="10dp"
|
||||
android:text="Calls"
|
||||
android:textStyle="@{callsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
android:textStyle="@{viewModel.callsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
app:layout_constraintBottom_toTopOf="@id/conversations"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
@ -79,16 +64,16 @@
|
|||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/bottom_nav_bar_label_style"
|
||||
android:id="@+id/conversations"
|
||||
android:visibility="@{hideConversations ? View.GONE : View.VISIBLE}"
|
||||
android:visibility="@{viewModel.hideConversations ? View.GONE : View.VISIBLE}"
|
||||
android:enabled="false"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableTop="@drawable/conversations"
|
||||
android:drawablePadding="10dp"
|
||||
android:drawableTint="@{conversationsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:drawableTint="@{viewModel.conversationsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:onClick="@{onConversationsClicked}"
|
||||
android:text="Conversations"
|
||||
android:textStyle="@{conversationsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
android:textStyle="@{viewModel.conversationsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
app:layout_constraintBottom_toTopOf="@id/meetings"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
@ -98,14 +83,14 @@
|
|||
style="@style/bottom_nav_bar_label_style"
|
||||
android:onClick="@{onMeetingsClicked}"
|
||||
android:id="@+id/meetings"
|
||||
android:visibility="@{hideMeetings ? View.GONE : View.VISIBLE}"
|
||||
android:visibility="@{viewModel.hideMeetings ? View.GONE : View.VISIBLE}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableTop="@drawable/meetings"
|
||||
android:drawablePadding="10dp"
|
||||
android:drawableTint="@{meetingsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:drawableTint="@{viewModel.meetingsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:text="Meetings"
|
||||
android:textStyle="@{meetingsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
android:textStyle="@{viewModel.meetingsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
|
|||
|
|
@ -19,23 +19,8 @@
|
|||
name="onMeetingsClicked"
|
||||
type="View.OnClickListener" />
|
||||
<variable
|
||||
name="contactsSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="callsSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="conversationsSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="meetingsSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="hideConversations"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="hideMeetings"
|
||||
type="Boolean" />
|
||||
name="viewModel"
|
||||
type="org.linphone.ui.main.viewmodel.BottomNavBarViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
|
@ -54,9 +39,9 @@
|
|||
android:paddingBottom="16dp"
|
||||
android:drawableTop="@drawable/contacts"
|
||||
android:drawablePadding="10dp"
|
||||
android:drawableTint="@{contactsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:drawableTint="@{viewModel.contactsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:text="Contacts"
|
||||
android:textStyle="@{contactsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
android:textStyle="@{viewModel.contactsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/calls"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
@ -73,9 +58,9 @@
|
|||
android:paddingBottom="16dp"
|
||||
android:drawableTop="@drawable/calls"
|
||||
android:drawablePadding="10dp"
|
||||
android:drawableTint="@{callsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:drawableTint="@{viewModel.callsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:text="Calls"
|
||||
android:textStyle="@{callsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
android:textStyle="@{viewModel.callsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/conversations"
|
||||
app:layout_constraintStart_toEndOf="@id/contacts"
|
||||
|
|
@ -84,7 +69,7 @@
|
|||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/bottom_nav_bar_label_style"
|
||||
android:onClick="@{onConversationsClicked}"
|
||||
android:visibility="@{hideConversations ? View.GONE : View.VISIBLE}"
|
||||
android:visibility="@{viewModel.hideConversations ? View.GONE : View.VISIBLE}"
|
||||
android:enabled="false"
|
||||
android:id="@+id/conversations"
|
||||
android:layout_width="0dp"
|
||||
|
|
@ -94,9 +79,9 @@
|
|||
android:paddingBottom="16dp"
|
||||
android:drawableTop="@drawable/conversations"
|
||||
android:drawablePadding="10dp"
|
||||
android:drawableTint="@{conversationsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:drawableTint="@{viewModel.conversationsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:text="Conversations"
|
||||
android:textStyle="@{conversationsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
android:textStyle="@{viewModel.conversationsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/meetings"
|
||||
app:layout_constraintStart_toEndOf="@id/calls"
|
||||
|
|
@ -106,7 +91,7 @@
|
|||
style="@style/bottom_nav_bar_label_style"
|
||||
android:onClick="@{onMeetingsClicked}"
|
||||
android:id="@+id/meetings"
|
||||
android:visibility="@{hideMeetings ? View.GONE : View.VISIBLE}"
|
||||
android:visibility="@{viewModel.hideMeetings ? View.GONE : View.VISIBLE}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="18dp"
|
||||
|
|
@ -114,9 +99,9 @@
|
|||
android:paddingBottom="16dp"
|
||||
android:drawableTop="@drawable/meetings"
|
||||
android:drawablePadding="10dp"
|
||||
android:drawableTint="@{meetingsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:drawableTint="@{viewModel.meetingsSelected ? @color/primary_color : @color/gray_9, default=@color/gray_9}"
|
||||
android:text="Meetings"
|
||||
android:textStyle="@{meetingsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
android:textStyle="@{viewModel.meetingsSelected ? Typeface.BOLD : Typeface.NORMAL}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/conversations"
|
||||
|
|
|
|||
|
|
@ -81,7 +81,6 @@
|
|||
|
||||
<include
|
||||
bind:onContactsClicked="@{onContactsClicked}"
|
||||
bind:conversationsSelected="@{true}"
|
||||
android:id="@+id/bottom_nav_bar"
|
||||
layout="@layout/bottom_nav_bar"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue