Jelajahi Sumber

chooseTheme-2

faterhenry 6 tahun lalu
induk
melakukan
dec0e8bbf6

+ 2 - 3
src/main/AndroidManifest.xml

@@ -19,9 +19,8 @@
             android:label="@string/title_activity_movie_edit"
             android:screenOrientation="landscape" />
         <activity
-            android:name="com.bomostory.sceneeditmodule.ChooseThemeActivity">
-            android:screenOrientation="landscape"
-        </activity>
+            android:name="com.bomostory.sceneeditmodule.ChooseThemeActivity"
+            android:screenOrientation="landscape"/>
     </application>
 
 </manifest>

+ 3 - 3
src/main/java/com/bomostory/sceneeditmodule/ChooseThemeActivity.kt

@@ -33,7 +33,7 @@ class ChooseThemeActivity : AppCompatActivity() {
         otherThemes = Gson().fromJson<OtherThemes>(intent.getStringExtra("other_theme"), OtherThemes::class.java)
         for (i in 0 until otherThemes.themes.size) {
             var theme = otherThemes.themes[i]
-            val path = "${theme.assetFolder.path}/${theme.themeAssetIndex.largeFile}"
+            val path = "${theme.assetFolder.path}/${"asset"}/${theme.themeAssetIndex.largeFile}"
             coverPath.add(path)
         }
         for (i in 0 until coverPath.size)  {
@@ -44,7 +44,7 @@ class ChooseThemeActivity : AppCompatActivity() {
                         otherThemes.themes[i].themeAssetIndex.contains.actor.forEach {
                             add(ArrayList<String>().apply {
                                 it.value.values.forEach {
-                                    val path = "${otherThemes.themes[i].assetFolder.path}/${it.smallFile}"
+                                    val path = "${otherThemes.themes[i].assetFolder.path}/${"asset"}/${it.smallFile}"
                                     add(path)
                                 }
                             })
@@ -52,7 +52,7 @@ class ChooseThemeActivity : AppCompatActivity() {
                     }
                     resourceObjectPath = java.util.ArrayList<String>().apply {
                         otherThemes.themes[i].themeAssetIndex.contains.obj.values.forEach {
-                            val path = "${otherThemes.themes[i].assetFolder.path}/${it.smallFile}"
+                            val path = "${otherThemes.themes[i].assetFolder.path}/${"asset"}/${it.smallFile}"
                             add(path)
                         }
                     }

+ 8 - 0
src/main/java/com/bomostory/sceneeditmodule/IBoMoThemeData.kt

@@ -0,0 +1,8 @@
+package com.bomostory.sceneeditmodule
+
+interface IBoMoThemeData {
+    val id: Int
+    val name: String
+    val channel: String
+    val sourcePathUrl: String?
+}

+ 15 - 0
src/main/java/com/bomostory/sceneeditmodule/IThemeManager.kt

@@ -0,0 +1,15 @@
+package com.bomostory.sceneeditmodule
+
+import com.example.bomocloud.theme.ThemeAssetIndex
+import io.reactivex.Single
+import java.io.File
+
+interface IThemeManager {
+    val themes: List<IBoMoThemeData>
+    fun canUse(bomoThemeData: IBoMoThemeData): Boolean
+    fun getAssetResourceFolder(bomoThemeData: IBoMoThemeData): File
+    fun getAssetFolder(bomoThemeData: IBoMoThemeData): File
+    fun getAssetIndexFile(bomoThemeData: IBoMoThemeData): File
+    fun loadThemeAssetIndex(bomoThemeData: IBoMoThemeData): Single<ThemeAssetIndex>
+    fun isDownloaded(bomoThemeData: IBoMoThemeData): Boolean
+}

+ 24 - 16
src/main/java/com/bomostory/sceneeditmodule/SceneEditActivity.kt

@@ -6,13 +6,11 @@ import android.content.Context
 import android.content.DialogInterface
 import android.content.Intent
 import android.graphics.Bitmap
-import android.graphics.Paint
 import android.os.Bundle
 import android.support.v7.app.AppCompatActivity
 import android.support.v7.widget.LinearLayoutManager
 import android.support.v7.widget.RecyclerView
 import android.util.DisplayMetrics
-import android.util.Log
 import android.view.*
 import android.widget.PopupWindow
 import android.widget.SeekBar
@@ -57,6 +55,7 @@ import kotlinx.android.synthetic.main.scene_brush_view.view.*
 import java.io.File
 import java.util.*
 import java.util.concurrent.CopyOnWriteArrayList
+import kotlin.collections.ArrayList
 
 
 class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener, EditActorView.OnActorChangeListener,
@@ -65,7 +64,6 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         BrushView.OnSelectBrush {
 
     private lateinit var project: Project
-    private lateinit var otherThemes: OtherThemes
     private var currentSceneIndex = 0
     private var currentLayerIndex = 6
     private var startRecordTime = 0L
@@ -106,10 +104,6 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         actionBar?.hide()
         supportActionBar?.hide()
         project = Gson().fromJson<Project>(intent.getStringExtra("project"), Project::class.java)
-        otherThemes = when(intent.getStringExtra("other_theme")){
-            null -> OtherThemes()
-            else -> Gson().fromJson<OtherThemes>(intent.getStringExtra("other_theme"), OtherThemes::class.java)
-        }
         resourceThemeBitmap = project.sceneResource as ArrayList<String>
         resourceThemeBitmap.add(File(Config.ASSETS_FOLDER, Config.PROJECT_WHITE_FILE_NAME).path)
         resourceActorBitmap = when(intent.getStringExtra("resource_actor")) {
@@ -125,7 +119,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                     }
                 }
             }
-            else -> {intent.getStringArrayListExtra("resource_object")}
+            else -> { intent.getStringArrayListExtra("resource_object")}
         }
         windowManager.defaultDisplay.getMetrics(monitorSize)
         var layoutPrams = sceneEditView.layoutParams
@@ -404,7 +398,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
             viewContainer.removeAllViews()
         }
         startRecord.visibility = View.INVISIBLE
-        if (currentLayerIndex == 6){
+        if (currentLayerIndex == 6) {
             switchLayer(0)
             initActorRecyclerView()
         }
@@ -430,13 +424,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
             }
         }
         selectActorView.btn_choose_theme.setOnClickListener {
-            if (!otherThemes.themes.isEmpty()) {
-                var intent = Intent(this, ChooseThemeActivity::class.java)
-                intent.putExtra("project", Gson().toJson(project))
-                intent.putExtra("other_theme", Gson().toJson(otherThemes))
-                startActivity(intent)
-                finish()
-        }
+            chooseTheme()
         }
     }
     private fun initDialogueView(){
@@ -1536,4 +1524,24 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
             paint_view.brush = it
         }
     }
+
+    private fun chooseTheme(){
+        var otherThemes =  OtherThemes()
+        SuperAppModule.themeManager.themes.forEach {
+            if (SuperAppModule.themeManager.canUse(it) && SuperAppModule.themeManager.isDownloaded(it)) {
+                val index = SuperAppModule.themeManager.loadThemeAssetIndex(it).blockingGet()
+                val data = it
+                var theme = Theme(index,SuperAppModule.themeManager.getAssetFolder(data))
+                otherThemes.themes.add(theme)
+            }
+        }
+        val json = Gson().toJson(project)
+        val themeJson = Gson().toJson(otherThemes)
+        val intent = Intent(this@SceneEditActivity, ChooseThemeActivity::class.java).apply {
+            putExtra("project", json)
+            putExtra("other_theme", themeJson)
+            }
+        startActivity(intent)
+        finish()
+    }
 }

+ 5 - 0
src/main/java/com/bomostory/sceneeditmodule/SuperAppModule.kt

@@ -0,0 +1,5 @@
+package com.bomostory.sceneeditmodule
+
+object SuperAppModule {
+    lateinit var themeManager: IThemeManager
+}

+ 0 - 6
src/main/java/com/bomostory/sceneeditmodule/basicdata/RecentStory.kt

@@ -1,6 +0,0 @@
-package com.bomostory.sceneeditmodule.basicdata
-
-class RecentStory {
-    var order: Int = 0
-    var filePath: String? = null
-}