mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Try to open unsupported files in native app
This commit is contained in:
parent
aa34132047
commit
2274cdd343
6 changed files with 55 additions and 13 deletions
|
|
@ -19,12 +19,16 @@
|
|||
*/
|
||||
package org.linphone.ui.main.chat.fragment
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.core.view.doOnPreDraw
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
|
@ -36,12 +40,14 @@ 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.main.MainActivity
|
||||
import org.linphone.ui.main.chat.adapter.ConversationsListAdapter
|
||||
import org.linphone.ui.main.chat.viewmodel.ConversationsListViewModel
|
||||
import org.linphone.ui.main.fragment.AbstractTopBarFragment
|
||||
import org.linphone.ui.main.history.fragment.HistoryMenuDialogFragment
|
||||
import org.linphone.ui.main.viewer.fragment.FileViewerFragmentDirections
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.FileUtils
|
||||
|
||||
@UiThread
|
||||
class ConversationsListFragment : AbstractTopBarFragment() {
|
||||
|
|
@ -236,9 +242,32 @@ class ConversationsListFragment : AbstractTopBarFragment() {
|
|||
it.consume { path ->
|
||||
if (findNavController().currentDestination?.id == R.id.conversationsListFragment) {
|
||||
Log.i("$TAG Navigating to file viewer fragment with path [$path]")
|
||||
val action =
|
||||
FileViewerFragmentDirections.actionGlobalFileViewerFragment(path)
|
||||
findNavController().navigate(action)
|
||||
val extension = FileUtils.getExtensionFromFileName(path)
|
||||
val mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||
when (FileUtils.getMimeType(mime)) {
|
||||
FileUtils.MimeType.Image, FileUtils.MimeType.Video, FileUtils.MimeType.Pdf -> {
|
||||
val action =
|
||||
FileViewerFragmentDirections.actionGlobalFileViewerFragment(path)
|
||||
findNavController().navigate(action)
|
||||
}
|
||||
else -> {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
val contentUri: Uri =
|
||||
FileUtils.getPublicFilePath(requireContext(), path)
|
||||
intent.setDataAndType(contentUri, "file/$mime")
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
try {
|
||||
requireContext().startActivity(intent)
|
||||
} catch (anfe: ActivityNotFoundException) {
|
||||
Log.e("$TAG Can't open file [$path] in third party app: $anfe")
|
||||
val message = getString(
|
||||
R.string.toast_no_app_registered_to_handle_content_type_error
|
||||
)
|
||||
val icon = R.drawable.file
|
||||
(requireActivity() as MainActivity).showRedToast(message, icon)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ class FileViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val pdfPages = MutableLiveData<String>()
|
||||
|
||||
val isImage = MutableLiveData<Boolean>()
|
||||
|
||||
val isVideo = MutableLiveData<Boolean>()
|
||||
|
||||
val isVideoPlaying = MutableLiveData<Boolean>()
|
||||
|
|
@ -119,14 +121,24 @@ class FileViewModel @UiThread constructor() : ViewModel() {
|
|||
}
|
||||
}
|
||||
}
|
||||
FileUtils.MimeType.Image -> {
|
||||
Log.i("$TAG File [$file] seems to be an image")
|
||||
isImage.value = true
|
||||
path.value = file
|
||||
}
|
||||
FileUtils.MimeType.Video -> {
|
||||
Log.i("$TAG File [$file] seems to be a video")
|
||||
isVideo.value = true
|
||||
isVideoPlaying.value = false
|
||||
}
|
||||
FileUtils.MimeType.Audio -> {
|
||||
// TODO: handle audio files
|
||||
}
|
||||
FileUtils.MimeType.PlainText -> {
|
||||
// TODO: handle plain text files
|
||||
}
|
||||
else -> {
|
||||
path.value = file
|
||||
// TODO FIXME : handle audio & plain text files, open native app for unsupported files
|
||||
// TODO: open native app for unsupported files
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="88dp"
|
||||
android:height="88dp"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="256"
|
||||
android:viewportHeight="256">
|
||||
<path
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
android:onClick="@{() -> viewModel.toggleFullScreen()}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:visibility="@{viewModel.isVideo ? View.VISIBLE : View.GONE}"
|
||||
android:visibility="@{viewModel.isVideo ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
@ -65,7 +65,7 @@
|
|||
android:paddingEnd="5dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE}"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE, default=gone}"
|
||||
android:text="@{viewModel.pdfCurrentPage + ` / ` + viewModel.pdfPages, default=`1 / 30`}"
|
||||
android:textColor="@color/white"
|
||||
android:background="#80000000"
|
||||
|
|
@ -82,7 +82,7 @@
|
|||
android:adjustViewBounds="true"
|
||||
android:scaleType="fitCenter"
|
||||
coilFile="@{viewModel.path}"
|
||||
android:visibility="@{viewModel.isPdf || viewModel.isVideo ? View.GONE : View.VISIBLE}" />
|
||||
android:visibility="@{viewModel.isImage ? View.VISIBLE : View.GONE, default=gone}" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back"
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
android:onClick="@{() -> viewModel.toggleFullScreen()}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="@{viewModel.isVideo ? View.VISIBLE : View.GONE}"
|
||||
android:visibility="@{viewModel.isVideo ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
android:paddingEnd="5dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE}"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE, default=gone}"
|
||||
android:text="@{viewModel.pdfCurrentPage + ` / ` + viewModel.pdfPages, default=`1 / 30`}"
|
||||
android:textColor="@color/white"
|
||||
android:background="#80000000"
|
||||
|
|
@ -80,7 +80,7 @@
|
|||
android:adjustViewBounds="true"
|
||||
android:scaleType="fitCenter"
|
||||
coilFile="@{viewModel.path}"
|
||||
android:visibility="@{viewModel.isPdf || viewModel.isVideo ? View.GONE : View.VISIBLE}" />
|
||||
android:visibility="@{viewModel.isImage ? View.VISIBLE : View.GONE, default=gone}" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back"
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@
|
|||
<string name="toast_conversation_history_deleted">History has been successfully deleted</string>
|
||||
<string name="toast_group_conversation_left">You have left the group</string>
|
||||
<string name="toast_low_media_volume">Media volume is low, you may not hear anything!</string>
|
||||
<string name="toast_no_app_registered_to_handle_content_type_error">No app found to open this kind of file</string>
|
||||
|
||||
<string name="assistant_account_login">Login</string>
|
||||
<string name="assistant_scan_qr_code">Scan QR code</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue