Added share / download long press menu items for call recordings

This commit is contained in:
Sylvain Berfini 2024-05-20 14:38:40 +02:00
parent 6cfec04424
commit 26e1332421
7 changed files with 130 additions and 10 deletions

View file

@ -19,21 +19,30 @@
*/
package org.linphone.ui.main.recordings.fragment
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.UiThread
import androidx.core.content.FileProvider
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import java.io.File
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.linphone.R
import org.linphone.core.tools.Log
import org.linphone.databinding.RecordingsListFragmentBinding
import org.linphone.ui.GenericActivity
import org.linphone.ui.main.fragment.GenericMainFragment
import org.linphone.ui.main.recordings.adapter.RecordingsListAdapter
import org.linphone.ui.main.recordings.viewmodel.RecordingsListViewModel
import org.linphone.utils.AppUtils
import org.linphone.utils.FileUtils
import org.linphone.utils.RecyclerViewHeaderDecoration
import org.linphone.utils.hideKeyboard
import org.linphone.utils.showKeyboard
@ -117,13 +126,17 @@ class RecordingsListFragment : GenericMainFragment() {
adapter.resetSelection()
},
{ // onShare
Log.i("$TAG Sharing call recording [${model.filePath}]")
shareFile(model.filePath, model.fileName)
adapter.resetSelection()
},
{ // onExport
Log.i("$TAG Saving call recording [${model.filePath}]")
exportFile(model.filePath)
adapter.resetSelection()
},
{ // onDelete
Log.i("$TAG Deleting meeting [${model.filePath}]")
Log.i("$TAG Deleting call recording [${model.filePath}]")
lifecycleScope.launch {
model.delete()
}
@ -142,4 +155,63 @@ class RecordingsListFragment : GenericMainFragment() {
bottomSheetDialog?.dismiss()
bottomSheetDialog = null
}
private fun exportFile(filePath: String) {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
Log.i(
"$TAG Export file [$filePath] to Android's MediaStore"
)
val mediaStorePath = FileUtils.addContentToMediaStore(filePath)
if (mediaStorePath.isNotEmpty()) {
Log.i(
"$TAG File [$filePath] has been successfully exported to MediaStore"
)
val message = AppUtils.getString(
R.string.toast_file_successfully_exported_to_media_store
)
(requireActivity() as GenericActivity).showGreenToast(
message,
R.drawable.check
)
} else {
Log.e(
"$TAG Failed to export file [$filePath] to MediaStore!"
)
val message = AppUtils.getString(
R.string.toast_export_file_to_media_store_error
)
(requireActivity() as GenericActivity).showRedToast(
message,
R.drawable.warning_circle
)
}
}
}
}
private fun shareFile(filePath: String, fileName: String) {
lifecycleScope.launch {
val publicUri = FileProvider.getUriForFile(
requireContext(),
getString(R.string.file_provider),
File(filePath)
)
Log.i(
"$TAG Public URI for file is [$publicUri], starting intent chooser"
)
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, publicUri)
putExtra(Intent.EXTRA_SUBJECT, fileName)
type = FileUtils.getMimeTypeFromExtension(
FileUtils.getExtensionFromFileName(fileName)
)
}
val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(shareIntent)
}
}
}

View file

@ -72,6 +72,16 @@ class RecordingsMenuDialogFragment(
dismiss()
}
view.setExportClickListener {
onExport?.invoke()
dismiss()
}
view.setShareClickListener {
onShare?.invoke()
dismiss()
}
return view.root
}
}

View file

@ -157,12 +157,12 @@
android:layout_height="@dimen/call_button_size"
android:layout_marginTop="@dimen/call_extra_button_top_margin"
android:padding="@dimen/call_button_icon_padding"
android:enabled="@{viewModel.isRecordingEnabled}"
android:enabled="false"
android:src="@drawable/record_fill"
android:contentDescription="@string/call_action_record_call"
android:selected="@{viewModel.isRecording()}"
android:background="@drawable/in_call_button_background_red"
app:tint="@color/in_call_button_tint_color"
android:background="@drawable/shape_round_in_call_disabled_button_background"
app:tint="?attr/color_grey_500"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toBottomOf="@id/main_actions"
app:layout_constraintStart_toStartOf="@id/record_call_label"
@ -246,7 +246,7 @@
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:text="@string/call_action_record_call"
android:enabled="@{viewModel.isRecordingEnabled}"
android:enabled="false"
app:layout_constraintTop_toBottomOf="@id/record_call"
app:layout_constraintStart_toEndOf="@id/pause_call_label"
app:layout_constraintEnd_toEndOf="parent" />

View file

@ -157,12 +157,12 @@
android:layout_height="@dimen/call_button_size"
android:layout_marginTop="@dimen/call_extra_button_top_margin"
android:padding="@dimen/call_button_icon_padding"
android:enabled="@{viewModel.isRecordingEnabled}"
android:enabled="false"
android:src="@drawable/record_fill"
android:contentDescription="@string/call_action_record_call"
android:selected="@{viewModel.isRecording()}"
android:background="@drawable/in_call_button_background_red"
app:tint="@color/in_call_button_tint_color"
android:background="@drawable/shape_round_in_call_disabled_button_background"
app:tint="?attr/color_grey_500"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toBottomOf="@id/calls_list_label"
app:layout_constraintStart_toStartOf="@id/calls_list"
@ -242,7 +242,7 @@
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:text="@string/call_action_record_call"
android:enabled="@{viewModel.isRecordingEnabled}"
android:enabled="false"
app:layout_constraintTop_toBottomOf="@id/record_call"
app:layout_constraintStart_toStartOf="@id/calls_list_label"
app:layout_constraintEnd_toEndOf="@id/calls_list_label" />

View file

@ -4,6 +4,12 @@
<data>
<import type="android.view.View" />
<variable
name="shareClickListener"
type="View.OnClickListener" />
<variable
name="exportClickListener"
type="View.OnClickListener" />
<variable
name="deleteClickListener"
type="View.OnClickListener" />
@ -15,12 +21,40 @@
android:background="?attr/color_main2_200">
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_action_label_style"
android:id="@+id/share"
android:onClick="@{shareClickListener}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/menu_share_selected_item"
android:background="@drawable/menu_item_background"
android:layout_marginBottom="1dp"
android:drawableStart="@drawable/share_network"
app:layout_constraintBottom_toTopOf="@id/export"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_action_label_style"
android:id="@+id/export"
android:onClick="@{exportClickListener}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/menu_export_selected_item"
android:background="@drawable/menu_item_background"
android:layout_marginBottom="1dp"
android:drawableStart="@drawable/download_simple"
app:layout_constraintBottom_toTopOf="@id/delete"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_danger_action_label_style"
android:id="@+id/delete"
android:onClick="@{deleteClickListener}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/menu_delete_selected_item"
style="@style/context_menu_danger_action_label_style"
android:background="@drawable/menu_item_background"
android:layout_marginBottom="1dp"
android:drawableStart="@drawable/trash_simple"

View file

@ -658,6 +658,8 @@
<string name="menu_reply_to_chat_message">Répondre</string>
<string name="menu_forward_chat_message">Transférer</string>
<string name="menu_copy_chat_message">Copier le texte</string>
<string name="menu_export_selected_item">Télécharger</string>
<string name="menu_share_selected_item">Partager</string>
<!-- Colors -->
<string name="orange">Orange</string>

View file

@ -694,6 +694,8 @@
<string name="menu_reply_to_chat_message">Reply</string>
<string name="menu_forward_chat_message">Forward</string>
<string name="menu_copy_chat_message">Copy</string>
<string name="menu_export_selected_item">Download</string>
<string name="menu_share_selected_item">Share</string>
<!-- Colors -->
<string name="orange">Orange</string>