修复某些模板加载时程序崩溃的问题。添加minVersion编辑框。
This commit is contained in:
parent
b614503b0d
commit
7686687c27
|
@ -26,9 +26,10 @@ class TemplateParserViewModel : BaseViewModel() {
|
||||||
//json数据
|
//json数据
|
||||||
private var jsonData: JSONObject? = null
|
private var jsonData: JSONObject? = null
|
||||||
private var template: Template? = null
|
private var template: Template? = null
|
||||||
private lateinit var arrayList :ArrayList<TemplateParser>
|
private lateinit var arrayList: ArrayList<TemplateParser>
|
||||||
|
|
||||||
//文件输出目录
|
//文件输出目录
|
||||||
private var outPutPath : String? = null
|
private var outPutPath: String? = null
|
||||||
|
|
||||||
|
|
||||||
//创建目录
|
//创建目录
|
||||||
|
@ -58,7 +59,12 @@ class TemplateParserViewModel : BaseViewModel() {
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
fun getCode(): 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
|
createDirectory
|
||||||
}
|
}
|
||||||
LogCat.d("构建文件", "是否需要独立创建文件夹${independentFolder} 文件夹目录${createPath}")
|
LogCat.d("构建文件", "是否需要独立创建文件夹${independentFolder} 文件夹目录${createPath}")
|
||||||
if (independentFolder){
|
if (independentFolder) {
|
||||||
val folder = File(createPath)
|
val folder = File(createPath)
|
||||||
if (folder.exists()) {
|
if (folder.exists()) {
|
||||||
LogCat.e("构建文件", "创建目录${createPath}已存在。")
|
LogCat.e("构建文件", "创建目录${createPath}已存在。")
|
||||||
|
@ -124,7 +130,7 @@ class TemplateParserViewModel : BaseViewModel() {
|
||||||
* 获取文件输出目录(当构建文件完毕后,返回有效值。否则返回null)
|
* 获取文件输出目录(当构建文件完毕后,返回有效值。否则返回null)
|
||||||
* @return String?
|
* @return String?
|
||||||
*/
|
*/
|
||||||
fun getOutputPath():String?{
|
fun getOutputPath(): String? {
|
||||||
return outPutPath
|
return outPutPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,57 +181,63 @@ class TemplateParserViewModel : BaseViewModel() {
|
||||||
* @return ArrayList<TemplateParser>
|
* @return ArrayList<TemplateParser>
|
||||||
*/
|
*/
|
||||||
fun getTemplateParserList(context: Context): ArrayList<TemplateParser> {
|
fun getTemplateParserList(context: Context): ArrayList<TemplateParser> {
|
||||||
if (this::arrayList.isInitialized)
|
if (this::arrayList.isInitialized) {
|
||||||
{
|
LogCat.d("获取模板解析器", "已经被调用了一次,返回成员变量")
|
||||||
LogCat.d("获取模板解析器","已经被调用了一次,返回成员变量")
|
|
||||||
return arrayList
|
return arrayList
|
||||||
}
|
}
|
||||||
arrayList = ArrayList()
|
arrayList = ArrayList()
|
||||||
val gson = Gson()
|
val gson = Gson()
|
||||||
val jsonArray = jsonData?.getJSONArray("action")
|
try {
|
||||||
if (jsonArray == null) {
|
val jsonArray = jsonData?.getJSONArray("action")
|
||||||
LogCat.e("获取模板解析器", "此模板没有action,无法读取。")
|
if (jsonArray == null) {
|
||||||
return arrayList
|
LogCat.e("获取模板解析器", "此模板没有action,无法读取。")
|
||||||
} else {
|
return arrayList
|
||||||
val len = jsonArray.length()
|
} else {
|
||||||
for (i in 0 until len) {
|
val len = jsonArray.length()
|
||||||
val templateParserData = jsonArray.getJSONObject(i)
|
for (i in 0 until len) {
|
||||||
when (templateParserData.getString("type")) {
|
val templateParserData = jsonArray.getJSONObject(i)
|
||||||
"input" -> {
|
when (templateParserData.getString("type")) {
|
||||||
arrayList.add(
|
"input" -> {
|
||||||
InputParser(
|
arrayList.add(
|
||||||
context,
|
InputParser(
|
||||||
gson.fromJson(
|
context,
|
||||||
templateParserData.toString(4),
|
gson.fromJson(
|
||||||
InputParserDataBean::class.java
|
templateParserData.toString(4),
|
||||||
|
InputParserDataBean::class.java
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
"comment" -> {
|
||||||
"comment" -> {
|
arrayList.add(
|
||||||
arrayList.add(
|
IntroducingParser(
|
||||||
IntroducingParser(
|
context, gson.fromJson(
|
||||||
context, gson.fromJson(
|
templateParserData.toString(4),
|
||||||
templateParserData.toString(4),
|
IntroducingDataBean::class.java
|
||||||
IntroducingDataBean::class.java
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
"valueSelector" -> {
|
||||||
"valueSelector" -> {
|
arrayList.add(
|
||||||
arrayList.add(
|
ListParser(
|
||||||
ListParser(
|
context, gson.fromJson(
|
||||||
context, gson.fromJson(
|
templateParserData.toString(4),
|
||||||
templateParserData.toString(4),
|
ListParserDataBean::class.java
|
||||||
ListParserDataBean::class.java
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return arrayList
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
LogCat.e("获取模板解析器", "解析action出错$e。")
|
||||||
return arrayList
|
return arrayList
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -70,11 +70,27 @@
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<Button
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/createbutton"
|
android:id="@+id/minVersionInputLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
app:counterEnabled="true"
|
||||||
android:layout_below="@id/modDescribeInputLayout"
|
android:layout_below="@id/modDescribeInputLayout"
|
||||||
|
app:counterMaxLength="20"
|
||||||
|
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:hint="@string/minVersion"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/createbutton"
|
||||||
|
android:layout_below="@id/minVersionInputLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/create" />
|
android:text="@string/create" />
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,7 @@
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
android:id="@+id/numberLayout"
|
android:id="@+id/numberLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="46dp">
|
android:layout_height="46dp">
|
||||||
|
|
|
@ -955,4 +955,5 @@
|
||||||
<string name="search_type_template_package">模板包</string>
|
<string name="search_type_template_package">模板包</string>
|
||||||
<string name="public_mod">公开</string>
|
<string name="public_mod">公开</string>
|
||||||
<string name="private_mod">私有</string>
|
<string name="private_mod">私有</string>
|
||||||
|
<string name="minVersion">最低游戏版本</string>
|
||||||
</resources>
|
</resources>
|
|
@ -52,11 +52,17 @@ data class WebTemplateData(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(language: String): String {
|
override fun getName(language: String): String {
|
||||||
return if (getJson().has("name_$language")) {
|
try {
|
||||||
return getJson().getString("name_$language")
|
return if (getJson().has("name_$language")) {
|
||||||
} else {
|
return getJson().getString("name_$language")
|
||||||
return getJson().getString("name")
|
} else {
|
||||||
|
return getJson().getString("name")
|
||||||
|
}
|
||||||
|
}catch (e:Exception){
|
||||||
|
e.printStackTrace()
|
||||||
|
return "Unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getIcon(): Any? {
|
override fun getIcon(): Any? {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user