Fixes issue on Android Q where the gif type was wrong

blinds
Laurent 5 years ago
parent 55b15780d1
commit a87e18f950
  1. 22
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt
  2. 12
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt

@ -5,6 +5,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.widget.Toast
@ -164,9 +165,13 @@ class HandHistoryActivity : BaseActivity() {
Toast.makeText(this, R.string.video_export_started, Toast.LENGTH_LONG).show()
askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), RequestCode.PERMISSION_WRITE_EXTERNAL_STORAGE.value) { granted ->
if (granted) {
gifExport()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
gifExport()
} else {
askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), RequestCode.PERMISSION_WRITE_EXTERNAL_STORAGE.value) { granted ->
if (granted) {
gifExport()
}
}
}
}
@ -175,11 +180,16 @@ class HandHistoryActivity : BaseActivity() {
Toast.makeText(this, R.string.video_export_started, Toast.LENGTH_LONG).show()
askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), RequestCode.PERMISSION_WRITE_EXTERNAL_STORAGE.value) { granted ->
if (granted) {
videoExport()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
videoExport()
} else {
askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), RequestCode.PERMISSION_WRITE_EXTERNAL_STORAGE.value) { granted ->
if (granted) {
videoExport()
}
}
}
}
private fun videoExport() {

@ -31,8 +31,8 @@ import java.util.*
import kotlin.coroutines.CoroutineContext
enum class FileType(var value: String) {
IMAGE("image/gif"),
VIDEO("video/*")
IMAGE_GIF("image/gif"),
VIDEO_MP4("video/mp4")
}
class ReplayExportService : Service() {
@ -92,7 +92,7 @@ class ReplayExportService : Service() {
animator.configure(width.toFloat(), height.toFloat(), context)
val formattedDate = Date().dateTimeFileFormatted
val fileName = "hand_${formattedDate}.gif"
val fileName = "hand_${formattedDate}"
// Add a specific media item.
val resolver = applicationContext.contentResolver
@ -102,6 +102,7 @@ class ReplayExportService : Service() {
val gifDetails = ContentValues().apply {
put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
put(MediaStore.Images.Media.MIME_TYPE, FileType.IMAGE_GIF.value)
}
val uri = resolver.insert(imageCollection, gifDetails)
@ -135,7 +136,7 @@ class ReplayExportService : Service() {
writer.finishWrite(os)
realm.close()
notifyUser(uri, FileType.IMAGE)
notifyUser(uri, FileType.IMAGE_GIF)
} else {
Timber.w("Resolver insert ended without uri...")
}
@ -206,6 +207,7 @@ class ReplayExportService : Service() {
val fileDetails = ContentValues().apply {
Timber.d("set file details = $fileName")
put(MediaStore.Video.Media.DISPLAY_NAME, fileName)
put(MediaStore.Images.Media.MIME_TYPE, FileType.VIDEO_MP4.value)
}
// copy video to nice path
@ -219,7 +221,7 @@ class ReplayExportService : Service() {
file.delete() // delete temp file
notifyUser(uri, FileType.VIDEO)
notifyUser(uri, FileType.VIDEO_MP4)
} ?: run {
Timber.w("Resolver insert ended without uri...")

Loading…
Cancel
Save