2022-04-04 14:03:10 +00:00
|
|
|
package com.coldmint.rust.pro
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import com.coldmint.rust.pro.base.BaseActivity
|
|
|
|
import org.json.JSONObject
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.content.Intent
|
2022-08-14 02:43:53 +00:00
|
|
|
import android.util.Log
|
2022-04-04 14:03:10 +00:00
|
|
|
import com.coldmint.rust.pro.tool.AppSettings
|
|
|
|
import org.json.JSONException
|
|
|
|
import org.json.JSONArray
|
|
|
|
import android.view.inputmethod.EditorInfo
|
2022-08-14 02:43:53 +00:00
|
|
|
import android.view.LayoutInflater
|
2022-04-04 14:03:10 +00:00
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuItem
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
import com.coldmint.rust.core.SourceFile
|
|
|
|
import android.view.View
|
|
|
|
import android.view.inputmethod.InputMethodManager
|
|
|
|
import android.widget.*
|
|
|
|
import androidx.core.view.isVisible
|
2022-08-14 02:43:53 +00:00
|
|
|
import androidx.lifecycle.viewModelScope
|
2022-04-04 14:03:10 +00:00
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
2022-08-14 02:43:53 +00:00
|
|
|
import com.coldmint.dialog.CoreDialog
|
|
|
|
import com.coldmint.rust.core.LocalTemplatePackage
|
2022-04-04 14:03:10 +00:00
|
|
|
import com.coldmint.rust.core.dataBean.InputParserDataBean
|
|
|
|
import com.coldmint.rust.core.dataBean.IntroducingDataBean
|
|
|
|
import com.coldmint.rust.core.dataBean.ListParserDataBean
|
2022-08-14 02:43:53 +00:00
|
|
|
import com.coldmint.rust.core.dataBean.template.LocalTemplateFile
|
|
|
|
import com.coldmint.rust.core.dataBean.template.TemplatePackage
|
2022-04-04 14:03:10 +00:00
|
|
|
import com.coldmint.rust.core.interfaces.TemplateParser
|
|
|
|
import com.coldmint.rust.core.templateParser.InputParser
|
|
|
|
import com.coldmint.rust.core.templateParser.IntroducingParser
|
|
|
|
import com.coldmint.rust.core.templateParser.ListParser
|
|
|
|
import com.coldmint.rust.core.tool.FileOperator
|
|
|
|
import com.coldmint.rust.pro.databinding.ActivityTemplateParserBinding
|
2022-07-06 06:04:54 +00:00
|
|
|
import com.coldmint.rust.pro.tool.UnitAutoCompleteHelper
|
2022-08-14 02:43:53 +00:00
|
|
|
import com.coldmint.rust.pro.viewmodel.TemplateParserViewModel
|
2022-04-04 14:03:10 +00:00
|
|
|
import com.google.android.material.textfield.TextInputLayout
|
|
|
|
import com.google.gson.Gson
|
|
|
|
import java.io.File
|
|
|
|
import java.util.*
|
|
|
|
import java.util.concurrent.Executors
|
|
|
|
import kotlin.collections.ArrayList
|
|
|
|
import kotlin.concurrent.thread
|
|
|
|
|
2022-08-14 02:43:53 +00:00
|
|
|
class TemplateParserActivity : BaseActivity<ActivityTemplateParserBinding>() {
|
2022-04-04 14:03:10 +00:00
|
|
|
|
2022-08-14 02:43:53 +00:00
|
|
|
val viewModel: TemplateParserViewModel by lazy {
|
|
|
|
TemplateParserViewModel()
|
|
|
|
}
|
|
|
|
|
|
|
|
private val language by lazy {
|
|
|
|
AppSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
|
2022-04-04 14:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
|
val inflater = menuInflater
|
|
|
|
inflater.inflate(R.menu.menu_template, menu)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("CheckResult")
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
when (item.itemId) {
|
|
|
|
R.id.preview_static_code -> {
|
2022-08-14 02:43:53 +00:00
|
|
|
var code = viewModel.getCode()
|
|
|
|
if (code.isBlank()) {
|
|
|
|
code = getString(R.string.not_found_data2)
|
2022-04-04 14:03:10 +00:00
|
|
|
}
|
2022-08-14 02:43:53 +00:00
|
|
|
CoreDialog(this).setTitle(viewModel.getTemplateName(language)).setMessage(code)
|
|
|
|
.setPositiveButton(R.string.dialog_ok) {
|
2022-04-04 14:03:10 +00:00
|
|
|
|
2022-08-14 02:43:53 +00:00
|
|
|
}.show()
|
2022-04-04 14:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-14 02:43:53 +00:00
|
|
|
return super.onOptionsItemSelected(item)
|
2022-04-04 14:03:10 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 02:43:53 +00:00
|
|
|
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
|
|
|
|
if (canUseView) {
|
2022-04-04 14:03:10 +00:00
|
|
|
|
2022-08-14 02:43:53 +00:00
|
|
|
setReturnButton()
|
|
|
|
val link = intent.getStringExtra("link")
|
|
|
|
if (link == null) {
|
|
|
|
Toast.makeText(this, "请设置链接", Toast.LENGTH_SHORT).show()
|
|
|
|
finish()
|
|
|
|
return
|
2022-04-04 14:03:10 +00:00
|
|
|
}
|
2022-08-14 02:43:53 +00:00
|
|
|
val isLocal = intent.getBooleanExtra("isLocal", false)
|
|
|
|
if (isLocal) {
|
|
|
|
Log.d("模板解析器", "读取本地模板$link")
|
|
|
|
viewModel.setTemplate(LocalTemplateFile(File(link)))
|
|
|
|
val templateParserList = viewModel.getTemplateParserList(this)
|
|
|
|
templateParserList.forEach {
|
|
|
|
viewBinding.base.addView(it.contextView)
|
2022-04-04 14:03:10 +00:00
|
|
|
}
|
2022-08-14 02:43:53 +00:00
|
|
|
viewBinding.linearLayout.isVisible = false
|
|
|
|
viewBinding.nestedScrollView.isVisible = true
|
|
|
|
title = viewModel.getTemplateName(language)
|
|
|
|
} else {
|
2022-04-04 14:03:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-14 02:43:53 +00:00
|
|
|
override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityTemplateParserBinding {
|
|
|
|
return ActivityTemplateParserBinding.inflate(layoutInflater)
|
2022-04-04 14:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|