diff --git a/android/navi-chat/src/main/java/com/navi/chat/ui/activities/NaviChatViewImageActivity.kt b/android/navi-chat/src/main/java/com/navi/chat/ui/activities/NaviChatViewImageActivity.kt index cde399fdb3..00c75ba5fe 100644 --- a/android/navi-chat/src/main/java/com/navi/chat/ui/activities/NaviChatViewImageActivity.kt +++ b/android/navi-chat/src/main/java/com/navi/chat/ui/activities/NaviChatViewImageActivity.kt @@ -23,6 +23,7 @@ import com.navi.chat.utils.ChatFileHelper import com.navi.chat.utils.FILENAME import com.navi.chat.utils.FILE_URI import com.navi.chat.utils.ToolbarInteraction +import com.navi.common.utils.log import dagger.hilt.android.EntryPointAccessors import java.io.File import javax.inject.Inject @@ -68,23 +69,34 @@ class NaviChatViewImageActivity : ChatBaseActivity(), ToolbarInteraction { private fun showImageInImageView(fileName: String?) { fileName?.let { - val ext = fileHelper.getExtensionFromFileName(fileName) - if (fileHelper.isSupportedFile(ext)) { - val sd: File = this.cacheDir - val folder = File(sd, "/chat/") - val outputFile = File(folder, fileName) - val uri = - if (outputFile.exists()) { - FileProvider.getUriForFile( + try { + val ext = fileHelper.getExtensionFromFileName(fileName) + if (fileHelper.isSupportedFile(ext)) { + val sd: File = this.cacheDir + val folder = File(sd, "/chat/") + val outputFile = File(folder, fileName) + val uri = + if (outputFile.exists()) { + FileProvider.getUriForFile( + this, + "${this.packageName}.fileprovider", + outputFile + ) + } else { + intent.getStringExtra(FILE_URI)?.toUri() + } + Glide.with(this).load(uri).into(binding.ivImageAttachment) + } else { + Toast.makeText( this, - "${this.packageName}.fileprovider", - outputFile + getString(R.string.file_cannot_be_opened), + Toast.LENGTH_LONG ) - } else { - intent.getStringExtra(FILE_URI)?.toUri() - } - Glide.with(this).load(uri).into(binding.ivImageAttachment) - } else { + .show() + finish() + } + } catch (e: Exception) { + e.log() Toast.makeText(this, getString(R.string.file_cannot_be_opened), Toast.LENGTH_LONG) .show() finish() diff --git a/android/navi-chat/src/main/java/com/navi/chat/usecase/ChatAttachmentViewClickedUseCase.kt b/android/navi-chat/src/main/java/com/navi/chat/usecase/ChatAttachmentViewClickedUseCase.kt index fa707899c3..30f30ce821 100644 --- a/android/navi-chat/src/main/java/com/navi/chat/usecase/ChatAttachmentViewClickedUseCase.kt +++ b/android/navi-chat/src/main/java/com/navi/chat/usecase/ChatAttachmentViewClickedUseCase.kt @@ -23,6 +23,7 @@ import com.navi.chat.utils.FILENAME import com.navi.chat.utils.FILE_TYPE_PARAM import com.navi.chat.utils.NaviChatAnalytics import com.navi.chat.utils.NaviChatAnalytics.Companion.CHAT_ATTACHMENT_PREVIEW_AFTER_SEND +import com.navi.common.utils.log import java.io.File import timber.log.Timber @@ -84,35 +85,46 @@ constructor(private val context: Context, private val fileHelper: ChatFileHelper } AttachmentType.PDF, AttachmentType.DOCUMENT -> { - val sd: File = context.cacheDir - val folder = File(sd, "/chat/") - val outputFile = File(folder, fileName.orEmpty()) - val uri = - FileProvider.getUriForFile( - context, - "${context.packageName}.fileprovider", - outputFile - ) - val newIntent = Intent(Intent.ACTION_VIEW) - newIntent.data = uri - newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK - newIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION try { - context.startActivity(newIntent) - } catch (e: ActivityNotFoundException) { + val sd: File = context.cacheDir + val folder = File(sd, "/chat/") + val outputFile = File(folder, fileName.orEmpty()) + val uri = + FileProvider.getUriForFile( + context, + "${context.packageName}.fileprovider", + outputFile + ) + val newIntent = Intent(Intent.ACTION_VIEW) + newIntent.data = uri + newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + newIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION + try { + context.startActivity(newIntent) + } catch (e: ActivityNotFoundException) { + e.log() + Toast.makeText( + context, + context.getString(R.string.no_handler_for_this_file), + Toast.LENGTH_LONG + ) + .show() + } + crmEventTracker.sendEvent( + CHAT_ATTACHMENT_PREVIEW_AFTER_SEND, + hashMapOf( + FILENAME to fileName.orEmpty(), + ) + ) + } catch (e: Exception) { + e.log() Toast.makeText( context, - context.getString(R.string.no_handler_for_this_file), + context.getString(R.string.file_cannot_be_opened), Toast.LENGTH_LONG ) .show() } - crmEventTracker.sendEvent( - CHAT_ATTACHMENT_PREVIEW_AFTER_SEND, - hashMapOf( - FILENAME to fileName.orEmpty(), - ) - ) } null -> Toast.makeText( diff --git a/android/navi-common/src/main/res/xml/file_provider.xml b/android/navi-common/src/main/res/xml/file_provider.xml index 948118f352..1b2cf158f9 100644 --- a/android/navi-common/src/main/res/xml/file_provider.xml +++ b/android/navi-common/src/main/res/xml/file_provider.xml @@ -33,4 +33,7 @@ + diff --git a/android/navi-insurance/src/main/AndroidManifest.xml b/android/navi-insurance/src/main/AndroidManifest.xml index d4ab995220..559e2645d8 100644 --- a/android/navi-insurance/src/main/AndroidManifest.xml +++ b/android/navi-insurance/src/main/AndroidManifest.xml @@ -300,13 +300,13 @@ android:value="${GOOGLE_MAPS_KEY}" /> + android:resource="@xml/file_provider" /> diff --git a/android/navi-insurance/src/main/java/com/navi/insurance/util/DownloadShareUtil.kt b/android/navi-insurance/src/main/java/com/navi/insurance/util/DownloadShareUtil.kt index 8c05a9a448..c05f34698c 100644 --- a/android/navi-insurance/src/main/java/com/navi/insurance/util/DownloadShareUtil.kt +++ b/android/navi-insurance/src/main/java/com/navi/insurance/util/DownloadShareUtil.kt @@ -9,6 +9,7 @@ import android.net.Uri import android.webkit.MimeTypeMap import androidx.core.content.ContextCompat.getSystemService import androidx.core.content.FileProvider +import com.navi.common.CommonLibManager import com.navi.insurance.R import dagger.hilt.android.qualifiers.ActivityContext import dagger.hilt.android.qualifiers.ApplicationContext @@ -63,10 +64,11 @@ class DownloadShareUtil @Inject constructor(@ActivityContext val context: Contex broadcastReceiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE) ) + } companion object{ - private const val AUTHORITY = "com.naviapp.fileprovider" + private val AUTHORITY = "${CommonLibManager.applicationId}.fileprovider" private const val HI_DIRECTORY = "healthInsurance" } } @@ -78,4 +80,4 @@ sealed class DownloadState{ data object Success: DownloadState() } -class NaviFileProvider: FileProvider(R.xml.file_paths) \ No newline at end of file +class NaviInsuranceFileProvider: FileProvider(com.navi.common.R.xml.file_provider) \ No newline at end of file diff --git a/android/navi-insurance/src/main/res/xml/file_paths.xml b/android/navi-insurance/src/main/res/xml/file_paths.xml deleted file mode 100644 index d64bbd9d1e..0000000000 --- a/android/navi-insurance/src/main/res/xml/file_paths.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file