Also handle text waiting to be shared in newly added top bar

This commit is contained in:
Sylvain Berfini 2025-06-16 13:39:43 +02:00
parent 6602c7692b
commit 654e790a6d
7 changed files with 38 additions and 37 deletions

View file

@ -46,7 +46,6 @@ import androidx.core.view.updatePadding
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.observe
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavOptions
@ -250,9 +249,10 @@ class MainActivity : GenericActivity() {
}
}
viewModel.clearFilesPendingSharingEvent.observe(this) {
viewModel.clearFilesOrTextPendingSharingEvent.observe(this) {
it.consume {
sharedViewModel.filesToShareFromIntent.value = arrayListOf<String>()
sharedViewModel.textToShareFromIntent.value = ""
}
}
@ -260,7 +260,15 @@ class MainActivity : GenericActivity() {
if (list.isNotEmpty()) {
viewModel.addFilesPendingSharing(list)
} else {
viewModel.filesPendingSharingListCleared()
viewModel.filesOrTextPendingSharingListCleared()
}
}
sharedViewModel.textToShareFromIntent.observe(this) { text ->
if (!text.isEmpty()) {
viewModel.addTextPendingSharing()
} else {
viewModel.filesOrTextPendingSharingListCleared()
}
}

View file

@ -36,7 +36,6 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import org.linphone.R
import org.linphone.core.tools.Log
import org.linphone.databinding.ChatListFragmentBinding
import org.linphone.ui.GenericActivity
import org.linphone.ui.fileviewer.FileViewerActivity
import org.linphone.ui.fileviewer.MediaViewerActivity
import org.linphone.ui.main.MainActivity.Companion.ARGUMENTS_CONVERSATION_ID
@ -250,15 +249,6 @@ class ConversationsListFragment : AbstractMainFragment() {
}
}
sharedViewModel.textToShareFromIntent.observe(viewLifecycleOwner) { textToShare ->
if (textToShare.isNotEmpty()) {
val message = getString(R.string.conversations_text_waiting_to_be_shared_toast)
val icon = R.drawable.file_text
(requireActivity() as GenericActivity).showGreenToast(message, icon)
Log.i("$TAG Found text waiting to be shared")
}
}
sharedViewModel.updateConversationLastMessageEvent.observe(viewLifecycleOwner) {
it.consume { conversationId ->
val model = listViewModel.conversations.value.orEmpty().find {

View file

@ -78,11 +78,9 @@ class MainViewModel
val callsStatus = MutableLiveData<String>()
val pendingFileSharing = MutableLiveData<Boolean>()
val pendingFilesOrTextSharing = MutableLiveData<Boolean>()
val filesCountPendingSharing = MutableLiveData<Int>()
val filesPendingSharingLabel = MutableLiveData<String>()
val filesOrTextPendingSharingLabel = MutableLiveData<String>()
val goBackToCallEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
@ -112,7 +110,7 @@ class MainViewModel
MutableLiveData<Event<Boolean>>()
}
val clearFilesPendingSharingEvent: MutableLiveData<Event<Boolean>> by lazy {
val clearFilesOrTextPendingSharingEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
@ -349,9 +347,8 @@ class MainViewModel
maxAlertLevel.value = NONE
nonDefaultAccountNotificationsCount = 0
pendingFileSharing.value = false
filesCountPendingSharing.value = 0
filesPendingSharingLabel.value = ""
pendingFilesOrTextSharing.value = false
filesOrTextPendingSharingLabel.value = ""
enableAccountMonitoring(true)
@ -480,28 +477,32 @@ class MainViewModel
val count = list.size
Log.i("$TAG Adding [$count] files to pending sharing files list")
if (count > 0) {
filesCountPendingSharing.value = count
filesPendingSharingLabel.value = AppUtils.getStringWithPlural(
filesOrTextPendingSharingLabel.value = AppUtils.getStringWithPlural(
R.plurals.conversations_files_waiting_to_be_shared_toast,
count,
"$count"
)
pendingFileSharing.value = true
pendingFilesOrTextSharing.value = true
}
}
@UiThread
fun filesPendingSharingListCleared() {
pendingFileSharing.value = false
filesCountPendingSharing.value = 0
filesPendingSharingLabel.value = ""
fun addTextPendingSharing() {
filesOrTextPendingSharingLabel.value = AppUtils.getString(R.string.conversations_text_waiting_to_be_shared_toast)
pendingFilesOrTextSharing.value = true
}
@UiThread
fun filesOrTextPendingSharingListCleared() {
pendingFilesOrTextSharing.value = false
filesOrTextPendingSharingLabel.value = ""
Log.i("$TAG List of files pending sharing has been cleared")
}
@UiThread
fun cancelFileSharing() {
fun cancelFileOrTextSharing() {
Log.i("$TAG Clearing list of files pending sharing")
clearFilesPendingSharingEvent.value = Event(true)
clearFilesOrTextPendingSharingEvent.value = Event(true)
}
@UiThread

View file

@ -27,7 +27,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@{viewModel.showAlert ? (viewModel.maxAlertLevel >= 10 ? @drawable/color_danger_500 : @drawable/color_main_activity_top_bar) : (viewModel.pendingFileSharing ? @drawable/color_main_activity_top_bar : (viewModel.atLeastOneCall ? @drawable/color_success_500 : @drawable/color_main1_500)), default=@drawable/color_main1_500}"
android:background="@{viewModel.showAlert ? (viewModel.maxAlertLevel >= 10 ? @drawable/color_danger_500 : @drawable/color_main_activity_top_bar) : (viewModel.pendingFilesOrTextSharing ? @drawable/color_main_activity_top_bar : (viewModel.atLeastOneCall ? @drawable/color_success_500 : @drawable/color_main1_500)), default=@drawable/color_main1_500}"
app:layout_constraintTop_toTopOf="parent">
<include
@ -40,10 +40,10 @@
<include
android:id="@+id/file_sharing_top_bar"
layout="@layout/main_activity_pending_file_sharing_top_bar"
layout="@layout/main_activity_pending_sharing_top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="@{viewModel.pendingFileSharing ? View.VISIBLE : View.GONE, default=gone}"
android:visibility="@{viewModel.pendingFilesOrTextSharing ? View.VISIBLE : View.GONE, default=gone}"
app:viewModel="@{viewModel}"/>
<include

View file

@ -22,7 +22,7 @@
android:layout_marginStart="16dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:src="@{viewModel.filesCountPendingSharing > 1 ? @drawable/files : @drawable/file, default=@drawable/file}"
android:src="@drawable/share_network"
android:contentDescription="@null"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
@ -39,7 +39,7 @@
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"
android:text="@{viewModel.filesPendingSharingLabel, default=@plurals/conversations_files_waiting_to_be_shared_toast}"
android:text="@{viewModel.filesOrTextPendingSharingLabel, default=@plurals/conversations_files_waiting_to_be_shared_toast}"
android:textColor="@color/bc_white"
android:textSize="16sp"
android:maxLines="1"
@ -51,13 +51,13 @@
<ImageView
android:id="@+id/close_notif"
android:onClick="@{() -> viewModel.cancelFileSharing()}"
android:onClick="@{() -> viewModel.cancelFileOrTextSharing()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:src="@drawable/x"
app:tint="@color/bc_white"
android:contentDescription="@string/content_description_dismiss_notification"
android:contentDescription="@string/content_description_cancel_files_or_text_pending_sharing"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

View file

@ -921,4 +921,5 @@
<string name="content_description_copy_text_to_clipboard">Copier le texte dans le presse-papier</string>
<string name="content_description_voicemail_available">Au moins un message vocal est disponible</string>
<string name="content_description_call_voicemail">Faire un appui long pour appeler la boite vocale</string>
<string name="content_description_cancel_files_or_text_pending_sharing">Cliquer pour annuler le partage des fichiers ou du texte en attente</string>
</resources>

View file

@ -963,6 +963,7 @@
<string name="content_description_copy_text_to_clipboard">Copy text to clipboard</string>
<string name="content_description_voicemail_available">Voice message are available</string>
<string name="content_description_call_voicemail">Long press to dial voicemail</string>
<string name="content_description_cancel_files_or_text_pending_sharing">Click to cancel files or text pending sharing</string>
<!-- Copy of private hosts_allowlist_sample in androidx.car.app:app:1.7.0-beta01, as they recommend it -->
<string-array name="hosts_allowlist_sample_copy" translatable="false">