Browse Source

Merge branch 'pdf'

Wayne 6 năm trước cách đây
mục cha
commit
22142b3e03

+ 5 - 20
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditActivity.kt

@@ -6,7 +6,6 @@ import android.arch.lifecycle.Observer
 import android.arch.lifecycle.ViewModelProviders
 import android.content.DialogInterface
 import android.content.Intent
-import android.net.Uri
 import android.os.Bundle
 import android.os.Environment
 import android.os.Handler
@@ -32,6 +31,7 @@ import com.bomostory.sceneeditmodule.share.ExportPdfDialog
 import com.bomostory.sceneeditmodule.share.ShareDialog
 import com.bomostory.sceneeditmodule.utils.MoviePlayerV2
 import com.bomostory.sceneeditmodule.utils.MusicPlayerV2
+import com.bomostory.sceneeditmodule.utils.Utils
 import com.example.exportmedia.MediaHelper
 import com.example.tfat.myapplication.R
 import com.google.gson.Gson
@@ -457,7 +457,10 @@ class MovieEditActivity : AppCompatActivity(),
                     exportPdfFile(second, Runnable {
                         exportPdfDialog.dismiss()
                     }, Runnable {
-                        showPdfExportCompleteDialog(first)
+                        val context = this@MovieEditActivity
+                        val file = first
+                        val authority = "com.bomostory.android"
+                        Utils.showExportPdfCompleteThenViewDialog(context, authority, file)
                     })
                 }
             }
@@ -537,22 +540,4 @@ class MovieEditActivity : AppCompatActivity(),
                     onComplete.run()
                 })
     }
-
-    private fun showPdfExportCompleteDialog(file: File) {
-        AlertDialog.Builder(this@MovieEditActivity)
-                .setMessage("Complete")
-                .setPositiveButton("View") { _, _ ->
-                    val uri = Uri.parse(file.absolutePath)
-                    val intent = Intent(Intent.ACTION_VIEW, uri).apply {
-                        setDataAndType(uri, "application/pdf")
-                    }
-                    if (intent.resolveActivity(packageManager) != null) {
-                        Intent.createChooser(intent, "").apply {
-                            startActivity(this)
-                        }
-                    } else {
-                        Toast.makeText(this@MovieEditActivity, "No app can view pdf", Toast.LENGTH_SHORT).show()
-                    }
-                }.show()
-    }
 }

+ 32 - 0
src/main/java/com/bomostory/sceneeditmodule/utils/Utils.kt

@@ -0,0 +1,32 @@
+package com.bomostory.sceneeditmodule.utils
+
+import android.app.AlertDialog
+import android.content.Context
+import android.content.Intent
+import android.support.v4.content.FileProvider
+import android.widget.Toast
+import com.example.tfat.myapplication.R
+import java.io.File
+
+object Utils {
+    fun showExportPdfCompleteThenViewDialog(context: Context, authority: String, file: File) {
+        AlertDialog.Builder(context)
+                .setMessage(R.string.export_pdf_complete_dialog_msg)
+                .setPositiveButton(R.string.export_pdf_complete_dialog_positive) { _, _ ->
+                    val uri = FileProvider.getUriForFile(context, authority, file)
+                    val intent = Intent(Intent.ACTION_VIEW, uri).apply {
+                        addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+                        addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
+                        addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+                        setDataAndType(uri, "application/pdf")
+                    }
+                    if (intent.resolveActivity(context.packageManager) != null) {
+                        Intent.createChooser(intent, "").apply {
+                            context.startActivity(this)
+                        }
+                    } else {
+                        Toast.makeText(context, R.string.share_pdf_failed_no_app, Toast.LENGTH_SHORT).show()
+                    }
+                }.show()
+    }
+}

+ 4 - 0
src/main/res/values/strings.xml

@@ -48,4 +48,8 @@
     <string name="category_item_culture">Culture</string>
     <string name="category_item_fables">Fables</string>
     <string name="category_item_others">Others</string>
+
+    <string name="export_pdf_complete_dialog_msg">Complete</string>
+    <string name="export_pdf_complete_dialog_positive">View</string>
+    <string name="share_pdf_failed_no_app">No app can view pdf file.</string>
 </resources>