diff --git a/.gradle/7.2/executionHistory/executionHistory.bin b/.gradle/7.2/executionHistory/executionHistory.bin index 169d2bd..39a9510 100644 Binary files a/.gradle/7.2/executionHistory/executionHistory.bin and b/.gradle/7.2/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.2/executionHistory/executionHistory.lock b/.gradle/7.2/executionHistory/executionHistory.lock index 408039c..c626328 100644 Binary files a/.gradle/7.2/executionHistory/executionHistory.lock and b/.gradle/7.2/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.2/fileHashes/fileHashes.bin b/.gradle/7.2/fileHashes/fileHashes.bin index 4a22236..8fe011b 100644 Binary files a/.gradle/7.2/fileHashes/fileHashes.bin and b/.gradle/7.2/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.2/fileHashes/fileHashes.lock b/.gradle/7.2/fileHashes/fileHashes.lock index 2820a7b..57ac74f 100644 Binary files a/.gradle/7.2/fileHashes/fileHashes.lock and b/.gradle/7.2/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.2/fileHashes/resourceHashesCache.bin b/.gradle/7.2/fileHashes/resourceHashesCache.bin index 3e4dc66..96bdbf6 100644 Binary files a/.gradle/7.2/fileHashes/resourceHashesCache.bin and b/.gradle/7.2/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 344dcb8..dbc21b9 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 377c01f..ab532df 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/app/build.gradle b/app/build.gradle index 945101a..72d1bfa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,7 +31,7 @@ android { minSdkVersion 21 targetSdkVersion 32 versionCode 13 - versionName "2.0 Release 6(2022-3-26)" + versionName "2.0 Release 7(2022-4-5)" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt b/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt index fcc3c07..a0e228a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt @@ -23,15 +23,11 @@ import java.util.* abstract class BaseActivity : AppCompatActivity() { -// abstract fun getViewModelObject(viewModelProvider: ViewModelProvider): ViewModelType abstract fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) abstract fun getViewBindingObject(): ViewBingType -// protected val viewModel: ViewModelType by lazy { -// getViewModelObject(ViewModelProvider(this)) -// } protected val viewBinding: ViewBingType by lazy { getViewBindingObject() @@ -45,14 +41,15 @@ abstract class BaseActivity : } override fun onCreate(savedInstanceState: Bundle?) { +// loadLanguage() whenCreateActivity(savedInstanceState, false) super.onCreate(savedInstanceState) setContentView(viewBinding.root) whenCreateActivity(savedInstanceState, true) - } + /** * 展示Toast * @param str String @@ -66,8 +63,6 @@ abstract class BaseActivity : */ protected fun setReturnButton() { if (supportActionBar != null) { - //激活返回按钮 - supportActionBar!!.setHomeButtonEnabled(true) //将显示主页设置为已启用 supportActionBar!!.setDisplayHomeAsUpEnabled(true) } diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeCompiler2.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeCompiler2.kt index 1f304f8..ee9b7a8 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeCompiler2.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/CodeCompiler2.kt @@ -161,12 +161,11 @@ class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInte val tokenizer = StringTokenizer(code, split, true) //缓存翻译数据,以便加速重复数据的翻译 val translationMap = HashMap() - //保存是否为注释 - var isNote = false //保存每次代码的翻译结果 val codeResult = StringBuilder() //保存完整的翻译结果 val translationResult = StringBuilder() + var codeBlockType = CompileConfiguration.CodeBlockType.Key handler.post { translatorListener.beforeTranslate() } @@ -178,19 +177,26 @@ class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInte codeResult.delete(0, codeResult.length) when (code) { "\n" -> { - isNote = false + codeBlockType = CompileConfiguration.CodeBlockType.Key codeResult.append(code) } "\r" -> { } - ":", " ", ",", "(", ")", "=", "%", "{", "}", "+", "*", "/" -> codeResult.append( + " ", ",", "(", ")", "=", "%", "{", "}", "+", "*", "/" -> codeResult.append( code ) - else -> if (isNote) { + ":" -> { + if (codeBlockType == CompileConfiguration.CodeBlockType.Key) { + codeBlockType = + CompileConfiguration.CodeBlockType.Value + } + codeResult.append(code) + } + else -> if (codeBlockType == CompileConfiguration.CodeBlockType.Note) { codeResult.append(code) } else { if (code.startsWith("#")) { - isNote = true + codeBlockType = CompileConfiguration.CodeBlockType.Note codeResult.append(code) } else if (code.startsWith("[") && code.endsWith("]")) { val symbolPosition = code.lastIndexOf("_") @@ -245,13 +251,23 @@ class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInte codeResult.append(code) } } else { + //是否需要检查值 + if (codeBlockType == CompileConfiguration.CodeBlockType.Key) { + val type = getValueData(codeInfo.type) + val tag = type?.tag + if (!tag.isNullOrBlank()) { + //如果此类型为特殊标注,那么设置为注释 + codeBlockType = + CompileConfiguration.CodeBlockType.Note + } + } codeResult.append(codeInfo.translate) } } } } - //如果代码不是注释,也不是换行,那么缓存它。 - if (!isNote && code != "\n") { + //如果代码不是注释,也不是换行,不是冒号,那么缓存它。 + if (codeBlockType != CompileConfiguration.CodeBlockType.Note && code != ":" && code != "\n") { translationMap[code] = codeResult.toString() } translationResult.append(codeResult.toString()) @@ -324,11 +340,14 @@ class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInte compileConfiguration.appendResult(translation) } ":" -> { - if (compileConfiguration.codeBlockType == CompileConfiguration.CodeBlockType.Value) { - compileConfiguration.appendResult(translation) - } else { - compileConfiguration.codeBlockType = - CompileConfiguration.CodeBlockType.Value + when (compileConfiguration.codeBlockType) { + CompileConfiguration.CodeBlockType.Value -> { + compileConfiguration.appendResult(translation) + } + CompileConfiguration.CodeBlockType.Key -> { + compileConfiguration.codeBlockType = + CompileConfiguration.CodeBlockType.Value + } } codeResult.append(translation) } @@ -380,6 +399,16 @@ class CodeCompiler2 private constructor(val context: Context) : CodeCompilerInte codeResult.append(translation) } } else { + //是否需要检查值 + if (compileConfiguration.codeBlockType == CompileConfiguration.CodeBlockType.Key) { + val type = getValueData(codeInfo.type) + val tag = type?.tag + if (!tag.isNullOrBlank()) { + //如果此类型为特殊标注,那么设置为注释 + compileConfiguration.codeBlockType = + CompileConfiguration.CodeBlockType.Note + } + } codeResult.append(codeInfo.code) } //翻译代码段完毕后,加入行结果集合 diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/CompileConfiguration.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/CompileConfiguration.kt index 0a1032a..c90f1c2 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/CompileConfiguration.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/CompileConfiguration.kt @@ -105,6 +105,7 @@ data class CompileConfiguration( /** * 代码块类 + * 键,值,节,注释,变量名 */ enum class CodeBlockType { Key, Value, Section, Note, VariableName