Started missed calls count in bottom nav bar

This commit is contained in:
Sylvain Berfini 2023-08-22 17:52:15 +02:00
parent 09bbe05f08
commit 5e150ee16a
6 changed files with 80 additions and 4 deletions

View file

@ -194,6 +194,13 @@ class CallsListFragment : GenericFragment() {
}
}
override fun onResume() {
super.onResume()
Log.i("$TAG Fragment is resumed, resetting missed calls count")
sharedViewModel.resetMissedCallsCountEvent.value = Event(true)
}
private fun copyNumberOrAddressToClipboard(value: String) {
val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val label = "SIP address"

View file

@ -97,5 +97,11 @@ class BottomNavBarFragment : Fragment() {
viewModel.callsSelected.value = it == R.id.callsFragment
viewModel.conversationsSelected.value = it == R.id.conversationsFragment
}
sharedViewModel.resetMissedCallsCountEvent.observe(viewLifecycleOwner) {
it.consume {
viewModel.resetMissedCallsCount()
}
}
}
}

View file

@ -20,6 +20,7 @@
package org.linphone.ui.main.viewmodel
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
@ -27,6 +28,7 @@ import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.core.Call
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.tools.Log
class BottomNavBarViewModel @UiThread constructor() : ViewModel() {
companion object {
@ -45,25 +47,33 @@ class BottomNavBarViewModel @UiThread constructor() : ViewModel() {
val hideMeetings = MutableLiveData<Boolean>()
val missedCallsCount = MutableLiveData<Int>()
private val coreListener = object : CoreListenerStub() {
@WorkerThread
override fun onCallStateChanged(
core: Core,
call: Call,
state: Call.State?,
message: String
) {
if (state == Call.State.End || state == Call.State.Error) {
updateMissedCallsCount()
}
}
}
init {
coreContext.postOnCoreThread { core ->
core.addListener(coreListener)
updateMissedCallsCount()
}
hideConversations.value = corePreferences.disableChat || true // TODO
hideMeetings.value = true // TODO
}
@UiThread
override fun onCleared() {
super.onCleared()
@ -71,4 +81,22 @@ class BottomNavBarViewModel @UiThread constructor() : ViewModel() {
core.removeListener(coreListener)
}
}
@WorkerThread
fun updateMissedCallsCount() {
val count = coreContext.core.missedCallsCount
val moreThanOne = count > 1
Log.i(
"$TAG There ${if (moreThanOne) "are" else "is"} [$count] missed ${if (moreThanOne) "calls" else "call"}"
)
missedCallsCount.postValue(count)
}
@UiThread
fun resetMissedCallsCount() {
coreContext.postOnCoreThread { core ->
core.resetMissedCallsCount()
updateMissedCallsCount()
}
}
}

View file

@ -84,4 +84,8 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
val forceRefreshCallLogsListEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val resetMissedCallsCountEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
}

View file

@ -61,10 +61,24 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/contacts" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/missed_calls"
android:layout_width="24dp"
android:layout_height="24dp"
android:gravity="center"
android:background="@drawable/shape_orange_round"
android:text="@{String.valueOf(viewModel.missedCallsCount), default=`1`}"
android:textColor="@color/white"
android:textSize="13sp"
android:visibility="@{viewModel.missedCallsCount > 0 ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toTopOf="@id/calls"
app:layout_constraintEnd_toEndOf="@id/calls"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/bottom_nav_bar_label_style"
android:id="@+id/conversations"
android:visibility="@{viewModel.hideConversations ? View.GONE : View.VISIBLE}"
android:visibility="@{viewModel.hideConversations ? View.GONE : View.VISIBLE, default=gone}"
android:enabled="false"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -83,7 +97,7 @@
style="@style/bottom_nav_bar_label_style"
android:onClick="@{onMeetingsClicked}"
android:id="@+id/meetings"
android:visibility="@{viewModel.hideMeetings ? View.GONE : View.VISIBLE}"
android:visibility="@{viewModel.hideMeetings ? View.GONE : View.VISIBLE, default=gone}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableTop="@drawable/meetings"

View file

@ -66,10 +66,27 @@
app:layout_constraintStart_toEndOf="@id/contacts"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/missed_calls"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="50dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:background="@drawable/shape_orange_round"
android:text="@{String.valueOf(viewModel.missedCallsCount), default=`1`}"
android:textColor="@color/white"
android:textSize="13sp"
android:visibility="@{viewModel.missedCallsCount > 0 ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toTopOf="@id/calls"
app:layout_constraintStart_toStartOf="@id/calls"
app:layout_constraintEnd_toEndOf="@id/calls"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/bottom_nav_bar_label_style"
android:onClick="@{onConversationsClicked}"
android:visibility="@{viewModel.hideConversations ? View.GONE : View.VISIBLE}"
android:visibility="@{viewModel.hideConversations ? View.GONE : View.VISIBLE, default=gone}"
android:enabled="false"
android:id="@+id/conversations"
android:layout_width="0dp"
@ -91,7 +108,7 @@
style="@style/bottom_nav_bar_label_style"
android:onClick="@{onMeetingsClicked}"
android:id="@+id/meetings"
android:visibility="@{viewModel.hideMeetings ? View.GONE : View.VISIBLE}"
android:visibility="@{viewModel.hideMeetings ? View.GONE : View.VISIBLE, default=gone}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"