TP-63401 | Show image in chat crash fix (#10391)
Co-authored-by: sangaraboinarishvik <rishvik.vardhan@navi.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -33,4 +33,7 @@
|
||||
<external-cache-path
|
||||
name="cache"
|
||||
path="cache/" />
|
||||
<external-cache-path
|
||||
name="health_insurance"
|
||||
path="healthInsurance/"/>
|
||||
</paths>
|
||||
|
||||
@@ -300,13 +300,13 @@
|
||||
android:value="${GOOGLE_MAPS_KEY}" />
|
||||
|
||||
<provider
|
||||
android:name="com.navi.insurance.util.NaviFileProvider"
|
||||
android:name="com.navi.insurance.util.NaviInsuranceFileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
android:resource="@xml/file_provider" />
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
|
||||
@@ -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)
|
||||
class NaviInsuranceFileProvider: FileProvider(com.navi.common.R.xml.file_provider)
|
||||
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<external-cache-path
|
||||
name="health_insurance"
|
||||
path="healthInsurance/"/>
|
||||
</paths>
|
||||
Reference in New Issue
Block a user