From 7686687c2759ab9465f67974e6c153a7051cc359 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Mon, 10 Apr 2023 13:55:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=8A=A0=E8=BD=BD=E6=97=B6=E7=A8=8B=E5=BA=8F=E5=B4=A9?= =?UTF-8?q?=E6=BA=83=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?minVersion=E7=BC=96=E8=BE=91=E6=A1=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/viewmodel/TemplateParserViewModel.kt | 94 +++++++++++-------- .../main/res/layout/activity_create_mod.xml | 20 +++- .../res/layout/activity_user_home_page.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../core/dataBean/template/WebTemplateData.kt | 14 ++- 5 files changed, 83 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateParserViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateParserViewModel.kt index b00128e..5381ba6 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateParserViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateParserViewModel.kt @@ -26,9 +26,10 @@ class TemplateParserViewModel : BaseViewModel() { //json数据 private var jsonData: JSONObject? = null private var template: Template? = null - private lateinit var arrayList :ArrayList + private lateinit var arrayList: ArrayList + //文件输出目录 - private var outPutPath : String? = null + private var outPutPath: String? = null //创建目录 @@ -58,7 +59,12 @@ class TemplateParserViewModel : BaseViewModel() { * @return String */ fun getCode(): String { - return jsonData?.getString("data") ?: "" + try { + return jsonData?.getString("data") ?: "" + } catch (e: Exception) { + e.printStackTrace() + return "" + } } @@ -97,7 +103,7 @@ class TemplateParserViewModel : BaseViewModel() { createDirectory } LogCat.d("构建文件", "是否需要独立创建文件夹${independentFolder} 文件夹目录${createPath}") - if (independentFolder){ + if (independentFolder) { val folder = File(createPath) if (folder.exists()) { LogCat.e("构建文件", "创建目录${createPath}已存在。") @@ -124,7 +130,7 @@ class TemplateParserViewModel : BaseViewModel() { * 获取文件输出目录(当构建文件完毕后,返回有效值。否则返回null) * @return String? */ - fun getOutputPath():String?{ + fun getOutputPath(): String? { return outPutPath } @@ -175,57 +181,63 @@ class TemplateParserViewModel : BaseViewModel() { * @return ArrayList */ fun getTemplateParserList(context: Context): ArrayList { - if (this::arrayList.isInitialized) - { - LogCat.d("获取模板解析器","已经被调用了一次,返回成员变量") + if (this::arrayList.isInitialized) { + LogCat.d("获取模板解析器", "已经被调用了一次,返回成员变量") return arrayList } arrayList = ArrayList() val gson = Gson() - val jsonArray = jsonData?.getJSONArray("action") - if (jsonArray == null) { - LogCat.e("获取模板解析器", "此模板没有action,无法读取。") - return arrayList - } else { - val len = jsonArray.length() - for (i in 0 until len) { - val templateParserData = jsonArray.getJSONObject(i) - when (templateParserData.getString("type")) { - "input" -> { - arrayList.add( - InputParser( - context, - gson.fromJson( - templateParserData.toString(4), - InputParserDataBean::class.java + try { + val jsonArray = jsonData?.getJSONArray("action") + if (jsonArray == null) { + LogCat.e("获取模板解析器", "此模板没有action,无法读取。") + return arrayList + } else { + val len = jsonArray.length() + for (i in 0 until len) { + val templateParserData = jsonArray.getJSONObject(i) + when (templateParserData.getString("type")) { + "input" -> { + arrayList.add( + InputParser( + context, + gson.fromJson( + templateParserData.toString(4), + InputParserDataBean::class.java + ) ) ) - ) - } - "comment" -> { - arrayList.add( - IntroducingParser( - context, gson.fromJson( - templateParserData.toString(4), - IntroducingDataBean::class.java + } + "comment" -> { + arrayList.add( + IntroducingParser( + context, gson.fromJson( + templateParserData.toString(4), + IntroducingDataBean::class.java + ) ) ) - ) - } - "valueSelector" -> { - arrayList.add( - ListParser( - context, gson.fromJson( - templateParserData.toString(4), - ListParserDataBean::class.java + } + "valueSelector" -> { + arrayList.add( + ListParser( + context, gson.fromJson( + templateParserData.toString(4), + ListParserDataBean::class.java + ) ) ) - ) + } } } + return arrayList } + } catch (e: Exception) { + e.printStackTrace() + LogCat.e("获取模板解析器", "解析action出错$e。") return arrayList } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_create_mod.xml b/app/src/main/res/layout/activity_create_mod.xml index cd272c1..0b15070 100644 --- a/app/src/main/res/layout/activity_create_mod.xml +++ b/app/src/main/res/layout/activity_create_mod.xml @@ -70,11 +70,27 @@ -