Browse Source

Share to others app choose by user not youtube, fb, twitter only

Wayne 6 years ago
parent
commit
b0294c4092

+ 14 - 34
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditActivity.kt

@@ -4,15 +4,12 @@ import android.app.AlertDialog
 import android.app.ProgressDialog
 import android.arch.lifecycle.Observer
 import android.arch.lifecycle.ViewModelProviders
-import android.content.ContentResolver
-import android.content.ContentValues
 import android.content.DialogInterface
 import android.content.Intent
 import android.net.Uri
 import android.os.Bundle
 import android.os.Environment
 import android.os.Handler
-import android.provider.MediaStore
 import android.support.v4.app.DialogFragment
 import android.support.v4.content.FileProvider
 import android.support.v7.app.AppCompatActivity
@@ -23,14 +20,16 @@ import android.widget.Toast
 import com.bomostory.sceneeditmodule.Config
 import com.bomostory.sceneeditmodule.PdfMaker
 import com.bomostory.sceneeditmodule.SuperMovieMaker
-import com.bomostory.sceneeditmodule.basicdata.*
+import com.bomostory.sceneeditmodule.basicdata.Music
+import com.bomostory.sceneeditmodule.basicdata.Project
+import com.bomostory.sceneeditmodule.basicdata.Scene
 import com.bomostory.sceneeditmodule.screen.movie.music.MusicEditDialog
 import com.bomostory.sceneeditmodule.screen.movie.music.MusicSelectDialog
 import com.bomostory.sceneeditmodule.screen.movie.music.MusicSelectFragment
-import com.bomostory.sceneeditmodule.share.ShareDialog
 import com.bomostory.sceneeditmodule.screen.view.AudioTrackGroupView
 import com.bomostory.sceneeditmodule.screen.view.MovieSelectView
 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.example.exportmedia.MediaHelper
@@ -400,13 +399,18 @@ class MovieEditActivity : AppCompatActivity(),
                     }
                 })
             }
-            onClickYoutube = Runnable {
+            onClickMore = Runnable {
                 saveMovie(object : OnMovieSavedListener {
                     override fun onSaved(file: File) {
-                        val isSuc = shareToOtherApp(file, "com.google.android.youtube")
-                        if (!isSuc) {
-                            Toast.makeText(context, R.string.share_youtube_not_found, Toast.LENGTH_SHORT).show()
-                        }
+                        val authority = "$packageName"
+                        val context = this@MovieEditActivity
+                        val uri = FileProvider.getUriForFile(context, authority, file)
+
+                        val intent = Intent(Intent.ACTION_SEND)
+                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
+                        intent.type = "video/mp4"
+                        intent.putExtra(Intent.EXTRA_STREAM, uri)
+                        startActivity(Intent.createChooser(intent, ""))
                     }
                 })
             }
@@ -419,30 +423,6 @@ class MovieEditActivity : AppCompatActivity(),
         }.show(supportFragmentManager)
     }
 
-    private fun shareToOtherApp(file: File, packageNameKeyWord: String): Boolean {
-        val authority = "$packageName"
-        val context = this@MovieEditActivity
-        val uri = FileProvider.getUriForFile(context, authority, file)
-
-        val intent = Intent(Intent.ACTION_SEND)
-        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
-        intent.type = "video/mp4"
-        intent.putExtra(Intent.EXTRA_STREAM, uri)
-
-        val activities = packageManager.queryIntentActivities(intent, 0)
-        if (!activities.isEmpty()) {
-            activities.forEach {
-                val name = it.activityInfo.packageName
-                if (name.contains(packageNameKeyWord)) {
-                    intent.setClassName(name, it.activityInfo.name)
-                    startActivity(intent)
-                    return true
-                }
-            }
-        }
-        return false
-    }
-
     private fun onClickExportPdf() {
         ExportPdfDialog().also { exportPdfDialog ->
             exportPdfDialog.image1Path = viewModel.project?.scene1File?.path ?: ""

+ 3 - 1
src/main/res/layout/dialog_share.xml

@@ -124,6 +124,7 @@
 
     <ImageView
         android:id="@+id/iv_shareDialog_youtube"
+        android:visibility="gone"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
@@ -136,6 +137,7 @@
 
     <ImageView
         android:id="@+id/iv_shareDialog_facebook"
+        android:visibility="gone"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
@@ -148,6 +150,7 @@
 
     <ImageView
         android:id="@+id/iv_shareDialog_twitter"
+        android:visibility="gone"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
@@ -166,7 +169,6 @@
         android:layout_marginRight="36dp"
         android:layout_marginTop="16dp"
         android:src="@drawable/ic_btn_more_01"
-        android:tint="@android:color/darker_gray"
         app:layout_constraintLeft_toRightOf="@id/movieView_shareDialog_preview"
         app:layout_constraintTop_toBottomOf="@id/iv_shareDialog_twitter" />
 

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

@@ -22,6 +22,4 @@
     <string name="export_pdf_dialog_radio_foldable_booklet">Foldable Booklet</string>
     <string name="export_pdf_dialog_print">Print</string>
     <string name="export_pdf_dialog_cancel">Cancel</string>
-
-    <string name="share_youtube_not_found">Cannot find Youtube.</string>
 </resources>