Procházet zdrojové kódy

Merge branch 'change-project-path'

cooperku_kdanmobile před 6 roky
rodič
revize
7175ae0911

+ 3 - 2
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditViewModel.kt

@@ -126,12 +126,13 @@ class MovieEditViewModel : ViewModel() {
     }
 
     fun saveProject(context: Context, project: Project, oldName: String): Completable {
+        var newProject = project
         project.name?.let { projectName ->
             if (projectName != oldName) {
-                com.bomostory.sceneeditmodule.utils.FileUtils.changeProjectName(oldName, projectName)
+                newProject = com.bomostory.sceneeditmodule.utils.FileUtils.changeProjectName(oldName, projectName)
             }
         }
-        return FileUtils.saveProject(context, project, 1920, 1080)
+        return FileUtils.saveProject(context, newProject, 1920, 1080)
                 .andThen {
                     onProjectSavedListeners.forEach { it.run() }
                     it.onComplete()

+ 14 - 15
src/main/java/com/bomostory/sceneeditmodule/utils/FileUtils.kt

@@ -233,18 +233,17 @@ object FileUtils {
         }
     }
 
-    fun changeProjectName(oldName: String, newName: String): Boolean {
+    fun changeProjectName(oldName: String, newName: String): Project {
         val oldProjectFile = File("${Config.PROJECTS_FOLDER}/$oldName/${Config.PROJECT_FILE_NAME}")
-        if (!oldProjectFile.exists())
-            return false
         var oldProject = Gson().fromJson<Project>(readFileToString(oldProjectFile), Project::class.java)
 
         val oldProjectFolder = File(Config.PROJECTS_FOLDER, oldName)
         val newProjectFolder = File(Config.PROJECTS_FOLDER, newName)
-        val result = oldProjectFolder.renameTo(newProjectFolder)
-
-        if (result) {
+        val success = oldProjectFolder.renameTo(newProjectFolder)
 
+        if (!success) {
+            return oldProject
+        } else {
             val newProjectFile = File("${Config.PROJECTS_FOLDER}/$newName/${Config.PROJECT_FILE_NAME}")
             var oldProjectPath = File(Config.PROJECTS_FOLDER, oldName).absolutePath
             var newProjectPath = File(Config.PROJECTS_FOLDER, newName).absolutePath
@@ -287,17 +286,17 @@ object FileUtils {
                 }
                 println("count = $count")
             }
+            return newProject
 
-            try {
-                val fileWriter = FileWriter(newProjectFile)
-                fileWriter.write(Gson().toJson(newProject))
-                fileWriter.flush()
-                fileWriter.close()
-            } catch (e: Exception) {
-                e.printStackTrace()
-            }
+//                try {
+//                    val fileWriter = FileWriter(newProjectFile)
+//                    fileWriter.write(Gson().toJson(newProject))
+//                    fileWriter.flush()
+//                    fileWriter.close()
+//                } catch (e: Exception) {
+//                    e.printStackTrace()
+//                }
         }
-        return result
     }
 
     fun saveProject(context: Context, project: Project, scaleWidth: Int, scaleHeight: Int): Completable {

+ 3 - 0
src/main/res/layout/view_front_cover_editor.xml

@@ -64,6 +64,9 @@
     <!-- TODO: remove enabled="false" after solve project rename issue -->
     <EditText
         android:enabled="true"
+        android:singleLine="true"
+        android:maxLines="1"
+        android:inputType="text"
         android:id="@+id/et_frontCoverEditor_projectName"
         style="@style/BomoEditText"
         android:layout_width="320dp"