订阅模板包

This commit is contained in:
coldmint 2022-08-14 10:43:53 +08:00
parent f2da30d523
commit 23a43c98f5
124 changed files with 1982 additions and 1272 deletions

Binary file not shown.

View File

@ -88167,7 +88167,7 @@ com.coldmint.rust.pro.ui.ModActionAdapter$shareItem$2 -> com.coldmint.rust.pro.u
# {"id":"sourceFile","fileName":"ModActionAdapter.kt"} # {"id":"sourceFile","fileName":"ModActionAdapter.kt"}
java.io.File $file -> c java.io.File $file -> c
com.coldmint.rust.pro.ui.ModActionAdapter this$0 -> b com.coldmint.rust.pro.ui.ModActionAdapter this$0 -> b
com.coldmint.rust.pro.tool.AppSettings $appSettings -> a com.coldmint.rust.pro.tool.AppSettings $AppSettings -> a
1:2:void invoke(com.afollestad.materialdialogs.MaterialDialog):320:321 -> a 1:2:void invoke(com.afollestad.materialdialogs.MaterialDialog):320:321 -> a
1:1:java.lang.Object invoke(java.lang.Object):316:316 -> invoke 1:1:java.lang.Object invoke(java.lang.Object):316:316 -> invoke
com.coldmint.rust.pro.ui.ModAdapter -> com.coldmint.rust.pro.ui.ModAdapter: com.coldmint.rust.pro.ui.ModAdapter -> com.coldmint.rust.pro.ui.ModAdapter:

View File

@ -35194,7 +35194,7 @@ androidx.media.MediaBrowserProtocol: java.lang.String EXTRA_SERVICE_VERSION
com.google.android.material.R$styleable: int Constraint_layout_constraintBaseline_toBaselineOf com.google.android.material.R$styleable: int Constraint_layout_constraintBaseline_toBaselineOf
androidx.preference.ktx.R$id: int action_mode_close_button androidx.preference.ktx.R$id: int action_mode_close_button
com.coldmint.rust.core.R$id: int text2 com.coldmint.rust.core.R$id: int text2
com.coldmint.rust.pro.ui.ModActionAdapter$shareItem$2: com.coldmint.rust.pro.tool.AppSettings $appSettings com.coldmint.rust.pro.ui.ModActionAdapter$shareItem$2: com.coldmint.rust.pro.tool.AppSettings $AppSettings
androidx.core.app.NotificationCompatJellybean: boolean sActionsAccessFailed androidx.core.app.NotificationCompatJellybean: boolean sActionsAccessFailed
androidx.navigation.ui.R$attr: int listPreferredItemHeight androidx.navigation.ui.R$attr: int listPreferredItemHeight
com.afollestad.materialdialogs.input.R$id: int design_navigation_view com.afollestad.materialdialogs.input.R$id: int design_navigation_view
@ -68266,7 +68266,7 @@ androidx.preference.ktx.R$attr: int logo
kotlinx.coroutines.flow.FlowKt__MergeKt$map$$inlined$unsafeTransform$1$1: int label kotlinx.coroutines.flow.FlowKt__MergeKt$map$$inlined$unsafeTransform$1$1: int label
com.afollestad.materialdialogs.bottomsheets.R$styleable: int SearchView_layout com.afollestad.materialdialogs.bottomsheets.R$styleable: int SearchView_layout
com.afollestad.materialdialogs.input.R$attr: int splitTrack com.afollestad.materialdialogs.input.R$attr: int splitTrack
com.coldmint.rust.pro.ui.BaseActivity: com.coldmint.rust.pro.tool.AppSettings appSettings com.coldmint.rust.pro.ui.BaseActivity: com.coldmint.rust.pro.tool.AppSettings AppSettings
androidx.constraintlayout.solver.widgets.ConstraintAnchor: androidx.constraintlayout.solver.widgets.ConstraintAnchor$Type mType androidx.constraintlayout.solver.widgets.ConstraintAnchor: androidx.constraintlayout.solver.widgets.ConstraintAnchor$Type mType
kotlinx.coroutines.internal.LockFreeTaskQueueCore: java.util.concurrent.atomic.AtomicReferenceFieldUpdater _next$FU kotlinx.coroutines.internal.LockFreeTaskQueueCore: java.util.concurrent.atomic.AtomicReferenceFieldUpdater _next$FU
io.github.rosemoe.editor.widget.CodeEditor: android.view.inputmethod.InputMethodManager mInputMethodManager io.github.rosemoe.editor.widget.CodeEditor: android.view.inputmethod.InputMethodManager mInputMethodManager

View File

@ -4,6 +4,7 @@ import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import android.text.Html import android.text.Html
import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@ -60,7 +61,7 @@ class AboutActivity : BaseActivity<ActivityAboutBinding>() {
| |
""".trimMargin() """.trimMargin()
viewBinding.aboutView.text = Html.fromHtml(aboutText) viewBinding.aboutView.text = Html.fromHtml(aboutText)
val time = appSettings.getValue(AppSettings.Setting.ExpirationTime, 0.toLong()) val time = AppSettings.getValue(com.coldmint.rust.pro.tool.AppSettings.Setting.ExpirationTime, 0.toLong())
if (time == 0.toLong()) { if (time == 0.toLong()) {
viewBinding.expirationTimeView.text = getString(R.string.please_login_first) viewBinding.expirationTimeView.text = getString(R.string.please_login_first)
} else { } else {
@ -112,7 +113,7 @@ class AboutActivity : BaseActivity<ActivityAboutBinding>() {
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
override fun getViewBindingObject(): ActivityAboutBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityAboutBinding {
return ActivityAboutBinding.inflate(layoutInflater) return ActivityAboutBinding.inflate(layoutInflater)
} }

View File

@ -7,6 +7,7 @@ import android.text.SpannableString
import android.text.Spanned import android.text.Spanned
import android.text.method.LinkMovementMethod import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan import android.text.style.ClickableSpan
import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@ -206,7 +207,7 @@ class ActivateActivity : BaseActivity<ActivityActivateBinding>() {
} }
override fun getViewBindingObject(): ActivityActivateBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityActivateBinding {
return ActivityActivateBinding.inflate(layoutInflater) return ActivityActivateBinding.inflate(layoutInflater)
} }
@ -233,7 +234,8 @@ class ActivateActivity : BaseActivity<ActivityActivateBinding>() {
if (canUseView) { if (canUseView) {
title = getText(R.string.activation_app) title = getText(R.string.activation_app)
setReturnButton() setReturnButton()
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.
Setting.Account, "")
if (account.isBlank()) { if (account.isBlank()) {
showError(getString(R.string.please_login_first)) showError(getString(R.string.please_login_first))
return return

View File

@ -7,6 +7,7 @@ import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -134,7 +135,7 @@ class ApplicationListActivity : BaseActivity<ActivityApplicationListBinding>() {
} }
override fun getViewBindingObject(): ActivityApplicationListBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityApplicationListBinding {
return ActivityApplicationListBinding.inflate( return ActivityApplicationListBinding.inflate(
layoutInflater layoutInflater
) )

View File

@ -9,6 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import android.content.Intent import android.content.Intent
import android.view.KeyEvent import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
@ -226,7 +227,7 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
return super.onKeyDown(keyCode, event) return super.onKeyDown(keyCode, event)
} }
override fun getViewBindingObject(): ActivityBookmarkManagerBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityBookmarkManagerBinding {
return ActivityBookmarkManagerBinding.inflate( return ActivityBookmarkManagerBinding.inflate(
layoutInflater layoutInflater
) )

View File

@ -4,6 +4,7 @@ import android.graphics.Bitmap
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.KeyEvent import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.webkit.WebChromeClient import android.webkit.WebChromeClient
@ -76,7 +77,7 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>() {
return super.onKeyDown(keyCode, event) return super.onKeyDown(keyCode, event)
} }
override fun getViewBindingObject(): ActivityBrowserBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityBrowserBinding {
return ActivityBrowserBinding.inflate(layoutInflater) return ActivityBrowserBinding.inflate(layoutInflater)
} }

View File

@ -6,10 +6,7 @@ import android.text.Spannable
import android.text.SpannableString import android.text.SpannableString
import android.text.method.LinkMovementMethod import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan import android.text.style.ClickableSpan
import android.view.KeyEvent import android.view.*
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton import com.afollestad.materialdialogs.WhichButton
@ -189,7 +186,7 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
override fun getViewBindingObject(): ActivityCodeTableBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCodeTableBinding {
return ActivityCodeTableBinding.inflate(layoutInflater) return ActivityCodeTableBinding.inflate(layoutInflater)
} }
} }

View File

@ -6,6 +6,7 @@ import com.coldmint.rust.pro.base.BaseActivity
import android.text.TextWatcher import android.text.TextWatcher
import android.text.Editable import android.text.Editable
import android.os.Environment import android.os.Environment
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.Toast import android.widget.Toast
@ -133,7 +134,7 @@ class CreateModActivity : BaseActivity<ActivityCreateModBinding>() {
} }
override fun getViewBindingObject(): ActivityCreateModBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCreateModBinding {
return ActivityCreateModBinding.inflate(layoutInflater) return ActivityCreateModBinding.inflate(layoutInflater)
} }

View File

@ -1,138 +1,286 @@
package com.coldmint.rust.pro package com.coldmint.rust.pro
import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import com.coldmint.rust.core.TemplatePackage import android.text.Editable
import com.coldmint.rust.core.dataBean.template.TemplateInfo import android.text.TextWatcher
import android.view.LayoutInflater
import android.widget.Toast
import com.coldmint.rust.core.dataBean.ApiResponse
import com.coldmint.rust.core.interfaces.ApiCallBack
import com.coldmint.rust.core.tool.AppOperator import com.coldmint.rust.core.tool.AppOperator
import com.coldmint.rust.core.web.ServerConfiguration
import com.coldmint.rust.core.web.TemplatePhp
import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.base.BaseActivity
import com.coldmint.rust.pro.databinding.ActivityCreateTemplateBinding import com.coldmint.rust.pro.databinding.ActivityCreateTemplateBinding
import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.AppSettings
import com.google.gson.Gson import com.google.android.material.snackbar.Snackbar
import org.json.JSONObject
import java.io.File
class CreateTemplateActivity : BaseActivity<ActivityCreateTemplateBinding>() { class CreateTemplateActivity : BaseActivity<ActivityCreateTemplateBinding>() {
private var path: String? = null private var path: String? = null
private var editMode = false private var editMode = false
private val gson by lazy { Gson() }
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
if (canUseView) { if (canUseView) {
setTitle(R.string.create_template) setTitle(R.string.create_template)
setReturnButton() setReturnButton()
initView() // initView()
initAction() initAction()
} }
} }
fun initView() { fun initView() {
val intent = intent // val intent = intent
val bundle = intent.getBundleExtra("data") // val bundle = intent.getBundleExtra("data")
if (bundle != null) { // if (bundle != null) {
val jsonText = bundle.getString("json") // val jsonText = bundle.getString("json")
val temPath = bundle.getString("path") // val temPath = bundle.getString("path")
if (temPath == null) { // if (temPath == null) {
showError("请输入路径") // showError("请输入路径")
return // return
} // }
path = temPath // path = temPath
if (jsonText != null) { // if (jsonText != null) {
val jsonObject = JSONObject(jsonText) // val jsonObject = JSONObject(jsonText)
viewBinding.templateNameEdit.setText(jsonObject.getString("name")) // viewBinding.templateNameEdit.setText(jsonObject.getString("name"))
viewBinding.templateDescribeEdit.setText(jsonObject.getString("description")) // viewBinding.templateDescribeEdit.setText(jsonObject.getString("description"))
viewBinding.templateDeveloperEdit.setText(jsonObject.getString("developer")) // viewBinding.templateDeveloperEdit.setText(jsonObject.getString("developer"))
viewBinding.templateUpdateEdit.setText(jsonObject.getString("update")) // viewBinding.templateUpdateEdit.setText(jsonObject.getString("update"))
viewBinding.templateVersionName.setText(jsonObject.getString("versionName")) // viewBinding.templateVersionName.setText(jsonObject.getString("versionName"))
viewBinding.templateVersionNum.setText(jsonObject.getString("versionNum")) // viewBinding.templateVersionNum.setText(jsonObject.getString("versionNum"))
editMode = true // editMode = true
viewBinding.createbutton.setText(R.string.edit_function) // viewBinding.createbutton.setText(R.string.edit_function)
} // }
} // }
} }
fun initAction() { /**
viewBinding.createbutton.setOnClickListener { * 检查名称返回是否有错误
val name = viewBinding.templateNameEdit.text.toString() * @return Boolean
if (name.isEmpty()) { */
fun checkName(): Boolean {
val text = viewBinding.templateNameEdit.text.toString()
return if (text.isBlank()) {
setErrorAndInput( setErrorAndInput(
viewBinding.templateNameEdit, viewBinding.templateNameEdit,
getString(R.string.template_name_error) getString(R.string.template_name_error),
viewBinding.templateNameInputLayout
) )
return@setOnClickListener true
}
val description = viewBinding.templateDescribeEdit.text.toString()
if (description.isEmpty()) {
setErrorAndInput(
viewBinding.templateDescribeEdit,
getString(R.string.template_description_error)
)
return@setOnClickListener
}
val developer = viewBinding.templateDeveloperEdit.text.toString()
if (developer.isEmpty()) {
setErrorAndInput(
viewBinding.templateDeveloperEdit,
getString(R.string.template_developer_error)
)
return@setOnClickListener
}
val update = viewBinding.templateUpdateEdit.text.toString()
if (update.isEmpty()) {
setErrorAndInput(
viewBinding.templateUpdateEdit,
getString(R.string.template_update_error)
)
return@setOnClickListener
}
val versionName = viewBinding.templateVersionName.text.toString()
if (update.isEmpty()) {
setErrorAndInput(
viewBinding.templateVersionName,
getString(R.string.template_version_name_error)
)
return@setOnClickListener
}
val versionNum = viewBinding.templateVersionNum.text.toString()
if (update.isEmpty()) {
setErrorAndInput(
viewBinding.templateVersionNum,
getString(R.string.template_version_num_error)
)
return@setOnClickListener
}
val now = AppOperator.getAppVersionNum(this, this.packageName)
val templateInfo = TemplateInfo(
now,
description,
developer,
name,
update,
versionName,
versionNum.toInt()
)
val directent = appSettings.getValue(
AppSettings.Setting.TemplateDirectory,
this@CreateTemplateActivity.filesDir.absolutePath + "/template/"
)
val newDiectent = "$directent$name/"
val targetFile = File(newDiectent)
if (targetFile.exists()) {
setErrorAndInput(viewBinding.templateNameEdit, getString(R.string.template_error))
return@setOnClickListener
}
val templateClass = TemplatePackage(targetFile)
if (editMode) {
templateClass.create(templateInfo, File(path))
} else { } else {
templateClass.create(templateInfo) viewBinding.templateNameInputLayout.isErrorEnabled = false
} false
finish()
} }
} }
override fun getViewBindingObject(): ActivityCreateTemplateBinding { /**
* 检查描述
* @return Boolean
*/
fun checkDescribe(): Boolean {
val text = viewBinding.templateDescribeEdit.text.toString()
return if (text.isBlank()) {
setErrorAndInput(
viewBinding.templateDescribeEdit,
getString(R.string.template_description_error),
viewBinding.templateDescribeInputLayout
)
true
} else {
viewBinding.templateDescribeInputLayout.isErrorEnabled = false
false
}
}
/**
* 检查版本名错误
* @return Boolean
*/
fun checkTemplateVersionName(): Boolean {
val text = viewBinding.templateVersionName.text.toString()
return if (text.isBlank()) {
setErrorAndInput(
viewBinding.templateVersionName,
getString(R.string.template_version_name_error),
viewBinding.templateVersionNameLayout
)
true
} else {
viewBinding.templateVersionNameLayout.isErrorEnabled = false
false
}
}
/**
* 检查id
* @return Boolean
*/
fun checkId(): Boolean {
val text = viewBinding.templateIdEdit.text.toString()
return if (text.isBlank()) {
setErrorAndInput(
viewBinding.templateIdEdit,
getString(R.string.template_id_error),
viewBinding.templateIdInputLayout
)
true
} else {
viewBinding.templateIdInputLayout.isErrorEnabled = false
false
}
}
fun initAction() {
viewBinding.templateNameEdit.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun afterTextChanged(p0: Editable?) {
checkName()
}
})
viewBinding.templateDescribeEdit.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun afterTextChanged(p0: Editable?) {
checkDescribe()
}
})
viewBinding.templateIdEdit.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun afterTextChanged(p0: Editable?) {
checkId()
}
})
viewBinding.templateVersionName.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun afterTextChanged(p0: Editable?) {
checkTemplateVersionName()
}
})
viewBinding.createbutton.setOnClickListener {
if (checkId()) {
return@setOnClickListener
}
if (checkName()) {
return@setOnClickListener
}
if (checkDescribe()) {
return@setOnClickListener
}
if (checkTemplateVersionName()) {
return@setOnClickListener
}
if (checkId()) {
return@setOnClickListener
}
var versionName = "版本号"
try {
val packageInfo = packageManager.getPackageInfo(packageName, 0)
versionName = packageInfo.versionName
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
TemplatePhp.instance.createTemplatePackage(
viewBinding.templateIdEdit.text.toString(),
AppSettings.getValue(AppSettings.Setting.Token, ""),
viewBinding.templateNameEdit.text.toString(),
viewBinding.templateDescribeEdit.text.toString(),
viewBinding.templateVersionName.text.toString(),
versionName,
AppOperator.getAppVersionNum(this), true, object : ApiCallBack<ApiResponse> {
override fun onResponse(t: ApiResponse) {
if (t.code == 0) {
finish()
} else {
if (ServerConfiguration.isEvent(t.message)) {
if (t.message == "@event:id重复") {
viewBinding.templateIdInputLayout.error =
getString(R.string.template_id_error2)
} else if (t.message == "@event:名称重复") {
viewBinding.templateNameInputLayout.error =
getString(R.string.template_name_error2)
}
} else {
Toast.makeText(
this@CreateTemplateActivity,
t.message,
Toast.LENGTH_SHORT
).show()
}
}
}
override fun onFailure(e: Exception) {
e.printStackTrace()
Snackbar.make(viewBinding.createbutton, e.toString(), Snackbar.LENGTH_SHORT)
.show()
}
}
)
// val templateInfo = TemplateInfo(
// now,
// description,
// developer,
// name,
// update,
// versionName,
// versionNum.toInt()
// )
// val directent = AppSettings.getValue(
// AppSettings.Setting.TemplateDirectory,
// this@CreateTemplateActivity.filesDir.absolutePath + "/template/"
// )
// val newDiectent = "$directent$name/"
// val targetFile = File(newDiectent)
// if (targetFile.exists()) {
// setErrorAndInput(viewBinding.templateNameEdit, getString(R.string.template_error))
// return@setOnClickListener
// }
// val templateClass = LocalTemplatePackage(targetFile)
// if (editMode) {
// templateClass.create(templateInfo, File(path))
// } else {
// templateClass.create(templateInfo)
// }
// finish()
}
}
override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCreateTemplateBinding {
return ActivityCreateTemplateBinding.inflate( return ActivityCreateTemplateBinding.inflate(
layoutInflater layoutInflater
) )

View File

@ -2,177 +2,58 @@ package com.coldmint.rust.pro
import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.base.BaseActivity
import android.os.Bundle import android.os.Bundle
import com.coldmint.rust.pro.tool.AppSettings
import android.content.Intent import android.content.Intent
import android.os.Environment import android.view.LayoutInflater
import org.json.JSONObject
import org.json.JSONException
import android.widget.AdapterView.OnItemLongClickListener
import com.afollestad.materialdialogs.MaterialDialog
import android.widget.* import android.widget.*
import com.coldmint.rust.core.TemplatePackage import com.coldmint.rust.pro.adapters.CreateUnitPageAdapter
import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.pro.adapters.TemplateAdapter
import com.coldmint.rust.pro.databinding.ActivityCreateUnitBinding import com.coldmint.rust.pro.databinding.ActivityCreateUnitBinding
import java.io.File import com.google.android.material.tabs.TabLayoutMediator
import java.util.*
class CreateUnitActivity : BaseActivity<ActivityCreateUnitBinding>() { class CreateUnitActivity : BaseActivity<ActivityCreateUnitBinding>() {
private lateinit var mCreatePath: String
private var mRootPath: String? = null
private var mTemplateAdapter: TemplateAdapter? = null
lateinit var createUnitPageAdapter: CreateUnitPageAdapter
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
if (canUseView) { if (canUseView) {
setTitle(R.string.create_unit) setTitle(R.string.create_unit)
setReturnButton() setReturnButton()
initView() initView()
initAction()
} }
} }
fun initView() { fun initView() {
val useing = appSettings.getValue(AppSettings.Setting.DatabasePath, "")
val intent = intent val intent = intent
val bundle = intent.getBundleExtra("data") val bundle = intent.getBundleExtra("data")
if (bundle == null) { if (bundle == null) {
Toast.makeText(this, "无效的请求", Toast.LENGTH_SHORT).show() Toast.makeText(this, "无效的请求", Toast.LENGTH_SHORT).show()
finish() finish()
} else { } else {
mRootPath = bundle.getString("modPath") createUnitPageAdapter = CreateUnitPageAdapter(this)
mCreatePath = bundle.getString("createPath", mRootPath) viewBinding.viewPager2.adapter = createUnitPageAdapter
var relativePath = FileOperator.getRelativePath( TabLayoutMediator(viewBinding.tabLayout, viewBinding.viewPager2) { tab, i ->
mCreatePath, tab.text = if (i == 0) {
appSettings.getValue( getString(R.string.installated)
AppSettings.Setting.ModFolder,
Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/"
)
)
if (relativePath == null) {
relativePath = mCreatePath
}
viewBinding.unitPathView.setText(
String.format(
(resources.getText(R.string.unit_path) as String),
relativePath
)
)
loadlist()
}
}
fun getmCreatePath(): String {
return mCreatePath
}
fun loadlist() {
val directent = appSettings.getValue(
AppSettings.Setting.TemplateDirectory,
this@CreateUnitActivity.filesDir.absolutePath + "/template/"
)
val only_load_language =
appSettings.getValue(AppSettings.Setting.OnlyLoadConantLanguageTemple, false)
val environmentLanguage =
appSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
val path = File(directent)
if (!path.exists()) {
path.mkdirs()
return
}
val group: MutableList<TemplatePackage> = ArrayList()
val item: MutableList<List<File>> = ArrayList()
//扫描模板根目录(加载所有模板包)
if (path.isDirectory) {
val files = path.listFiles()
if (files.size > 0) {
for (directents in files) {
//读取模板包
val templateClass = TemplatePackage(directents)
if (templateClass.isTemplate) {
group.add(templateClass)
//添加子集
val itemlist: MutableList<File> = ArrayList()
search(directents, itemlist, only_load_language, environmentLanguage)
item.add(itemlist)
}
}
}
}
mTemplateAdapter =
TemplateAdapter(this@CreateUnitActivity, group, item, environmentLanguage)
viewBinding.expandableList.setAdapter(mTemplateAdapter)
}
//扫描某目录的模板(目录,欲保存到的集合,全局语言,全局方法,仅加载符合语言的?,环境语言)
private fun search(
directents: File,
list: MutableList<File>,
only: Boolean,
environmentLanguage: String
) {
for (f in directents.listFiles()) {
if (f.isDirectory) {
search(f, list, only, environmentLanguage)
} else { } else {
val type = FileOperator.getFileType(f) getString(R.string.template_community)
if (type == "json") {
if (only) {
val data = FileOperator.readFile(f)
try {
val jsonObject = JSONObject(data)
val s = jsonObject.getString("language")
if (s == "ALL" || s == environmentLanguage) {
list.add(f)
}
} catch (exception: JSONException) {
exception.printStackTrace()
}
} else {
list.add(f)
}
}
} }
}.attach()
val root = bundle.getString("modPath")
createUnitPageAdapter.setRootPath(root)
val set = createUnitPageAdapter.setCreatePath(bundle.getString("createPath", root))
// if (!set) {
// //如果没有设置成功当fragment没有附加到activity
// viewBinding.toolbar.postDelayed({
// createUnitPageAdapter.setCreatePath(bundle.getString("createPath", root))
// }, 50)
// }
// loadlist()
} }
} }
fun initAction() { // fun getmCreatePath(): String {
viewBinding.selectPathButton.setOnClickListener { // return mCreatePath
val bundle = Bundle() // }
val intent = Intent(this@CreateUnitActivity, FileManagerActivity::class.java)
bundle.putString("type", "selectDirectents")
bundle.putString("path", mCreatePath)
bundle.putString("rootpath", mRootPath)
intent.putExtra("data", bundle)
startActivityForResult(intent, 1)
}
//长按监听
viewBinding.expandableList.onItemLongClickListener =
OnItemLongClickListener { parent, view, flatPos, l -> //得到点击的父位置,子位置
val packedPos = (parent as ExpandableListView).getExpandableListPosition(flatPos)
val groupPosition = ExpandableListView.getPackedPositionGroup(packedPos)
val childPosition = ExpandableListView.getPackedPositionChild(packedPos)
if (childPosition == -1) { //长按的是父项
//这里做关于父项的相关操作......
val numView = view.findViewById<TextView>(R.id.template_num)
val templateClass = mTemplateAdapter!!.getGroup(groupPosition) as TemplatePackage
MaterialDialog(this).show {
title(R.string.template_info).message(
text = templateClass.getInfo()?.description
?: templateClass.directest.absolutePath
).cancelable(false).positiveButton(R.string.dialog_ok).positiveButton {
numView.setText(R.string.del_moding)
Thread {
FileOperator.delete_files(templateClass.directest)
runOnUiThread { loadlist() }
}.start()
}.negativeButton(R.string.dialog_cancel)
}
} else { //长按的是子项
//这里做关于子项的相关操作.......
}
true
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@ -181,21 +62,7 @@ class CreateUnitActivity : BaseActivity<ActivityCreateUnitBinding>() {
1 -> if (resultCode == RESULT_OK) { 1 -> if (resultCode == RESULT_OK) {
val directents = data!!.getStringExtra("Directents") val directents = data!!.getStringExtra("Directents")
if (directents != null) { if (directents != null) {
mCreatePath = directents createUnitPageAdapter.setCreatePath(directents)
var relativePath = FileOperator.getRelativePath(
mCreatePath,
appSettings.getValue(
AppSettings.Setting.ModFolder,
Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/"
)
)
if (relativePath == null) {
relativePath = mCreatePath
}
viewBinding.unitPathView.text = String.format(
(resources.getText(R.string.unit_path) as String),
relativePath
)
} }
} }
2 -> if (resultCode == RESULT_OK) { 2 -> if (resultCode == RESULT_OK) {
@ -208,7 +75,7 @@ class CreateUnitActivity : BaseActivity<ActivityCreateUnitBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityCreateUnitBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCreateUnitBinding {
return ActivityCreateUnitBinding.inflate(layoutInflater) return ActivityCreateUnitBinding.inflate(layoutInflater)
} }

View File

@ -3,6 +3,7 @@ package com.coldmint.rust.pro
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.coldmint.rust.pro.adapters.GuideAdapter import com.coldmint.rust.pro.adapters.GuideAdapter
@ -140,7 +141,7 @@ class CreationWizardActivity : BaseActivity<ActivityCreationWizardBinding>() {
Intent(this, FileManagerActivity::class.java) Intent(this, FileManagerActivity::class.java)
val fileBundle = Bundle() val fileBundle = Bundle()
fileBundle.putString("type", "selectFile") fileBundle.putString("type", "selectFile")
val packDirectory = appSettings.getValue( val packDirectory = AppSettings.getValue(
AppSettings.Setting.PackDirectory, AppSettings.Setting.PackDirectory,
AppSettings.dataRootDirectory + "/bin/" AppSettings.dataRootDirectory + "/bin/"
) )
@ -158,7 +159,7 @@ class CreationWizardActivity : BaseActivity<ActivityCreationWizardBinding>() {
viewBinding.recyclerView.adapter = adapter viewBinding.recyclerView.adapter = adapter
} }
override fun getViewBindingObject(): ActivityCreationWizardBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCreationWizardBinding {
return ActivityCreationWizardBinding.inflate(layoutInflater) return ActivityCreationWizardBinding.inflate(layoutInflater)
} }

View File

@ -112,8 +112,8 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
fun showRenewalTip() { fun showRenewalTip() {
val debugKey = "续费提示" val debugKey = "续费提示"
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
val time = appSettings.getValue(AppSettings.Setting.ExpirationTime, 0.toLong()) val time = AppSettings.getValue(AppSettings.Setting.ExpirationTime, 0.toLong())
if (time == 0.toLong() || account.isBlank()) { if (time == 0.toLong() || account.isBlank()) {
DebugHelper.printLog(debugKey, "没有账号或续费信息,关闭界面。") DebugHelper.printLog(debugKey, "没有账号或续费信息,关闭界面。")
Toast.makeText(this, "请先登录", Toast.LENGTH_SHORT).show() Toast.makeText(this, "请先登录", Toast.LENGTH_SHORT).show()
@ -452,7 +452,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
//当用户切换到其他应用界面时 //当用户切换到其他应用界面时
override fun onPause() { override fun onPause() {
if (viewModel.needCheckAutoSave) { if (viewModel.needCheckAutoSave) {
val need = appSettings.getValue(AppSettings.Setting.AutoSave, true) val need = AppSettings.getValue(AppSettings.Setting.AutoSave, true)
if (need) { if (need) {
viewModel.saveAllFile( viewModel.saveAllFile(
viewBinding.tabLayout.selectedTabPosition, viewBinding.tabLayout.selectedTabPosition,
@ -947,7 +947,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
items.add(getString(R.string.code_table)) items.add(getString(R.string.code_table))
// items.add(getString(R.string.code_language_on)) // items.add(getString(R.string.code_language_on))
items.add(getString(R.string.symbol11)) items.add(getString(R.string.symbol11))
val customSymbol = appSettings.getValue( val customSymbol = AppSettings.getValue(
AppSettings.Setting.CustomSymbol, AppSettings.Setting.CustomSymbol,
"[],:='*_$%@#{}()" "[],:='*_$%@#{}()"
) )
@ -1060,7 +1060,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
val codeInfoList = if (lineData.isBlank()) { val codeInfoList = if (lineData.isBlank()) {
codeDataBase.getCodeDao().findCodeBySection(trueSection) codeDataBase.getCodeDao().findCodeBySection(trueSection)
} else { } else {
val number = appSettings.getValue( val number = AppSettings.getValue(
AppSettings.Setting.IdentifiersPromptNumber, AppSettings.Setting.IdentifiersPromptNumber,
40 40
) )
@ -1095,10 +1095,6 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
val info = ErrorInfo()
info.describe = "自动保存-代码提示异常"
info.allErrorDetails = e.toString()
info.save()
} }
} }
@ -1107,10 +1103,6 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
symbolChannel.insertSymbol(item, item.length) symbolChannel.insertSymbol(item, item.length)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
val info = ErrorInfo()
info.describe = "自动保存-插入符号异常"
info.allErrorDetails = e.toString()
info.save()
} }
} }
} }
@ -1126,7 +1118,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
fun initCodeEditor() { fun initCodeEditor() {
//CodEditor初始化 //CodEditor初始化
viewBinding.codeEditor.isWordwrap = true viewBinding.codeEditor.isWordwrap = true
val useFont = appSettings.getValue(AppSettings.Setting.UseJetBrainsMonoFont, true) val useFont = AppSettings.getValue(AppSettings.Setting.UseJetBrainsMonoFont, true)
if (useFont) { if (useFont) {
viewBinding.codeEditor.typefaceText = Typeface.createFromAsset( viewBinding.codeEditor.typefaceText = Typeface.createFromAsset(
assets, assets,
@ -1134,7 +1126,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
) )
} }
val language = val language =
appSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) AppSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
rustLanguage = RustLanguage(this) rustLanguage = RustLanguage(this)
rustLanguage.setCodeDataBase(CodeDataBase.getInstance(this)) rustLanguage.setCodeDataBase(CodeDataBase.getInstance(this))
rustLanguage.setFileDataBase( rustLanguage.setFileDataBase(
@ -1145,7 +1137,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
) )
// rustLanguage.setAnalyzerEnglishMode(viewModel.englishModeLiveData) // rustLanguage.setAnalyzerEnglishMode(viewModel.englishModeLiveData)
rustLanguage.setCodeEditor(viewBinding.codeEditor) rustLanguage.setCodeEditor(viewBinding.codeEditor)
val night = appSettings.getValue(AppSettings.Setting.NightMode, false) val night = AppSettings.getValue(AppSettings.Setting.NightMode, false)
val editorColorScheme = EditorColorScheme() val editorColorScheme = EditorColorScheme()
if (night) { if (night) {
//代码(可识别的关键字) //代码(可识别的关键字)
@ -1255,7 +1247,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
).show() ).show()
} }
R.id.open_game_test -> { R.id.open_game_test -> {
val packName = appSettings.getValue( val packName = AppSettings.getValue(
AppSettings.Setting.GamePackage, AppSettings.Setting.GamePackage,
GlobalMethod.DEFAULT_GAME_PACKAGE GlobalMethod.DEFAULT_GAME_PACKAGE
) )
@ -1630,7 +1622,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
} }
override fun getViewBindingObject(): ActivityEditBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityEditBinding {
return ActivityEditBinding.inflate(layoutInflater) return ActivityEditBinding.inflate(layoutInflater)
} }
} }

View File

@ -15,6 +15,7 @@ import android.os.Build
import android.graphics.drawable.AnimatedVectorDrawable import android.graphics.drawable.AnimatedVectorDrawable
import android.net.Uri import android.net.Uri
import android.view.KeyEvent import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.* import android.widget.*
@ -555,7 +556,7 @@ class EditModInfoActivity : BaseActivity<ActivityEditModInfoBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityEditModInfoBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityEditModInfoBinding {
return ActivityEditModInfoBinding.inflate(layoutInflater) return ActivityEditModInfoBinding.inflate(layoutInflater)
} }

View File

@ -9,6 +9,7 @@ import android.os.Environment
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.util.Log import android.util.Log
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.PopupMenu import android.widget.PopupMenu
import android.widget.Toast import android.widget.Toast
@ -279,7 +280,7 @@ class EditUserInfoActivity : BaseActivity<ActivityEditUserInfoBinding>() {
} }
viewBinding.button.hide() viewBinding.button.hide()
val token = val token =
AppSettings.getInstance(this).getValue(AppSettings.Setting.Token, "") AppSettings.getValue(AppSettings.Setting.Token, "")
User.updateSpaceInfo( User.updateSpaceInfo(
token, token,
userName, userName,
@ -456,7 +457,7 @@ class EditUserInfoActivity : BaseActivity<ActivityEditUserInfoBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityEditUserInfoBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityEditUserInfoBinding {
return ActivityEditUserInfoBinding.inflate(layoutInflater) return ActivityEditUserInfoBinding.inflate(layoutInflater)
} }

View File

@ -9,6 +9,7 @@ import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -52,7 +53,7 @@ class ErrorActivity() : BaseActivity<ActivityErrorBinding>() {
} }
viewBinding.errorInfo.text = errorInfo.allErrorDetails viewBinding.errorInfo.text = errorInfo.allErrorDetails
Log.e("错误日志", errorInfo.allErrorDetails) Log.e("错误日志", errorInfo.allErrorDetails)
if (appSettings.getValue(AppSettings.Setting.ExperiencePlan, true)) { if (AppSettings.getValue(AppSettings.Setting.ExperiencePlan, true)) {
val info = packageManager.getPackageInfo(packageName, 0) val info = packageManager.getPackageInfo(packageName, 0)
ErrorReport.instance.send( ErrorReport.instance.send(
errorInfo.allErrorDetails, errorInfo.allErrorDetails,
@ -61,7 +62,8 @@ class ErrorActivity() : BaseActivity<ActivityErrorBinding>() {
object : ApiCallBack<ApiResponse> { object : ApiCallBack<ApiResponse> {
override fun onResponse(t: ApiResponse) { override fun onResponse(t: ApiResponse) {
if (t.code == ServerConfiguration.Success_Code) { if (t.code == ServerConfiguration.Success_Code) {
viewBinding.shareLogButton.isVisible = false viewBinding.shareLogButton.isEnabled = false
viewBinding.shareLogButton.text = getString(R.string.anonymous_send_completed)
} }
} }
@ -69,7 +71,12 @@ class ErrorActivity() : BaseActivity<ActivityErrorBinding>() {
e.printStackTrace() e.printStackTrace()
} }
}) },
AppSettings.getValue(
AppSettings.Setting.ServerAddress,
ServerConfiguration.website
)
)
} }
saveLog() saveLog()
} }
@ -102,7 +109,7 @@ class ErrorActivity() : BaseActivity<ActivityErrorBinding>() {
* 创建错误日志 * 创建错误日志
*/ */
fun saveLog(): Boolean { fun saveLog(): Boolean {
errorInfo.describe = viewBinding.inputEditView.text.toString() // errorInfo.describe = viewBinding.inputEditView.text.toString()
return errorInfo.save() return errorInfo.save()
} }
@ -141,7 +148,7 @@ class ErrorActivity() : BaseActivity<ActivityErrorBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityErrorBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityErrorBinding {
return ActivityErrorBinding.inflate(layoutInflater) return ActivityErrorBinding.inflate(layoutInflater)
} }

View File

@ -3,6 +3,7 @@ package com.coldmint.rust.pro
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.view.LayoutInflater
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.coldmint.rust.core.interfaces.FileFinderListener import com.coldmint.rust.core.interfaces.FileFinderListener
@ -93,7 +94,7 @@ class ErrorInfoActivity : BaseActivity<ActivityErrorInfoBinding>() {
viewBinding.tipView.setText(resId) viewBinding.tipView.setText(resId)
} }
override fun getViewBindingObject(): ActivityErrorInfoBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityErrorInfoBinding {
return ActivityErrorInfoBinding.inflate(layoutInflater) return ActivityErrorInfoBinding.inflate(layoutInflater)
} }
} }

View File

@ -823,7 +823,7 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// return null // return null
// } // }
// //
// override fun getViewBindingObject(): ActivityFileBinding { // override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityFileBinding {
// return ActivityFileBinding.inflate(layoutInflater) // return ActivityFileBinding.inflate(layoutInflater)
// } // }
// //
@ -875,15 +875,15 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
loadTitle() loadTitle()
loadObserve() loadObserve()
initAction() initAction()
FastScrollerBuilder(viewBinding.recyclerView).useMd2Style() viewModel.initBookmarkManager(this)
.setPopupTextProvider(adapter).build() viewModel.loadFiles()
viewModel.loadSortType(this)
viewBinding.swipeRefreshLayout.setOnRefreshListener { viewBinding.swipeRefreshLayout.setOnRefreshListener {
viewModel.loadFiles(viewModel.getCurrentPath()) viewModel.loadFiles(viewModel.getCurrentPath())
viewBinding.swipeRefreshLayout.isRefreshing = false viewBinding.swipeRefreshLayout.isRefreshing = false
} }
viewModel.initBookmarkManager(this) FastScrollerBuilder(viewBinding.recyclerView).useMd2Style()
viewModel.loadFiles() .setPopupTextProvider(adapter).build()
viewModel.loadSortType(this)
} else { } else {
val bundle = intent.getBundleExtra("data") val bundle = intent.getBundleExtra("data")
if (bundle == null) { if (bundle == null) {
@ -1098,6 +1098,10 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
} }
} }
viewModel.currentPathLiveData.observe(this) { viewModel.currentPathLiveData.observe(this) {
if (it==null)
{
return@observe
}
val root = getString(R.string.root_path) val root = getString(R.string.root_path)
val path = root + it.substring(viewModel.getRootPath().length) val path = root + it.substring(viewModel.getRootPath().length)
val lineParser = LineParser(path) val lineParser = LineParser(path)
@ -1172,7 +1176,7 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityFileBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityFileBinding {
return ActivityFileBinding.inflate(layoutInflater) return ActivityFileBinding.inflate(layoutInflater)
} }

View File

@ -2,6 +2,7 @@ package com.coldmint.rust.pro
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.coldmint.rust.core.web.ServerConfiguration import com.coldmint.rust.core.web.ServerConfiguration
import com.coldmint.rust.pro.databinding.ActivityFullScreenCoverBinding import com.coldmint.rust.pro.databinding.ActivityFullScreenCoverBinding
@ -12,7 +13,7 @@ import com.gyf.immersionbar.ktx.immersionBar
class FullScreenCoverActivity : BaseActivity<ActivityFullScreenCoverBinding>() { class FullScreenCoverActivity : BaseActivity<ActivityFullScreenCoverBinding>() {
override fun getViewBindingObject(): ActivityFullScreenCoverBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityFullScreenCoverBinding {
return ActivityFullScreenCoverBinding.inflate(layoutInflater) return ActivityFullScreenCoverBinding.inflate(layoutInflater)
} }

View File

@ -2,6 +2,7 @@ package com.coldmint.rust.pro
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.base.BaseActivity
import android.view.View import android.view.View
import com.coldmint.rust.core.tool.AppOperator import com.coldmint.rust.core.tool.AppOperator
@ -15,7 +16,7 @@ import com.coldmint.rust.pro.tool.AppSettings
*/ */
class GameCheckActivity : BaseActivity<ActivityGameCheckBinding>() { class GameCheckActivity : BaseActivity<ActivityGameCheckBinding>() {
override fun getViewBindingObject(): ActivityGameCheckBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityGameCheckBinding {
return ActivityGameCheckBinding.inflate(layoutInflater) return ActivityGameCheckBinding.inflate(layoutInflater)
} }
@ -40,7 +41,7 @@ class GameCheckActivity : BaseActivity<ActivityGameCheckBinding>() {
} }
}) })
viewBinding.completionButton.setOnClickListener(View.OnClickListener { viewBinding.completionButton.setOnClickListener(View.OnClickListener {
appSettings.setValue(AppSettings.Setting.SetGameStorage, true) AppSettings.setValue(AppSettings.Setting.SetGameStorage, true)
finish() finish()
}) })
} }

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.InputType import android.text.InputType
import android.text.TextWatcher import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.inputmethod.InputMethodInfo import android.view.inputmethod.InputMethodInfo
import android.widget.AdapterView import android.widget.AdapterView
@ -271,7 +272,7 @@ class GlobalOperationsActivity : BaseActivity<ActivityGlobalOperationsBinding>()
} }
override fun getViewBindingObject(): ActivityGlobalOperationsBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityGlobalOperationsBinding {
return ActivityGlobalOperationsBinding.inflate(layoutInflater) return ActivityGlobalOperationsBinding.inflate(layoutInflater)
} }
} }

View File

@ -1,19 +1,15 @@
package com.coldmint.rust.pro package com.coldmint.rust.pro
import android.Manifest
import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.base.BaseActivity
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri import android.net.Uri
import android.os.* import android.os.*
import android.view.LayoutInflater
import android.widget.Toast import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.coldmint.rust.core.CompressionManager import com.coldmint.rust.core.CompressionManager
import com.coldmint.rust.core.TemplatePackage import com.coldmint.rust.core.LocalTemplatePackage
import com.coldmint.rust.core.dataBean.template.TemplateInfo import com.coldmint.rust.core.dataBean.template.TemplateInfo
import com.coldmint.rust.core.interfaces.UnzipListener import com.coldmint.rust.core.interfaces.UnzipListener
import com.coldmint.rust.core.tool.AppOperator import com.coldmint.rust.core.tool.AppOperator
@ -122,13 +118,13 @@ class ImporterActivity : BaseActivity<ActivityImporterBinding>() {
val onclickType = viewBinding.okButton.text val onclickType = viewBinding.okButton.text
val importName = getString(R.string.import_name) val importName = getString(R.string.import_name)
if ((type == "rwmod" || type == "zip") && onclickType == importName) { if ((type == "rwmod" || type == "zip") && onclickType == importName) {
importMod(File(appSettings.getValue(AppSettings.Setting.ModFolder, ""))) importMod(File(AppSettings.getValue(AppSettings.Setting.ModFolder, "")))
} else if (type == "rp") { } else if (type == "rp") {
val file = File( val file = File(
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.TemplateDirectory, AppSettings.Setting.TemplateDirectory,
this.filesDir.absolutePath + "/template/" this.filesDir.absolutePath + "/template/"
) + TemplatePackage.getAbsoluteFileName(filename = fileName) ) + LocalTemplatePackage.getAbsoluteFileName(filename = fileName)
) )
val cacheDirectory = File(cacheDir.absolutePath + "/template/") val cacheDirectory = File(cacheDir.absolutePath + "/template/")
if (!cacheDirectory.exists()) { if (!cacheDirectory.exists()) {
@ -186,7 +182,7 @@ class ImporterActivity : BaseActivity<ActivityImporterBinding>() {
//如果建立缓存完成,并且模板文件存在 //如果建立缓存完成,并且模板文件存在
if (templateDirectory.exists()) { if (templateDirectory.exists()) {
val newInfoData = val newInfoData =
compressionManager.readEntry(newFile, TemplatePackage.INFONAME) compressionManager.readEntry(newFile, LocalTemplatePackage.INFONAME)
val newInfo = val newInfo =
gson.fromJson(newInfoData, TemplateInfo::class.java) gson.fromJson(newInfoData, TemplateInfo::class.java)
if (newInfo == null) { if (newInfo == null) {
@ -205,7 +201,7 @@ class ImporterActivity : BaseActivity<ActivityImporterBinding>() {
} }
return@Runnable return@Runnable
} else { } else {
val templateClass = TemplatePackage(templateDirectory) val templateClass = LocalTemplatePackage(templateDirectory)
val oldInfo = templateClass.getInfo() val oldInfo = templateClass.getInfo()
if (oldInfo == null) { if (oldInfo == null) {
handler.post { handler.post {
@ -266,7 +262,7 @@ class ImporterActivity : BaseActivity<ActivityImporterBinding>() {
} else { } else {
//常规导入 //常规导入
val newInfo = val newInfo =
compressionManager.readEntry(newFile, TemplatePackage.INFONAME) compressionManager.readEntry(newFile, LocalTemplatePackage.INFONAME)
if (newInfo == null) { if (newInfo == null) {
handler.post { handler.post {
viewBinding.okButton.setBackgroundColor( viewBinding.okButton.setBackgroundColor(
@ -469,7 +465,7 @@ class ImporterActivity : BaseActivity<ActivityImporterBinding>() {
} }
override fun getViewBindingObject(): ActivityImporterBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityImporterBinding {
return ActivityImporterBinding.inflate(layoutInflater) return ActivityImporterBinding.inflate(layoutInflater)
} }

View File

@ -1,6 +1,7 @@
package com.coldmint.rust.pro package com.coldmint.rust.pro
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.base.BaseActivity
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -158,7 +159,7 @@ class LibraryActivity : BaseActivity<ActivityLibraryBinding>() {
return libInfoArrayList return libInfoArrayList
} }
override fun getViewBindingObject(): ActivityLibraryBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityLibraryBinding {
return ActivityLibraryBinding.inflate(layoutInflater) return ActivityLibraryBinding.inflate(layoutInflater)
} }

View File

@ -14,6 +14,7 @@ import android.text.TextWatcher
import android.text.method.LinkMovementMethod import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan import android.text.style.ClickableSpan
import android.util.Log import android.util.Log
import android.view.LayoutInflater
import android.view.View import android.view.View
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton import com.afollestad.materialdialogs.WhichButton
@ -44,7 +45,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
transparentStatusBar().statusBarDarkFont(true) transparentStatusBar().statusBarDarkFont(true)
.transparentNavigationBar().navigationBarDarkIcon(true) .transparentNavigationBar().navigationBarDarkIcon(true)
} }
Log.d("应用识别码", appSettings.getValue(AppSettings.Setting.AppID, "")) Log.d("应用识别码", AppSettings.getValue(AppSettings.Setting.AppID, ""))
viewBinding.accountView.addTextChangedListener(object : TextWatcher { viewBinding.accountView.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
@ -110,7 +111,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
if (!checkPassword(passWord)) { if (!checkPassword(passWord)) {
return@OnClickListener return@OnClickListener
} }
val appId = appSettings.getValue(AppSettings.Setting.AppID, ""); val appId = AppSettings.getValue(AppSettings.Setting.AppID, "");
isLogin = true isLogin = true
viewBinding.button.setText(R.string.request_data) viewBinding.button.setText(R.string.request_data)
User.login(LoginRequestData(account, passWord, appId), User.login(LoginRequestData(account, passWord, appId),
@ -119,12 +120,12 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
isLogin = false isLogin = false
viewBinding.button.setText(R.string.login) viewBinding.button.setText(R.string.login)
if (userData.code == ServerConfiguration.Success_Code) { if (userData.code == ServerConfiguration.Success_Code) {
appSettings.forceSetValue(AppSettings.Setting.PassWord, passWord) AppSettings.forceSetValue(AppSettings.Setting.PassWord, passWord)
appSettings.forceSetValue( AppSettings.forceSetValue(
AppSettings.Setting.Account, AppSettings.Setting.Account,
userData.data.account userData.data.account
) )
appSettings.forceSetValue( AppSettings.forceSetValue(
AppSettings.Setting.Token, AppSettings.Setting.Token,
userData.data.token userData.data.token
) )
@ -132,8 +133,8 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
//更新本地激活时间 //更新本地激活时间
val expirationTime = userData.data.expirationTime val expirationTime = userData.data.expirationTime
val time = ServerConfiguration.toLongTime(expirationTime) val time = ServerConfiguration.toLongTime(expirationTime)
appSettings.forceSetValue(AppSettings.Setting.ExpirationTime, time) AppSettings.forceSetValue(AppSettings.Setting.ExpirationTime, time)
appSettings.forceSetValue(AppSettings.Setting.LoginStatus, true) AppSettings.forceSetValue(AppSettings.Setting.LoginStatus, true)
startActivity(Intent(this@LoginActivity, MainActivity::class.java)) startActivity(Intent(this@LoginActivity, MainActivity::class.java))
finish() finish()
} else { } else {
@ -356,11 +357,11 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
viewBinding.checkbox.setHintTextColor(Color.TRANSPARENT) viewBinding.checkbox.setHintTextColor(Color.TRANSPARENT)
viewBinding.checkbox.movementMethod = LinkMovementMethod.getInstance(); viewBinding.checkbox.movementMethod = LinkMovementMethod.getInstance();
} }
val agree = appSettings.getValue(AppSettings.Setting.AgreePolicy, false) val agree = AppSettings.getValue(AppSettings.Setting.AgreePolicy, false)
viewBinding.checkbox.isChecked = agree viewBinding.checkbox.isChecked = agree
viewBinding.checkbox.setOnCheckedChangeListener { p0, p1 -> viewBinding.checkbox.setOnCheckedChangeListener { p0, p1 ->
setLoginButtonEnable() setLoginButtonEnable()
appSettings.setValue(AppSettings.Setting.AgreePolicy, p1) AppSettings.setValue(AppSettings.Setting.AgreePolicy, p1)
} }
viewBinding.registerView.setOnClickListener { viewBinding.registerView.setOnClickListener {
@ -374,7 +375,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
viewBinding.changeServerView.setOnClickListener { viewBinding.changeServerView.setOnClickListener {
InputDialog(this).setTitle(R.string.changing_the_server) InputDialog(this).setTitle(R.string.changing_the_server)
.setMessage(R.string.changing_the_server_tip).setMaxNumber(255).setText( .setMessage(R.string.changing_the_server_tip).setMaxNumber(255).setText(
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.ServerAddress, AppSettings.Setting.ServerAddress,
ServerConfiguration.website ServerConfiguration.website
) )
@ -383,7 +384,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
!(s.startsWith("http://") || s.startsWith("https://")) !(s.startsWith("http://") || s.startsWith("https://"))
}.setPositiveButton(R.string.dialog_ok) { input -> }.setPositiveButton(R.string.dialog_ok) { input ->
if (input.isNotBlank()) { if (input.isNotBlank()) {
appSettings.setValue(AppSettings.Setting.ServerAddress, input) AppSettings.setValue(AppSettings.Setting.ServerAddress, input)
ServerConfiguration.website = input ServerConfiguration.website = input
Snackbar.make( Snackbar.make(
viewBinding.button, viewBinding.button,
@ -472,8 +473,8 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
override fun onResume() { override fun onResume() {
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
val passWord = appSettings.getValue(AppSettings.Setting.PassWord, "") val passWord = AppSettings.getValue(AppSettings.Setting.PassWord, "")
val inputAccount = viewBinding.accountView.text.toString() val inputAccount = viewBinding.accountView.text.toString()
val inputPassWord = viewBinding.passwordView.text.toString() val inputPassWord = viewBinding.passwordView.text.toString()
if (account.isNotBlank() && inputAccount.isEmpty()) { if (account.isNotBlank() && inputAccount.isEmpty()) {
@ -485,7 +486,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
super.onResume() super.onResume()
} }
override fun getViewBindingObject(): ActivityLoginBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityLoginBinding {
return ActivityLoginBinding.inflate(layoutInflater) return ActivityLoginBinding.inflate(layoutInflater)
} }

View File

@ -19,10 +19,9 @@ import androidx.navigation.findNavController
import androidx.navigation.ui.* import androidx.navigation.ui.*
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.coldmint.rust.pro.dialog.CommentDialog
import com.coldmint.dialog.CoreDialog import com.coldmint.dialog.CoreDialog
import com.coldmint.rust.core.CompressionManager import com.coldmint.rust.core.CompressionManager
import com.coldmint.rust.core.TemplatePackage import com.coldmint.rust.core.LocalTemplatePackage
import com.coldmint.rust.core.dataBean.AppUpdateData import com.coldmint.rust.core.dataBean.AppUpdateData
import com.coldmint.rust.core.dataBean.template.TemplateInfo import com.coldmint.rust.core.dataBean.template.TemplateInfo
import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.interfaces.ApiCallBack
@ -80,7 +79,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val navController = findNavController(R.id.baseFragment) val navController = findNavController(R.id.baseFragment)
navController.navInflater.inflate(R.navigation.main_nav).apply { navController.navInflater.inflate(R.navigation.main_nav).apply {
val use = val use =
appSettings.getValue(AppSettings.Setting.UseTheCommunityAsTheLaunchPage, true) AppSettings.getValue(AppSettings.Setting.UseTheCommunityAsTheLaunchPage, true)
startDestination = if (use) { startDestination = if (use) {
viewBinding.mainButton.hide() viewBinding.mainButton.hide()
R.id.community_item R.id.community_item
@ -114,7 +113,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if (t.code == ServerConfiguration.Success_Code && data != null) { if (t.code == ServerConfiguration.Success_Code && data != null) {
val gson = Gson() val gson = Gson()
//同步离线的更新对话框 //同步离线的更新对话框
appSettings.forceSetValue(AppSettings.Setting.UpdateData, gson.toJson(data)) AppSettings.forceSetValue(AppSettings.Setting.UpdateData, gson.toJson(data))
ifNeedShowUpdate(data) ifNeedShowUpdate(data)
} else { } else {
Snackbar.make(viewBinding.mainButton, t.message, Snackbar.LENGTH_SHORT).show() Snackbar.make(viewBinding.mainButton, t.message, Snackbar.LENGTH_SHORT).show()
@ -122,7 +121,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} }
override fun onFailure(e: Exception) { override fun onFailure(e: Exception) {
val updateData = appSettings.getValue(AppSettings.Setting.UpdateData, "") val updateData = AppSettings.getValue(AppSettings.Setting.UpdateData, "")
if (updateData.isNotBlank()) { if (updateData.isNotBlank()) {
val gson = Gson() val gson = Gson()
val updateDataObj = gson.fromJson(updateData, AppUpdateData.Data::class.java) val updateDataObj = gson.fromJson(updateData, AppUpdateData.Data::class.java)
@ -143,7 +142,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val key = "应用更新" val key = "应用更新"
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0) val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
val checkBetaUpdate = val checkBetaUpdate =
appSettings.getValue(AppSettings.Setting.CheckBetaUpdate, false) AppSettings.getValue(AppSettings.Setting.CheckBetaUpdate, false)
var needShowDialog = false var needShowDialog = false
//如果自身是Beta版则强制更新Beta版本 //如果自身是Beta版则强制更新Beta版本
if (BuildConfig.DEBUG && packageInfo.versionName.contains("Beta")) { if (BuildConfig.DEBUG && packageInfo.versionName.contains("Beta")) {
@ -204,7 +203,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
* 显示游戏配置对话框 * 显示游戏配置对话框
*/ */
fun showGameConfiguredDialog() { fun showGameConfiguredDialog() {
if (!appSettings.getValue(AppSettings.Setting.SetGameStorage, false)) { if (!AppSettings.getValue(AppSettings.Setting.SetGameStorage, false)) {
try { try {
val packageInfo = packageManager.getPackageInfo( val packageInfo = packageManager.getPackageInfo(
GlobalMethod.DEFAULT_GAME_PACKAGE, GlobalMethod.DEFAULT_GAME_PACKAGE,
@ -223,11 +222,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
) )
) )
}.setNeutralButton(R.string.no_longer_prompt) { i, i2 -> }.setNeutralButton(R.string.no_longer_prompt) { i, i2 ->
appSettings.setValue(AppSettings.Setting.SetGameStorage, true) AppSettings.setValue(AppSettings.Setting.SetGameStorage, true)
}.setNeutralButton(R.string.dialog_cancel) { i, i2 -> }.setNeutralButton(R.string.dialog_cancel) { i, i2 ->
}.setCancelable(false).show() }.setCancelable(false).show()
} else { } else {
appSettings.setValue(AppSettings.Setting.SetGameStorage, true) AppSettings.setValue(AppSettings.Setting.SetGameStorage, true)
} }
} catch (e: PackageManager.NameNotFoundException) { } catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace() e.printStackTrace()
@ -240,7 +239,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if (first) { if (first) {
first = false first = false
} else { } else {
val newLanguage = appSettings.getValue(AppSettings.Setting.AppLanguage, "en") val newLanguage = AppSettings.getValue(AppSettings.Setting.AppLanguage, "en")
if (oldLanguage != newLanguage) { if (oldLanguage != newLanguage) {
recreate() recreate()
return return
@ -339,7 +338,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} }
menu.findItem(R.id.startGame).setOnMenuItemClickListener { menu.findItem(R.id.startGame).setOnMenuItemClickListener {
val packName = appSettings.getValue( val packName = AppSettings.getValue(
AppSettings.Setting.GamePackage, AppSettings.Setting.GamePackage,
GlobalMethod.DEFAULT_GAME_PACKAGE GlobalMethod.DEFAULT_GAME_PACKAGE
) )
@ -366,7 +365,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} }
//激活暂时不可用 //激活暂时不可用
val longTime = appSettings.getValue( val longTime = AppSettings.getValue(
AppSettings.Setting.ExpirationTime, AppSettings.Setting.ExpirationTime,
0.toLong() 0.toLong()
) )
@ -395,7 +394,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val type = FileOperator.getFileType(from) val type = FileOperator.getFileType(from)
if (requestCode == 1) { if (requestCode == 1) {
if ("rwmod" == type || "zip" == type) { if ("rwmod" == type || "zip" == type) {
val modDirectory = appSettings.getValue(AppSettings.Setting.ModFolder, "") val modDirectory = AppSettings.getValue(AppSettings.Setting.ModFolder, "")
val to = File(modDirectory + from.name) val to = File(modDirectory + from.name)
if (FileOperator.copyFile(from, to)) { if (FileOperator.copyFile(from, to)) {
Snackbar.make( Snackbar.make(
@ -420,10 +419,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} else if (requestCode == 2) { } else if (requestCode == 2) {
if ("rp" == type) { if ("rp" == type) {
val outputFolder = File( val outputFolder = File(
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.TemplateDirectory, AppSettings.Setting.TemplateDirectory,
this.filesDir.absolutePath + "/template/" this.filesDir.absolutePath + "/template/"
) + TemplatePackage.getAbsoluteFileName(from) ) + LocalTemplatePackage.getAbsoluteFileName(from)
) )
importTemplate(from, outputFolder) importTemplate(from, outputFolder)
} else { } else {
@ -449,7 +448,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val compressionManager = CompressionManager.instance val compressionManager = CompressionManager.instance
if (templateDirectory.exists()) { if (templateDirectory.exists()) {
val gson = Gson() val gson = Gson()
val newInfoData = compressionManager.readEntry(formFile, TemplatePackage.INFONAME) val newInfoData = compressionManager.readEntry(formFile, LocalTemplatePackage.INFONAME)
if (newInfoData == null) { if (newInfoData == null) {
handler.post { handler.post {
Snackbar.make( Snackbar.make(
@ -461,7 +460,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
return@Runnable return@Runnable
} else { } else {
val newInfo = gson.fromJson(newInfoData, TemplateInfo::class.java) val newInfo = gson.fromJson(newInfoData, TemplateInfo::class.java)
val templateClass = TemplatePackage(templateDirectory) val templateClass = LocalTemplatePackage(templateDirectory)
val oldInfo = templateClass.getInfo() val oldInfo = templateClass.getInfo()
if (oldInfo == null) { if (oldInfo == null) {
handler.post { handler.post {
@ -507,7 +506,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} }
} else { } else {
//常规导入 //常规导入
val newInfo = compressionManager.readEntry(formFile, TemplatePackage.INFONAME) val newInfo = compressionManager.readEntry(formFile, LocalTemplatePackage.INFONAME)
if (newInfo == null) { if (newInfo == null) {
handler.post { handler.post {
Snackbar.make( Snackbar.make(
@ -603,7 +602,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
return false return false
} }
override fun getViewBindingObject(): ActivityMainBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityMainBinding {
return ActivityMainBinding.inflate(layoutInflater) return ActivityMainBinding.inflate(layoutInflater)
} }
@ -692,7 +691,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
if (canUseView) { if (canUseView) {
oldLanguage = appSettings.getValue(AppSettings.Setting.AppLanguage, "en") oldLanguage = AppSettings.getValue(AppSettings.Setting.AppLanguage, "en")
useToolbarSetSupportActionBar() useToolbarSetSupportActionBar()
initNav() initNav()
observeStartViewModel() observeStartViewModel()

View File

@ -13,6 +13,7 @@ import android.text.style.ClickableSpan
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import android.text.Spanned import android.text.Spanned
import android.os.Looper import android.os.Looper
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.* import android.widget.*
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -478,7 +479,7 @@ class OptimizeActivity : BaseActivity<ActivityOptimizeBinding>() {
} }
override fun getViewBindingObject(): ActivityOptimizeBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityOptimizeBinding {
return ActivityOptimizeBinding.inflate(layoutInflater) return ActivityOptimizeBinding.inflate(layoutInflater)
} }

View File

@ -30,10 +30,10 @@ import com.google.android.material.snackbar.Snackbar
class OrderListActivity : BaseActivity<ActivityOrderListBinding>() { class OrderListActivity : BaseActivity<ActivityOrderListBinding>() {
var loadAll = false var loadAll = false
val account by lazy { val account by lazy {
appSettings.getValue(AppSettings.Setting.Account, "") AppSettings.getValue(AppSettings.Setting.Account, "")
} }
val appId by lazy { val appId by lazy {
appSettings.getValue(AppSettings.Setting.AppID, "") AppSettings.getValue(AppSettings.Setting.AppID, "")
} }
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
@ -190,7 +190,7 @@ class OrderListActivity : BaseActivity<ActivityOrderListBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityOrderListBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityOrderListBinding {
return ActivityOrderListBinding.inflate(layoutInflater) return ActivityOrderListBinding.inflate(layoutInflater)
} }

View File

@ -9,6 +9,7 @@ import com.coldmint.rust.pro.tool.AppSettings
import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.tool.GlobalMethod
import android.os.Looper import android.os.Looper
import android.view.KeyEvent import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.* import android.widget.*
@ -80,10 +81,10 @@ class PackActivity : BaseActivity<ActivityPackBinding>() {
modName = modClass.modName modName = modClass.modName
item = resources.getStringArray(R.array.update_type_entries) item = resources.getStringArray(R.array.update_type_entries)
needRecyclingFile = needRecyclingFile =
appSettings.getValue(AppSettings.Setting.EnableRecoveryStation, true) AppSettings.getValue(AppSettings.Setting.EnableRecoveryStation, true)
if (needRecyclingFile) { if (needRecyclingFile) {
val recoveryStationFolder = StringBuilder( val recoveryStationFolder = StringBuilder(
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.RecoveryStationFolder, AppSettings.Setting.RecoveryStationFolder,
this@PackActivity.filesDir.absolutePath + "/backup/" this@PackActivity.filesDir.absolutePath + "/backup/"
) )
@ -105,7 +106,7 @@ class PackActivity : BaseActivity<ActivityPackBinding>() {
configurationData = data configurationData = data
loadInfoToView(data) loadInfoToView(data)
} }
outputFolder = appSettings.getValue( outputFolder = AppSettings.getValue(
AppSettings.Setting.PackDirectory, AppSettings.Setting.PackDirectory,
AppSettings.dataRootDirectory + "/bin/" AppSettings.dataRootDirectory + "/bin/"
) )
@ -428,7 +429,7 @@ class PackActivity : BaseActivity<ActivityPackBinding>() {
} }
override fun getViewBindingObject(): ActivityPackBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityPackBinding {
return ActivityPackBinding.inflate(layoutInflater) return ActivityPackBinding.inflate(layoutInflater)
} }

View File

@ -17,6 +17,7 @@ import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan import android.text.style.StyleSpan
import android.util.Log import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MenuItem import android.view.MenuItem
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
@ -344,7 +345,7 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
viewBinding.payMoneyView.text = spannableString viewBinding.payMoneyView.text = spannableString
} }
override fun getViewBindingObject(): ActivityPayBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityPayBinding {
return ActivityPayBinding.inflate(layoutInflater) return ActivityPayBinding.inflate(layoutInflater)
} }
} }

View File

@ -2,6 +2,7 @@ package com.coldmint.rust.pro
import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.base.BaseActivity
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.AppSettings
@ -26,12 +27,12 @@ class RecyclingStationActivity : BaseActivity<ActivityRecyclingStationBinding>()
title = getString(R.string.enable_the_recovery_station) title = getString(R.string.enable_the_recovery_station)
viewBinding.backupList.layoutManager = viewBinding.backupList.layoutManager =
LinearLayoutManager(this@RecyclingStationActivity) LinearLayoutManager(this@RecyclingStationActivity)
val workFolderPath = appSettings.getValue( val workFolderPath = AppSettings.getValue(
AppSettings.Setting.RecoveryStationFolder, AppSettings.Setting.RecoveryStationFolder,
this@RecyclingStationActivity.filesDir.absolutePath + "/backup/" this@RecyclingStationActivity.filesDir.absolutePath + "/backup/"
) )
mDayNum = Integer.valueOf( mDayNum = Integer.valueOf(
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.RecoveryStationFileSaveDays, AppSettings.Setting.RecoveryStationFileSaveDays,
7 7
) )
@ -91,7 +92,7 @@ class RecyclingStationActivity : BaseActivity<ActivityRecyclingStationBinding>()
working = true working = true
val removePath: String val removePath: String
val modDirectory = val modDirectory =
appSettings.getValue(AppSettings.Setting.ModFolder, "") AppSettings.getValue(AppSettings.Setting.ModFolder, "")
val removeFile: File val removeFile: File
if (file.isDirectory) { if (file.isDirectory) {
removePath = modDirectory + file.name + "/" removePath = modDirectory + file.name + "/"
@ -163,7 +164,7 @@ class RecyclingStationActivity : BaseActivity<ActivityRecyclingStationBinding>()
} }
FileOperator.removeFiles( FileOperator.removeFiles(
mWorkFolder, mWorkFolder,
File(appSettings.getValue(AppSettings.Setting.ModFolder, "")) File(AppSettings.getValue(AppSettings.Setting.ModFolder, ""))
) )
runOnUiThread { runOnUiThread {
viewBinding.progressBar.isVisible = false viewBinding.progressBar.isVisible = false
@ -185,7 +186,7 @@ class RecyclingStationActivity : BaseActivity<ActivityRecyclingStationBinding>()
} }
override fun getViewBindingObject(): ActivityRecyclingStationBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityRecyclingStationBinding {
return ActivityRecyclingStationBinding.inflate(layoutInflater) return ActivityRecyclingStationBinding.inflate(layoutInflater)
} }

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.InputType import android.text.InputType
import android.text.TextWatcher import android.text.TextWatcher
import android.view.LayoutInflater
import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.base.BaseActivity
import android.view.View import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -147,7 +148,7 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
) )
) )
viewBinding.registerButton.setText(R.string.request_data) viewBinding.registerButton.setText(R.string.request_data)
val appID = appSettings.getValue(AppSettings.Setting.AppID, "") val appID = AppSettings.getValue(AppSettings.Setting.AppID, "")
User.register( User.register(
RegisterRequestData(account, passWord, userName, email, appID), RegisterRequestData(account, passWord, userName, email, appID),
object : ApiCallBack<ApiResponse> { object : ApiCallBack<ApiResponse> {
@ -160,9 +161,9 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
) )
viewBinding.registerButton.setText(R.string.register) viewBinding.registerButton.setText(R.string.register)
if (apiResponse.code == ServerConfiguration.Success_Code) { if (apiResponse.code == ServerConfiguration.Success_Code) {
appSettings.forceSetValue(AppSettings.Setting.Account, account) AppSettings.forceSetValue(AppSettings.Setting.Account, account)
appSettings.forceSetValue(AppSettings.Setting.PassWord, passWord) AppSettings.forceSetValue(AppSettings.Setting.PassWord, passWord)
appSettings.forceSetValue(AppSettings.Setting.UserName, userName) AppSettings.forceSetValue(AppSettings.Setting.UserName, userName)
MaterialDialog(this@RegisterActivity).show { MaterialDialog(this@RegisterActivity).show {
title(R.string.register_successed).message(R.string.registration_success_message) title(R.string.register_successed).message(R.string.registration_success_message)
.cancelable(false).positiveButton(R.string.close) { .cancelable(false).positiveButton(R.string.close) {
@ -412,7 +413,7 @@ class RegisterActivity : BaseActivity<ActivityRegisterBinding>() {
) && checkEmail(email, false) ) && checkEmail(email, false)
} }
override fun getViewBindingObject(): ActivityRegisterBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityRegisterBinding {
return ActivityRegisterBinding.inflate(layoutInflater) return ActivityRegisterBinding.inflate(layoutInflater)
} }

View File

@ -8,6 +8,7 @@ import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.util.Log import android.util.Log
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.PopupMenu import android.widget.PopupMenu
import android.widget.Toast import android.widget.Toast
@ -121,7 +122,7 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
showError("模组id为空") showError("模组id为空")
return return
} }
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
if (account.isBlank()) { if (account.isBlank()) {
showError(getString(R.string.please_login_first)) showError(getString(R.string.please_login_first))
return return
@ -422,7 +423,7 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
viewBinding.modTagEdit.setText( viewBinding.modTagEdit.setText(
String.format( String.format(
getString(R.string.default_tags), getString(R.string.default_tags),
appSettings.getValue(AppSettings.Setting.Account, "未知用户") AppSettings.getValue(AppSettings.Setting.Account, "未知用户")
) )
) )
@ -724,7 +725,7 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
} }
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
if (account.isBlank()) { if (account.isBlank()) {
Snackbar.make( Snackbar.make(
viewBinding.releaseButton, viewBinding.releaseButton,
@ -751,7 +752,7 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
when (AppOperator.getNetworkType(this)) { when (AppOperator.getNetworkType(this)) {
AppOperator.NetWorkType.NetWorkType_Moble -> { AppOperator.NetWorkType.NetWorkType_Moble -> {
val useMobileNetWork = val useMobileNetWork =
appSettings.getValue(AppSettings.Setting.UseMobileNetwork, false) AppSettings.getValue(AppSettings.Setting.UseMobileNetwork, false)
if (useMobileNetWork) { if (useMobileNetWork) {
if (isUpdateMode) { if (isUpdateMode) {
updateModWork( updateModWork(
@ -793,7 +794,7 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
} }
} }
negativeButton(R.string.always_allow) { negativeButton(R.string.always_allow) {
appSettings.setValue(AppSettings.Setting.UseMobileNetwork, true) AppSettings.setValue(AppSettings.Setting.UseMobileNetwork, true)
if (isUpdateMode) { if (isUpdateMode) {
updateModWork( updateModWork(
modId, modId,
@ -865,8 +866,8 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
title(R.string.release).customView(view = loadFileLayoutBinding.root) title(R.string.release).customView(view = loadFileLayoutBinding.root)
.positiveButton(R.string.dialog_ok).cancelable(false) .positiveButton(R.string.dialog_ok).cancelable(false)
} }
WebMod.instance.releaseMod(appSettings.getValue(AppSettings.Setting.AppID, ""), modId, WebMod.instance.releaseMod(AppSettings.getValue(AppSettings.Setting.AppID, ""), modId,
appSettings.getValue(AppSettings.Setting.Token, ""), AppSettings.getValue(AppSettings.Setting.Token, ""),
modName, modName,
modDescribe, modDescribe,
tagsBuilder.toString(), tagsBuilder.toString(),
@ -889,7 +890,7 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
//发布动态 //发布动态
val check = viewBinding.checkbox.isChecked val check = viewBinding.checkbox.isChecked
if (check) { if (check) {
val token = appSettings.getValue(AppSettings.Setting.Token, "") val token = AppSettings.getValue(AppSettings.Setting.Token, "")
Dynamic.instance.send( Dynamic.instance.send(
token, token,
String.format(getString(R.string.auto_send), modId), String.format(getString(R.string.auto_send), modId),
@ -977,7 +978,7 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
title(R.string.release).customView(view = loadFileLayoutBinding.root) title(R.string.release).customView(view = loadFileLayoutBinding.root)
.positiveButton(R.string.dialog_ok).cancelable(false) .positiveButton(R.string.dialog_ok).cancelable(false)
} }
WebMod.instance.updateMod(appSettings.getValue(AppSettings.Setting.AppID, ""), modId, WebMod.instance.updateMod(AppSettings.getValue(AppSettings.Setting.AppID, ""), modId,
account, account,
modName, modName,
modDescribe, modDescribe,
@ -1002,7 +1003,7 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
//发布动态 //发布动态
val check = viewBinding.checkbox.isChecked val check = viewBinding.checkbox.isChecked
if (check) { if (check) {
val token = appSettings.getValue(AppSettings.Setting.Token, "") val token = AppSettings.getValue(AppSettings.Setting.Token, "")
Dynamic.instance.send( Dynamic.instance.send(
token, token,
String.format( String.format(
@ -1270,7 +1271,7 @@ class ReleaseModActivity : BaseActivity<ActivityReleaseModBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityReleaseModBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityReleaseModBinding {
return ActivityReleaseModBinding.inflate(layoutInflater) return ActivityReleaseModBinding.inflate(layoutInflater)
} }

View File

@ -3,6 +3,7 @@ package com.coldmint.rust.pro
import android.os.Bundle import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.view.LayoutInflater
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.dataBean.ApiResponse
@ -24,7 +25,7 @@ class ReportActivity : BaseActivity<ActivityReportBinding>() {
lateinit var type: String lateinit var type: String
lateinit var target: String lateinit var target: String
override fun getViewBindingObject(): ActivityReportBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityReportBinding {
return ActivityReportBinding.inflate(layoutInflater) return ActivityReportBinding.inflate(layoutInflater)
} }
@ -58,7 +59,7 @@ class ReportActivity : BaseActivity<ActivityReportBinding>() {
return return
} }
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
if (account.isBlank()) { if (account.isBlank()) {
showError(getString(R.string.please_login_first)) showError(getString(R.string.please_login_first))
return return

View File

@ -1,6 +1,7 @@
package com.coldmint.rust.pro package com.coldmint.rust.pro
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -24,7 +25,7 @@ class ReportListActivity : BaseActivity<ActivityReportListBinding>() {
if (canUseView) { if (canUseView) {
title = getText(R.string.report_to_deal) title = getText(R.string.report_to_deal)
setReturnButton() setReturnButton()
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
if (account.isBlank()) { if (account.isBlank()) {
showInfoToView(R.string.please_login_first) showInfoToView(R.string.please_login_first)
return return
@ -153,7 +154,7 @@ class ReportListActivity : BaseActivity<ActivityReportListBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityReportListBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityReportListBinding {
return ActivityReportListBinding.inflate(layoutInflater) return ActivityReportListBinding.inflate(layoutInflater)
} }
} }

View File

@ -2,6 +2,7 @@ package com.coldmint.rust.pro
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -23,7 +24,7 @@ import com.google.android.material.snackbar.Snackbar
*/ */
class ReviewModActivity : BaseActivity<ActivityReviewModBinding>() { class ReviewModActivity : BaseActivity<ActivityReviewModBinding>() {
val token by lazy { val token by lazy {
AppSettings.getInstance(this).getValue(AppSettings.Setting.Token, "") AppSettings.getValue(AppSettings.Setting.Token, "")
} }
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
@ -153,7 +154,7 @@ class ReviewModActivity : BaseActivity<ActivityReviewModBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityReviewModBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityReviewModBinding {
return ActivityReviewModBinding.inflate(layoutInflater) return ActivityReviewModBinding.inflate(layoutInflater)
} }
} }

View File

@ -18,11 +18,11 @@ class RustApplication : Application() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
AppSettings.initAppSettings(this)
//动态颜色 //动态颜色
val options = DynamicColorsOptions.Builder() val options = DynamicColorsOptions.Builder()
.setPrecondition { activity, theme -> .setPrecondition { activity, theme ->
AppSettings.getInstance(this) AppSettings
.getValue( .getValue(
AppSettings.Setting.DynamicColor, AppSettings.Setting.DynamicColor,
DynamicColors.isDynamicColorAvailable() DynamicColors.isDynamicColorAvailable()
@ -48,7 +48,6 @@ class RustApplication : Application() {
} }
override fun attachBaseContext(base: Context?) { override fun attachBaseContext(base: Context?) {
super.attachBaseContext(MultiLanguages.attach(base)) super.attachBaseContext(MultiLanguages.attach(base))
} }

View File

@ -3,6 +3,7 @@ package com.coldmint.rust.pro
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -113,7 +114,7 @@ class SearchActivity : BaseActivity<ActivitySearchBinding>() {
}) })
} }
override fun getViewBindingObject(): ActivitySearchBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivitySearchBinding {
return ActivitySearchBinding.inflate(layoutInflater) return ActivitySearchBinding.inflate(layoutInflater)
} }

View File

@ -1,6 +1,7 @@
package com.coldmint.rust.pro package com.coldmint.rust.pro
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.coldmint.rust.core.dataBean.user.SearchResultDataBean import com.coldmint.rust.core.dataBean.user.SearchResultDataBean
import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.interfaces.ApiCallBack
@ -103,7 +104,7 @@ class SearchResultActivity : BaseActivity<ActivitySearchResultBinding>() {
} }
override fun getViewBindingObject(): ActivitySearchResultBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivitySearchResultBinding {
return ActivitySearchResultBinding.inflate(layoutInflater) return ActivitySearchResultBinding.inflate(layoutInflater)
} }
} }

View File

@ -7,6 +7,7 @@ import android.content.Intent
import android.os.Build import android.os.Build
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.view.LayoutInflater
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.* import androidx.preference.*
@ -32,15 +33,14 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
manager.findPreference<Preference>(getString(R.string.setting_app_language)) as ListPreference? manager.findPreference<Preference>(getString(R.string.setting_app_language)) as ListPreference?
listPreference!!.onPreferenceChangeListener = listPreference!!.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { preference, newValue -> Preference.OnPreferenceChangeListener { preference, newValue ->
val appSettings = AppSettings.getInstance(requireContext())
val oldLanguage = val oldLanguage =
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.AppLanguage, AppSettings.Setting.AppLanguage,
Locale.getDefault().language Locale.getDefault().language
) )
val newLanguage = newValue.toString() val newLanguage = newValue.toString()
if (oldLanguage != newLanguage) { if (oldLanguage != newLanguage) {
val restart = appSettings.setLanguage(newValue.toString()) val restart = AppSettings.setLanguage(newValue.toString())
if (restart) { if (restart) {
requireActivity().recreate() requireActivity().recreate()
} }
@ -211,7 +211,7 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
} }
} }
override fun getViewBindingObject(): ActivitySettingsBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivitySettingsBinding {
return ActivitySettingsBinding.inflate(layoutInflater) return ActivitySettingsBinding.inflate(layoutInflater)
} }

View File

@ -2,6 +2,7 @@ package com.coldmint.rust.pro
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -112,7 +113,7 @@ class TagActivity : BaseActivity<ActivityTagBinding>() {
} }
override fun getViewBindingObject(): ActivityTagBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityTagBinding {
return ActivityTagBinding.inflate(layoutInflater) return ActivityTagBinding.inflate(layoutInflater)
} }

View File

@ -16,7 +16,7 @@ import android.view.*
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.list.listItemsMultiChoice import com.afollestad.materialdialogs.list.listItemsMultiChoice
import com.coldmint.rust.core.TemplatePackage import com.coldmint.rust.core.LocalTemplatePackage
import com.coldmint.rust.core.interfaces.LineParserEvent import com.coldmint.rust.core.interfaces.LineParserEvent
import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.core.tool.LineParser import com.coldmint.rust.core.tool.LineParser
@ -267,11 +267,11 @@ class TemplateMakerActivity : BaseActivity<ActivityTemplateMakerBinding>() {
val arrayList = ArrayList<String>() val arrayList = ArrayList<String>()
val pathList = ArrayList<String>() val pathList = ArrayList<String>()
val environmentLanguage = val environmentLanguage =
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.AppLanguage, AppSettings.Setting.AppLanguage,
Locale.getDefault().language Locale.getDefault().language
) )
val templateDirectory = appSettings.getValue( val templateDirectory = AppSettings.getValue(
AppSettings.Setting.TemplateDirectory, AppSettings.Setting.TemplateDirectory,
this.filesDir.absolutePath + "/template/" this.filesDir.absolutePath + "/template/"
) )
@ -280,7 +280,7 @@ class TemplateMakerActivity : BaseActivity<ActivityTemplateMakerBinding>() {
val files = directory.listFiles() val files = directory.listFiles()
if (files.isNotEmpty()) { if (files.isNotEmpty()) {
for (file in files) { for (file in files) {
val templateClass = TemplatePackage(file) val templateClass = LocalTemplatePackage(file)
if (templateClass.isTemplate) { if (templateClass.isTemplate) {
arrayList.add( arrayList.add(
templateClass.getName() templateClass.getName()
@ -323,7 +323,7 @@ class TemplateMakerActivity : BaseActivity<ActivityTemplateMakerBinding>() {
class CodeData(val code: String, val section: String?) class CodeData(val code: String, val section: String?)
override fun getViewBindingObject(): ActivityTemplateMakerBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityTemplateMakerBinding {
return ActivityTemplateMakerBinding.inflate(layoutInflater) return ActivityTemplateMakerBinding.inflate(layoutInflater)
} }

View File

@ -5,15 +5,12 @@ import com.coldmint.rust.pro.base.BaseActivity
import org.json.JSONObject import org.json.JSONObject
import android.os.Bundle import android.os.Bundle
import android.content.Intent import android.content.Intent
import android.util.Log
import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.AppSettings
import org.json.JSONException import org.json.JSONException
import org.json.JSONArray import org.json.JSONArray
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import android.text.Editable import android.view.LayoutInflater
import android.text.SpannableString
import android.text.TextWatcher
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
@ -22,11 +19,15 @@ import android.view.View
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.* import android.widget.*
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.viewModelScope
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.coldmint.rust.core.TemplatePackage import com.coldmint.dialog.CoreDialog
import com.coldmint.rust.core.LocalTemplatePackage
import com.coldmint.rust.core.dataBean.InputParserDataBean import com.coldmint.rust.core.dataBean.InputParserDataBean
import com.coldmint.rust.core.dataBean.IntroducingDataBean import com.coldmint.rust.core.dataBean.IntroducingDataBean
import com.coldmint.rust.core.dataBean.ListParserDataBean import com.coldmint.rust.core.dataBean.ListParserDataBean
import com.coldmint.rust.core.dataBean.template.LocalTemplateFile
import com.coldmint.rust.core.dataBean.template.TemplatePackage
import com.coldmint.rust.core.interfaces.TemplateParser import com.coldmint.rust.core.interfaces.TemplateParser
import com.coldmint.rust.core.templateParser.InputParser import com.coldmint.rust.core.templateParser.InputParser
import com.coldmint.rust.core.templateParser.IntroducingParser import com.coldmint.rust.core.templateParser.IntroducingParser
@ -34,6 +35,7 @@ import com.coldmint.rust.core.templateParser.ListParser
import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.pro.databinding.ActivityTemplateParserBinding import com.coldmint.rust.pro.databinding.ActivityTemplateParserBinding
import com.coldmint.rust.pro.tool.UnitAutoCompleteHelper import com.coldmint.rust.pro.tool.UnitAutoCompleteHelper
import com.coldmint.rust.pro.viewmodel.TemplateParserViewModel
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import com.google.gson.Gson import com.google.gson.Gson
import java.io.File import java.io.File
@ -42,24 +44,14 @@ import java.util.concurrent.Executors
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.concurrent.thread import kotlin.concurrent.thread
class TemplateParserActivity() : BaseActivity<ActivityTemplateParserBinding>() { class TemplateParserActivity : BaseActivity<ActivityTemplateParserBinding>() {
private lateinit var mCreatePath: String
private var mRootPath: String? = null
private lateinit var mTemplatePackage: TemplatePackage
private var working = false
private lateinit var mJsonObject: JSONObject
private var mCreateIndependentFolder = false
private val gson = Gson()
lateinit var environmentLanguage: String
private val templateParserList = ArrayList<TemplateParser>()
private val executorService = Executors.newSingleThreadExecutor()
fun getTemplateName(): String { val viewModel: TemplateParserViewModel by lazy {
return if (mJsonObject.has("name_$environmentLanguage")) { TemplateParserViewModel()
mJsonObject.getString("name_$environmentLanguage")
} else {
mJsonObject.getString("name")
} }
private val language by lazy {
AppSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
@ -72,357 +64,49 @@ class TemplateParserActivity() : BaseActivity<ActivityTemplateParserBinding>() {
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.preview_static_code -> { R.id.preview_static_code -> {
var data = mJsonObject.getString("data") var code = viewModel.getCode()
if (data.isBlank()) { if (code.isBlank()) {
data = getString(R.string.not_found_data2) code = getString(R.string.not_found_data2)
}
MaterialDialog(this).show {
title(text = getTemplateName()).message(text = data)
.positiveButton(R.string.dialog_ok)
} }
CoreDialog(this).setTitle(viewModel.getTemplateName(language)).setMessage(code)
.setPositiveButton(R.string.dialog_ok) {
}.show()
} }
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
/**
* 创建视图
* @param jsonArray JSONArray js数组
*/
private fun createView(jsonArray: JSONArray) {
try {
var jsonObject: JSONObject
val len = jsonArray.length() - 1
val setFileNameEditTextPointToNxt = false
if (len > -1) {
for (i in 0..len) {
jsonObject = jsonArray.getJSONObject(i)
val type = jsonObject.getString("type")
when (type) {
"input" -> {
if (!setFileNameEditTextPointToNxt) {
viewBinding.fileNameInputView.imeOptions =
EditorInfo.IME_ACTION_NEXT
}
val data = gson.fromJson<InputParserDataBean>(
jsonObject.toString(),
InputParserDataBean::class.java
)
val inputParser = InputParser(this, data)
if (i < len) {
inputParser.pointToNextView()
}
addTemplateParser(inputParser)
}
"valueSelector" -> {
val data = gson.fromJson<ListParserDataBean>(
jsonObject.toString(),
ListParserDataBean::class.java
)
val listParser = ListParser(this, data)
addTemplateParser(listParser)
}
"comment" -> {
val data = gson.fromJson<IntroducingDataBean>(
jsonObject.toString(),
IntroducingDataBean::class.java
)
val introducingParser = IntroducingParser(this, data)
addTemplateParser(introducingParser)
}
else -> {
showError(String.format(getString(R.string.unknown_type), type))
break
}
}
}
}
} catch (exception: JSONException) {
showError(exception.toString())
exception.printStackTrace()
}
}
/**
* 添加模板解析器
* 到视图和数据集合内
* @param templateParser T
*/
fun <T : TemplateParser> addTemplateParser(templateParser: T) {
viewBinding.base.addView(templateParser.contextView)
templateParserList.add(templateParser)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
999 -> if (resultCode == RESULT_OK) {
mCreatePath = data!!.getStringExtra("Directents").toString()
Snackbar.make(
viewBinding.fab,
R.string.change_path_ok,
Snackbar.LENGTH_SHORT
).show()
}
else -> if (resultCode == RESULT_OK) {
val path = data!!.getStringExtra("File")
//mObjectArrayList[requestCode].setinput(path)
}
}
}
private fun initAction() {
val unitAutoCompleteHelper = UnitAutoCompleteHelper(this)
unitAutoCompleteHelper.onBindAutoCompleteTextView(viewBinding.fileNameInputView)
viewBinding.fab.setOnClickListener(object : View.OnClickListener {
override fun onClick(v: View) {
if (working) {
Snackbar.make(
viewBinding.fab,
R.string.create_uniting,
Snackbar.LENGTH_SHORT
).show()
return
}
viewBinding.fab.setImageResource(R.drawable.wait)
executorService.submit {
working = true
val filename = viewBinding.fileNameInputView.text.toString()
var needFileType = true
val index = filename.lastIndexOf('.')
//文件夹名
var folderName = filename
if (filename.isBlank()) {
setErrorAndInput(
viewBinding.fileNameInputView,
getString(R.string.unit_name_error), viewBinding.fileNameInputLayout
)
return@submit
} else if (index > -1) {
needFileType = false
folderName = filename.substring(0 until index)
}
//真实创建目录
val authenticallyCreateDirectory: String = if (mCreateIndependentFolder) {
"$mCreatePath/$folderName"
} else {
mCreatePath
}
val sourceFileClass = SourceFile(mJsonObject.getString("data"))
//执行活动(用户输入)
val len = templateParserList.size
if (len > 0) {
for (parser in templateParserList) {
if (parser.needParse) {
val input = parser.input
if (input.isBlank()) {
runOnUiThread {
parser.setError(getString(R.string.value_data_error))
}
return@submit
} else {
val section = parser.section
if (section == null) {
sourceFileClass.writeValue(parser.code, parser.input)
} else {
sourceFileClass.writeValueFromSection(
parser.code,
parser.input,
section
)
}
}
}
}
}
//复制附加内容
if (mJsonObject.has("attachFile")) {
try {
val jsonArray = mJsonObject.getJSONArray("attachFile")
var num = 0
while (jsonArray.getString(num) != null) {
val copyFile =
File(mRootPath + "/" + jsonArray.getString(num))
if (copyFile.exists() && !copyFile.isDirectory) {
val newPath =
File(authenticallyCreateDirectory + "/" + copyFile.name)
if (!FileOperator.copyFile(copyFile, newPath)) {
runOnUiThread(Runnable {
Snackbar.make(
viewBinding.fab,
R.string.copy_file_error_change_directory,
Snackbar.LENGTH_SHORT
).setAction(
getText(R.string.change_path),
View.OnClickListener {
val bundle = Bundle()
val intent = Intent(
this@TemplateParserActivity,
FileManagerActivity::class.java
)
bundle.putString(
"type",
"selectDirectents"
)
bundle.putString(
"path",
authenticallyCreateDirectory
)
bundle.putString(
"rootpath",
mRootPath
)
intent.putExtra("data", bundle)
startActivityForResult(
intent,
999
)
}).show()
working = false
viewBinding.fab.setImageResource(
R.drawable.done
)
return@Runnable
})
return@submit
}
}
num++
}
} catch (exception: JSONException) {
exception.printStackTrace()
}
}
val file: File = if (needFileType) {
File("$authenticallyCreateDirectory/${filename}.ini")
} else {
File("$authenticallyCreateDirectory/$filename")
}
val folder = File(authenticallyCreateDirectory)
if (!folder.exists()) {
folder.mkdirs()
}
if (file.exists()) {
setErrorAndInput(
viewBinding.fileNameInputView,
getString(R.string.unit_error),
viewBinding.fileNameInputLayout
)
} else {
if (FileOperator.writeFile(file, sourceFileClass.text)) {
val intent = Intent()
intent.putExtra("File", file.absolutePath)
setResult(RESULT_OK, intent)
finish()
} else {
runOnUiThread(Runnable {
Snackbar.make(
viewBinding.fab,
R.string.create_unit_failed,
Snackbar.LENGTH_SHORT
).show()
working = false
viewBinding.fab.setImageResource(R.drawable.done)
return@Runnable
})
}
}
}
}
})
}
override fun setErrorAndInput(
editText: EditText,
str: String,
inputLayout: TextInputLayout?,
selectAll: Boolean,
requestFocus: Boolean
) {
runOnUiThread {
working = false
viewBinding.fab.setImageResource(R.drawable.done)
super@TemplateParserActivity.setErrorAndInput(
editText,
str,
inputLayout,
selectAll,
requestFocus
)
}
}
override fun getViewBindingObject(): ActivityTemplateParserBinding {
return ActivityTemplateParserBinding.inflate(
layoutInflater
)
}
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
if (canUseView) { if (canUseView) {
setReturnButton() setReturnButton()
viewBinding.fab.hide() val link = intent.getStringExtra("link")
val intent = intent if (link == null) {
val bundle = intent.getBundleExtra("data") Toast.makeText(this, "请设置链接", Toast.LENGTH_SHORT).show()
if (bundle == null) {
showError("意外的请求")
return
} else {
val dataBasePath = appSettings.getValue(AppSettings.Setting.DatabasePath, "")
environmentLanguage = appSettings.getValue(
AppSettings.Setting.AppLanguage,
Locale.getDefault().language
)
mCreateIndependentFolder =
appSettings.getValue(AppSettings.Setting.IndependentFolder, true)
mRootPath = bundle.getString("rootFolder")
mCreatePath = bundle.getString("path").toString()
val templatePath = bundle.getString("templatePath")
if (templatePath == null) {
showError("模板路径读取错误")
return
}
mTemplatePackage = TemplatePackage(File(templatePath))
val jsonData = bundle.getString("json")
if (jsonData == null) {
Toast.makeText(this, "json数据为空", Toast.LENGTH_SHORT).show()
finish() finish()
return return
} }
thread { val isLocal = intent.getBooleanExtra("isLocal", false)
try { if (isLocal) {
mJsonObject = JSONObject(jsonData) Log.d("模板解析器", "读取本地模板$link")
title = getTemplateName() viewModel.setTemplate(LocalTemplateFile(File(link)))
if (mJsonObject.has("action")) { val templateParserList = viewModel.getTemplateParserList(this)
runOnUiThread { templateParserList.forEach {
createView(mJsonObject.getJSONArray("action")) viewBinding.base.addView(it.contextView)
} }
}
runOnUiThread {
viewBinding.nestedScrollView.isVisible = true
viewBinding.linearLayout.isVisible = false viewBinding.linearLayout.isVisible = false
viewBinding.fileNameInputView.requestFocus() viewBinding.nestedScrollView.isVisible = true
val imm = title = viewModel.getTemplateName(language)
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager } else {
imm.showSoftInput(
viewBinding.fileNameInputView,
InputMethodManager.SHOW_IMPLICIT
)
viewBinding.fab.show()
} }
} catch (exception: JSONException) {
exception.printStackTrace()
runOnUiThread {
showError(exception.toString())
}
}
}
}
initAction()
} }
} }
override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityTemplateParserBinding {
return ActivityTemplateParserBinding.inflate(layoutInflater)
}
} }

View File

@ -1,6 +1,7 @@
package com.coldmint.rust.pro package com.coldmint.rust.pro
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.coldmint.rust.pro.adapters.ThanksAdapter import com.coldmint.rust.pro.adapters.ThanksAdapter
@ -15,7 +16,7 @@ import com.google.android.material.divider.MaterialDividerItemDecoration
*/ */
class ThanksActivity : BaseActivity<ActivityThanksBinding>() { class ThanksActivity : BaseActivity<ActivityThanksBinding>() {
override fun getViewBindingObject(): ActivityThanksBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityThanksBinding {
return ActivityThanksBinding.inflate(layoutInflater) return ActivityThanksBinding.inflate(layoutInflater)
} }

View File

@ -6,6 +6,7 @@ import android.annotation.SuppressLint
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
@ -66,7 +67,7 @@ class TurretDesignActivity : BaseActivity<ActivityTurretDesignBinding>() {
} }
override fun getViewBindingObject(): ActivityTurretDesignBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityTurretDesignBinding {
return ActivityTurretDesignBinding.inflate(layoutInflater) return ActivityTurretDesignBinding.inflate(layoutInflater)
} }

View File

@ -210,7 +210,7 @@ class UnitsActivity : BaseActivity<ActivityUnitsBinding>() {
} }
override fun getViewBindingObject(): ActivityUnitsBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityUnitsBinding {
return ActivityUnitsBinding.inflate(layoutInflater) return ActivityUnitsBinding.inflate(layoutInflater)
} }

View File

@ -8,6 +8,7 @@ import android.graphics.Color
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Bundle import android.os.Bundle
import android.view.Gravity import android.view.Gravity
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import android.widget.EditText import android.widget.EditText
@ -66,7 +67,7 @@ class UserHomePageActivity : BaseActivity<ActivityUserHomePageBinding>() {
userId = temUserId userId = temUserId
} }
val temAccount = appSettings.getValue(AppSettings.Setting.Account, "") val temAccount = AppSettings.getValue(AppSettings.Setting.Account, "")
if (temAccount.isBlank()) { if (temAccount.isBlank()) {
showError("请先登录") showError("请先登录")
return return
@ -330,7 +331,7 @@ class UserHomePageActivity : BaseActivity<ActivityUserHomePageBinding>() {
CommentDialog(this).setTitle(R.string.send_dynamic).setCancelable(false) CommentDialog(this).setTitle(R.string.send_dynamic).setCancelable(false)
.setSubmitFun { button, textInputLayout, s, alertDialog -> .setSubmitFun { button, textInputLayout, s, alertDialog ->
val token = val token =
AppSettings.getInstance(this).getValue(AppSettings.Setting.Token, "") AppSettings.getValue(AppSettings.Setting.Token, "")
if (!s.isBlank()) { if (!s.isBlank()) {
Dynamic.instance.send( Dynamic.instance.send(
token, token,
@ -481,7 +482,7 @@ class UserHomePageActivity : BaseActivity<ActivityUserHomePageBinding>() {
} }
} }
override fun getViewBindingObject(): ActivityUserHomePageBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityUserHomePageBinding {
return ActivityUserHomePageBinding.inflate(layoutInflater) return ActivityUserHomePageBinding.inflate(layoutInflater)
} }

View File

@ -3,6 +3,7 @@ package com.coldmint.rust.pro
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -33,7 +34,7 @@ class UserListActivity : BaseActivity<ActivityUserListBinding>() {
} }
override fun getViewBindingObject(): ActivityUserListBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityUserListBinding {
return ActivityUserListBinding.inflate(layoutInflater) return ActivityUserListBinding.inflate(layoutInflater)
} }

View File

@ -10,6 +10,7 @@ import android.widget.ArrayAdapter
import android.text.TextWatcher import android.text.TextWatcher
import android.text.Editable import android.text.Editable
import android.view.KeyEvent import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
@ -283,7 +284,7 @@ class ValueTypeActivity : BaseActivity<ActivityValueTypeBinding>() {
return super.onKeyDown(keyCode, event) return super.onKeyDown(keyCode, event)
} }
override fun getViewBindingObject(): ActivityValueTypeBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityValueTypeBinding {
return ActivityValueTypeBinding.inflate(layoutInflater) return ActivityValueTypeBinding.inflate(layoutInflater)
} }

View File

@ -59,7 +59,7 @@ class WebModInfoActivity : BaseActivity<ActivityWebModInfoBinding>() {
lateinit var modId: String lateinit var modId: String
lateinit var tip: String lateinit var tip: String
val targetFile: File by lazy { val targetFile: File by lazy {
val modFolderPath = appSettings.getValue( val modFolderPath = AppSettings.getValue(
AppSettings.Setting.ModFolder, AppSettings.Setting.ModFolder,
Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/"
) )
@ -71,7 +71,7 @@ class WebModInfoActivity : BaseActivity<ActivityWebModInfoBinding>() {
File(modFilePath) File(modFilePath)
} }
val token by lazy { val token by lazy {
appSettings.getValue(AppSettings.Setting.Token, "") AppSettings.getValue(AppSettings.Setting.Token, "")
} }
var developer: String? = null var developer: String? = null
@ -253,7 +253,7 @@ class WebModInfoActivity : BaseActivity<ActivityWebModInfoBinding>() {
when (AppOperator.getNetworkType(this)) { when (AppOperator.getNetworkType(this)) {
AppOperator.NetWorkType.NetWorkType_Moble -> { AppOperator.NetWorkType.NetWorkType_Moble -> {
val useMobileNetWork = val useMobileNetWork =
appSettings.getValue(AppSettings.Setting.UseMobileNetwork, false) AppSettings.getValue(AppSettings.Setting.UseMobileNetwork, false)
if (useMobileNetWork) { if (useMobileNetWork) {
downloadWork(fileLink) downloadWork(fileLink)
} else { } else {
@ -263,7 +263,7 @@ class WebModInfoActivity : BaseActivity<ActivityWebModInfoBinding>() {
downloadWork(fileLink) downloadWork(fileLink)
} }
negativeButton(R.string.always_allow) { negativeButton(R.string.always_allow) {
appSettings.setValue(AppSettings.Setting.UseMobileNetwork, true) AppSettings.setValue(AppSettings.Setting.UseMobileNetwork, true)
downloadWork(fileLink) downloadWork(fileLink)
} }
neutralButton(R.string.dialog_cancel) { neutralButton(R.string.dialog_cancel) {
@ -470,7 +470,7 @@ class WebModInfoActivity : BaseActivity<ActivityWebModInfoBinding>() {
private fun initAction() { private fun initAction() {
viewBinding.sendDiscussion.setOnClickListener { viewBinding.sendDiscussion.setOnClickListener {
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
if (account.isBlank()) { if (account.isBlank()) {
showError(getString(R.string.please_login_first)) showError(getString(R.string.please_login_first))
return@setOnClickListener return@setOnClickListener
@ -481,7 +481,7 @@ class WebModInfoActivity : BaseActivity<ActivityWebModInfoBinding>() {
.setSubmitFun { button, textInputLayout, s, alertDialog -> .setSubmitFun { button, textInputLayout, s, alertDialog ->
button.isEnabled = false button.isEnabled = false
WebMod.instance.sendComment( WebMod.instance.sendComment(
appSettings.getValue(AppSettings.Setting.Token, ""), AppSettings.getValue(AppSettings.Setting.Token, ""),
modId, modId,
s, s,
object : ApiCallBack<ApiResponse> { object : ApiCallBack<ApiResponse> {
@ -509,7 +509,7 @@ class WebModInfoActivity : BaseActivity<ActivityWebModInfoBinding>() {
} }
override fun getViewBindingObject(): ActivityWebModInfoBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityWebModInfoBinding {
return ActivityWebModInfoBinding.inflate(layoutInflater) return ActivityWebModInfoBinding.inflate(layoutInflater)
} }

View File

@ -3,6 +3,7 @@ package com.coldmint.rust.pro
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.PopupMenu import android.widget.PopupMenu
import android.widget.Toast import android.widget.Toast
@ -46,13 +47,13 @@ class WorkManagementActivity : BaseActivity<ActivityWorkmangementBinding>() {
} }
override fun getViewBindingObject(): ActivityWorkmangementBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityWorkmangementBinding {
return ActivityWorkmangementBinding.inflate(layoutInflater) return ActivityWorkmangementBinding.inflate(layoutInflater)
} }
override fun onResume() { override fun onResume() {
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
if (account.isBlank()) { if (account.isBlank()) {
showErrorInView(R.string.please_login_first) showErrorInView(R.string.please_login_first)
} else { } else {
@ -175,7 +176,7 @@ class WorkManagementActivity : BaseActivity<ActivityWorkmangementBinding>() {
.positiveButton(R.string.dialog_ok) .positiveButton(R.string.dialog_ok)
.positiveButton { .positiveButton {
WebMod.instance.afreshAuditMod( WebMod.instance.afreshAuditMod(
AppSettings.getInstance(this@WorkManagementActivity) AppSettings
.getValue( .getValue(
AppSettings.Setting.Token, AppSettings.Setting.Token,
"" ""

View File

@ -90,8 +90,7 @@ class ApplicationListAdapter(
).show() ).show()
return@OnMenuItemClickListener false return@OnMenuItemClickListener false
} }
val appSettings = AppSettings.getInstance(context) val result = AppSettings.setValue(
val result = appSettings.setValue(
AppSettings.Setting.GamePackage, AppSettings.Setting.GamePackage,
data.packageName data.packageName
) )
@ -158,7 +157,7 @@ class ApplicationListAdapter(
materialDialog.setActionButtonEnabled(WhichButton.POSITIVE, false) materialDialog.setActionButtonEnabled(WhichButton.POSITIVE, false)
val gameSynchronizer = GameSynchronizer(context, data) val gameSynchronizer = GameSynchronizer(context, data)
gameSynchronizer.generateData( gameSynchronizer.generateData(
AppSettings.getInstance(context).getValue( AppSettings.getValue(
AppSettings.Setting.TemplateDirectory, AppSettings.Setting.TemplateDirectory,
context.filesDir.absolutePath + "/template/" context.filesDir.absolutePath + "/template/"
), object : GameSynchronizerListener { ), object : GameSynchronizerListener {

View File

@ -41,7 +41,7 @@ class CodeTableAdapter(
//Label点击事件 //Label点击事件
var labelFunction: ((Int, View, String) -> Unit)? = null var labelFunction: ((Int, View, String) -> Unit)? = null
private val developerMode by lazy { private val developerMode by lazy {
AppSettings.getInstance(context) AppSettings
.getValue(AppSettings.Setting.DeveloperMode, false) .getValue(AppSettings.Setting.DeveloperMode, false)
} }

View File

@ -24,7 +24,7 @@ class CommunityAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
UserInfoFragment() UserInfoFragment()
} }
else -> { else -> {
NullObjectFragment() NullFragment()
} }
} }

View File

@ -0,0 +1,53 @@
package com.coldmint.rust.pro.adapters
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.coldmint.rust.pro.fragments.InstalledTemplateFragment
import com.coldmint.rust.pro.fragments.NullFragment
import com.coldmint.rust.pro.fragments.TemplateCommunityFragment
/**
* 创建单位适配器
* @constructor
*/
class CreateUnitPageAdapter(fragmentActivity: FragmentActivity) :
FragmentStateAdapter(fragmentActivity) {
/**
* 已安装的模板碎片
*/
private val installedTemplateFragment by lazy {
InstalledTemplateFragment()
}
/**
* 设置Root目录
* @param rootPath String
*/
fun setRootPath(rootPath:String?){
installedTemplateFragment.viewModel.mRootPath = rootPath
}
/**
* 设置创建的目录
* @param createPath String
*/
fun setCreatePath(createPath :String){
return installedTemplateFragment.setCreatePath(createPath)
}
override fun getItemCount(): Int {
return 2
}
override fun createFragment(position: Int): Fragment {
return if (position == 0) {
installedTemplateFragment
} else {
TemplateCommunityFragment()
}
}
}

View File

@ -69,10 +69,10 @@ class DynamicAdapter( context: Context, dataList: MutableList<DynamicItemDataBea
GlobalMethod.copyText(context, data.content, view) GlobalMethod.copyText(context, data.content, view)
} }
context.getString(R.string.delete_title) -> { context.getString(R.string.delete_title) -> {
val account = AppSettings.getInstance(context) val account = AppSettings.
.getValue(AppSettings.Setting.Account, "") getValue(AppSettings.Setting.Account, "")
val appId = val appId =
AppSettings.getInstance(context) AppSettings
.getValue(AppSettings.Setting.AppID, "") .getValue(AppSettings.Setting.AppID, "")
Dynamic.instance.deleteDynamic( Dynamic.instance.deleteDynamic(
account, account,

View File

@ -29,13 +29,12 @@ class ErrorInfoAdapter( context: Context, dataList: ArrayList<ErrorInfo>) :
position: Int position: Int
) { ) {
viewBinding.timeView.text = data.time viewBinding.timeView.text = data.time
val des = data.describe // if (des == null || des.isBlank()) {
if (des == null || des.isBlank()) { // viewBinding.describeView.isVisible = false
viewBinding.describeView.isVisible = false // } else {
} else { // viewBinding.describeView.isVisible = true
viewBinding.describeView.isVisible = true // viewBinding.describeView.text = des
viewBinding.describeView.text = des // }
}
viewBinding.root.setOnClickListener { view -> viewBinding.root.setOnClickListener { view ->
MaterialDialog(context, BottomSheet()).show { MaterialDialog(context, BottomSheet()).show {
title(text = data.time).message(text = data.allErrorDetails) title(text = data.time).message(text = data.allErrorDetails)

View File

@ -167,7 +167,7 @@ class ModActionAdapter(
?: ".+\\.ini|.+\\.template" ?: ".+\\.ini|.+\\.template"
val codeCompiler2 = CodeCompiler2.getInstance(mContext) val codeCompiler2 = CodeCompiler2.getInstance(mContext)
val apkFolder = GameSynchronizer.getPackAgeFolder( val apkFolder = GameSynchronizer.getPackAgeFolder(
mContext, AppSettings.getInstance(mContext).getValue( mContext, AppSettings.getValue(
AppSettings.Setting.GamePackage, AppSettings.Setting.GamePackage,
GlobalMethod.DEFAULT_GAME_PACKAGE GlobalMethod.DEFAULT_GAME_PACKAGE
) )
@ -539,8 +539,7 @@ class ModActionAdapter(
private fun shareItem() { private fun shareItem() {
val file = File(mModpath) val file = File(mModpath)
if (file.isDirectory) { if (file.isDirectory) {
val appSettings = AppSettings.getInstance(mContext) val needShowTip = AppSettings.getValue(AppSettings.Setting.ShareTip, true)
val needShowTip = appSettings.getValue(AppSettings.Setting.ShareTip, true)
if (needShowTip) { if (needShowTip) {
val materialDialog = MaterialDialog(mContext, MaterialDialog.DEFAULT_BEHAVIOR) val materialDialog = MaterialDialog(mContext, MaterialDialog.DEFAULT_BEHAVIOR)
materialDialog.title(R.string.packmod, null) materialDialog.title(R.string.packmod, null)
@ -556,7 +555,7 @@ class ModActionAdapter(
R.string.no_longer_prompt, R.string.no_longer_prompt,
null null
) { materialDialog: MaterialDialog? -> ) { materialDialog: MaterialDialog? ->
appSettings.setValue(AppSettings.Setting.ShareTip, false) AppSettings.setValue(AppSettings.Setting.ShareTip, false)
packShare(file) packShare(file)
null null
} }
@ -783,7 +782,7 @@ class ModActionAdapter(
override fun run() { override fun run() {
super.run() super.run()
val main_path = val main_path =
AppSettings.getInstance(mContext).getValue(AppSettings.Setting.ModFolder, "") AppSettings.getValue(AppSettings.Setting.ModFolder, "")
val unzip_path = File( val unzip_path = File(
main_path + FileOperator.getPrefixName( main_path + FileOperator.getPrefixName(
File( File(
@ -855,17 +854,16 @@ class ModActionAdapter(
override fun whenUnzipComplete(result: Boolean) { override fun whenUnzipComplete(result: Boolean) {
if (result) { if (result) {
val appSettings = AppSettings.getInstance(mContext) val keepFile = AppSettings.getValue(AppSettings.Setting.KeepRwmodFile, true)
val keepFile = appSettings.getValue(AppSettings.Setting.KeepRwmodFile, true)
if (!keepFile) { if (!keepFile) {
val modFile = File(mModpath) val modFile = File(mModpath)
val needRecycling = appSettings.getValue( val needRecycling = AppSettings.getValue(
AppSettings.Setting.EnableRecoveryStation, AppSettings.Setting.EnableRecoveryStation,
true true
) )
if (needRecycling) { if (needRecycling) {
val removeFile: File val removeFile: File
val removePath: String = appSettings.getValue( val removePath: String = AppSettings.getValue(
AppSettings.Setting.RecoveryStationFolder, AppSettings.Setting.RecoveryStationFolder,
mContext.filesDir.absolutePath + "/backup/" mContext.filesDir.absolutePath + "/backup/"
).toString() + modFile.name ).toString() + modFile.name

View File

@ -19,21 +19,8 @@ class ModAdapter(context: Context, dataList: MutableList<ModClass>) :
BaseAdapter<ModListItemBinding, ModClass>(context, dataList) { BaseAdapter<ModListItemBinding, ModClass>(context, dataList) {
init { init {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { dataList.sortBy {
dataList.sortWith(java.util.Comparator { o1, o2 -> it.modName
val different = o1.modFile.lastModified() - o2.modFile.lastModified()
when {
different > 0 -> {
-1
}
different < 0 -> {
1
}
else -> {
0
}
}
})
} }
} }

View File

@ -8,8 +8,6 @@ import com.coldmint.rust.core.database.file.FileDataBase
//package com.coldmint.rust.core.database.file. //package com.coldmint.rust.core.database.file.
import com.coldmint.rust.pro.fragments.AllUnitsFragment import com.coldmint.rust.pro.fragments.AllUnitsFragment
import com.coldmint.rust.pro.fragments.HistoryUnitFragment import com.coldmint.rust.pro.fragments.HistoryUnitFragment
import com.coldmint.rust.pro.fragments.NullObjectFragment
import java.io.File
/** /**
* @author Cold Mint * @author Cold Mint

View File

@ -1,6 +1,7 @@
package com.coldmint.rust.pro.adapters package com.coldmint.rust.pro.adapters
import com.coldmint.rust.pro.CreateUnitActivity import android.app.Activity
import android.content.Context
import android.widget.BaseExpandableListAdapter import android.widget.BaseExpandableListAdapter
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
@ -14,18 +15,35 @@ import com.coldmint.rust.pro.TemplateParserActivity
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import com.coldmint.rust.core.TemplatePackage import com.bumptech.glide.Glide
import com.coldmint.rust.core.LocalTemplatePackage
import com.coldmint.rust.core.dataBean.template.Template
import com.coldmint.rust.core.dataBean.template.TemplatePackage
import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.pro.databinding.TemplateGroupBinding
import com.coldmint.rust.pro.databinding.TemplateItemBinding
import java.io.File import java.io.File
class TemplateAdapter( class TemplateAdapter(
private val mCreateUnitActivity:CreateUnitActivity, private val context: Context,
private val mGroup: List<TemplatePackage>, private val mGroup: List<TemplatePackage>,
private val mItemList: List<List<File>>, private val mItemList: List<List<Template>>,
mEnvironmentLanguage: String mEnvironmentLanguage: String
) : BaseExpandableListAdapter() { ) : BaseExpandableListAdapter() {
private val mInflater: LayoutInflater private val layoutInflater: LayoutInflater = LayoutInflater.from(context)
private val mEnvironmentLanguage: String private val mEnvironmentLanguage: String
private var createPath: String? = null
private val templateNum by lazy {
context.getString(R.string.template_num)
}
/**
* 设置创建目录
* @param path String
*/
fun setCreatePath(path: String) {
createPath = path
}
//父项的个数 //父项的个数
override fun getGroupCount(): Int { override fun getGroupCount(): Int {
@ -67,20 +85,14 @@ class TemplateAdapter(
parent: ViewGroup parent: ViewGroup
): View { ): View {
val convertView: View = if (view == null) { val templateGroupBinding = TemplateGroupBinding.inflate(layoutInflater, parent, false)
mInflater.inflate(R.layout.template_group, parent, false)
} else {
view
}
val nametextView = convertView.findViewById<TextView>(R.id.template_name)
val numtextView = convertView.findViewById<TextView>(R.id.template_num)
val templateClass = mGroup[groupPosition] val templateClass = mGroup[groupPosition]
nametextView.text = templateClass.getName() templateGroupBinding.templateName.text = templateClass.getName()
numtextView.text = String.format( templateGroupBinding.templateNum.text = String.format(
mCreateUnitActivity.getText(R.string.template_num).toString(), templateNum,
mItemList[groupPosition].size mItemList[groupPosition].size
) )
return convertView return templateGroupBinding.root
} }
//获取子项的view //获取子项的view
@ -91,83 +103,23 @@ class TemplateAdapter(
view: View?, view: View?,
parent: ViewGroup parent: ViewGroup
): View { ): View {
val convertView: View val templateItemBinding = TemplateItemBinding.inflate(layoutInflater, parent, false)
if (view == null) { val templateClass = mItemList[groupPosition][childPosition]
convertView = mInflater.inflate(R.layout.template_item, parent, false) templateItemBinding.nameView.text = templateClass.getName(mEnvironmentLanguage)
val icon = templateClass.getIcon()
if (icon == null) {
Glide.with(context).load(R.drawable.template).into(templateItemBinding.templateIconView)
} else { } else {
convertView = view Glide.with(context).load(templateClass.getIcon())
.into(templateItemBinding.templateIconView)
} }
val templateClass = mGroup[groupPosition] templateItemBinding.root.setOnClickListener {
var child: JSONObject? = null val intent = Intent(context, TemplateParserActivity::class.java)
try { intent.putExtra("link", templateClass.getLink())
val s = FileOperator.readFile(mItemList[groupPosition][childPosition]) intent.putExtra("isLocal", templateClass.isLocal())
child = JSONObject(s) context.startActivity(intent)
} catch (exception: JSONException) {
exception.printStackTrace()
} }
if (child == null) { return templateItemBinding.root
return convertView
}
val textView = convertView.findViewById<TextView>(R.id.name_view)
val imageView = convertView.findViewById<ImageView>(R.id.template_icon_view)
val rootFolder = templateClass.directest.absolutePath + "/"
try {
if (child.has("name_$mEnvironmentLanguage")) {
textView.text = child.getString("name_$mEnvironmentLanguage")
} else {
textView.text = child.getString("name")
}
} catch (exception: JSONException) {
exception.printStackTrace()
}
if (child.has("icon")) {
try {
val iconFile = File(rootFolder + child.getString("icon"))
if (iconFile.exists()) {
val bitmap = BitmapFactory.decodeFile(iconFile.absolutePath)
imageView.setImageBitmap(bitmap)
}
} catch (exception: JSONException) {
exception.printStackTrace()
}
}
/*String modIcon = null;
String globalIcon = templateClass.getIconPath();
if (!globalIcon.isEmpty()) {
File file = new File(rootFolder + globalIcon);
if (file.exists()) {
modIcon = file.getAbsolutePath();
}
}
String icon = null;
try {
icon = child.getString("icon");
} catch (JSONException exception) {
exception.printStackTrace();
}
if (!icon.isEmpty()) {
File file = new File(rootFolder + icon);
if (file.exists()) {
modIcon = file.getAbsolutePath();
}
}
if (modIcon != null) {
imageView.setImageBitmap(BitmapFactory.decodeFile(modIcon));
}*/
val finalChild: JSONObject = child
convertView.setOnClickListener {
val intent = Intent(mCreateUnitActivity, TemplateParserActivity::class.java)
val bundle = Bundle()
bundle.putString("path", mCreateUnitActivity.getmCreatePath())
bundle.putString("rootFolder", rootFolder)
bundle.putString("json", finalChild.toString())
bundle.putString("templatePath", templateClass.directest.absolutePath)
intent.putExtra("data", bundle)
mCreateUnitActivity.startActivityForResult(intent, 2)
}
return convertView
} }
//子项是否可选中,如果要设置子项的点击事件,需要返回true //子项是否可选中,如果要设置子项的点击事件,需要返回true
@ -176,7 +128,6 @@ class TemplateAdapter(
} }
init { init {
mInflater = LayoutInflater.from(mCreateUnitActivity)
this.mEnvironmentLanguage = mEnvironmentLanguage this.mEnvironmentLanguage = mEnvironmentLanguage
} }
} }

View File

@ -12,7 +12,7 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.coldmint.rust.core.CompressionManager import com.coldmint.rust.core.CompressionManager
import com.coldmint.rust.core.TemplatePackage import com.coldmint.rust.core.LocalTemplatePackage
import com.coldmint.rust.core.interfaces.CompressionListener import com.coldmint.rust.core.interfaces.CompressionListener
import com.coldmint.rust.core.tool.AppOperator import com.coldmint.rust.core.tool.AppOperator
import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.tool.FileOperator
@ -26,20 +26,20 @@ import java.io.File
class TemplateListAdapter( class TemplateListAdapter(
context: Context, context: Context,
dataList: ArrayList<TemplatePackage>, dataList: ArrayList<LocalTemplatePackage>,
private val language: String, private val language: String,
private val rootPath: String private val rootPath: String
) : BaseAdapter<TemplateListItemBinding, TemplatePackage>(context, dataList) { ) : BaseAdapter<TemplateListItemBinding, LocalTemplatePackage>(context, dataList) {
/** /**
* 编辑信息 * 编辑信息
* @param context Context * @param context Context
* @param templatePackage TemplatePackage * @param localTemplatePackage LocalTemplatePackage
*/ */
private fun editInfo(context: Context, templatePackage: TemplatePackage) { private fun editInfo(context: Context, localTemplatePackage: LocalTemplatePackage) {
val bundle = Bundle() val bundle = Bundle()
bundle.putString("json", FileOperator.readFile(templatePackage.infoFile)) bundle.putString("json", FileOperator.readFile(localTemplatePackage.infoFile))
bundle.putString("path", templatePackage.infoFile.absolutePath) bundle.putString("path", localTemplatePackage.infoFile.absolutePath)
val intent = Intent(context, CreateTemplateActivity::class.java) val intent = Intent(context, CreateTemplateActivity::class.java)
intent.putExtra("data", bundle) intent.putExtra("data", bundle)
context.startActivity(intent) context.startActivity(intent)
@ -48,9 +48,9 @@ class TemplateListAdapter(
/** /**
* 点击了分享 * 点击了分享
* @param context Context * @param context Context
* @param templatePackage TemplatePackage * @param localTemplatePackage LocalTemplatePackage
*/ */
private fun share(context: Context, templatePackage: TemplatePackage) { private fun share(context: Context, localTemplatePackage: LocalTemplatePackage) {
val materialDialog = MaterialDialog(context) val materialDialog = MaterialDialog(context)
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
Thread { Thread {
@ -61,7 +61,7 @@ class TemplateListAdapter(
} }
val toFile = val toFile =
File( File(
cacheDirectory.absolutePath + "/" + templatePackage.getName() + "_" + templatePackage.getInfo()?.versionName + ".rp" cacheDirectory.absolutePath + "/" + localTemplatePackage.getName() + "_" + localTemplatePackage.getInfo()?.versionName + ".rp"
) )
if (toFile.exists()) { if (toFile.exists()) {
toFile.delete() toFile.delete()
@ -75,7 +75,7 @@ class TemplateListAdapter(
CompressionManager.instance CompressionManager.instance
compressionManager.compression( compressionManager.compression(
templatePackage.directest, localTemplatePackage.directest,
toFile, toFile,
object : CompressionListener { object : CompressionListener {
override fun whenCompressionFile(file: File): Boolean { override fun whenCompressionFile(file: File): Boolean {
@ -108,7 +108,7 @@ class TemplateListAdapter(
title(R.string.share_mod).message( title(R.string.share_mod).message(
text = String.format( text = String.format(
context.getString(R.string.pack_success), context.getString(R.string.pack_success),
templatePackage.getName() localTemplatePackage.getName()
) )
).positiveButton(R.string.share) { ).positiveButton(R.string.share) {
FileOperator.shareFile( FileOperator.shareFile(
@ -135,9 +135,9 @@ class TemplateListAdapter(
/** /**
* 点击了导出文件 * 点击了导出文件
* @param context Context * @param context Context
* @param templatePackage TemplatePackage * @param localTemplatePackage LocalTemplatePackage
*/ */
private fun exportFile(context: Context, templatePackage: TemplatePackage) { private fun exportFile(context: Context, localTemplatePackage: LocalTemplatePackage) {
val materialDialog = MaterialDialog(context) val materialDialog = MaterialDialog(context)
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
Thread { Thread {
@ -148,7 +148,7 @@ class TemplateListAdapter(
} }
val toFile = val toFile =
File( File(
cacheDirectory.absolutePath + "/" + templatePackage.getName() + "_" + templatePackage.getInfo()?.versionName + ".rp" cacheDirectory.absolutePath + "/" + localTemplatePackage.getName() + "_" + localTemplatePackage.getInfo()?.versionName + ".rp"
) )
if (toFile.exists()) { if (toFile.exists()) {
toFile.delete() toFile.delete()
@ -162,7 +162,7 @@ class TemplateListAdapter(
CompressionManager.instance CompressionManager.instance
compressionManager.compression( compressionManager.compression(
templatePackage.directest, localTemplatePackage.directest,
toFile, toFile,
object : CompressionListener { object : CompressionListener {
override fun whenCompressionFile(file: File): Boolean { override fun whenCompressionFile(file: File): Boolean {
@ -195,7 +195,7 @@ class TemplateListAdapter(
title(R.string.export_file).message( title(R.string.export_file).message(
text = String.format( text = String.format(
context.getString(R.string.pack_success2), context.getString(R.string.pack_success2),
templatePackage.getName() localTemplatePackage.getName()
) )
).positiveButton(R.string.export) { ).positiveButton(R.string.export) {
val intent = val intent =
@ -246,7 +246,7 @@ class TemplateListAdapter(
} }
override fun onBingView( override fun onBingView(
data: TemplatePackage, data: LocalTemplatePackage,
viewBinding: TemplateListItemBinding, viewBinding: TemplateListItemBinding,
viewHolder: ViewHolder<TemplateListItemBinding>, viewHolder: ViewHolder<TemplateListItemBinding>,
position: Int position: Int

View File

@ -24,7 +24,7 @@ class UnitAdapter(
) : BaseAdapter<UnitItemBinding, SourceFile>(context, dataList) { ) : BaseAdapter<UnitItemBinding, SourceFile>(context, dataList) {
private val language: String by lazy { private val language: String by lazy {
AppSettings.getInstance(context).getValue( AppSettings.getValue(
AppSettings.Setting.AppLanguage, AppSettings.Setting.AppLanguage,
Locale.getDefault().language Locale.getDefault().language
) )

View File

@ -1,11 +1,9 @@
package com.coldmint.rust.pro.adapters package com.coldmint.rust.pro.adapters
import android.app.Activity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import com.coldmint.rust.pro.fragments.DynamicFragment import com.coldmint.rust.pro.fragments.DynamicFragment
import com.coldmint.rust.pro.fragments.NullObjectFragment
import com.coldmint.rust.pro.fragments.PersonalHomeFragment import com.coldmint.rust.pro.fragments.PersonalHomeFragment
class UserHomeStateAdapter(activity: FragmentActivity, val userId: String) : class UserHomeStateAdapter(activity: FragmentActivity, val userId: String) :

View File

@ -22,7 +22,7 @@ class WarehouseAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
MapFragment() MapFragment()
} }
else -> { else -> {
NullObjectFragment() NullFragment()
} }
} }
} }

View File

@ -0,0 +1,46 @@
package com.coldmint.rust.pro.adapters
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.coldmint.rust.core.dataBean.webTemplate.WebTemplatePackageListData
import com.coldmint.rust.pro.R
import com.coldmint.rust.pro.base.BaseAdapter
import com.coldmint.rust.pro.databinding.ItemWebTemplateBinding
import me.zhanghai.android.fastscroll.PopupTextProvider
/**
* 网络模板适配器
* @constructor
*/
class WebTemplateAdapter(context: Context, dataList: MutableList<WebTemplatePackageListData.Data>) :
BaseAdapter<ItemWebTemplateBinding, WebTemplatePackageListData.Data>(context, dataList),
PopupTextProvider {
override fun getViewBindingObject(
layoutInflater: LayoutInflater,
parent: ViewGroup,
viewType: Int
): ItemWebTemplateBinding {
return ItemWebTemplateBinding.inflate(layoutInflater, parent, false)
}
override fun onBingView(
data: WebTemplatePackageListData.Data,
viewBinding: ItemWebTemplateBinding,
viewHolder: ViewHolder<ItemWebTemplateBinding>,
position: Int
) {
viewBinding.titleView.text = data.name
viewBinding.describeView.text = data.describe
viewBinding.infoView.text = data.modificationTime
if (data.subscribe){
viewBinding.button.setText(R.string.de_subscription)
}else{
viewBinding.button.setText(R.string.subscription)
}
}
override fun getPopupText(position: Int): String {
return getInitial(dataList[position].name).toString()
}
}

View File

@ -5,6 +5,7 @@ import android.content.res.Configuration
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.AppSettings
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
@ -33,16 +34,13 @@ abstract class BaseActivity<ViewBingType : ViewBinding> :
abstract fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) abstract fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean)
abstract fun getViewBindingObject(): ViewBingType abstract fun getViewBindingObject(layoutInflater: LayoutInflater): ViewBingType
protected val viewBinding: ViewBingType by lazy { protected val viewBinding: ViewBingType by lazy {
getViewBindingObject() getViewBindingObject(LayoutInflater.from(this))
} }
protected val appSettings: AppSettings by lazy {
AppSettings.getInstance(this)
}
protected val inputMethodManager: InputMethodManager by lazy { protected val inputMethodManager: InputMethodManager by lazy {
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
} }

View File

@ -10,12 +10,12 @@ import androidx.viewbinding.ViewBinding
import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.AppSettings
abstract class BaseFragment<T : ViewBinding> : Fragment() { abstract class BaseFragment<T : ViewBinding> : Fragment() {
protected lateinit var appSettings: AppSettings
val viewBinding: T by lazy { val viewBinding: T by lazy {
getViewBindingObject() getViewBindingObject(layoutInflater)
} }
/** /**
* 显示Toast * 显示Toast
* @param text String * @param text String
@ -39,7 +39,7 @@ abstract class BaseFragment<T : ViewBinding> : Fragment() {
/** /**
* 获取视图绑定对象 * 获取视图绑定对象
*/ */
abstract fun getViewBindingObject(): T abstract fun getViewBindingObject(layoutInflater: LayoutInflater): T
override fun onCreateView( override fun onCreateView(
@ -47,7 +47,6 @@ abstract class BaseFragment<T : ViewBinding> : Fragment() {
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
appSettings = AppSettings.getInstance(requireContext())
return viewBinding.root return viewBinding.root
} }

View File

@ -22,10 +22,10 @@ data class ErrorInfo(
val id: String = UUID.randomUUID().toString(), val id: String = UUID.randomUUID().toString(),
var allErrorDetails: String = "", var allErrorDetails: String = "",
var activityLog: String? = null, var activityLog: String? = null,
var describe: String? = null, var autoSave: Boolean = true,
var autoSave: Boolean = true
) { ) {
/** /**
* 保存ErrorInfo * 保存ErrorInfo
* @return Boolean * @return Boolean

View File

@ -42,7 +42,7 @@ class RustAutoComplete2(val context: Context) : AutoCompleteProvider, EnglishMod
tem tem
} }
private val identifiersPromptNumber: Int by lazy { private val identifiersPromptNumber: Int by lazy {
AppSettings.getInstance(context).getValue(AppSettings.Setting.IdentifiersPromptNumber, 40) AppSettings.getValue(AppSettings.Setting.IdentifiersPromptNumber, 40)
} }
//类型转换器 //类型转换器

View File

@ -89,7 +89,7 @@ class AllUnitsFragment(
val funData: () -> Unit = { val funData: () -> Unit = {
val path = file.file.absolutePath val path = file.file.absolutePath
val name = file.getName( val name = file.getName(
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.AppLanguage, AppSettings.Setting.AppLanguage,
Locale.getDefault().language Locale.getDefault().language
) )
@ -240,7 +240,7 @@ class AllUnitsFragment(
dataList.clear() dataList.clear()
val data = modClass.modConfigurationManager?.readData() val data = modClass.modConfigurationManager?.readData()
val sourceFileFilteringRule = data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template" val sourceFileFilteringRule = data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template"
val language = AppSettings.getInstance(requireContext()) val language = AppSettings
.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) .getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
val fileFinder2 = FileFinder2(file) val fileFinder2 = FileFinder2(file)
fileFinder2.findMode = true fileFinder2.findMode = true
@ -332,7 +332,7 @@ class AllUnitsFragment(
notFindUnits(handler) notFindUnits(handler)
} else { } else {
val newList = ArrayList<SourceFile>() val newList = ArrayList<SourceFile>()
val language = AppSettings.getInstance(requireContext()) val language = AppSettings
.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) .getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
dataList.forEach { dataList.forEach {
if (it.getName(language).contains(key)) { if (it.getName(language).contains(key)) {
@ -370,7 +370,7 @@ class AllUnitsFragment(
} }
} }
override fun getViewBindingObject(): FragmentAllUnitsBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentAllUnitsBinding {
return FragmentAllUnitsBinding.inflate(layoutInflater) return FragmentAllUnitsBinding.inflate(layoutInflater)
} }

View File

@ -51,7 +51,7 @@ class CommunityFragment : BaseFragment<CommunityFragmentBinding>() {
} }
override fun getViewBindingObject(): CommunityFragmentBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): CommunityFragmentBinding {
return CommunityFragmentBinding.inflate(layoutInflater) return CommunityFragmentBinding.inflate(layoutInflater)
} }

View File

@ -34,7 +34,7 @@ class DatabaseFragment : BaseFragment<DatabaseFragmentBinding>() {
override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
viewBinding.databaseList.layoutManager = LinearLayoutManager(requireContext()) viewBinding.databaseList.layoutManager = LinearLayoutManager(requireContext())
val database_directory = appSettings.getValue( val database_directory = AppSettings.getValue(
AppSettings.Setting.DatabaseDirectory, AppSettings.Setting.DatabaseDirectory,
requireContext().filesDir.absolutePath + "/database/" requireContext().filesDir.absolutePath + "/database/"
) )
@ -151,7 +151,7 @@ class DatabaseFragment : BaseFragment<DatabaseFragmentBinding>() {
} }
override fun getViewBindingObject(): DatabaseFragmentBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): DatabaseFragmentBinding {
return DatabaseFragmentBinding.inflate(layoutInflater) return DatabaseFragmentBinding.inflate(layoutInflater)
} }
} }

View File

@ -52,7 +52,7 @@ class DynamicFragment(val userId: String) : BaseFragment<FragmentDynamicBinding>
} }
override fun getViewBindingObject(): FragmentDynamicBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentDynamicBinding {
return FragmentDynamicBinding.inflate(layoutInflater) return FragmentDynamicBinding.inflate(layoutInflater)
} }

View File

@ -29,7 +29,7 @@ import com.coldmint.rust.pro.tool.AppSettings
*/ */
class FollowFragment : BaseFragment<FragmentFollowBinding>() { class FollowFragment : BaseFragment<FragmentFollowBinding>() {
val selfAccount by lazy { val selfAccount by lazy {
appSettings.getValue(AppSettings.Setting.Account, "") AppSettings.getValue(AppSettings.Setting.Account, "")
} }
var oldSize: Int = 0 var oldSize: Int = 0
var lastIndex = 0 var lastIndex = 0
@ -212,7 +212,7 @@ class FollowFragment : BaseFragment<FragmentFollowBinding>() {
} }
} }
override fun getViewBindingObject(): FragmentFollowBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentFollowBinding {
return FragmentFollowBinding.inflate(layoutInflater) return FragmentFollowBinding.inflate(layoutInflater)
} }

View File

@ -111,7 +111,7 @@ class HistoryUnitFragment(
val bundle = Bundle() val bundle = Bundle()
val path = file.file.absolutePath val path = file.file.absolutePath
// val name = fileClass.getName( // val name = fileClass.getName(
// appSettings.getValue( // AppSettings.getValue(
// AppSettings.Setting.AppLanguage, // AppSettings.Setting.AppLanguage,
// Locale.getDefault().language // Locale.getDefault().language
// ) // )
@ -140,7 +140,7 @@ class HistoryUnitFragment(
} }
} }
override fun getViewBindingObject(): FragmentHistoryBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentHistoryBinding {
return FragmentHistoryBinding.inflate(layoutInflater) return FragmentHistoryBinding.inflate(layoutInflater)
} }
} }

View File

@ -0,0 +1,132 @@
package com.coldmint.rust.pro.fragments
import android.content.Intent
import android.os.Bundle
import android.os.Environment
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.widget.AdapterView
import android.widget.ExpandableListView
import android.widget.TextView
import androidx.lifecycle.MutableLiveData
import com.coldmint.dialog.CoreDialog
import com.coldmint.rust.core.LocalTemplatePackage
import com.coldmint.rust.core.dataBean.template.LocalTemplateFile
import com.coldmint.rust.core.dataBean.template.Template
import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.pro.FileManagerActivity
import com.coldmint.rust.pro.R
import com.coldmint.rust.pro.adapters.TemplateAdapter
import com.coldmint.rust.pro.base.BaseFragment
import com.coldmint.rust.pro.databinding.FragmentInstalledTemplateBinding
import com.coldmint.rust.pro.tool.AppSettings
import com.coldmint.rust.pro.viewmodel.InstalledTemplateViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.json.JSONException
import org.json.JSONObject
import java.io.File
import java.util.*
class InstalledTemplateFragment : BaseFragment<FragmentInstalledTemplateBinding>() {
val viewModel: InstalledTemplateViewModel by lazy {
InstalledTemplateViewModel()
}
var mTemplateAdapter: TemplateAdapter? = null
/**
* 设置创建目录
* @param createPath String
* @return Boolean 是否设置成功
*/
fun setCreatePath(createPath: String) {
viewModel.createPathLiveData.value = createPath
}
fun initAction() {
viewBinding.selectPathButton.setOnClickListener {
val createPath = viewModel.createPathLiveData.value
val bundle = Bundle()
val intent = Intent(requireContext(), FileManagerActivity::class.java)
bundle.putString("type", "selectDirectents")
bundle.putString("path", createPath)
bundle.putString("rootpath", viewModel.mRootPath)
intent.putExtra("data", bundle)
startActivityForResult(intent, 1)
}
//长按监听
viewBinding.expandableList.onItemLongClickListener =
AdapterView.OnItemLongClickListener { parent, view, flatPos, l -> //得到点击的父位置,子位置
val packedPos = (parent as ExpandableListView).getExpandableListPosition(flatPos)
val groupPosition = ExpandableListView.getPackedPositionGroup(packedPos)
val childPosition = ExpandableListView.getPackedPositionChild(packedPos)
if (childPosition == -1) { //长按的是父项
//这里做关于父项的相关操作......
val numView = view.findViewById<TextView>(R.id.template_num)
val templateClass =
mTemplateAdapter!!.getGroup(groupPosition) as LocalTemplatePackage
CoreDialog(requireContext()).setTitle(R.string.template_info)
.setMessage(
templateClass.getInfo()?.description
?: requireContext().getString(R.string.describe)
).setCancelable(false).setPositiveButton(R.string.delete_title) {
numView.setText(R.string.del_moding)
val handler = Handler(Looper.getMainLooper())
val scope = CoroutineScope(Job())
scope.launch {
FileOperator.delete_files(templateClass.directest)
handler.post {
viewModel.loadTemplate(requireContext())
}
}
}.setNegativeButton(R.string.dialog_cancel) {
}.show()
} else { //长按的是子项
//这里做关于子项的相关操作.......
}
true
}
}
override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
initAction()
viewModel.createPathLiveData.observe(this) {
var relativePath = FileOperator.getRelativePath(
it,
AppSettings.getValue(
AppSettings.Setting.ModFolder,
Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/"
)
)
if (relativePath == null) {
relativePath = it
}
viewBinding.unitPathView.text = String.format(
(requireContext().getText(R.string.unit_path) as String),
relativePath
)
mTemplateAdapter?.setCreatePath(it)
}
viewModel.setLoadCallBack {
mTemplateAdapter = TemplateAdapter(
requireContext(),
viewModel.getGroupData(),
viewModel.getItemData(),
viewModel.environmentLanguage
)
viewBinding.expandableList.setAdapter(mTemplateAdapter!!)
}
viewModel.loadTemplate(requireContext())
}
override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentInstalledTemplateBinding {
return FragmentInstalledTemplateBinding.inflate(layoutInflater)
}
}

View File

@ -131,7 +131,7 @@ class MapFragment : BaseFragment<FragmentMapBinding>() {
viewBinding.mapErrorIcon.isVisible = true viewBinding.mapErrorIcon.isVisible = true
} }
override fun getViewBindingObject(): FragmentMapBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentMapBinding {
return FragmentMapBinding.inflate(layoutInflater) return FragmentMapBinding.inflate(layoutInflater)
} }
@ -143,7 +143,7 @@ class MapFragment : BaseFragment<FragmentMapBinding>() {
DividerItemDecoration.VERTICAL DividerItemDecoration.VERTICAL
) )
) )
val path = appSettings.getValue(AppSettings.Setting.MapFolder, "") val path = AppSettings.getValue(AppSettings.Setting.MapFolder, "")
if (path.isNotBlank()) { if (path.isNotBlank()) {
loadPath(File(path)) loadPath(File(path))
} }

View File

@ -41,7 +41,7 @@ class ModFragment : BaseFragment<ModFragmentBinding>() {
lateinit var modAdapter: ModAdapter lateinit var modAdapter: ModAdapter
val needRecycling by lazy { val needRecycling by lazy {
if (GlobalMethod.isActive) { if (GlobalMethod.isActive) {
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.EnableRecoveryStation, AppSettings.Setting.EnableRecoveryStation,
true true
) )
@ -64,7 +64,7 @@ class ModFragment : BaseFragment<ModFragmentBinding>() {
viewBinding.modList.isVisible = false viewBinding.modList.isVisible = false
} }
} }
val mod_directory = File(appSettings.getValue(AppSettings.Setting.ModFolder, "")) val mod_directory = File(AppSettings.getValue(AppSettings.Setting.ModFolder, ""))
if (!mod_directory.exists()) { if (!mod_directory.exists()) {
mod_directory.mkdirs() mod_directory.mkdirs()
} }
@ -93,6 +93,7 @@ class ModFragment : BaseFragment<ModFragmentBinding>() {
handler.post { loadMods() } handler.post { loadMods() }
} }
} }
// modAdapter.
modAdapter.setItemEvent { i, modListItemBinding, viewHolder, modClass -> modAdapter.setItemEvent { i, modListItemBinding, viewHolder, modClass ->
modListItemBinding.root.setOnClickListener { modListItemBinding.root.setOnClickListener {
onClickItemWork(modListItemBinding, modClass) onClickItemWork(modListItemBinding, modClass)
@ -167,7 +168,7 @@ class ModFragment : BaseFragment<ModFragmentBinding>() {
val removePath: String val removePath: String
val removeFile: File val removeFile: File
if (targetFile.isDirectory) { if (targetFile.isDirectory) {
removePath = appSettings.getValue( removePath = AppSettings.getValue(
AppSettings.Setting.RecoveryStationFolder, AppSettings.Setting.RecoveryStationFolder,
requireContext().filesDir.absolutePath + "/backup/" requireContext().filesDir.absolutePath + "/backup/"
).toString() + targetFile.name + "/" ).toString() + targetFile.name + "/"
@ -176,7 +177,7 @@ class ModFragment : BaseFragment<ModFragmentBinding>() {
removeFile.mkdirs() removeFile.mkdirs()
} }
} else { } else {
removePath = appSettings.getValue( removePath = AppSettings.getValue(
AppSettings.Setting.RecoveryStationFolder, AppSettings.Setting.RecoveryStationFolder,
requireContext().filesDir.absolutePath + "/backup/" requireContext().filesDir.absolutePath + "/backup/"
).toString() + targetFile.name ).toString() + targetFile.name
@ -269,7 +270,7 @@ class ModFragment : BaseFragment<ModFragmentBinding>() {
configurationManager?.readData() configurationManager?.readData()
val works: MutableList<String> = ArrayList() val works: MutableList<String> = ArrayList()
if (modClass.modFile.isDirectory) { if (modClass.modFile.isDirectory) {
val developerMode = appSettings.getValue(AppSettings.Setting.DeveloperMode, false) val developerMode = AppSettings.getValue(AppSettings.Setting.DeveloperMode, false)
if (developerMode) { if (developerMode) {
works.add(getString(R.string.generate_error_report)) works.add(getString(R.string.generate_error_report))
} }
@ -356,7 +357,7 @@ class ModFragment : BaseFragment<ModFragmentBinding>() {
viewBinding.progressBar.isVisible = false viewBinding.progressBar.isVisible = false
} }
override fun getViewBindingObject(): ModFragmentBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): ModFragmentBinding {
return ModFragmentBinding.inflate(layoutInflater) return ModFragmentBinding.inflate(layoutInflater)
} }

View File

@ -6,10 +6,12 @@ import com.coldmint.rust.pro.base.BaseFragment
import com.coldmint.rust.pro.databinding.FragmentNullBinding import com.coldmint.rust.pro.databinding.FragmentNullBinding
//该类的实例是表示集合中单个对象的片段。 /**
class NullObjectFragment : BaseFragment<FragmentNullBinding>() { * 没有内容的碎片
*/
class NullFragment : BaseFragment<FragmentNullBinding>() {
override fun getViewBindingObject(): FragmentNullBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentNullBinding {
return FragmentNullBinding.inflate(layoutInflater) return FragmentNullBinding.inflate(layoutInflater)
} }

View File

@ -23,7 +23,7 @@ import com.coldmint.rust.pro.databinding.FragmentPersonalHomeBinding
*/ */
class PersonalHomeFragment(val userId: String) : BaseFragment<FragmentPersonalHomeBinding>() { class PersonalHomeFragment(val userId: String) : BaseFragment<FragmentPersonalHomeBinding>() {
override fun getViewBindingObject(): FragmentPersonalHomeBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentPersonalHomeBinding {
return FragmentPersonalHomeBinding.inflate(LayoutInflater.from(requireContext())) return FragmentPersonalHomeBinding.inflate(LayoutInflater.from(requireContext()))
} }

View File

@ -123,7 +123,7 @@ class RankingFragment : BaseFragment<FragmentRankingBinding>() {
} }
override fun getViewBindingObject(): FragmentRankingBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentRankingBinding {
return FragmentRankingBinding.inflate(layoutInflater) return FragmentRankingBinding.inflate(layoutInflater)
} }
} }

View File

@ -97,7 +97,7 @@ class RecommendedFragment : BaseFragment<RecommendedFragmentBinding>() {
fun loadSoleRecommended() { fun loadSoleRecommended() {
viewBinding.soleRecommendedCardView.isVisible = false viewBinding.soleRecommendedCardView.isVisible = false
viewBinding.soleRecommendedProgressIndicator.isVisible = true viewBinding.soleRecommendedProgressIndicator.isVisible = true
val account = appSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
if (account.isNotBlank()) { if (account.isNotBlank()) {
WebMod.instance.soleRecommended(account, object : ApiCallBack<WebModListData> { WebMod.instance.soleRecommended(account, object : ApiCallBack<WebModListData> {
override fun onResponse(t: WebModListData) { override fun onResponse(t: WebModListData) {
@ -132,7 +132,7 @@ class RecommendedFragment : BaseFragment<RecommendedFragmentBinding>() {
val dataList = t.data val dataList = t.data
if (dataList != null && dataList.isNotEmpty()) { if (dataList != null && dataList.isNotEmpty()) {
val forever = val forever =
appSettings.getValue( AppSettings.getValue(
AppSettings.Setting.ExpirationTime, AppSettings.Setting.ExpirationTime,
0.toLong() 0.toLong()
) == (-2).toLong() ) == (-2).toLong()
@ -221,7 +221,7 @@ class RecommendedFragment : BaseFragment<RecommendedFragmentBinding>() {
loadBannerData() loadBannerData()
} }
override fun getViewBindingObject(): RecommendedFragmentBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): RecommendedFragmentBinding {
return RecommendedFragmentBinding.inflate(layoutInflater) return RecommendedFragmentBinding.inflate(layoutInflater)
} }

View File

@ -44,7 +44,7 @@ class SearchResultFragment(
return list return list
} }
override fun getViewBindingObject(): FragmentSearchResultBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentSearchResultBinding {
return FragmentSearchResultBinding.inflate(layoutInflater) return FragmentSearchResultBinding.inflate(layoutInflater)
} }
} }

View File

@ -0,0 +1,66 @@
package com.coldmint.rust.pro.fragments
import android.os.Bundle
import android.view.LayoutInflater
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.coldmint.rust.core.dataBean.webTemplate.WebTemplatePackageListData
import com.coldmint.rust.core.interfaces.ApiCallBack
import com.coldmint.rust.core.web.TemplatePhp
import com.coldmint.rust.pro.adapters.WebTemplateAdapter
import com.coldmint.rust.pro.base.BaseFragment
import com.coldmint.rust.pro.databinding.FragmentTemplateCommunityBinding
import com.coldmint.rust.pro.tool.AppSettings
import me.zhanghai.android.fastscroll.FastScrollerBuilder
/**
* 模板社区
*/
class TemplateCommunityFragment : BaseFragment<FragmentTemplateCommunityBinding>() {
val token = AppSettings.getValue(AppSettings.Setting.Token, "")
override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
viewBinding.recyclerView.addItemDecoration(
DividerItemDecoration(
requireContext(),
DividerItemDecoration.VERTICAL
)
)
viewBinding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
loadData()
viewBinding.swipeRefreshLayout.setOnRefreshListener {
loadData()
viewBinding.swipeRefreshLayout.isRefreshing = false
}
}
fun loadData() {
TemplatePhp.instance.getPublicTemplatePackageList(token, object :
ApiCallBack<WebTemplatePackageListData> {
override fun onResponse(t: WebTemplatePackageListData) {
viewBinding.swipeRefreshLayout.isVisible = true
viewBinding.loadView.isVisible = false
viewBinding.errorLayout.isVisible = false
val adapter = WebTemplateAdapter(requireContext(), t.data)
viewBinding.recyclerView.adapter = adapter
FastScrollerBuilder(viewBinding.recyclerView).useMd2Style()
.setPopupTextProvider(adapter).build()
}
override fun onFailure(e: Exception) {
e.printStackTrace()
viewBinding.loadView.isVisible = false
viewBinding.errorLayout.isVisible = true
viewBinding.swipeRefreshLayout.isVisible = false
}
})
}
override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentTemplateCommunityBinding {
return FragmentTemplateCommunityBinding.inflate(layoutInflater)
}
}

View File

@ -6,8 +6,7 @@ import android.os.Bundle
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.AppSettings
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener import com.coldmint.rust.core.LocalTemplatePackage
import com.coldmint.rust.core.TemplatePackage
import com.coldmint.rust.pro.adapters.TemplateListAdapter import com.coldmint.rust.pro.adapters.TemplateListAdapter
import com.coldmint.rust.pro.base.BaseFragment import com.coldmint.rust.pro.base.BaseFragment
import com.coldmint.rust.pro.databinding.TemplateFragemntBinding import com.coldmint.rust.pro.databinding.TemplateFragemntBinding
@ -21,7 +20,7 @@ class TemplateFragment : BaseFragment<TemplateFragemntBinding>() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (!first) { if (!first) {
val directent = appSettings.getValue( val directent = AppSettings.getValue(
AppSettings.Setting.TemplateDirectory, AppSettings.Setting.TemplateDirectory,
requireContext().filesDir.absolutePath + "/template/" requireContext().filesDir.absolutePath + "/template/"
) )
@ -33,13 +32,13 @@ class TemplateFragment : BaseFragment<TemplateFragemntBinding>() {
fun loadList(path: String) { fun loadList(path: String) {
val language = val language =
appSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) AppSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
val file = File(path) val file = File(path)
if (file.exists() && file.isDirectory) { if (file.exists() && file.isDirectory) {
val files = file.listFiles() val files = file.listFiles()
val mutableList: ArrayList<TemplatePackage> = ArrayList() val mutableList: ArrayList<LocalTemplatePackage> = ArrayList()
for (f in files) { for (f in files) {
val tem = TemplatePackage(f) val tem = LocalTemplatePackage(f)
if (tem.isTemplate) { if (tem.isTemplate) {
mutableList.add(tem) mutableList.add(tem)
} }
@ -60,12 +59,12 @@ class TemplateFragment : BaseFragment<TemplateFragemntBinding>() {
} }
} }
override fun getViewBindingObject(): TemplateFragemntBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): TemplateFragemntBinding {
return TemplateFragemntBinding.inflate(layoutInflater) return TemplateFragemntBinding.inflate(layoutInflater)
} }
override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
val directent = appSettings.getValue( val directent = AppSettings.getValue(
AppSettings.Setting.TemplateDirectory, AppSettings.Setting.TemplateDirectory,
requireContext().filesDir.absolutePath + "/template/" requireContext().filesDir.absolutePath + "/template/"
) )

View File

@ -95,14 +95,14 @@ class UserInfoFragment : BaseFragment<FragmentUserInfoBinding>() {
startActivity(intent) startActivity(intent)
} }
override fun getViewBindingObject(): FragmentUserInfoBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentUserInfoBinding {
return FragmentUserInfoBinding.inflate(layoutInflater) return FragmentUserInfoBinding.inflate(layoutInflater)
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
val token = appSettings.getValue(AppSettings.Setting.Token, "") val token = AppSettings.getValue(AppSettings.Setting.Token, "")
if (token.isNotBlank()) { if (token.isNotBlank()) {
User.getUserActivationInfo(token, object : ApiCallBack<ActivationInfo> { User.getUserActivationInfo(token, object : ApiCallBack<ActivationInfo> {
@ -110,7 +110,7 @@ class UserInfoFragment : BaseFragment<FragmentUserInfoBinding>() {
viewBinding.nameView.text = account viewBinding.nameView.text = account
loadRecyclerView(3) loadRecyclerView(3)
// val localTime = // val localTime =
// appSettings.getValue(AppSettings.Setting.ExpirationTime, 0.toLong()) // AppSettings.getValue(AppSettings.Setting.ExpirationTime, 0.toLong())
// viewBinding.expirationTimeView.text = // viewBinding.expirationTimeView.text =
// ServerConfiguration.toStringTime(localTime) // ServerConfiguration.toStringTime(localTime)
} }
@ -138,7 +138,7 @@ class UserInfoFragment : BaseFragment<FragmentUserInfoBinding>() {
} }
override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
account = appSettings.getValue(AppSettings.Setting.Account, "") account = AppSettings.getValue(AppSettings.Setting.Account, "")
viewBinding.myHomeView.setOnClickListener { viewBinding.myHomeView.setOnClickListener {
val intent = Intent( val intent = Intent(
requireActivity(), requireActivity(),
@ -151,7 +151,7 @@ class UserInfoFragment : BaseFragment<FragmentUserInfoBinding>() {
} }
viewBinding.logOutButton.setOnClickListener { viewBinding.logOutButton.setOnClickListener {
appSettings.setValue(AppSettings.Setting.LoginStatus, false) AppSettings.setValue(AppSettings.Setting.LoginStatus, false)
startActivity(Intent(requireContext(), LoginActivity::class.java)) startActivity(Intent(requireContext(), LoginActivity::class.java))
} }
} }

View File

@ -43,7 +43,7 @@ class WarehouseFragment : BaseFragment<FragmentWarehouseBinding>() {
} }
} }
override fun getViewBindingObject(): FragmentWarehouseBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentWarehouseBinding {
return FragmentWarehouseBinding.inflate(layoutInflater) return FragmentWarehouseBinding.inflate(layoutInflater)
} }

View File

@ -1,6 +1,7 @@
package com.coldmint.rust.pro.tool package com.coldmint.rust.pro.tool
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Application
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import com.coldmint.rust.pro.R import com.coldmint.rust.pro.R
@ -15,33 +16,25 @@ import java.util.*
* 程序设置类 * 程序设置类
* Program setup class * Program setup class
*/ */
class AppSettings private constructor(val mContext: Context) { object AppSettings {
private lateinit var mApplication: Application
companion object {
private var instance: AppSettings? = null
fun getInstance(context: Context): AppSettings {
if (instance == null) {
synchronized(AppSettings::class.java)
{
if (instance == null) {
instance = AppSettings(context.applicationContext)
}
}
}
return instance!!
}
@JvmField @JvmField
val dataRootDirectory = val dataRootDirectory =
Environment.getExternalStorageDirectory().absolutePath + "/rustAssistant" Environment.getExternalStorageDirectory().absolutePath + "/rustAssistant"
val Locale_Russia = Locale("RU", "ru", "") val Locale_Russia = Locale("RU", "ru", "")
}
private val mFileName: String = mContext.packageName + "_preferences" private val mFileName: String by lazy {
private val sharedPreferences: SharedPreferences = mApplication.packageName + "_preferences"
mContext.getSharedPreferences(mFileName, Context.MODE_PRIVATE) }
private val editor: SharedPreferences.Editor = sharedPreferences.edit() private val sharedPreferences: SharedPreferences by lazy {
mApplication.getSharedPreferences(mFileName, Context.MODE_PRIVATE)
}
private val editor: SharedPreferences.Editor by lazy {
sharedPreferences.edit()
}
enum class Setting { enum class Setting {
DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeepRwmodFile, EnableRecoveryStation, RecoveryStationFileSaveDays, RecoveryStationFolder, IndependentFolder, SetGameStorage, PackDirectory, IdentifiersPromptNumber, UserName, UseJetBrainsMonoFont, AppID, Account, PassWord, ExpirationTime, CheckBetaUpdate, UpdateData, ShareTip, AgreePolicy, EnglishEditingMode, NightModeFollowSystem, UseMobileNetwork, MapFolder, ModFolder, UseTheCommunityAsTheLaunchPage, AutoSave, ServerAddress, Token, LoginStatus, DynamicColor, ExperiencePlan, FileSortType DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeepRwmodFile, EnableRecoveryStation, RecoveryStationFileSaveDays, RecoveryStationFolder, IndependentFolder, SetGameStorage, PackDirectory, IdentifiersPromptNumber, UserName, UseJetBrainsMonoFont, AppID, Account, PassWord, ExpirationTime, CheckBetaUpdate, UpdateData, ShareTip, AgreePolicy, EnglishEditingMode, NightModeFollowSystem, UseMobileNetwork, MapFolder, ModFolder, UseTheCommunityAsTheLaunchPage, AutoSave, ServerAddress, Token, LoginStatus, DynamicColor, ExperiencePlan, FileSortType
@ -71,6 +64,71 @@ class AppSettings private constructor(val mContext: Context) {
return false return false
} }
/**
* 初始化App设置
* @param application mApplication
*/
fun initAppSettings(application: Application) {
this.mApplication = application
map[Setting.DatabasePath] = mApplication.getString(R.string.setting_database_path)
map[Setting.AppLanguage] =
mApplication.getString(R.string.setting_app_language)
map[Setting.DatabaseDirectory] = mApplication.getString(R.string.setting_database_directory)
map[Setting.DeveloperMode] = mApplication.getString(R.string.setting_developer_mode)
map[Setting.CustomSymbol] =
mApplication.getString(R.string.setting_custom_symbol)
map[Setting.TemplateDirectory] =
mApplication.getString(R.string.setting_template_directory)
map[Setting.AutoCreateNomedia] =
mApplication.getString(R.string.setting_auto_create_nomedia)
map[Setting.OnlyLoadConantLanguageTemple] =
mApplication.getString(R.string.setting_only_load_conant_language_temple)
map[Setting.NightMode] = mApplication.getString(R.string.setting_night_mode)
map[Setting.GamePackage] = mApplication.getString(R.string.setting_game_package)
map[Setting.KeepRwmodFile] = mApplication.getString(R.string.setting_keep_rwmod_file)
map[Setting.EnableRecoveryStation] =
mApplication.getString(R.string.setting_enable_recovery_station)
map[Setting.RecoveryStationFileSaveDays] =
mApplication.getString(R.string.setting_recovery_station_file_save_days)
map[Setting.RecoveryStationFolder] =
mApplication.getString(R.string.setting_recovery_station_folder)
map[Setting.IndependentFolder] = mApplication.getString(R.string.setting_independent_folder)
map[Setting.PackDirectory] =
mApplication.getString(R.string.setting_pack_directory)
map[Setting.IdentifiersPromptNumber] =
mApplication.getString(R.string.setting_identifiers_prompt_number)
map[Setting.UserName] =
mApplication.getString(R.string.setting_user_name)
map[Setting.UseJetBrainsMonoFont] =
mApplication.getString(R.string.setting_use_jetBrains_mono_font)
map[Setting.CheckBetaUpdate] = mApplication.getString(R.string.setting_check_beta_update)
map[Setting.EnglishEditingMode] =
mApplication.getString(R.string.setting_english_editing_mode)
map[Setting.NightModeFollowSystem] =
mApplication.getString(R.string.setting_night_mode_follow_system)
map[Setting.UseMobileNetwork] = mApplication.getString(R.string.setting_use_mobile_network)
map[Setting.MapFolder] = mApplication.getString(R.string.setting_map_folder)
map[Setting.ModFolder] = mApplication.getString(R.string.setting_mod_folder)
map[Setting.UseTheCommunityAsTheLaunchPage] =
mApplication.getString(R.string.setting_use_the_community_as_the_launch_page)
map[Setting.AutoSave] = mApplication.getString(R.string.setting_auto_save)
map[Setting.ServerAddress] = mApplication.getString(R.string.setting_server_address)
map[Setting.DynamicColor] = mApplication.getString(R.string.setting_dynamic_color)
map[Setting.ExperiencePlan] = mApplication.getString(R.string.setting_experience_the_plan)
map[Setting.FileSortType] = mApplication.getString(R.string.setting_file_sort_type)
//仅保存不可显示
map[Setting.SetGameStorage] = "SetGameStorage"
map[Setting.AppID] = "AppId"
map[Setting.Account] = "Account"
map[Setting.PassWord] = "PassWord"
map[Setting.ExpirationTime] = "ExpirationTime"
map[Setting.UpdateData] = "UpdateData"
map[Setting.ShareTip] = "ShareTip"
map[Setting.AgreePolicy] = "AgreePolicy"
map[Setting.LoginStatus] = "LoginStatus"
map[Setting.Token] = "Token"
}
/** /**
* 初始化设置仅第一次调用有效 * 初始化设置仅第一次调用有效
* Initialization Settings, valid only for the first call. * Initialization Settings, valid only for the first call.
@ -106,7 +164,7 @@ class AppSettings private constructor(val mContext: Context) {
* @return Boolean 是否需要重启App * @return Boolean 是否需要重启App
*/ */
fun setLanguage(language: String): Boolean { fun setLanguage(language: String): Boolean {
return MultiLanguages.setAppLanguage(mContext, toLocaleValue(language)) return MultiLanguages.setAppLanguage(mApplication, toLocaleValue(language))
} }
@ -240,67 +298,4 @@ class AppSettings private constructor(val mContext: Context) {
return resultValue return resultValue
} }
/**
* 构造AppSettings类
* Construct the AppSettings class
*/
init {
map[Setting.DatabasePath] = mContext.getString(R.string.setting_database_path)
map[Setting.AppLanguage] =
mContext.getString(R.string.setting_app_language)
map[Setting.DatabaseDirectory] = mContext.getString(R.string.setting_database_directory)
map[Setting.DeveloperMode] = mContext.getString(R.string.setting_developer_mode)
map[Setting.CustomSymbol] =
mContext.getString(R.string.setting_custom_symbol)
map[Setting.TemplateDirectory] =
mContext.getString(R.string.setting_template_directory)
map[Setting.AutoCreateNomedia] =
mContext.getString(R.string.setting_auto_create_nomedia)
map[Setting.OnlyLoadConantLanguageTemple] =
mContext.getString(R.string.setting_only_load_conant_language_temple)
map[Setting.NightMode] = mContext.getString(R.string.setting_night_mode)
map[Setting.GamePackage] = mContext.getString(R.string.setting_game_package)
map[Setting.KeepRwmodFile] = mContext.getString(R.string.setting_keep_rwmod_file)
map[Setting.EnableRecoveryStation] =
mContext.getString(R.string.setting_enable_recovery_station)
map[Setting.RecoveryStationFileSaveDays] =
mContext.getString(R.string.setting_recovery_station_file_save_days)
map[Setting.RecoveryStationFolder] =
mContext.getString(R.string.setting_recovery_station_folder)
map[Setting.IndependentFolder] = mContext.getString(R.string.setting_independent_folder)
map[Setting.PackDirectory] =
mContext.getString(R.string.setting_pack_directory)
map[Setting.IdentifiersPromptNumber] =
mContext.getString(R.string.setting_identifiers_prompt_number)
map[Setting.UserName] =
mContext.getString(R.string.setting_user_name)
map[Setting.UseJetBrainsMonoFont] =
mContext.getString(R.string.setting_use_jetBrains_mono_font)
map[Setting.CheckBetaUpdate] = mContext.getString(R.string.setting_check_beta_update)
map[Setting.EnglishEditingMode] = mContext.getString(R.string.setting_english_editing_mode)
map[Setting.NightModeFollowSystem] =
mContext.getString(R.string.setting_night_mode_follow_system)
map[Setting.UseMobileNetwork] = mContext.getString(R.string.setting_use_mobile_network)
map[Setting.MapFolder] = mContext.getString(R.string.setting_map_folder)
map[Setting.ModFolder] = mContext.getString(R.string.setting_mod_folder)
map[Setting.UseTheCommunityAsTheLaunchPage] =
mContext.getString(R.string.setting_use_the_community_as_the_launch_page)
map[Setting.AutoSave] = mContext.getString(R.string.setting_auto_save)
map[Setting.ServerAddress] = mContext.getString(R.string.setting_server_address)
map[Setting.DynamicColor] = mContext.getString(R.string.setting_dynamic_color)
map[Setting.ExperiencePlan] = mContext.getString(R.string.setting_experience_the_plan)
map[Setting.FileSortType] = mContext.getString(R.string.setting_file_sort_type)
//仅保存不可显示
map[Setting.SetGameStorage] = "SetGameStorage"
map[Setting.AppID] = "AppId"
map[Setting.Account] = "Account"
map[Setting.PassWord] = "PassWord"
map[Setting.ExpirationTime] = "ExpirationTime"
map[Setting.UpdateData] = "UpdateData"
map[Setting.ShareTip] = "ShareTip"
map[Setting.AgreePolicy] = "AgreePolicy"
map[Setting.LoginStatus] = "LoginStatus"
map[Setting.Token] = "Token"
}
} }

View File

@ -297,7 +297,7 @@ class TextStyleMaker private constructor() {
} }
"activate" -> { "activate" -> {
val time = ServerConfiguration.toStringTime( val time = ServerConfiguration.toStringTime(
AppSettings.getInstance(context) AppSettings
.getValue(AppSettings.Setting.ExpirationTime, 0.toLong()) .getValue(AppSettings.Setting.ExpirationTime, 0.toLong())
) )
if (time == ServerConfiguration.ForeverTime) { if (time == ServerConfiguration.ForeverTime) {

View File

@ -60,7 +60,7 @@ class EditViewModel(application: Application) : BaseAndroidViewModel(application
*/ */
val apkFolder by lazy { val apkFolder by lazy {
GameSynchronizer.getPackAgeFolder( GameSynchronizer.getPackAgeFolder(
getApplication(), AppSettings.getInstance(getApplication()).getValue( getApplication(), AppSettings.getValue(
AppSettings.Setting.GamePackage, AppSettings.Setting.GamePackage,
GlobalMethod.DEFAULT_GAME_PACKAGE GlobalMethod.DEFAULT_GAME_PACKAGE
) )
@ -504,7 +504,7 @@ class EditViewModel(application: Application) : BaseAndroidViewModel(application
if (fileDataBase != null) { if (fileDataBase != null) {
val path = file.file.absolutePath val path = file.file.absolutePath
val name = file.getName( val name = file.getName(
AppSettings.getInstance(getApplication()).getValue( AppSettings.getValue(
AppSettings.Setting.AppLanguage, AppSettings.Setting.AppLanguage,
Locale.getDefault().language Locale.getDefault().language
) )
@ -573,7 +573,7 @@ class EditViewModel(application: Application) : BaseAndroidViewModel(application
* 加载数据 * 加载数据
*/ */
fun loadData() { fun loadData() {
val english = AppSettings.getInstance(getApplication()) val english = AppSettings
.getValue(AppSettings.Setting.EnglishEditingMode, false) .getValue(AppSettings.Setting.EnglishEditingMode, false)
setEnglish(english) setEnglish(english)
} }

View File

@ -85,9 +85,8 @@ class FileManagerViewModel : BaseViewModel() {
* 从设置中读取排序方式 * 从设置中读取排序方式
*/ */
fun loadSortType(context: Context) { fun loadSortType(context: Context) {
val appSettings = AppSettings.getInstance(context)
//从设置中读取排序方式 //从设置中读取排序方式
val sortType = appSettings.getValue( val sortType = AppSettings.getValue(
AppSettings.Setting.FileSortType, AppSettings.Setting.FileSortType,
context.getString(R.string.setting_file_list_action_sort_by_name) context.getString(R.string.setting_file_list_action_sort_by_name)
) )
@ -116,7 +115,6 @@ class FileManagerViewModel : BaseViewModel() {
* @return Boolean * @return Boolean
*/ */
fun saveSortType(context: Context): Boolean { fun saveSortType(context: Context): Boolean {
val appSettings = AppSettings.getInstance(context)
val value = val value =
sortTypeLiveData.value ?: SortType.BY_NAME sortTypeLiveData.value ?: SortType.BY_NAME
val text = when (value) { val text = when (value) {
@ -136,7 +134,7 @@ class FileManagerViewModel : BaseViewModel() {
context.getString(R.string.setting_file_list_action_sort_by_name) context.getString(R.string.setting_file_list_action_sort_by_name)
} }
} }
return appSettings.setValue(AppSettings.Setting.FileSortType, text) return AppSettings.setValue(AppSettings.Setting.FileSortType, text)
} }
/** /**

View File

@ -0,0 +1,163 @@
package com.coldmint.rust.pro.viewmodel
import android.content.Context
import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.coldmint.rust.core.LocalTemplatePackage
import com.coldmint.rust.core.dataBean.template.LocalTemplateFile
import com.coldmint.rust.core.dataBean.template.Template
import com.coldmint.rust.core.dataBean.template.TemplatePackage
import com.coldmint.rust.core.interfaces.FileFinderListener
import com.coldmint.rust.core.tool.FileFinder2
import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.pro.base.BaseViewModel
import com.coldmint.rust.pro.tool.AppSettings
import org.json.JSONException
import org.json.JSONObject
import java.io.File
import java.util.*
import kotlin.collections.ArrayList
/**
* 已安装的模板
*/
class InstalledTemplateViewModel : BaseViewModel() {
val createPathLiveData: MutableLiveData<String> by lazy {
MutableLiveData()
}
val onlyLoad by lazy {
AppSettings.getValue(AppSettings.Setting.OnlyLoadConantLanguageTemple, false)
}
val environmentLanguage by lazy {
AppSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
}
private var loadCallBack: (() -> Unit)? = null
/**
* 设置加载完成的回调
* @param callBack Function0<Unit>?
*/
fun setLoadCallBack(callBack: (() -> Unit)? = null) {
loadCallBack = callBack
}
var mRootPath: String? = null
private val groupList: ArrayList<TemplatePackage> by lazy {
ArrayList()
}
private val itemList: ArrayList<ArrayList<Template>> by lazy {
ArrayList()
}
/**
* 获取组
* @return ArrayList<TemplatePackage>
*/
fun getGroupData(): ArrayList<TemplatePackage> {
return groupList
}
/**
* 获取组
* @return ArrayList<TemplatePackage>
*/
fun getItemData(): ArrayList<ArrayList<Template>> {
return itemList
}
/**
* 加载本地和网络模板
* 如果设置了[InstalledTemplateViewModel.setLoadCallBack]回调那么会调用接口.
* 请在回调内使用[InstalledTemplateViewModel.getGroupData][InstalledTemplateViewModel.getItemData]获取加载结果
* @param context Context
*/
fun loadTemplate(context: Context) {
groupList.clear()
itemList.clear()
loadLocalTemplate(context)
loadCallBack?.invoke()
}
/**
* 加载本地模板
* @param context Context
*/
private fun loadLocalTemplate(context: Context) {
val templateDirectory = File(
AppSettings.getValue(
AppSettings.Setting.TemplateDirectory,
context.filesDir.absolutePath + "/template/"
)
)
if (templateDirectory.exists() && templateDirectory.isDirectory) {
Log.d("加载本地模板", "正在读取" + templateDirectory.absolutePath)
val files = templateDirectory.listFiles()
if (files.isNotEmpty()) {
files.forEach {
if (it.isDirectory) {
//如果是文件夹那么创建组
val templatePackage =
LocalTemplatePackage(it)
if (templatePackage.isTemplate) {
groupList.add(templatePackage)
Log.d("加载本地模板", "已创建" + templatePackage.getName() + "")
val temList = ArrayList<Template>()
itemList.add(temList)
val fileFinder2 = FileFinder2(it)
fileFinder2.setFinderListener(object : FileFinderListener {
override fun whenFindFile(file: File): Boolean {
if (FileOperator.getFileType(file) == "json") {
//读取目录内所有json文件将其添加到子集内
val templateFile = LocalTemplateFile(file)
if (onlyLoad) {
val data = FileOperator.readFile(file)
try {
val jsonObject = JSONObject(data)
val s = jsonObject.getString("language")
if (s == "ALL" || s == environmentLanguage) {
temList.add(templateFile)
Log.d("加载本地模板", "已成功分配" + file.absolutePath)
} else {
Log.w("加载本地模板", "不符合语言的项目" + file.absolutePath)
}
} catch (exception: JSONException) {
exception.printStackTrace()
}
} else {
temList.add(templateFile)
Log.d("加载本地模板", "已成功分配" + file.absolutePath)
}
} else {
Log.e("加载本地模板", "无法分配" + file.absolutePath)
}
return true
}
override fun whenFindFolder(folder: File): Boolean {
return true
}
})
fileFinder2.onStart()
} else {
Log.w("加载本地模板", "文件" + it.absolutePath + "不是模板包")
}
} else {
Log.w("加载本地模板", "文件" + it.absolutePath + "不是文件夹")
}
}
} else {
Log.w("加载本地模板", "目录" + templateDirectory.absolutePath + "内,没有文件,无法加载。")
}
} else {
Log.e("加载本地模板", "模板目录不存在或不是文件夹" + templateDirectory.absolutePath)
}
}
}

Some files were not shown because too many files have changed in this diff Show More