mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 19:38:08 +00:00
Removed TopBarFragment, simply include layout and have the view model inherits TopBarViewModel (now abstract)
This commit is contained in:
parent
cb48f73fd9
commit
26c79e6740
12 changed files with 78 additions and 138 deletions
|
|
@ -46,7 +46,6 @@ import org.linphone.databinding.MainActivityBinding
|
|||
import org.linphone.ui.assistant.AssistantActivity
|
||||
import org.linphone.ui.main.settings.fragment.AccountProfileFragmentDirections
|
||||
import org.linphone.ui.main.viewmodel.DrawerMenuViewModel
|
||||
import org.linphone.ui.welcome.WelcomeActivity
|
||||
import org.linphone.utils.slideInToastFromTopForDuration
|
||||
|
||||
@UiThread
|
||||
|
|
@ -125,7 +124,7 @@ class MainActivity : AppCompatActivity() {
|
|||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
|
||||
startActivity(Intent(this, WelcomeActivity::class.java))
|
||||
// TODO startActivity(Intent(this, WelcomeActivity::class.java))
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ import org.linphone.ui.main.calls.viewmodel.CallsListViewModel
|
|||
import org.linphone.ui.main.fragment.GenericFragment
|
||||
import org.linphone.utils.DialogUtils
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.hideKeyboard
|
||||
import org.linphone.utils.showKeyboard
|
||||
|
||||
@UiThread
|
||||
class CallsListFragment : GenericFragment() {
|
||||
|
|
@ -179,12 +181,6 @@ class CallsListFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
sharedViewModel.searchFilter.observe(viewLifecycleOwner) {
|
||||
it.consume { filter ->
|
||||
listViewModel.applyFilter(filter)
|
||||
}
|
||||
}
|
||||
|
||||
binding.setMenuClickListener {
|
||||
showPopupMenu()
|
||||
}
|
||||
|
|
@ -192,6 +188,31 @@ class CallsListFragment : GenericFragment() {
|
|||
binding.setStartCallClickListener {
|
||||
findNavController().navigate(R.id.action_global_startCallFragment)
|
||||
}
|
||||
|
||||
// TopBarFragment related
|
||||
|
||||
listViewModel.openDrawerMenuEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
(requireActivity() as MainActivity).toggleDrawerMenu()
|
||||
}
|
||||
}
|
||||
|
||||
listViewModel.searchFilter.observe(viewLifecycleOwner) { filter ->
|
||||
listViewModel.applyFilter(filter)
|
||||
}
|
||||
|
||||
listViewModel.focusSearchBarEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { show ->
|
||||
if (show) {
|
||||
// To automatically open keyboard
|
||||
binding.topBar.search.showKeyboard(requireActivity().window)
|
||||
} else {
|
||||
binding.topBar.search.hideKeyboard()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listViewModel.title.value = "Calls"
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
|
|
|||
|
|
@ -22,15 +22,15 @@ package org.linphone.ui.main.calls.viewmodel
|
|||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.CallLog
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
import org.linphone.ui.main.calls.model.CallLogModel
|
||||
import org.linphone.ui.main.viewmodel.AbstractTopBarViewModel
|
||||
import org.linphone.utils.Event
|
||||
|
||||
class CallsListViewModel @UiThread constructor() : ViewModel() {
|
||||
class CallsListViewModel @UiThread constructor() : AbstractTopBarViewModel() {
|
||||
val callLogs = MutableLiveData<ArrayList<CallLogModel>>()
|
||||
|
||||
val historyDeletedEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
|
|
|
|||
|
|
@ -38,10 +38,13 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
|||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.ContactsListFragmentBinding
|
||||
import org.linphone.ui.main.MainActivity
|
||||
import org.linphone.ui.main.contacts.adapter.ContactsListAdapter
|
||||
import org.linphone.ui.main.contacts.viewmodel.ContactsListViewModel
|
||||
import org.linphone.ui.main.fragment.GenericFragment
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.hideKeyboard
|
||||
import org.linphone.utils.showKeyboard
|
||||
|
||||
@UiThread
|
||||
class ContactsListFragment : GenericFragment() {
|
||||
|
|
@ -130,12 +133,6 @@ class ContactsListFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
sharedViewModel.searchFilter.observe(viewLifecycleOwner) {
|
||||
it.consume { filter ->
|
||||
listViewModel.applyFilter(filter)
|
||||
}
|
||||
}
|
||||
|
||||
binding.setOnNewContactClicked {
|
||||
sharedViewModel.showNewContactEvent.value = Event(true)
|
||||
}
|
||||
|
|
@ -144,6 +141,31 @@ class ContactsListFragment : GenericFragment() {
|
|||
// TODO FIXME: show context menu first to let user decides which filter to use
|
||||
listViewModel.toggleContactsFilter()
|
||||
}
|
||||
|
||||
// TopBarFragment related
|
||||
|
||||
listViewModel.openDrawerMenuEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
(requireActivity() as MainActivity).toggleDrawerMenu()
|
||||
}
|
||||
}
|
||||
|
||||
listViewModel.searchFilter.observe(viewLifecycleOwner) { filter ->
|
||||
listViewModel.applyFilter(filter)
|
||||
}
|
||||
|
||||
listViewModel.focusSearchBarEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { show ->
|
||||
if (show) {
|
||||
// To automatically open keyboard
|
||||
binding.topBar.search.showKeyboard(requireActivity().window)
|
||||
} else {
|
||||
binding.topBar.search.hideKeyboard()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listViewModel.title.value = "Contacts"
|
||||
}
|
||||
|
||||
private fun configureAdapter(adapter: ContactsListAdapter) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ package org.linphone.ui.main.contacts.viewmodel
|
|||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import java.io.File
|
||||
import java.util.ArrayList
|
||||
|
|
@ -38,10 +37,11 @@ import org.linphone.core.SearchResult
|
|||
import org.linphone.core.tools.Log
|
||||
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||
import org.linphone.ui.main.model.isInSecureMode
|
||||
import org.linphone.ui.main.viewmodel.AbstractTopBarViewModel
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.FileUtils
|
||||
|
||||
class ContactsListViewModel @UiThread constructor() : ViewModel() {
|
||||
class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel() {
|
||||
companion object {
|
||||
private const val TAG = "[Contacts List ViewModel]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,106 +0,0 @@
|
|||
/*
|
||||
* 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.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import org.linphone.R
|
||||
import org.linphone.databinding.TopSearchBarBinding
|
||||
import org.linphone.ui.main.MainActivity
|
||||
import org.linphone.ui.main.viewmodel.SharedMainViewModel
|
||||
import org.linphone.ui.main.viewmodel.TopBarViewModel
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.hideKeyboard
|
||||
import org.linphone.utils.showKeyboard
|
||||
|
||||
@UiThread
|
||||
class TopBarFragment : Fragment() {
|
||||
private lateinit var binding: TopSearchBarBinding
|
||||
|
||||
private lateinit var viewModel: TopBarViewModel
|
||||
private lateinit var sharedViewModel: SharedMainViewModel
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = TopSearchBarBinding.inflate(layoutInflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel = requireActivity().run {
|
||||
ViewModelProvider(this)[TopBarViewModel::class.java]
|
||||
}
|
||||
|
||||
sharedViewModel = requireActivity().run {
|
||||
ViewModelProvider(this)[SharedMainViewModel::class.java]
|
||||
}
|
||||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
binding.viewModel = viewModel
|
||||
|
||||
viewModel.openDrawerMenuEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
(requireActivity() as MainActivity).toggleDrawerMenu()
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.focusSearchBarEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { show ->
|
||||
if (show) {
|
||||
// To automatically open keyboard
|
||||
binding.search.showKeyboard(requireActivity().window)
|
||||
} else {
|
||||
binding.search.hideKeyboard()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.searchFilter.observe(viewLifecycleOwner) { filter ->
|
||||
sharedViewModel.searchFilter.value = Event(filter)
|
||||
}
|
||||
|
||||
sharedViewModel.currentlyDisplayedFragment.observe(viewLifecycleOwner) {
|
||||
binding.title.text = when (it) {
|
||||
R.id.contactsFragment -> {
|
||||
"Contacts"
|
||||
}
|
||||
R.id.callsFragment -> {
|
||||
"Calls"
|
||||
}
|
||||
R.id.conversationsFragment -> {
|
||||
"Conversations"
|
||||
}
|
||||
else -> {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ import org.linphone.core.tools.Log
|
|||
import org.linphone.ui.main.model.AccountModel
|
||||
import org.linphone.utils.Event
|
||||
|
||||
class TopBarViewModel @UiThread constructor() : ViewModel() {
|
||||
open class AbstractTopBarViewModel @UiThread constructor() : ViewModel() {
|
||||
companion object {
|
||||
private const val TAG = "[Top Bar ViewModel]"
|
||||
}
|
||||
|
|
@ -33,13 +33,13 @@
|
|||
app:constraint_referenced_ids="no_calls_image, no_calls_label"
|
||||
android:visibility="@{viewModel.callLogs.empty ? View.VISIBLE : View.GONE}" />
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
<include
|
||||
android:id="@+id/top_bar"
|
||||
android:name="org.linphone.ui.main.fragment.TopBarFragment"
|
||||
layout="@layout/top_search_bar"
|
||||
bind:viewModel="@{viewModel}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/top_bar_height"
|
||||
android:layout_marginEnd="9dp"
|
||||
bind:layout="@layout/top_search_bar"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/bottom_nav_bar"
|
||||
app:layout_constraintEnd_toStartOf="@id/menu"/>
|
||||
|
|
@ -51,6 +51,7 @@
|
|||
android:layout_height="0dp"
|
||||
android:layout_marginEnd="9dp"
|
||||
android:src="@drawable/dots_three_vertical"
|
||||
android:visibility="@{viewModel.searchBarVisible ? View.GONE : View.VISIBLE}"
|
||||
app:tint="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/top_bar"
|
||||
|
|
|
|||
|
|
@ -37,13 +37,13 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
<include
|
||||
android:id="@+id/top_bar"
|
||||
android:name="org.linphone.ui.main.fragment.TopBarFragment"
|
||||
layout="@layout/top_search_bar"
|
||||
bind:viewModel="@{viewModel}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/top_bar_height"
|
||||
android:layout_marginEnd="9dp"
|
||||
bind:layout="@layout/top_search_bar"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/bottom_nav_bar"
|
||||
app:layout_constraintEnd_toStartOf="@id/filter"/>
|
||||
|
|
@ -55,6 +55,7 @@
|
|||
android:layout_height="0dp"
|
||||
android:layout_marginEnd="9dp"
|
||||
android:src="@drawable/funnel"
|
||||
android:visibility="@{viewModel.searchBarVisible ? View.GONE : View.VISIBLE}"
|
||||
app:tint="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/top_bar"
|
||||
|
|
|
|||
|
|
@ -33,13 +33,13 @@
|
|||
app:constraint_referenced_ids="no_calls_image, no_calls_label"
|
||||
android:visibility="@{viewModel.callLogs.empty ? View.VISIBLE : View.GONE}" />
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
<include
|
||||
android:id="@+id/top_bar"
|
||||
android:name="org.linphone.ui.main.fragment.TopBarFragment"
|
||||
layout="@layout/top_search_bar"
|
||||
bind:viewModel="@{viewModel}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/top_bar_height"
|
||||
android:layout_marginEnd="9dp"
|
||||
bind:layout="@layout/top_search_bar"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/menu"/>
|
||||
|
|
@ -51,6 +51,7 @@
|
|||
android:layout_height="0dp"
|
||||
android:layout_marginEnd="9dp"
|
||||
android:src="@drawable/dots_three_vertical"
|
||||
android:visibility="@{viewModel.searchBarVisible ? View.GONE : View.VISIBLE}"
|
||||
app:tint="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/top_bar"
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@
|
|||
app:constraint_referenced_ids="no_contacts_image, no_contacts_label"
|
||||
android:visibility="@{viewModel.contactsList.empty ? View.VISIBLE : View.GONE}" />
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
<include
|
||||
android:id="@+id/top_bar"
|
||||
android:name="org.linphone.ui.main.fragment.TopBarFragment"
|
||||
layout="@layout/top_search_bar"
|
||||
bind:viewModel="@{viewModel}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/top_bar_height"
|
||||
android:layout_marginEnd="9dp"
|
||||
bind:layout="@layout/top_search_bar"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/filter"/>
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
android:layout_height="0dp"
|
||||
android:layout_marginEnd="9dp"
|
||||
android:src="@drawable/funnel"
|
||||
android:visibility="@{viewModel.searchBarVisible ? View.GONE : View.VISIBLE}"
|
||||
app:tint="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/top_bar"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<import type="android.view.View" />
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="org.linphone.ui.main.viewmodel.TopBarViewModel" />
|
||||
type="org.linphone.ui.main.viewmodel.AbstractTopBarViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue