Selaa lähdekoodia

Merge branch 'scene-cover'

abc 6 vuotta sitten
vanhempi
commit
ce312046f7

+ 53 - 0
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditActivity.kt

@@ -23,6 +23,7 @@ import com.bomostory.sceneeditmodule.SuperMovieMaker
 import com.bomostory.sceneeditmodule.basicdata.Music
 import com.bomostory.sceneeditmodule.basicdata.Project
 import com.bomostory.sceneeditmodule.basicdata.Scene
+import com.bomostory.sceneeditmodule.cover.CoverEditorDialog
 import com.bomostory.sceneeditmodule.screen.movie.music.MusicEditDialog
 import com.bomostory.sceneeditmodule.screen.movie.music.MusicSelectDialog
 import com.bomostory.sceneeditmodule.screen.movie.music.MusicSelectFragment
@@ -379,9 +380,61 @@ class MovieEditActivity : AppCompatActivity(),
             }
             onClickExportPdf = Runnable { onClickExportPdf() }
             onClickPrint = Runnable { onClickPrint() }
+            onClickEditCover = Runnable { onClickEditCover(project) }
         }.show(supportFragmentManager)
     }
 
+    private fun onClickEditCover(project: Project) {
+        val dialog = CoverEditorDialog()
+        dialog.project = project
+        dialog.onViewCreated = Runnable {
+            dialog.apply {
+                val oldName = project.name ?: ""
+                onSave = View.OnClickListener { it ->
+                    if (storyName == "") {
+                        showEmptyProjectNameMsg()
+                    /** TODO: 目前不支援 rename **/
+                    /**
+                    } else if (storyName != oldName && viewModel.isProjectNameExist(storyName)) {
+                        showDuplicatedProjectNameMsg()
+                    **/
+                    } else {
+                        if (coverFile == null) {
+                            project.coverFile = null
+                        } else {
+                            project.coverFile = coverFile
+                        }
+                        project.name = storyName
+                        project.author = author
+                        project.frontCoverColor = frontCoverColor
+                        project.backCoverColor = backCoverColor
+                        project.category = category
+
+                        val context = this@MovieEditActivity
+                        val pd = ProgressDialog(context)
+                        viewModel.saveProject(context, project, oldName)
+                                .doOnSubscribe { pd.show() }
+                                .doFinally { pd.dismiss() }
+                                .subscribe {
+//                                    projectManager.reloadProjects()
+                                    dismiss()
+                                }
+                    }
+                }
+                coverFile = project.coverFile
+                onCancel = View.OnClickListener { this.dismiss() }
+                storyName = project.name ?: ""
+                author = project.author ?: ""
+                category = project.category
+                if (project.coverFile == null) {
+                    frontCoverColor = project.frontCoverColor
+                }
+                backCoverColor = project.backCoverColor
+            }
+        }
+        dialog.show(supportFragmentManager)
+    }
+
     private fun onClickPrint() {
         ExportPdfDialog().also { exportPdfDialog ->
             exportPdfDialog.project = viewModel.project!!

+ 24 - 0
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditViewModel.kt

@@ -6,20 +6,29 @@ import android.content.ContentResolver
 import android.content.Context
 import android.media.MediaMetadataRetriever
 import com.bomostory.sceneeditmodule.basicdata.*
+import com.bomostory.sceneeditmodule.utils.FileUtils
 import com.bomostory.sceneeditmodule.utils.TimeUtils
 import com.example.bomocloud.BoMoCloud
 import com.example.bomocloud.video.UploadVideoData
 import com.example.exportmedia.MediaHelper
 import com.example.exportmedia.audio.AudioEditor
 import com.example.tfat.myapplication.R
+import io.reactivex.Completable
 import io.reactivex.Observable
+import io.reactivex.android.schedulers.AndroidSchedulers
+import io.reactivex.schedulers.Schedulers
 import okhttp3.MediaType
 import okhttp3.MultipartBody
 import okhttp3.RequestBody
 import java.io.File
+import java.util.concurrent.CopyOnWriteArrayList
 
 class MovieEditViewModel : ViewModel() {
 
+    companion object {
+        val onProjectSavedListeners = CopyOnWriteArrayList<Runnable>()
+    }
+
     val storyLiveData = MutableLiveData<Story>()
 
     val storyPeriodLiveData = MutableLiveData<Long>()
@@ -116,4 +125,19 @@ class MovieEditViewModel : ViewModel() {
                 .uploadVideo(author, name, category, filePart)
     }
 
+    fun saveProject(context: Context, project: Project, oldName: String): Completable {
+        project.name?.let { projectName ->
+            if (projectName != oldName) {
+                com.bomostory.sceneeditmodule.utils.FileUtils.changeProjectName(oldName, projectName)
+            }
+        }
+        return FileUtils.saveProject(context, project, 1920, 1080)
+                .andThen {
+                    onProjectSavedListeners.forEach { it.run() }
+                    it.onComplete()
+                }
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+    }
+
 }

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

@@ -85,8 +85,10 @@
         app:layout_constraintRight_toRightOf="@id/iv_frontCoverSceneChooserDialog_coverMask"
         app:layout_constraintTop_toBottomOf="@id/tv_frontCoverSceneChooserDialog_coverTitle"
         tools:text="Author" />
-    
+
+    <!-- Remove visibility="gone" when implemented it -->
     <Spinner
+        android:visibility="invisible"
         android:id="@+id/spinner_frontCoverSceneChooserDialog_align"
         android:foreground="@drawable/bg_bomo_spinner"
         app:layout_constraintTop_toTopOf="@id/iv_frontCoverSceneChooserDialog_cover"