mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Removed navigation from MainActivity
This commit is contained in:
parent
bd42eebdcb
commit
2aeaf330a8
6 changed files with 1 additions and 185 deletions
|
|
@ -22,15 +22,10 @@ package org.linphone.ui
|
|||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.databinding.ActivityMainBinding
|
||||
|
|
@ -41,7 +36,6 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var viewModel: MainViewModel
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, true)
|
||||
|
|
@ -62,27 +56,11 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
|
||||
binding.lifecycleOwner = this
|
||||
|
||||
viewModel = ViewModelProvider(this)[MainViewModel::class.java]
|
||||
binding.viewModel = viewModel
|
||||
|
||||
viewModel.unreadMessagesCount.observe(this) { count ->
|
||||
if (count > 0) {
|
||||
getNavBar()?.getOrCreateBadge(R.id.conversationsFragment)?.apply {
|
||||
isVisible = true
|
||||
number = count
|
||||
}
|
||||
} else {
|
||||
getNavBar()?.removeBadge(R.id.conversationsFragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
|
||||
getNavBar()?.setupWithNavController(binding.mainNavHostFragment.findNavController())
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(
|
||||
arrayOf(Manifest.permission.READ_CONTACTS),
|
||||
|
|
@ -102,16 +80,4 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
}
|
||||
|
||||
private fun getNavBar(): NavigationBarView? {
|
||||
return binding.mainNavView ?: binding.mainNavRail
|
||||
}
|
||||
|
||||
fun hideNavBar() {
|
||||
getNavBar()?.visibility = View.GONE
|
||||
}
|
||||
|
||||
fun showNavBar() {
|
||||
getNavBar()?.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,61 +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
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.ChatMessage
|
||||
import org.linphone.core.ChatRoom
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
|
||||
class MainViewModel : ViewModel() {
|
||||
val unreadMessagesCount = MutableLiveData<Int>()
|
||||
|
||||
private val coreListener = object : CoreListenerStub() {
|
||||
override fun onMessagesReceived(
|
||||
core: Core,
|
||||
chatRoom: ChatRoom,
|
||||
messages: Array<out ChatMessage>
|
||||
) {
|
||||
unreadMessagesCount.postValue(core.unreadChatMessageCount)
|
||||
}
|
||||
|
||||
override fun onChatRoomRead(core: Core, chatRoom: ChatRoom) {
|
||||
unreadMessagesCount.postValue(core.unreadChatMessageCount)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
unreadMessagesCount.postValue(core.unreadChatMessageCount)
|
||||
core.addListener(coreListener)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
|
||||
coreContext.postOnCoreThread { core ->
|
||||
core.removeListener(coreListener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.linphone.R
|
||||
import org.linphone.databinding.ConversationsFragmentBinding
|
||||
import org.linphone.ui.MainActivity
|
||||
import org.linphone.ui.conversations.adapter.ConversationsListAdapter
|
||||
import org.linphone.ui.conversations.viewmodel.ConversationsListViewModel
|
||||
|
||||
|
|
@ -101,7 +100,6 @@ class ConversationsFragment : Fragment() {
|
|||
bundle.putString("remoteSipUri", data.remoteSipUri)
|
||||
|
||||
if (findNavController().currentDestination?.id == R.id.conversationsFragment) {
|
||||
(requireActivity() as MainActivity).hideNavBar()
|
||||
findNavController().navigate(
|
||||
R.id.action_conversationsFragment_to_conversationFragment,
|
||||
bundle
|
||||
|
|
@ -140,7 +138,6 @@ class ConversationsFragment : Fragment() {
|
|||
|
||||
binding.setOnNewConversationClicked {
|
||||
if (findNavController().currentDestination?.id == R.id.conversationsFragment) {
|
||||
(requireActivity() as MainActivity).hideNavBar()
|
||||
findNavController().navigate(
|
||||
R.id.action_conversationsFragment_to_newConversationFragment
|
||||
)
|
||||
|
|
@ -148,11 +145,6 @@ class ConversationsFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
(requireActivity() as MainActivity).showNavBar()
|
||||
}
|
||||
|
||||
private fun scrollToTop() {
|
||||
binding.conversationsList.scrollToPosition(0)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
<import type="android.view.View" />
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="org.linphone.ui.MainViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context=".ui.MainActivity">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.navigationrail.NavigationRailView
|
||||
android:id="@+id/main_nav_rail"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:menu="@menu/main_nav" />
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/main_nav_host_fragment"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="10dp"
|
||||
app:defaultNavHost="true"
|
||||
app:layout_constraintStart_toEndOf="@id/main_nav_rail"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:navGraph="@navigation/main_nav_graph"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
</layout>
|
||||
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
<data>
|
||||
<import type="android.view.View" />
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="org.linphone.ui.MainViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
|
|
@ -28,18 +25,8 @@
|
|||
android:layout_height="0dp"
|
||||
app:defaultNavHost="true"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/main_nav_view"
|
||||
app:navGraph="@navigation/main_nav_graph"/>
|
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/main_nav_view"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:menu="@menu/main_nav" />
|
||||
app:navGraph="@navigation/main_nav_graph"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/conversationsFragment"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/chat"
|
||||
android:title="Conversations"/>
|
||||
<item
|
||||
android:id="@+id/contactsFragment"
|
||||
android:enabled="true"
|
||||
android:title="Contacts"/>
|
||||
<item
|
||||
android:id="@+id/meetingsFragment"
|
||||
android:enabled="true"
|
||||
android:title="Réunions"/>
|
||||
<item
|
||||
android:id="@+id/historyFragment"
|
||||
android:enabled="true"
|
||||
android:title="Historique"/>
|
||||
</menu>
|
||||
Loading…
Add table
Reference in a new issue