diff --git a/.gradle/7.3.3/executionHistory/executionHistory.bin b/.gradle/7.3.3/executionHistory/executionHistory.bin index 2652fd4..7fba7eb 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.bin and b/.gradle/7.3.3/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.lock b/.gradle/7.3.3/executionHistory/executionHistory.lock index 5b0d58a..baffa9c 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.lock and b/.gradle/7.3.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.bin b/.gradle/7.3.3/fileHashes/fileHashes.bin index 215853c..8bb8b8d 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.bin and b/.gradle/7.3.3/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.lock b/.gradle/7.3.3/fileHashes/fileHashes.lock index 0759443..99afa18 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.lock and b/.gradle/7.3.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin index 96a1e02..739f5cc 100644 Binary files a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin and b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 0ef1419..662f050 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index a577f49..04ebcc5 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 6a3077c..3ad8a62 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/app/mapping.txt b/app/mapping.txt index 2851a54..cbf02ca 100644 --- a/app/mapping.txt +++ b/app/mapping.txt @@ -88167,7 +88167,7 @@ com.coldmint.rust.pro.ui.ModActionAdapter$shareItem$2 -> com.coldmint.rust.pro.u # {"id":"sourceFile","fileName":"ModActionAdapter.kt"} java.io.File $file -> c 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:1:java.lang.Object invoke(java.lang.Object):316:316 -> invoke com.coldmint.rust.pro.ui.ModAdapter -> com.coldmint.rust.pro.ui.ModAdapter: diff --git a/app/seeds.txt b/app/seeds.txt index 1b0b2c1..f68d922 100644 --- a/app/seeds.txt +++ b/app/seeds.txt @@ -35194,7 +35194,7 @@ androidx.media.MediaBrowserProtocol: java.lang.String EXTRA_SERVICE_VERSION com.google.android.material.R$styleable: int Constraint_layout_constraintBaseline_toBaselineOf androidx.preference.ktx.R$id: int action_mode_close_button 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.navigation.ui.R$attr: int listPreferredItemHeight 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 com.afollestad.materialdialogs.bottomsheets.R$styleable: int SearchView_layout 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 kotlinx.coroutines.internal.LockFreeTaskQueueCore: java.util.concurrent.atomic.AtomicReferenceFieldUpdater _next$FU io.github.rosemoe.editor.widget.CodeEditor: android.view.inputmethod.InputMethodManager mInputMethodManager diff --git a/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt b/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt index db2a1fa..47fd0c4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Bundle import android.text.Html +import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import android.view.View @@ -60,7 +61,7 @@ class AboutActivity : BaseActivity() { | """.trimMargin() 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()) { viewBinding.expirationTimeView.text = getString(R.string.please_login_first) } else { @@ -112,7 +113,7 @@ class AboutActivity : BaseActivity() { return super.onOptionsItemSelected(item) } - override fun getViewBindingObject(): ActivityAboutBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityAboutBinding { return ActivityAboutBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/ActivateActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ActivateActivity.kt index 901fa0c..2ddac64 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ActivateActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ActivateActivity.kt @@ -7,6 +7,7 @@ import android.text.SpannableString import android.text.Spanned import android.text.method.LinkMovementMethod import android.text.style.ClickableSpan +import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import android.view.View @@ -206,7 +207,7 @@ class ActivateActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityActivateBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityActivateBinding { return ActivityActivateBinding.inflate(layoutInflater) } @@ -233,7 +234,8 @@ class ActivateActivity : BaseActivity() { if (canUseView) { title = getText(R.string.activation_app) setReturnButton() - val account = appSettings.getValue(AppSettings.Setting.Account, "") + val account = AppSettings.getValue(AppSettings. + Setting.Account, "") if (account.isBlank()) { showError(getString(R.string.please_login_first)) return diff --git a/app/src/main/java/com/coldmint/rust/pro/ApplicationListActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ApplicationListActivity.kt index 3586c6e..264eef1 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ApplicationListActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ApplicationListActivity.kt @@ -7,6 +7,7 @@ import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import android.os.Bundle import android.os.Handler +import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import androidx.core.view.isVisible @@ -134,7 +135,7 @@ class ApplicationListActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityApplicationListBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityApplicationListBinding { return ActivityApplicationListBinding.inflate( layoutInflater ) diff --git a/app/src/main/java/com/coldmint/rust/pro/BookmarkManagerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/BookmarkManagerActivity.kt index 103b6ea..798efde 100644 --- a/app/src/main/java/com/coldmint/rust/pro/BookmarkManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/BookmarkManagerActivity.kt @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import android.content.Intent import android.view.KeyEvent +import android.view.LayoutInflater import android.view.MenuItem import android.view.View import androidx.appcompat.app.AlertDialog @@ -226,7 +227,7 @@ class BookmarkManagerActivity : BaseActivity() { return super.onKeyDown(keyCode, event) } - override fun getViewBindingObject(): ActivityBookmarkManagerBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityBookmarkManagerBinding { return ActivityBookmarkManagerBinding.inflate( layoutInflater ) diff --git a/app/src/main/java/com/coldmint/rust/pro/BrowserActivity.kt b/app/src/main/java/com/coldmint/rust/pro/BrowserActivity.kt index 2be0d02..6de6881 100644 --- a/app/src/main/java/com/coldmint/rust/pro/BrowserActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/BrowserActivity.kt @@ -4,6 +4,7 @@ import android.graphics.Bitmap import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.KeyEvent +import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import android.webkit.WebChromeClient @@ -76,7 +77,7 @@ class BrowserActivity : BaseActivity() { return super.onKeyDown(keyCode, event) } - override fun getViewBindingObject(): ActivityBrowserBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityBrowserBinding { return ActivityBrowserBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt b/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt index bb7880c..c161391 100644 --- a/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt @@ -6,10 +6,7 @@ import android.text.Spannable import android.text.SpannableString import android.text.method.LinkMovementMethod import android.text.style.ClickableSpan -import android.view.KeyEvent -import android.view.Menu -import android.view.MenuItem -import android.view.View +import android.view.* import androidx.core.view.isVisible import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.WhichButton @@ -189,7 +186,7 @@ class CodeTableActivity : BaseActivity() { return super.onOptionsItemSelected(item) } - override fun getViewBindingObject(): ActivityCodeTableBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCodeTableBinding { return ActivityCodeTableBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/CreateModActivity.kt b/app/src/main/java/com/coldmint/rust/pro/CreateModActivity.kt index 881b028..08bf542 100644 --- a/app/src/main/java/com/coldmint/rust/pro/CreateModActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/CreateModActivity.kt @@ -6,6 +6,7 @@ import com.coldmint.rust.pro.base.BaseActivity import android.text.TextWatcher import android.text.Editable import android.os.Environment +import android.view.LayoutInflater import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.Toast @@ -133,7 +134,7 @@ class CreateModActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityCreateModBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCreateModBinding { return ActivityCreateModBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/CreateTemplateActivity.kt b/app/src/main/java/com/coldmint/rust/pro/CreateTemplateActivity.kt index 3c3a57d..5e1e2b4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/CreateTemplateActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/CreateTemplateActivity.kt @@ -1,138 +1,286 @@ package com.coldmint.rust.pro +import android.content.pm.PackageManager import android.os.Bundle -import com.coldmint.rust.core.TemplatePackage -import com.coldmint.rust.core.dataBean.template.TemplateInfo +import android.text.Editable +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.web.ServerConfiguration +import com.coldmint.rust.core.web.TemplatePhp import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databinding.ActivityCreateTemplateBinding import com.coldmint.rust.pro.tool.AppSettings -import com.google.gson.Gson -import org.json.JSONObject -import java.io.File +import com.google.android.material.snackbar.Snackbar class CreateTemplateActivity : BaseActivity() { private var path: String? = null private var editMode = false - private val gson by lazy { Gson() } override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { setTitle(R.string.create_template) setReturnButton() - initView() +// initView() initAction() } } fun initView() { - val intent = intent - val bundle = intent.getBundleExtra("data") - if (bundle != null) { - val jsonText = bundle.getString("json") - val temPath = bundle.getString("path") - if (temPath == null) { - showError("请输入路径") - return - } - path = temPath - if (jsonText != null) { - val jsonObject = JSONObject(jsonText) - viewBinding.templateNameEdit.setText(jsonObject.getString("name")) - viewBinding.templateDescribeEdit.setText(jsonObject.getString("description")) - viewBinding.templateDeveloperEdit.setText(jsonObject.getString("developer")) - viewBinding.templateUpdateEdit.setText(jsonObject.getString("update")) - viewBinding.templateVersionName.setText(jsonObject.getString("versionName")) - viewBinding.templateVersionNum.setText(jsonObject.getString("versionNum")) - editMode = true - viewBinding.createbutton.setText(R.string.edit_function) - } +// val intent = intent +// val bundle = intent.getBundleExtra("data") +// if (bundle != null) { +// val jsonText = bundle.getString("json") +// val temPath = bundle.getString("path") +// if (temPath == null) { +// showError("请输入路径") +// return +// } +// path = temPath +// if (jsonText != null) { +// val jsonObject = JSONObject(jsonText) +// viewBinding.templateNameEdit.setText(jsonObject.getString("name")) +// viewBinding.templateDescribeEdit.setText(jsonObject.getString("description")) +// viewBinding.templateDeveloperEdit.setText(jsonObject.getString("developer")) +// viewBinding.templateUpdateEdit.setText(jsonObject.getString("update")) +// viewBinding.templateVersionName.setText(jsonObject.getString("versionName")) +// viewBinding.templateVersionNum.setText(jsonObject.getString("versionNum")) +// editMode = true +// viewBinding.createbutton.setText(R.string.edit_function) +// } +// } + } + + /** + * 检查名称,返回是否有错误 + * @return Boolean + */ + fun checkName(): Boolean { + val text = viewBinding.templateNameEdit.text.toString() + return if (text.isBlank()) { + setErrorAndInput( + viewBinding.templateNameEdit, + getString(R.string.template_name_error), + viewBinding.templateNameInputLayout + ) + true + } else { + viewBinding.templateNameInputLayout.isErrorEnabled = false + false } } + /** + * 检查描述 + * @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 { - val name = viewBinding.templateNameEdit.text.toString() - if (name.isEmpty()) { - setErrorAndInput( - viewBinding.templateNameEdit, - getString(R.string.template_name_error) - ) + if (checkId()) { return@setOnClickListener } - val description = viewBinding.templateDescribeEdit.text.toString() - if (description.isEmpty()) { - setErrorAndInput( - viewBinding.templateDescribeEdit, - getString(R.string.template_description_error) - ) + if (checkName()) { return@setOnClickListener } - val developer = viewBinding.templateDeveloperEdit.text.toString() - if (developer.isEmpty()) { - setErrorAndInput( - viewBinding.templateDeveloperEdit, - getString(R.string.template_developer_error) - ) + if (checkDescribe()) { return@setOnClickListener } - val update = viewBinding.templateUpdateEdit.text.toString() - if (update.isEmpty()) { - setErrorAndInput( - viewBinding.templateUpdateEdit, - getString(R.string.template_update_error) - ) + if (checkTemplateVersionName()) { return@setOnClickListener } - val versionName = viewBinding.templateVersionName.text.toString() - if (update.isEmpty()) { - setErrorAndInput( - viewBinding.templateVersionName, - getString(R.string.template_version_name_error) - ) + if (checkId()) { return@setOnClickListener } - val versionNum = viewBinding.templateVersionNum.text.toString() - if (update.isEmpty()) { - setErrorAndInput( - viewBinding.templateVersionNum, - getString(R.string.template_version_num_error) - ) - return@setOnClickListener + var versionName = "版本号" + try { + val packageInfo = packageManager.getPackageInfo(packageName, 0) + versionName = packageInfo.versionName + } catch (e: PackageManager.NameNotFoundException) { + e.printStackTrace() } - val now = AppOperator.getAppVersionNum(this, this.packageName) - val templateInfo = TemplateInfo( - now, - description, - developer, - name, - update, + + 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, - versionNum.toInt() + AppOperator.getAppVersionNum(this), true, object : ApiCallBack { + 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 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 { - templateClass.create(templateInfo) - } - finish() +// 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(): ActivityCreateTemplateBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCreateTemplateBinding { return ActivityCreateTemplateBinding.inflate( layoutInflater ) diff --git a/app/src/main/java/com/coldmint/rust/pro/CreateUnitActivity.kt b/app/src/main/java/com/coldmint/rust/pro/CreateUnitActivity.kt index 32ca72b..b50ae19 100644 --- a/app/src/main/java/com/coldmint/rust/pro/CreateUnitActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/CreateUnitActivity.kt @@ -2,177 +2,58 @@ package com.coldmint.rust.pro import com.coldmint.rust.pro.base.BaseActivity import android.os.Bundle -import com.coldmint.rust.pro.tool.AppSettings import android.content.Intent -import android.os.Environment -import org.json.JSONObject -import org.json.JSONException -import android.widget.AdapterView.OnItemLongClickListener -import com.afollestad.materialdialogs.MaterialDialog +import android.view.LayoutInflater import android.widget.* -import com.coldmint.rust.core.TemplatePackage -import com.coldmint.rust.core.tool.FileOperator -import com.coldmint.rust.pro.adapters.TemplateAdapter +import com.coldmint.rust.pro.adapters.CreateUnitPageAdapter import com.coldmint.rust.pro.databinding.ActivityCreateUnitBinding -import java.io.File -import java.util.* +import com.google.android.material.tabs.TabLayoutMediator class CreateUnitActivity : BaseActivity() { - 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) { if (canUseView) { setTitle(R.string.create_unit) setReturnButton() initView() - initAction() } } fun initView() { - val useing = appSettings.getValue(AppSettings.Setting.DatabasePath, "") val intent = intent val bundle = intent.getBundleExtra("data") if (bundle == null) { Toast.makeText(this, "无效的请求", Toast.LENGTH_SHORT).show() finish() } else { - mRootPath = bundle.getString("modPath") - mCreatePath = bundle.getString("createPath", mRootPath) - var relativePath = FileOperator.getRelativePath( - mCreatePath, - appSettings.getValue( - 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 = ArrayList() - val item: MutableList> = 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 = ArrayList() - search(directents, itemlist, only_load_language, environmentLanguage) - item.add(itemlist) - } + createUnitPageAdapter = CreateUnitPageAdapter(this) + viewBinding.viewPager2.adapter = createUnitPageAdapter + TabLayoutMediator(viewBinding.tabLayout, viewBinding.viewPager2) { tab, i -> + tab.text = if (i == 0) { + getString(R.string.installated) + } else { + getString(R.string.template_community) } - } - } - mTemplateAdapter = - TemplateAdapter(this@CreateUnitActivity, group, item, environmentLanguage) - viewBinding.expandableList.setAdapter(mTemplateAdapter) - } + }.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) +// } - //扫描某目录的模板(目录,欲保存到的集合,全局语言,全局方法,仅加载符合语言的?,环境语言) - private fun search( - directents: File, - list: MutableList, - only: Boolean, - environmentLanguage: String - ) { - for (f in directents.listFiles()) { - if (f.isDirectory) { - search(f, list, only, environmentLanguage) - } else { - val type = FileOperator.getFileType(f) - 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) - } - } - } + +// loadlist() } } - fun initAction() { - viewBinding.selectPathButton.setOnClickListener { - 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(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 - } - } +// fun getmCreatePath(): String { +// return mCreatePath +// } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { @@ -181,21 +62,7 @@ class CreateUnitActivity : BaseActivity() { 1 -> if (resultCode == RESULT_OK) { val directents = data!!.getStringExtra("Directents") if (directents != null) { - mCreatePath = 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 - ) + createUnitPageAdapter.setCreatePath(directents) } } 2 -> if (resultCode == RESULT_OK) { @@ -208,7 +75,7 @@ class CreateUnitActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivityCreateUnitBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCreateUnitBinding { return ActivityCreateUnitBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/CreationWizardActivity.kt b/app/src/main/java/com/coldmint/rust/pro/CreationWizardActivity.kt index d227c03..9385496 100644 --- a/app/src/main/java/com/coldmint/rust/pro/CreationWizardActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/CreationWizardActivity.kt @@ -3,6 +3,7 @@ package com.coldmint.rust.pro import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.LayoutInflater import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.coldmint.rust.pro.adapters.GuideAdapter @@ -140,7 +141,7 @@ class CreationWizardActivity : BaseActivity() { Intent(this, FileManagerActivity::class.java) val fileBundle = Bundle() fileBundle.putString("type", "selectFile") - val packDirectory = appSettings.getValue( + val packDirectory = AppSettings.getValue( AppSettings.Setting.PackDirectory, AppSettings.dataRootDirectory + "/bin/" ) @@ -158,7 +159,7 @@ class CreationWizardActivity : BaseActivity() { viewBinding.recyclerView.adapter = adapter } - override fun getViewBindingObject(): ActivityCreationWizardBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCreationWizardBinding { return ActivityCreationWizardBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt b/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt index c9d0dd9..12339ec 100644 --- a/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt @@ -112,8 +112,8 @@ class EditActivity : BaseActivity() { fun showRenewalTip() { val debugKey = "续费提示" - val account = appSettings.getValue(AppSettings.Setting.Account, "") - val time = appSettings.getValue(AppSettings.Setting.ExpirationTime, 0.toLong()) + val account = AppSettings.getValue(AppSettings.Setting.Account, "") + val time = AppSettings.getValue(AppSettings.Setting.ExpirationTime, 0.toLong()) if (time == 0.toLong() || account.isBlank()) { DebugHelper.printLog(debugKey, "没有账号或续费信息,关闭界面。") Toast.makeText(this, "请先登录", Toast.LENGTH_SHORT).show() @@ -452,7 +452,7 @@ class EditActivity : BaseActivity() { //当用户切换到其他应用界面时 override fun onPause() { if (viewModel.needCheckAutoSave) { - val need = appSettings.getValue(AppSettings.Setting.AutoSave, true) + val need = AppSettings.getValue(AppSettings.Setting.AutoSave, true) if (need) { viewModel.saveAllFile( viewBinding.tabLayout.selectedTabPosition, @@ -947,7 +947,7 @@ class EditActivity : BaseActivity() { items.add(getString(R.string.code_table)) // items.add(getString(R.string.code_language_on)) items.add(getString(R.string.symbol11)) - val customSymbol = appSettings.getValue( + val customSymbol = AppSettings.getValue( AppSettings.Setting.CustomSymbol, "[],:='*_$%@#{}()" ) @@ -1060,7 +1060,7 @@ class EditActivity : BaseActivity() { val codeInfoList = if (lineData.isBlank()) { codeDataBase.getCodeDao().findCodeBySection(trueSection) } else { - val number = appSettings.getValue( + val number = AppSettings.getValue( AppSettings.Setting.IdentifiersPromptNumber, 40 ) @@ -1095,10 +1095,6 @@ class EditActivity : BaseActivity() { } } catch (e: Exception) { e.printStackTrace() - val info = ErrorInfo() - info.describe = "自动保存-代码提示异常" - info.allErrorDetails = e.toString() - info.save() } } @@ -1107,10 +1103,6 @@ class EditActivity : BaseActivity() { symbolChannel.insertSymbol(item, item.length) } catch (e: Exception) { e.printStackTrace() - val info = ErrorInfo() - info.describe = "自动保存-插入符号异常" - info.allErrorDetails = e.toString() - info.save() } } } @@ -1126,7 +1118,7 @@ class EditActivity : BaseActivity() { fun initCodeEditor() { //CodEditor初始化 viewBinding.codeEditor.isWordwrap = true - val useFont = appSettings.getValue(AppSettings.Setting.UseJetBrainsMonoFont, true) + val useFont = AppSettings.getValue(AppSettings.Setting.UseJetBrainsMonoFont, true) if (useFont) { viewBinding.codeEditor.typefaceText = Typeface.createFromAsset( assets, @@ -1134,7 +1126,7 @@ class EditActivity : BaseActivity() { ) } val language = - appSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) + AppSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) rustLanguage = RustLanguage(this) rustLanguage.setCodeDataBase(CodeDataBase.getInstance(this)) rustLanguage.setFileDataBase( @@ -1145,7 +1137,7 @@ class EditActivity : BaseActivity() { ) // rustLanguage.setAnalyzerEnglishMode(viewModel.englishModeLiveData) rustLanguage.setCodeEditor(viewBinding.codeEditor) - val night = appSettings.getValue(AppSettings.Setting.NightMode, false) + val night = AppSettings.getValue(AppSettings.Setting.NightMode, false) val editorColorScheme = EditorColorScheme() if (night) { //代码(可识别的关键字) @@ -1255,7 +1247,7 @@ class EditActivity : BaseActivity() { ).show() } R.id.open_game_test -> { - val packName = appSettings.getValue( + val packName = AppSettings.getValue( AppSettings.Setting.GamePackage, GlobalMethod.DEFAULT_GAME_PACKAGE ) @@ -1630,7 +1622,7 @@ class EditActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityEditBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityEditBinding { return ActivityEditBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt index cfef658..98f503e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt @@ -15,6 +15,7 @@ import android.os.Build import android.graphics.drawable.AnimatedVectorDrawable import android.net.Uri import android.view.KeyEvent +import android.view.LayoutInflater import android.view.MenuItem import android.view.View import android.widget.* @@ -555,7 +556,7 @@ class EditModInfoActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivityEditModInfoBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityEditModInfoBinding { return ActivityEditModInfoBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/EditUserInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/EditUserInfoActivity.kt index c736e16..625d364 100644 --- a/app/src/main/java/com/coldmint/rust/pro/EditUserInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/EditUserInfoActivity.kt @@ -9,6 +9,7 @@ import android.os.Environment import android.text.Editable import android.text.TextWatcher import android.util.Log +import android.view.LayoutInflater import android.view.View import android.widget.PopupMenu import android.widget.Toast @@ -279,7 +280,7 @@ class EditUserInfoActivity : BaseActivity() { } viewBinding.button.hide() val token = - AppSettings.getInstance(this).getValue(AppSettings.Setting.Token, "") + AppSettings.getValue(AppSettings.Setting.Token, "") User.updateSpaceInfo( token, userName, @@ -456,7 +457,7 @@ class EditUserInfoActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivityEditUserInfoBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityEditUserInfoBinding { return ActivityEditUserInfoBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/ErrorActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ErrorActivity.kt index 3b8a9c4..a07870a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ErrorActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ErrorActivity.kt @@ -9,6 +9,7 @@ import android.content.pm.PackageManager import android.os.Bundle import android.util.Log import android.view.KeyEvent +import android.view.LayoutInflater import android.view.MenuItem import android.view.View import androidx.core.view.isVisible @@ -52,7 +53,7 @@ class ErrorActivity() : BaseActivity() { } viewBinding.errorInfo.text = 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) ErrorReport.instance.send( errorInfo.allErrorDetails, @@ -61,7 +62,8 @@ class ErrorActivity() : BaseActivity() { object : ApiCallBack { override fun onResponse(t: ApiResponse) { 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() { e.printStackTrace() } - }) + }, + AppSettings.getValue( + AppSettings.Setting.ServerAddress, + ServerConfiguration.website + ) + ) } saveLog() } @@ -102,7 +109,7 @@ class ErrorActivity() : BaseActivity() { * 创建错误日志 */ fun saveLog(): Boolean { - errorInfo.describe = viewBinding.inputEditView.text.toString() +// errorInfo.describe = viewBinding.inputEditView.text.toString() return errorInfo.save() } @@ -141,7 +148,7 @@ class ErrorActivity() : BaseActivity() { } } - override fun getViewBindingObject(): ActivityErrorBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityErrorBinding { return ActivityErrorBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/ErrorInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ErrorInfoActivity.kt index 16e5ad6..e12694e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ErrorInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ErrorInfoActivity.kt @@ -3,6 +3,7 @@ package com.coldmint.rust.pro import android.os.Bundle import android.os.Handler import android.os.Looper +import android.view.LayoutInflater import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager import com.coldmint.rust.core.interfaces.FileFinderListener @@ -93,7 +94,7 @@ class ErrorInfoActivity : BaseActivity() { viewBinding.tipView.setText(resId) } - override fun getViewBindingObject(): ActivityErrorInfoBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityErrorInfoBinding { return ActivityErrorInfoBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt index 2c82a38..cbdad11 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt @@ -823,7 +823,7 @@ class FileManagerActivity : BaseActivity() { // return null // } // -// override fun getViewBindingObject(): ActivityFileBinding { +// override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityFileBinding { // return ActivityFileBinding.inflate(layoutInflater) // } // @@ -875,15 +875,15 @@ class FileManagerActivity : BaseActivity() { loadTitle() loadObserve() initAction() - FastScrollerBuilder(viewBinding.recyclerView).useMd2Style() - .setPopupTextProvider(adapter).build() + viewModel.initBookmarkManager(this) + viewModel.loadFiles() + viewModel.loadSortType(this) viewBinding.swipeRefreshLayout.setOnRefreshListener { viewModel.loadFiles(viewModel.getCurrentPath()) viewBinding.swipeRefreshLayout.isRefreshing = false } - viewModel.initBookmarkManager(this) - viewModel.loadFiles() - viewModel.loadSortType(this) + FastScrollerBuilder(viewBinding.recyclerView).useMd2Style() + .setPopupTextProvider(adapter).build() } else { val bundle = intent.getBundleExtra("data") if (bundle == null) { @@ -1098,6 +1098,10 @@ class FileManagerActivity : BaseActivity() { } } viewModel.currentPathLiveData.observe(this) { + if (it==null) + { + return@observe + } val root = getString(R.string.root_path) val path = root + it.substring(viewModel.getRootPath().length) val lineParser = LineParser(path) @@ -1172,7 +1176,7 @@ class FileManagerActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivityFileBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityFileBinding { return ActivityFileBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/FullScreenCoverActivity.kt b/app/src/main/java/com/coldmint/rust/pro/FullScreenCoverActivity.kt index c853ec4..eabcd26 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FullScreenCoverActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FullScreenCoverActivity.kt @@ -2,6 +2,7 @@ package com.coldmint.rust.pro import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.LayoutInflater import com.bumptech.glide.Glide import com.coldmint.rust.core.web.ServerConfiguration import com.coldmint.rust.pro.databinding.ActivityFullScreenCoverBinding @@ -12,7 +13,7 @@ import com.gyf.immersionbar.ktx.immersionBar class FullScreenCoverActivity : BaseActivity() { - override fun getViewBindingObject(): ActivityFullScreenCoverBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityFullScreenCoverBinding { return ActivityFullScreenCoverBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/GameCheckActivity.kt b/app/src/main/java/com/coldmint/rust/pro/GameCheckActivity.kt index 6931d7d..ab7bb65 100644 --- a/app/src/main/java/com/coldmint/rust/pro/GameCheckActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/GameCheckActivity.kt @@ -2,6 +2,7 @@ package com.coldmint.rust.pro import android.os.Bundle +import android.view.LayoutInflater import com.coldmint.rust.pro.base.BaseActivity import android.view.View import com.coldmint.rust.core.tool.AppOperator @@ -15,7 +16,7 @@ import com.coldmint.rust.pro.tool.AppSettings */ class GameCheckActivity : BaseActivity() { - override fun getViewBindingObject(): ActivityGameCheckBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityGameCheckBinding { return ActivityGameCheckBinding.inflate(layoutInflater) } @@ -40,7 +41,7 @@ class GameCheckActivity : BaseActivity() { } }) viewBinding.completionButton.setOnClickListener(View.OnClickListener { - appSettings.setValue(AppSettings.Setting.SetGameStorage, true) + AppSettings.setValue(AppSettings.Setting.SetGameStorage, true) finish() }) } diff --git a/app/src/main/java/com/coldmint/rust/pro/GlobalOperationsActivity.kt b/app/src/main/java/com/coldmint/rust/pro/GlobalOperationsActivity.kt index 6ba2fc4..987c1be 100644 --- a/app/src/main/java/com/coldmint/rust/pro/GlobalOperationsActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/GlobalOperationsActivity.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.text.Editable import android.text.InputType import android.text.TextWatcher +import android.view.LayoutInflater import android.view.View import android.view.inputmethod.InputMethodInfo import android.widget.AdapterView @@ -271,7 +272,7 @@ class GlobalOperationsActivity : BaseActivity() } - override fun getViewBindingObject(): ActivityGlobalOperationsBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityGlobalOperationsBinding { return ActivityGlobalOperationsBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt index 8066f7a..3e04acb 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt @@ -1,19 +1,15 @@ package com.coldmint.rust.pro -import android.Manifest import com.coldmint.rust.pro.base.BaseActivity -import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.* +import android.view.LayoutInflater import android.widget.Toast -import androidx.core.app.ActivityCompat -import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider import com.afollestad.materialdialogs.MaterialDialog 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.interfaces.UnzipListener import com.coldmint.rust.core.tool.AppOperator @@ -122,13 +118,13 @@ class ImporterActivity : BaseActivity() { val onclickType = viewBinding.okButton.text val importName = getString(R.string.import_name) 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") { val file = File( - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.TemplateDirectory, this.filesDir.absolutePath + "/template/" - ) + TemplatePackage.getAbsoluteFileName(filename = fileName) + ) + LocalTemplatePackage.getAbsoluteFileName(filename = fileName) ) val cacheDirectory = File(cacheDir.absolutePath + "/template/") if (!cacheDirectory.exists()) { @@ -186,7 +182,7 @@ class ImporterActivity : BaseActivity() { //如果建立缓存完成,并且模板文件存在 if (templateDirectory.exists()) { val newInfoData = - compressionManager.readEntry(newFile, TemplatePackage.INFONAME) + compressionManager.readEntry(newFile, LocalTemplatePackage.INFONAME) val newInfo = gson.fromJson(newInfoData, TemplateInfo::class.java) if (newInfo == null) { @@ -205,7 +201,7 @@ class ImporterActivity : BaseActivity() { } return@Runnable } else { - val templateClass = TemplatePackage(templateDirectory) + val templateClass = LocalTemplatePackage(templateDirectory) val oldInfo = templateClass.getInfo() if (oldInfo == null) { handler.post { @@ -266,7 +262,7 @@ class ImporterActivity : BaseActivity() { } else { //常规导入 val newInfo = - compressionManager.readEntry(newFile, TemplatePackage.INFONAME) + compressionManager.readEntry(newFile, LocalTemplatePackage.INFONAME) if (newInfo == null) { handler.post { viewBinding.okButton.setBackgroundColor( @@ -469,7 +465,7 @@ class ImporterActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityImporterBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityImporterBinding { return ActivityImporterBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/LibraryActivity.kt b/app/src/main/java/com/coldmint/rust/pro/LibraryActivity.kt index a358a55..8d7d54a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/LibraryActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/LibraryActivity.kt @@ -1,6 +1,7 @@ package com.coldmint.rust.pro import android.os.Bundle +import android.view.LayoutInflater import androidx.recyclerview.widget.DividerItemDecoration import com.coldmint.rust.pro.base.BaseActivity import androidx.recyclerview.widget.LinearLayoutManager @@ -158,7 +159,7 @@ class LibraryActivity : BaseActivity() { return libInfoArrayList } - override fun getViewBindingObject(): ActivityLibraryBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityLibraryBinding { return ActivityLibraryBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt b/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt index 75a38dd..a64f867 100644 --- a/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt @@ -14,6 +14,7 @@ import android.text.TextWatcher import android.text.method.LinkMovementMethod import android.text.style.ClickableSpan import android.util.Log +import android.view.LayoutInflater import android.view.View import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.WhichButton @@ -44,7 +45,7 @@ class LoginActivity : BaseActivity() { transparentStatusBar().statusBarDarkFont(true) .transparentNavigationBar().navigationBarDarkIcon(true) } - Log.d("应用识别码", appSettings.getValue(AppSettings.Setting.AppID, "无")) + Log.d("应用识别码", AppSettings.getValue(AppSettings.Setting.AppID, "无")) viewBinding.accountView.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { @@ -110,7 +111,7 @@ class LoginActivity : BaseActivity() { if (!checkPassword(passWord)) { return@OnClickListener } - val appId = appSettings.getValue(AppSettings.Setting.AppID, ""); + val appId = AppSettings.getValue(AppSettings.Setting.AppID, ""); isLogin = true viewBinding.button.setText(R.string.request_data) User.login(LoginRequestData(account, passWord, appId), @@ -119,12 +120,12 @@ class LoginActivity : BaseActivity() { isLogin = false viewBinding.button.setText(R.string.login) if (userData.code == ServerConfiguration.Success_Code) { - appSettings.forceSetValue(AppSettings.Setting.PassWord, passWord) - appSettings.forceSetValue( + AppSettings.forceSetValue(AppSettings.Setting.PassWord, passWord) + AppSettings.forceSetValue( AppSettings.Setting.Account, userData.data.account ) - appSettings.forceSetValue( + AppSettings.forceSetValue( AppSettings.Setting.Token, userData.data.token ) @@ -132,8 +133,8 @@ class LoginActivity : BaseActivity() { //更新本地激活时间 val expirationTime = userData.data.expirationTime val time = ServerConfiguration.toLongTime(expirationTime) - appSettings.forceSetValue(AppSettings.Setting.ExpirationTime, time) - appSettings.forceSetValue(AppSettings.Setting.LoginStatus, true) + AppSettings.forceSetValue(AppSettings.Setting.ExpirationTime, time) + AppSettings.forceSetValue(AppSettings.Setting.LoginStatus, true) startActivity(Intent(this@LoginActivity, MainActivity::class.java)) finish() } else { @@ -356,11 +357,11 @@ class LoginActivity : BaseActivity() { viewBinding.checkbox.setHintTextColor(Color.TRANSPARENT) 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.setOnCheckedChangeListener { p0, p1 -> setLoginButtonEnable() - appSettings.setValue(AppSettings.Setting.AgreePolicy, p1) + AppSettings.setValue(AppSettings.Setting.AgreePolicy, p1) } viewBinding.registerView.setOnClickListener { @@ -374,7 +375,7 @@ class LoginActivity : BaseActivity() { viewBinding.changeServerView.setOnClickListener { InputDialog(this).setTitle(R.string.changing_the_server) .setMessage(R.string.changing_the_server_tip).setMaxNumber(255).setText( - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.ServerAddress, ServerConfiguration.website ) @@ -383,7 +384,7 @@ class LoginActivity : BaseActivity() { !(s.startsWith("http://") || s.startsWith("https://")) }.setPositiveButton(R.string.dialog_ok) { input -> if (input.isNotBlank()) { - appSettings.setValue(AppSettings.Setting.ServerAddress, input) + AppSettings.setValue(AppSettings.Setting.ServerAddress, input) ServerConfiguration.website = input Snackbar.make( viewBinding.button, @@ -472,8 +473,8 @@ class LoginActivity : BaseActivity() { override fun onResume() { - val account = appSettings.getValue(AppSettings.Setting.Account, "") - val passWord = appSettings.getValue(AppSettings.Setting.PassWord, "") + val account = AppSettings.getValue(AppSettings.Setting.Account, "") + val passWord = AppSettings.getValue(AppSettings.Setting.PassWord, "") val inputAccount = viewBinding.accountView.text.toString() val inputPassWord = viewBinding.passwordView.text.toString() if (account.isNotBlank() && inputAccount.isEmpty()) { @@ -485,7 +486,7 @@ class LoginActivity : BaseActivity() { super.onResume() } - override fun getViewBindingObject(): ActivityLoginBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityLoginBinding { return ActivityLoginBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt b/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt index 47e3b05..75afcc5 100644 --- a/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt @@ -19,10 +19,9 @@ import androidx.navigation.findNavController import androidx.navigation.ui.* import com.afollestad.materialdialogs.MaterialDialog import com.bumptech.glide.Glide -import com.coldmint.rust.pro.dialog.CommentDialog import com.coldmint.dialog.CoreDialog 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.template.TemplateInfo import com.coldmint.rust.core.interfaces.ApiCallBack @@ -80,7 +79,7 @@ class MainActivity : BaseActivity() { val navController = findNavController(R.id.baseFragment) navController.navInflater.inflate(R.navigation.main_nav).apply { val use = - appSettings.getValue(AppSettings.Setting.UseTheCommunityAsTheLaunchPage, true) + AppSettings.getValue(AppSettings.Setting.UseTheCommunityAsTheLaunchPage, true) startDestination = if (use) { viewBinding.mainButton.hide() R.id.community_item @@ -114,7 +113,7 @@ class MainActivity : BaseActivity() { if (t.code == ServerConfiguration.Success_Code && data != null) { val gson = Gson() //同步离线的更新对话框 - appSettings.forceSetValue(AppSettings.Setting.UpdateData, gson.toJson(data)) + AppSettings.forceSetValue(AppSettings.Setting.UpdateData, gson.toJson(data)) ifNeedShowUpdate(data) } else { Snackbar.make(viewBinding.mainButton, t.message, Snackbar.LENGTH_SHORT).show() @@ -122,7 +121,7 @@ class MainActivity : BaseActivity() { } override fun onFailure(e: Exception) { - val updateData = appSettings.getValue(AppSettings.Setting.UpdateData, "") + val updateData = AppSettings.getValue(AppSettings.Setting.UpdateData, "") if (updateData.isNotBlank()) { val gson = Gson() val updateDataObj = gson.fromJson(updateData, AppUpdateData.Data::class.java) @@ -143,7 +142,7 @@ class MainActivity : BaseActivity() { val key = "应用更新" val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0) val checkBetaUpdate = - appSettings.getValue(AppSettings.Setting.CheckBetaUpdate, false) + AppSettings.getValue(AppSettings.Setting.CheckBetaUpdate, false) var needShowDialog = false //如果自身是Beta版,则强制更新Beta版本 if (BuildConfig.DEBUG && packageInfo.versionName.contains("Beta")) { @@ -204,7 +203,7 @@ class MainActivity : BaseActivity() { * 显示游戏配置对话框 */ fun showGameConfiguredDialog() { - if (!appSettings.getValue(AppSettings.Setting.SetGameStorage, false)) { + if (!AppSettings.getValue(AppSettings.Setting.SetGameStorage, false)) { try { val packageInfo = packageManager.getPackageInfo( GlobalMethod.DEFAULT_GAME_PACKAGE, @@ -223,11 +222,11 @@ class MainActivity : BaseActivity() { ) ) }.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 -> }.setCancelable(false).show() } else { - appSettings.setValue(AppSettings.Setting.SetGameStorage, true) + AppSettings.setValue(AppSettings.Setting.SetGameStorage, true) } } catch (e: PackageManager.NameNotFoundException) { e.printStackTrace() @@ -240,7 +239,7 @@ class MainActivity : BaseActivity() { if (first) { first = false } else { - val newLanguage = appSettings.getValue(AppSettings.Setting.AppLanguage, "en") + val newLanguage = AppSettings.getValue(AppSettings.Setting.AppLanguage, "en") if (oldLanguage != newLanguage) { recreate() return @@ -339,7 +338,7 @@ class MainActivity : BaseActivity() { } menu.findItem(R.id.startGame).setOnMenuItemClickListener { - val packName = appSettings.getValue( + val packName = AppSettings.getValue( AppSettings.Setting.GamePackage, GlobalMethod.DEFAULT_GAME_PACKAGE ) @@ -366,7 +365,7 @@ class MainActivity : BaseActivity() { } //激活暂时不可用 - val longTime = appSettings.getValue( + val longTime = AppSettings.getValue( AppSettings.Setting.ExpirationTime, 0.toLong() ) @@ -395,7 +394,7 @@ class MainActivity : BaseActivity() { val type = FileOperator.getFileType(from) if (requestCode == 1) { 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) if (FileOperator.copyFile(from, to)) { Snackbar.make( @@ -420,10 +419,10 @@ class MainActivity : BaseActivity() { } else if (requestCode == 2) { if ("rp" == type) { val outputFolder = File( - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.TemplateDirectory, this.filesDir.absolutePath + "/template/" - ) + TemplatePackage.getAbsoluteFileName(from) + ) + LocalTemplatePackage.getAbsoluteFileName(from) ) importTemplate(from, outputFolder) } else { @@ -449,7 +448,7 @@ class MainActivity : BaseActivity() { val compressionManager = CompressionManager.instance if (templateDirectory.exists()) { val gson = Gson() - val newInfoData = compressionManager.readEntry(formFile, TemplatePackage.INFONAME) + val newInfoData = compressionManager.readEntry(formFile, LocalTemplatePackage.INFONAME) if (newInfoData == null) { handler.post { Snackbar.make( @@ -461,7 +460,7 @@ class MainActivity : BaseActivity() { return@Runnable } else { val newInfo = gson.fromJson(newInfoData, TemplateInfo::class.java) - val templateClass = TemplatePackage(templateDirectory) + val templateClass = LocalTemplatePackage(templateDirectory) val oldInfo = templateClass.getInfo() if (oldInfo == null) { handler.post { @@ -507,7 +506,7 @@ class MainActivity : BaseActivity() { } } else { //常规导入 - val newInfo = compressionManager.readEntry(formFile, TemplatePackage.INFONAME) + val newInfo = compressionManager.readEntry(formFile, LocalTemplatePackage.INFONAME) if (newInfo == null) { handler.post { Snackbar.make( @@ -603,7 +602,7 @@ class MainActivity : BaseActivity() { return false } - override fun getViewBindingObject(): ActivityMainBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityMainBinding { return ActivityMainBinding.inflate(layoutInflater) } @@ -692,7 +691,7 @@ class MainActivity : BaseActivity() { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { - oldLanguage = appSettings.getValue(AppSettings.Setting.AppLanguage, "en") + oldLanguage = AppSettings.getValue(AppSettings.Setting.AppLanguage, "en") useToolbarSetSupportActionBar() initNav() observeStartViewModel() diff --git a/app/src/main/java/com/coldmint/rust/pro/OptimizeActivity.kt b/app/src/main/java/com/coldmint/rust/pro/OptimizeActivity.kt index 084dd58..6105e5d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/OptimizeActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/OptimizeActivity.kt @@ -13,6 +13,7 @@ import android.text.style.ClickableSpan import com.afollestad.materialdialogs.MaterialDialog import android.text.Spanned import android.os.Looper +import android.view.LayoutInflater import android.view.View import android.widget.* import androidx.core.view.isVisible @@ -478,7 +479,7 @@ class OptimizeActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityOptimizeBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityOptimizeBinding { return ActivityOptimizeBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/OrderListActivity.kt b/app/src/main/java/com/coldmint/rust/pro/OrderListActivity.kt index a35ba80..9a13dcd 100644 --- a/app/src/main/java/com/coldmint/rust/pro/OrderListActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/OrderListActivity.kt @@ -30,10 +30,10 @@ import com.google.android.material.snackbar.Snackbar class OrderListActivity : BaseActivity() { var loadAll = false val account by lazy { - appSettings.getValue(AppSettings.Setting.Account, "") + AppSettings.getValue(AppSettings.Setting.Account, "") } val appId by lazy { - appSettings.getValue(AppSettings.Setting.AppID, "") + AppSettings.getValue(AppSettings.Setting.AppID, "") } override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { @@ -190,7 +190,7 @@ class OrderListActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivityOrderListBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityOrderListBinding { return ActivityOrderListBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/PackActivity.kt b/app/src/main/java/com/coldmint/rust/pro/PackActivity.kt index 08184de..b497838 100644 --- a/app/src/main/java/com/coldmint/rust/pro/PackActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/PackActivity.kt @@ -9,6 +9,7 @@ import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod import android.os.Looper import android.view.KeyEvent +import android.view.LayoutInflater import android.view.MenuItem import android.view.View import android.widget.* @@ -80,10 +81,10 @@ class PackActivity : BaseActivity() { modName = modClass.modName item = resources.getStringArray(R.array.update_type_entries) needRecyclingFile = - appSettings.getValue(AppSettings.Setting.EnableRecoveryStation, true) + AppSettings.getValue(AppSettings.Setting.EnableRecoveryStation, true) if (needRecyclingFile) { val recoveryStationFolder = StringBuilder( - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.RecoveryStationFolder, this@PackActivity.filesDir.absolutePath + "/backup/" ) @@ -105,7 +106,7 @@ class PackActivity : BaseActivity() { configurationData = data loadInfoToView(data) } - outputFolder = appSettings.getValue( + outputFolder = AppSettings.getValue( AppSettings.Setting.PackDirectory, AppSettings.dataRootDirectory + "/bin/" ) @@ -428,7 +429,7 @@ class PackActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityPackBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityPackBinding { return ActivityPackBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/PayActivity.kt b/app/src/main/java/com/coldmint/rust/pro/PayActivity.kt index 6a1568e..6d6b747 100644 --- a/app/src/main/java/com/coldmint/rust/pro/PayActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/PayActivity.kt @@ -17,6 +17,7 @@ import android.text.style.ForegroundColorSpan import android.text.style.StyleSpan import android.util.Log import android.view.KeyEvent +import android.view.LayoutInflater import android.view.MenuItem import androidx.core.view.isVisible import com.afollestad.materialdialogs.MaterialDialog @@ -344,7 +345,7 @@ class PayActivity : BaseActivity() { viewBinding.payMoneyView.text = spannableString } - override fun getViewBindingObject(): ActivityPayBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityPayBinding { return ActivityPayBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/RecyclingStationActivity.kt b/app/src/main/java/com/coldmint/rust/pro/RecyclingStationActivity.kt index 5864214..f66037f 100644 --- a/app/src/main/java/com/coldmint/rust/pro/RecyclingStationActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/RecyclingStationActivity.kt @@ -2,6 +2,7 @@ package com.coldmint.rust.pro import com.coldmint.rust.pro.base.BaseActivity import android.os.Bundle +import android.view.LayoutInflater import android.view.Menu import androidx.recyclerview.widget.LinearLayoutManager import com.coldmint.rust.pro.tool.AppSettings @@ -26,12 +27,12 @@ class RecyclingStationActivity : BaseActivity() title = getString(R.string.enable_the_recovery_station) viewBinding.backupList.layoutManager = LinearLayoutManager(this@RecyclingStationActivity) - val workFolderPath = appSettings.getValue( + val workFolderPath = AppSettings.getValue( AppSettings.Setting.RecoveryStationFolder, this@RecyclingStationActivity.filesDir.absolutePath + "/backup/" ) mDayNum = Integer.valueOf( - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.RecoveryStationFileSaveDays, 7 ) @@ -91,7 +92,7 @@ class RecyclingStationActivity : BaseActivity() working = true val removePath: String val modDirectory = - appSettings.getValue(AppSettings.Setting.ModFolder, "") + AppSettings.getValue(AppSettings.Setting.ModFolder, "") val removeFile: File if (file.isDirectory) { removePath = modDirectory + file.name + "/" @@ -163,7 +164,7 @@ class RecyclingStationActivity : BaseActivity() } FileOperator.removeFiles( mWorkFolder, - File(appSettings.getValue(AppSettings.Setting.ModFolder, "")) + File(AppSettings.getValue(AppSettings.Setting.ModFolder, "")) ) runOnUiThread { viewBinding.progressBar.isVisible = false @@ -185,7 +186,7 @@ class RecyclingStationActivity : BaseActivity() } - override fun getViewBindingObject(): ActivityRecyclingStationBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityRecyclingStationBinding { return ActivityRecyclingStationBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/RegisterActivity.kt b/app/src/main/java/com/coldmint/rust/pro/RegisterActivity.kt index 5c04d18..534de0a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/RegisterActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/RegisterActivity.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.text.Editable import android.text.InputType import android.text.TextWatcher +import android.view.LayoutInflater import com.coldmint.rust.pro.base.BaseActivity import android.view.View import androidx.core.view.isVisible @@ -147,7 +148,7 @@ class RegisterActivity : BaseActivity() { ) ) viewBinding.registerButton.setText(R.string.request_data) - val appID = appSettings.getValue(AppSettings.Setting.AppID, "") + val appID = AppSettings.getValue(AppSettings.Setting.AppID, "") User.register( RegisterRequestData(account, passWord, userName, email, appID), object : ApiCallBack { @@ -160,9 +161,9 @@ class RegisterActivity : BaseActivity() { ) viewBinding.registerButton.setText(R.string.register) if (apiResponse.code == ServerConfiguration.Success_Code) { - appSettings.forceSetValue(AppSettings.Setting.Account, account) - appSettings.forceSetValue(AppSettings.Setting.PassWord, passWord) - appSettings.forceSetValue(AppSettings.Setting.UserName, userName) + AppSettings.forceSetValue(AppSettings.Setting.Account, account) + AppSettings.forceSetValue(AppSettings.Setting.PassWord, passWord) + AppSettings.forceSetValue(AppSettings.Setting.UserName, userName) MaterialDialog(this@RegisterActivity).show { title(R.string.register_successed).message(R.string.registration_success_message) .cancelable(false).positiveButton(R.string.close) { @@ -412,7 +413,7 @@ class RegisterActivity : BaseActivity() { ) && checkEmail(email, false) } - override fun getViewBindingObject(): ActivityRegisterBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityRegisterBinding { return ActivityRegisterBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt index 8a371c4..887d215 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt @@ -8,6 +8,7 @@ import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.util.Log +import android.view.LayoutInflater import android.view.View import android.widget.PopupMenu import android.widget.Toast @@ -121,7 +122,7 @@ class ReleaseModActivity : BaseActivity() { showError("模组id为空") return } - val account = appSettings.getValue(AppSettings.Setting.Account, "") + val account = AppSettings.getValue(AppSettings.Setting.Account, "") if (account.isBlank()) { showError(getString(R.string.please_login_first)) return @@ -422,7 +423,7 @@ class ReleaseModActivity : BaseActivity() { viewBinding.modTagEdit.setText( String.format( getString(R.string.default_tags), - appSettings.getValue(AppSettings.Setting.Account, "未知用户") + AppSettings.getValue(AppSettings.Setting.Account, "未知用户") ) ) @@ -724,7 +725,7 @@ class ReleaseModActivity : BaseActivity() { } - val account = appSettings.getValue(AppSettings.Setting.Account, "") + val account = AppSettings.getValue(AppSettings.Setting.Account, "") if (account.isBlank()) { Snackbar.make( viewBinding.releaseButton, @@ -751,7 +752,7 @@ class ReleaseModActivity : BaseActivity() { when (AppOperator.getNetworkType(this)) { AppOperator.NetWorkType.NetWorkType_Moble -> { val useMobileNetWork = - appSettings.getValue(AppSettings.Setting.UseMobileNetwork, false) + AppSettings.getValue(AppSettings.Setting.UseMobileNetwork, false) if (useMobileNetWork) { if (isUpdateMode) { updateModWork( @@ -793,7 +794,7 @@ class ReleaseModActivity : BaseActivity() { } } negativeButton(R.string.always_allow) { - appSettings.setValue(AppSettings.Setting.UseMobileNetwork, true) + AppSettings.setValue(AppSettings.Setting.UseMobileNetwork, true) if (isUpdateMode) { updateModWork( modId, @@ -865,8 +866,8 @@ class ReleaseModActivity : BaseActivity() { title(R.string.release).customView(view = loadFileLayoutBinding.root) .positiveButton(R.string.dialog_ok).cancelable(false) } - WebMod.instance.releaseMod(appSettings.getValue(AppSettings.Setting.AppID, ""), modId, - appSettings.getValue(AppSettings.Setting.Token, ""), + WebMod.instance.releaseMod(AppSettings.getValue(AppSettings.Setting.AppID, ""), modId, + AppSettings.getValue(AppSettings.Setting.Token, ""), modName, modDescribe, tagsBuilder.toString(), @@ -889,7 +890,7 @@ class ReleaseModActivity : BaseActivity() { //发布动态 val check = viewBinding.checkbox.isChecked if (check) { - val token = appSettings.getValue(AppSettings.Setting.Token, "") + val token = AppSettings.getValue(AppSettings.Setting.Token, "") Dynamic.instance.send( token, String.format(getString(R.string.auto_send), modId), @@ -977,7 +978,7 @@ class ReleaseModActivity : BaseActivity() { title(R.string.release).customView(view = loadFileLayoutBinding.root) .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, modName, modDescribe, @@ -1002,7 +1003,7 @@ class ReleaseModActivity : BaseActivity() { //发布动态 val check = viewBinding.checkbox.isChecked if (check) { - val token = appSettings.getValue(AppSettings.Setting.Token, "") + val token = AppSettings.getValue(AppSettings.Setting.Token, "") Dynamic.instance.send( token, String.format( @@ -1270,7 +1271,7 @@ class ReleaseModActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivityReleaseModBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityReleaseModBinding { return ActivityReleaseModBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/ReportActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ReportActivity.kt index cca176b..924ed63 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ReportActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ReportActivity.kt @@ -3,6 +3,7 @@ package com.coldmint.rust.pro import android.os.Bundle import android.text.Editable import android.text.TextWatcher +import android.view.LayoutInflater import android.widget.ArrayAdapter import com.afollestad.materialdialogs.MaterialDialog import com.coldmint.rust.core.dataBean.ApiResponse @@ -24,7 +25,7 @@ class ReportActivity : BaseActivity() { lateinit var type: String lateinit var target: String - override fun getViewBindingObject(): ActivityReportBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityReportBinding { return ActivityReportBinding.inflate(layoutInflater) } @@ -58,7 +59,7 @@ class ReportActivity : BaseActivity() { return } - val account = appSettings.getValue(AppSettings.Setting.Account, "") + val account = AppSettings.getValue(AppSettings.Setting.Account, "") if (account.isBlank()) { showError(getString(R.string.please_login_first)) return diff --git a/app/src/main/java/com/coldmint/rust/pro/ReportListActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ReportListActivity.kt index 9cd5e86..83b4126 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ReportListActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ReportListActivity.kt @@ -1,6 +1,7 @@ package com.coldmint.rust.pro import android.os.Bundle +import android.view.LayoutInflater import android.view.View import android.widget.Toast import androidx.core.view.isVisible @@ -24,7 +25,7 @@ class ReportListActivity : BaseActivity() { if (canUseView) { title = getText(R.string.report_to_deal) setReturnButton() - val account = appSettings.getValue(AppSettings.Setting.Account, "") + val account = AppSettings.getValue(AppSettings.Setting.Account, "") if (account.isBlank()) { showInfoToView(R.string.please_login_first) return @@ -153,7 +154,7 @@ class ReportListActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivityReportListBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityReportListBinding { return ActivityReportListBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/ReviewModActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ReviewModActivity.kt index 0926c05..1cf7131 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ReviewModActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ReviewModActivity.kt @@ -2,6 +2,7 @@ package com.coldmint.rust.pro import android.content.Intent import android.os.Bundle +import android.view.LayoutInflater import android.view.View import android.widget.Toast import androidx.core.view.isVisible @@ -23,7 +24,7 @@ import com.google.android.material.snackbar.Snackbar */ class ReviewModActivity : BaseActivity() { val token by lazy { - AppSettings.getInstance(this).getValue(AppSettings.Setting.Token, "") + AppSettings.getValue(AppSettings.Setting.Token, "") } override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { @@ -153,7 +154,7 @@ class ReviewModActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivityReviewModBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityReviewModBinding { return ActivityReviewModBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt b/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt index 5bdc3d7..a9c0e16 100644 --- a/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt +++ b/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt @@ -18,11 +18,11 @@ class RustApplication : Application() { override fun onCreate() { super.onCreate() - + AppSettings.initAppSettings(this) //动态颜色 val options = DynamicColorsOptions.Builder() .setPrecondition { activity, theme -> - AppSettings.getInstance(this) + AppSettings .getValue( AppSettings.Setting.DynamicColor, DynamicColors.isDynamicColorAvailable() @@ -48,7 +48,6 @@ class RustApplication : Application() { } - override fun attachBaseContext(base: Context?) { super.attachBaseContext(MultiLanguages.attach(base)) } diff --git a/app/src/main/java/com/coldmint/rust/pro/SearchActivity.kt b/app/src/main/java/com/coldmint/rust/pro/SearchActivity.kt index fe4fb4f..40a065c 100644 --- a/app/src/main/java/com/coldmint/rust/pro/SearchActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/SearchActivity.kt @@ -3,6 +3,7 @@ package com.coldmint.rust.pro import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.LayoutInflater import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager @@ -113,7 +114,7 @@ class SearchActivity : BaseActivity() { }) } - override fun getViewBindingObject(): ActivitySearchBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivitySearchBinding { return ActivitySearchBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/SearchResultActivity.kt b/app/src/main/java/com/coldmint/rust/pro/SearchResultActivity.kt index d30dc44..93f934f 100644 --- a/app/src/main/java/com/coldmint/rust/pro/SearchResultActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/SearchResultActivity.kt @@ -1,6 +1,7 @@ package com.coldmint.rust.pro import android.os.Bundle +import android.view.LayoutInflater import androidx.core.view.isVisible import com.coldmint.rust.core.dataBean.user.SearchResultDataBean import com.coldmint.rust.core.interfaces.ApiCallBack @@ -103,7 +104,7 @@ class SearchResultActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivitySearchResultBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivitySearchResultBinding { return ActivitySearchResultBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt b/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt index 39e031f..6fc997d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt @@ -7,6 +7,7 @@ import android.content.Intent import android.os.Build import android.os.Handler import android.os.Looper +import android.view.LayoutInflater import android.widget.Toast import androidx.appcompat.app.AppCompatDelegate import androidx.preference.* @@ -32,15 +33,14 @@ class SettingsActivity : BaseActivity() { manager.findPreference(getString(R.string.setting_app_language)) as ListPreference? listPreference!!.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { preference, newValue -> - val appSettings = AppSettings.getInstance(requireContext()) val oldLanguage = - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.AppLanguage, Locale.getDefault().language ) val newLanguage = newValue.toString() if (oldLanguage != newLanguage) { - val restart = appSettings.setLanguage(newValue.toString()) + val restart = AppSettings.setLanguage(newValue.toString()) if (restart) { requireActivity().recreate() } @@ -211,7 +211,7 @@ class SettingsActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivitySettingsBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivitySettingsBinding { return ActivitySettingsBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/TagActivity.kt b/app/src/main/java/com/coldmint/rust/pro/TagActivity.kt index b721da6..c8ec8a7 100644 --- a/app/src/main/java/com/coldmint/rust/pro/TagActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/TagActivity.kt @@ -2,6 +2,7 @@ package com.coldmint.rust.pro import android.content.Intent import android.os.Bundle +import android.view.LayoutInflater import android.view.View import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager @@ -112,7 +113,7 @@ class TagActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityTagBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityTagBinding { return ActivityTagBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/TemplateMakerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/TemplateMakerActivity.kt index dc52380..8aa2c72 100644 --- a/app/src/main/java/com/coldmint/rust/pro/TemplateMakerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/TemplateMakerActivity.kt @@ -16,7 +16,7 @@ import android.view.* import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.bottomsheets.BottomSheet 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.tool.FileOperator import com.coldmint.rust.core.tool.LineParser @@ -267,11 +267,11 @@ class TemplateMakerActivity : BaseActivity() { val arrayList = ArrayList() val pathList = ArrayList() val environmentLanguage = - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.AppLanguage, Locale.getDefault().language ) - val templateDirectory = appSettings.getValue( + val templateDirectory = AppSettings.getValue( AppSettings.Setting.TemplateDirectory, this.filesDir.absolutePath + "/template/" ) @@ -280,7 +280,7 @@ class TemplateMakerActivity : BaseActivity() { val files = directory.listFiles() if (files.isNotEmpty()) { for (file in files) { - val templateClass = TemplatePackage(file) + val templateClass = LocalTemplatePackage(file) if (templateClass.isTemplate) { arrayList.add( templateClass.getName() @@ -323,7 +323,7 @@ class TemplateMakerActivity : BaseActivity() { class CodeData(val code: String, val section: String?) - override fun getViewBindingObject(): ActivityTemplateMakerBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityTemplateMakerBinding { return ActivityTemplateMakerBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/TemplateParserActivity.kt b/app/src/main/java/com/coldmint/rust/pro/TemplateParserActivity.kt index 2f3c28a..f88d11d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/TemplateParserActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/TemplateParserActivity.kt @@ -5,15 +5,12 @@ import com.coldmint.rust.pro.base.BaseActivity import org.json.JSONObject import android.os.Bundle import android.content.Intent +import android.util.Log import com.coldmint.rust.pro.tool.AppSettings import org.json.JSONException import org.json.JSONArray import android.view.inputmethod.EditorInfo -import android.text.Editable -import android.text.SpannableString -import android.text.TextWatcher -import android.text.method.LinkMovementMethod -import android.text.style.ClickableSpan +import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import com.google.android.material.snackbar.Snackbar @@ -22,11 +19,15 @@ import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.* import androidx.core.view.isVisible +import androidx.lifecycle.viewModelScope 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.IntroducingDataBean 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.templateParser.InputParser 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.pro.databinding.ActivityTemplateParserBinding import com.coldmint.rust.pro.tool.UnitAutoCompleteHelper +import com.coldmint.rust.pro.viewmodel.TemplateParserViewModel import com.google.android.material.textfield.TextInputLayout import com.google.gson.Gson import java.io.File @@ -42,24 +44,14 @@ import java.util.concurrent.Executors import kotlin.collections.ArrayList import kotlin.concurrent.thread -class TemplateParserActivity() : BaseActivity() { - 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() - private val executorService = Executors.newSingleThreadExecutor() +class TemplateParserActivity : BaseActivity() { - fun getTemplateName(): String { - return if (mJsonObject.has("name_$environmentLanguage")) { - mJsonObject.getString("name_$environmentLanguage") - } else { - mJsonObject.getString("name") - } + val viewModel: TemplateParserViewModel by lazy { + TemplateParserViewModel() + } + + private val language by lazy { + AppSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -72,357 +64,49 @@ class TemplateParserActivity() : BaseActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.preview_static_code -> { - var data = mJsonObject.getString("data") - if (data.isBlank()) { - data = getString(R.string.not_found_data2) - } - MaterialDialog(this).show { - title(text = getTemplateName()).message(text = data) - .positiveButton(R.string.dialog_ok) + var code = viewModel.getCode() + if (code.isBlank()) { + code = getString(R.string.not_found_data2) } + CoreDialog(this).setTitle(viewModel.getTemplateName(language)).setMessage(code) + .setPositiveButton(R.string.dialog_ok) { + + }.show() } } 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( - jsonObject.toString(), - InputParserDataBean::class.java - ) - val inputParser = InputParser(this, data) - if (i < len) { - inputParser.pointToNextView() - } - addTemplateParser(inputParser) - } - "valueSelector" -> { - val data = gson.fromJson( - jsonObject.toString(), - ListParserDataBean::class.java - ) - val listParser = ListParser(this, data) - addTemplateParser(listParser) - } - "comment" -> { - val data = gson.fromJson( - 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 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) { if (canUseView) { + setReturnButton() - viewBinding.fab.hide() - val intent = intent - val bundle = intent.getBundleExtra("data") - if (bundle == null) { - showError("意外的请求") + val link = intent.getStringExtra("link") + if (link == null) { + Toast.makeText(this, "请设置链接", Toast.LENGTH_SHORT).show() + finish() 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() - return - } - thread { - try { - mJsonObject = JSONObject(jsonData) - title = getTemplateName() - if (mJsonObject.has("action")) { - runOnUiThread { - createView(mJsonObject.getJSONArray("action")) - } - } - runOnUiThread { - viewBinding.nestedScrollView.isVisible = true - viewBinding.linearLayout.isVisible = false - viewBinding.fileNameInputView.requestFocus() - val imm = - getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager - imm.showSoftInput( - viewBinding.fileNameInputView, - InputMethodManager.SHOW_IMPLICIT - ) - viewBinding.fab.show() - } - } catch (exception: JSONException) { - exception.printStackTrace() - runOnUiThread { - showError(exception.toString()) - } - } - } } - initAction() + val isLocal = intent.getBooleanExtra("isLocal", false) + if (isLocal) { + Log.d("模板解析器", "读取本地模板$link") + viewModel.setTemplate(LocalTemplateFile(File(link))) + val templateParserList = viewModel.getTemplateParserList(this) + templateParserList.forEach { + viewBinding.base.addView(it.contextView) + } + viewBinding.linearLayout.isVisible = false + viewBinding.nestedScrollView.isVisible = true + title = viewModel.getTemplateName(language) + } else { + + } } } + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityTemplateParserBinding { + return ActivityTemplateParserBinding.inflate(layoutInflater) + } + + } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/ThanksActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ThanksActivity.kt index 6588a7d..25b2cc0 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ThanksActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ThanksActivity.kt @@ -1,6 +1,7 @@ package com.coldmint.rust.pro import android.os.Bundle +import android.view.LayoutInflater import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.coldmint.rust.pro.adapters.ThanksAdapter @@ -15,7 +16,7 @@ import com.google.android.material.divider.MaterialDividerItemDecoration */ class ThanksActivity : BaseActivity() { - override fun getViewBindingObject(): ActivityThanksBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityThanksBinding { return ActivityThanksBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/TurretDesignActivity.kt b/app/src/main/java/com/coldmint/rust/pro/TurretDesignActivity.kt index 42a5991..a55d4d1 100644 --- a/app/src/main/java/com/coldmint/rust/pro/TurretDesignActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/TurretDesignActivity.kt @@ -6,6 +6,7 @@ import android.annotation.SuppressLint import android.graphics.BitmapFactory import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.LayoutInflater import android.view.MotionEvent import android.view.View import com.bumptech.glide.Glide @@ -66,7 +67,7 @@ class TurretDesignActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityTurretDesignBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityTurretDesignBinding { return ActivityTurretDesignBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/UnitsActivity.kt b/app/src/main/java/com/coldmint/rust/pro/UnitsActivity.kt index 0282c38..a2fae81 100644 --- a/app/src/main/java/com/coldmint/rust/pro/UnitsActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/UnitsActivity.kt @@ -210,7 +210,7 @@ class UnitsActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityUnitsBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityUnitsBinding { return ActivityUnitsBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/UserHomePageActivity.kt b/app/src/main/java/com/coldmint/rust/pro/UserHomePageActivity.kt index ca48dd4..0f084f4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/UserHomePageActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/UserHomePageActivity.kt @@ -8,6 +8,7 @@ import android.graphics.Color import android.graphics.drawable.Drawable import android.os.Bundle import android.view.Gravity +import android.view.LayoutInflater import android.view.View import android.view.inputmethod.EditorInfo import android.widget.EditText @@ -66,7 +67,7 @@ class UserHomePageActivity : BaseActivity() { userId = temUserId } - val temAccount = appSettings.getValue(AppSettings.Setting.Account, "") + val temAccount = AppSettings.getValue(AppSettings.Setting.Account, "") if (temAccount.isBlank()) { showError("请先登录") return @@ -330,7 +331,7 @@ class UserHomePageActivity : BaseActivity() { CommentDialog(this).setTitle(R.string.send_dynamic).setCancelable(false) .setSubmitFun { button, textInputLayout, s, alertDialog -> val token = - AppSettings.getInstance(this).getValue(AppSettings.Setting.Token, "") + AppSettings.getValue(AppSettings.Setting.Token, "") if (!s.isBlank()) { Dynamic.instance.send( token, @@ -481,7 +482,7 @@ class UserHomePageActivity : BaseActivity() { } } - override fun getViewBindingObject(): ActivityUserHomePageBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityUserHomePageBinding { return ActivityUserHomePageBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/UserListActivity.kt b/app/src/main/java/com/coldmint/rust/pro/UserListActivity.kt index 74d62ce..b985924 100644 --- a/app/src/main/java/com/coldmint/rust/pro/UserListActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/UserListActivity.kt @@ -3,6 +3,7 @@ package com.coldmint.rust.pro import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.LayoutInflater import android.view.View import android.widget.Toast import androidx.core.view.isVisible @@ -33,7 +34,7 @@ class UserListActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityUserListBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityUserListBinding { return ActivityUserListBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/ValueTypeActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ValueTypeActivity.kt index 9406f9e..3be3453 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ValueTypeActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ValueTypeActivity.kt @@ -10,6 +10,7 @@ import android.widget.ArrayAdapter import android.text.TextWatcher import android.text.Editable import android.view.KeyEvent +import android.view.LayoutInflater import android.view.MenuItem import android.view.View import androidx.appcompat.app.AlertDialog @@ -283,7 +284,7 @@ class ValueTypeActivity : BaseActivity() { return super.onKeyDown(keyCode, event) } - override fun getViewBindingObject(): ActivityValueTypeBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityValueTypeBinding { return ActivityValueTypeBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt index d6689a4..dd2cca9 100644 --- a/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt @@ -59,7 +59,7 @@ class WebModInfoActivity : BaseActivity() { lateinit var modId: String lateinit var tip: String val targetFile: File by lazy { - val modFolderPath = appSettings.getValue( + val modFolderPath = AppSettings.getValue( AppSettings.Setting.ModFolder, Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" ) @@ -71,7 +71,7 @@ class WebModInfoActivity : BaseActivity() { File(modFilePath) } val token by lazy { - appSettings.getValue(AppSettings.Setting.Token, "") + AppSettings.getValue(AppSettings.Setting.Token, "") } var developer: String? = null @@ -253,7 +253,7 @@ class WebModInfoActivity : BaseActivity() { when (AppOperator.getNetworkType(this)) { AppOperator.NetWorkType.NetWorkType_Moble -> { val useMobileNetWork = - appSettings.getValue(AppSettings.Setting.UseMobileNetwork, false) + AppSettings.getValue(AppSettings.Setting.UseMobileNetwork, false) if (useMobileNetWork) { downloadWork(fileLink) } else { @@ -263,7 +263,7 @@ class WebModInfoActivity : BaseActivity() { downloadWork(fileLink) } negativeButton(R.string.always_allow) { - appSettings.setValue(AppSettings.Setting.UseMobileNetwork, true) + AppSettings.setValue(AppSettings.Setting.UseMobileNetwork, true) downloadWork(fileLink) } neutralButton(R.string.dialog_cancel) { @@ -470,7 +470,7 @@ class WebModInfoActivity : BaseActivity() { private fun initAction() { viewBinding.sendDiscussion.setOnClickListener { - val account = appSettings.getValue(AppSettings.Setting.Account, "") + val account = AppSettings.getValue(AppSettings.Setting.Account, "") if (account.isBlank()) { showError(getString(R.string.please_login_first)) return@setOnClickListener @@ -481,7 +481,7 @@ class WebModInfoActivity : BaseActivity() { .setSubmitFun { button, textInputLayout, s, alertDialog -> button.isEnabled = false WebMod.instance.sendComment( - appSettings.getValue(AppSettings.Setting.Token, ""), + AppSettings.getValue(AppSettings.Setting.Token, ""), modId, s, object : ApiCallBack { @@ -509,7 +509,7 @@ class WebModInfoActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityWebModInfoBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityWebModInfoBinding { return ActivityWebModInfoBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt b/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt index 85d19b1..d40b6c2 100644 --- a/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt @@ -3,6 +3,7 @@ package com.coldmint.rust.pro import android.content.Intent import android.os.Bundle import android.util.Log +import android.view.LayoutInflater import android.view.View import android.widget.PopupMenu import android.widget.Toast @@ -46,13 +47,13 @@ class WorkManagementActivity : BaseActivity() { } - override fun getViewBindingObject(): ActivityWorkmangementBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityWorkmangementBinding { return ActivityWorkmangementBinding.inflate(layoutInflater) } override fun onResume() { - val account = appSettings.getValue(AppSettings.Setting.Account, "") + val account = AppSettings.getValue(AppSettings.Setting.Account, "") if (account.isBlank()) { showErrorInView(R.string.please_login_first) } else { @@ -175,7 +176,7 @@ class WorkManagementActivity : BaseActivity() { .positiveButton(R.string.dialog_ok) .positiveButton { WebMod.instance.afreshAuditMod( - AppSettings.getInstance(this@WorkManagementActivity) + AppSettings .getValue( AppSettings.Setting.Token, "" diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt index d788b7a..89988c4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt @@ -90,8 +90,7 @@ class ApplicationListAdapter( ).show() return@OnMenuItemClickListener false } - val appSettings = AppSettings.getInstance(context) - val result = appSettings.setValue( + val result = AppSettings.setValue( AppSettings.Setting.GamePackage, data.packageName ) @@ -158,7 +157,7 @@ class ApplicationListAdapter( materialDialog.setActionButtonEnabled(WhichButton.POSITIVE, false) val gameSynchronizer = GameSynchronizer(context, data) gameSynchronizer.generateData( - AppSettings.getInstance(context).getValue( + AppSettings.getValue( AppSettings.Setting.TemplateDirectory, context.filesDir.absolutePath + "/template/" ), object : GameSynchronizerListener { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CodeTableAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CodeTableAdapter.kt index 1f87f68..4cab753 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CodeTableAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CodeTableAdapter.kt @@ -41,7 +41,7 @@ class CodeTableAdapter( //Label点击事件 var labelFunction: ((Int, View, String) -> Unit)? = null private val developerMode by lazy { - AppSettings.getInstance(context) + AppSettings .getValue(AppSettings.Setting.DeveloperMode, false) } diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CommunityAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CommunityAdapter.kt index 0d8022d..4fa1833 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CommunityAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CommunityAdapter.kt @@ -24,7 +24,7 @@ class CommunityAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) { UserInfoFragment() } else -> { - NullObjectFragment() + NullFragment() } } diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CreateUnitPageAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CreateUnitPageAdapter.kt new file mode 100644 index 0000000..f7075fa --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CreateUnitPageAdapter.kt @@ -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() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/DynamicAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/DynamicAdapter.kt index 67c1b14..6f629bb 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/DynamicAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/DynamicAdapter.kt @@ -69,10 +69,10 @@ class DynamicAdapter( context: Context, dataList: MutableList { - val account = AppSettings.getInstance(context) - .getValue(AppSettings.Setting.Account, "") + val account = AppSettings. + getValue(AppSettings.Setting.Account, "") val appId = - AppSettings.getInstance(context) + AppSettings .getValue(AppSettings.Setting.AppID, "") Dynamic.instance.deleteDynamic( account, diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ErrorInfoAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ErrorInfoAdapter.kt index 5b365eb..7d13696 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ErrorInfoAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ErrorInfoAdapter.kt @@ -29,13 +29,12 @@ class ErrorInfoAdapter( context: Context, dataList: ArrayList) : position: Int ) { viewBinding.timeView.text = data.time - val des = data.describe - if (des == null || des.isBlank()) { - viewBinding.describeView.isVisible = false - } else { - viewBinding.describeView.isVisible = true - viewBinding.describeView.text = des - } +// if (des == null || des.isBlank()) { +// viewBinding.describeView.isVisible = false +// } else { +// viewBinding.describeView.isVisible = true +// viewBinding.describeView.text = des +// } viewBinding.root.setOnClickListener { view -> MaterialDialog(context, BottomSheet()).show { title(text = data.time).message(text = data.allErrorDetails) diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt index 5c3129d..ef7a6a1 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt @@ -167,7 +167,7 @@ class ModActionAdapter( ?: ".+\\.ini|.+\\.template" val codeCompiler2 = CodeCompiler2.getInstance(mContext) val apkFolder = GameSynchronizer.getPackAgeFolder( - mContext, AppSettings.getInstance(mContext).getValue( + mContext, AppSettings.getValue( AppSettings.Setting.GamePackage, GlobalMethod.DEFAULT_GAME_PACKAGE ) @@ -539,8 +539,7 @@ class ModActionAdapter( private fun shareItem() { val file = File(mModpath) 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) { val materialDialog = MaterialDialog(mContext, MaterialDialog.DEFAULT_BEHAVIOR) materialDialog.title(R.string.packmod, null) @@ -556,7 +555,7 @@ class ModActionAdapter( R.string.no_longer_prompt, null ) { materialDialog: MaterialDialog? -> - appSettings.setValue(AppSettings.Setting.ShareTip, false) + AppSettings.setValue(AppSettings.Setting.ShareTip, false) packShare(file) null } @@ -783,7 +782,7 @@ class ModActionAdapter( override fun run() { super.run() val main_path = - AppSettings.getInstance(mContext).getValue(AppSettings.Setting.ModFolder, "") + AppSettings.getValue(AppSettings.Setting.ModFolder, "") val unzip_path = File( main_path + FileOperator.getPrefixName( File( @@ -855,17 +854,16 @@ class ModActionAdapter( override fun whenUnzipComplete(result: Boolean) { 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) { val modFile = File(mModpath) - val needRecycling = appSettings.getValue( + val needRecycling = AppSettings.getValue( AppSettings.Setting.EnableRecoveryStation, true ) if (needRecycling) { val removeFile: File - val removePath: String = appSettings.getValue( + val removePath: String = AppSettings.getValue( AppSettings.Setting.RecoveryStationFolder, mContext.filesDir.absolutePath + "/backup/" ).toString() + modFile.name diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt index 94fa7b5..73100b1 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt @@ -19,21 +19,8 @@ class ModAdapter(context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { init { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - dataList.sortWith(java.util.Comparator { o1, o2 -> - val different = o1.modFile.lastModified() - o2.modFile.lastModified() - when { - different > 0 -> { - -1 - } - different < 0 -> { - 1 - } - else -> { - 0 - } - } - }) + dataList.sortBy { + it.modName } } diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageAdapter.kt index 1212dcb..7708abd 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageAdapter.kt @@ -8,8 +8,6 @@ import com.coldmint.rust.core.database.file.FileDataBase //package com.coldmint.rust.core.database.file. import com.coldmint.rust.pro.fragments.AllUnitsFragment import com.coldmint.rust.pro.fragments.HistoryUnitFragment -import com.coldmint.rust.pro.fragments.NullObjectFragment -import java.io.File /** * @author Cold Mint diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateAdapter.kt index e8220fb..d420d6a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateAdapter.kt @@ -1,6 +1,7 @@ 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.view.LayoutInflater import android.view.ViewGroup @@ -14,18 +15,35 @@ import com.coldmint.rust.pro.TemplateParserActivity import android.os.Bundle import android.view.View 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.pro.databinding.TemplateGroupBinding +import com.coldmint.rust.pro.databinding.TemplateItemBinding import java.io.File class TemplateAdapter( - private val mCreateUnitActivity:CreateUnitActivity, + private val context: Context, private val mGroup: List, - private val mItemList: List>, + private val mItemList: List>, mEnvironmentLanguage: String ) : BaseExpandableListAdapter() { - private val mInflater: LayoutInflater + private val layoutInflater: LayoutInflater = LayoutInflater.from(context) 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 { @@ -67,20 +85,14 @@ class TemplateAdapter( parent: ViewGroup ): View { - val convertView: View = if (view == null) { - mInflater.inflate(R.layout.template_group, parent, false) - } else { - view - } - val nametextView = convertView.findViewById(R.id.template_name) - val numtextView = convertView.findViewById(R.id.template_num) + val templateGroupBinding = TemplateGroupBinding.inflate(layoutInflater, parent, false) val templateClass = mGroup[groupPosition] - nametextView.text = templateClass.getName() - numtextView.text = String.format( - mCreateUnitActivity.getText(R.string.template_num).toString(), + templateGroupBinding.templateName.text = templateClass.getName() + templateGroupBinding.templateNum.text = String.format( + templateNum, mItemList[groupPosition].size ) - return convertView + return templateGroupBinding.root } //获取子项的view @@ -91,83 +103,23 @@ class TemplateAdapter( view: View?, parent: ViewGroup ): View { - val convertView: View - if (view == null) { - convertView = mInflater.inflate(R.layout.template_item, parent, false) + val templateItemBinding = TemplateItemBinding.inflate(layoutInflater, parent, false) + val templateClass = mItemList[groupPosition][childPosition] + templateItemBinding.nameView.text = templateClass.getName(mEnvironmentLanguage) + val icon = templateClass.getIcon() + if (icon == null) { + Glide.with(context).load(R.drawable.template).into(templateItemBinding.templateIconView) } else { - convertView = view + Glide.with(context).load(templateClass.getIcon()) + .into(templateItemBinding.templateIconView) } - val templateClass = mGroup[groupPosition] - var child: JSONObject? = null - try { - val s = FileOperator.readFile(mItemList[groupPosition][childPosition]) - child = JSONObject(s) - } catch (exception: JSONException) { - exception.printStackTrace() + templateItemBinding.root.setOnClickListener { + val intent = Intent(context, TemplateParserActivity::class.java) + intent.putExtra("link", templateClass.getLink()) + intent.putExtra("isLocal", templateClass.isLocal()) + context.startActivity(intent) } - if (child == null) { - return convertView - } - val textView = convertView.findViewById(R.id.name_view) - val imageView = convertView.findViewById(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 + return templateItemBinding.root } //子项是否可选中,如果要设置子项的点击事件,需要返回true @@ -176,7 +128,6 @@ class TemplateAdapter( } init { - mInflater = LayoutInflater.from(mCreateUnitActivity) this.mEnvironmentLanguage = mEnvironmentLanguage } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt index 2845f43..68e11a8 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt @@ -12,7 +12,7 @@ import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager import com.afollestad.materialdialogs.MaterialDialog 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.tool.AppOperator import com.coldmint.rust.core.tool.FileOperator @@ -25,21 +25,21 @@ import com.google.android.material.bottomsheet.BottomSheetDialog import java.io.File class TemplateListAdapter( - context: Context, - dataList: ArrayList, + context: Context, + dataList: ArrayList, private val language: String, private val rootPath: String -) : BaseAdapter(context, dataList) { +) : BaseAdapter(context, dataList) { /** * 编辑信息 * @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() - bundle.putString("json", FileOperator.readFile(templatePackage.infoFile)) - bundle.putString("path", templatePackage.infoFile.absolutePath) + bundle.putString("json", FileOperator.readFile(localTemplatePackage.infoFile)) + bundle.putString("path", localTemplatePackage.infoFile.absolutePath) val intent = Intent(context, CreateTemplateActivity::class.java) intent.putExtra("data", bundle) context.startActivity(intent) @@ -48,9 +48,9 @@ class TemplateListAdapter( /** * 点击了分享 * @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 handler = Handler(Looper.getMainLooper()) Thread { @@ -61,7 +61,7 @@ class TemplateListAdapter( } val toFile = File( - cacheDirectory.absolutePath + "/" + templatePackage.getName() + "_" + templatePackage.getInfo()?.versionName + ".rp" + cacheDirectory.absolutePath + "/" + localTemplatePackage.getName() + "_" + localTemplatePackage.getInfo()?.versionName + ".rp" ) if (toFile.exists()) { toFile.delete() @@ -75,7 +75,7 @@ class TemplateListAdapter( CompressionManager.instance compressionManager.compression( - templatePackage.directest, + localTemplatePackage.directest, toFile, object : CompressionListener { override fun whenCompressionFile(file: File): Boolean { @@ -108,7 +108,7 @@ class TemplateListAdapter( title(R.string.share_mod).message( text = String.format( context.getString(R.string.pack_success), - templatePackage.getName() + localTemplatePackage.getName() ) ).positiveButton(R.string.share) { FileOperator.shareFile( @@ -135,9 +135,9 @@ class TemplateListAdapter( /** * 点击了导出文件 * @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 handler = Handler(Looper.getMainLooper()) Thread { @@ -148,7 +148,7 @@ class TemplateListAdapter( } val toFile = File( - cacheDirectory.absolutePath + "/" + templatePackage.getName() + "_" + templatePackage.getInfo()?.versionName + ".rp" + cacheDirectory.absolutePath + "/" + localTemplatePackage.getName() + "_" + localTemplatePackage.getInfo()?.versionName + ".rp" ) if (toFile.exists()) { toFile.delete() @@ -162,7 +162,7 @@ class TemplateListAdapter( CompressionManager.instance compressionManager.compression( - templatePackage.directest, + localTemplatePackage.directest, toFile, object : CompressionListener { override fun whenCompressionFile(file: File): Boolean { @@ -195,7 +195,7 @@ class TemplateListAdapter( title(R.string.export_file).message( text = String.format( context.getString(R.string.pack_success2), - templatePackage.getName() + localTemplatePackage.getName() ) ).positiveButton(R.string.export) { val intent = @@ -246,7 +246,7 @@ class TemplateListAdapter( } override fun onBingView( - data: TemplatePackage, + data: LocalTemplatePackage, viewBinding: TemplateListItemBinding, viewHolder: ViewHolder, position: Int diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt index d5b9291..c0e3dfc 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt @@ -24,7 +24,7 @@ class UnitAdapter( ) : BaseAdapter(context, dataList) { private val language: String by lazy { - AppSettings.getInstance(context).getValue( + AppSettings.getValue( AppSettings.Setting.AppLanguage, Locale.getDefault().language ) diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/UserHomeStateAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/UserHomeStateAdapter.kt index 3fbddc6..24a3f0a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/UserHomeStateAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/UserHomeStateAdapter.kt @@ -1,11 +1,9 @@ package com.coldmint.rust.pro.adapters -import android.app.Activity import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import androidx.viewpager2.adapter.FragmentStateAdapter import com.coldmint.rust.pro.fragments.DynamicFragment -import com.coldmint.rust.pro.fragments.NullObjectFragment import com.coldmint.rust.pro.fragments.PersonalHomeFragment class UserHomeStateAdapter(activity: FragmentActivity, val userId: String) : diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/WarehouseAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/WarehouseAdapter.kt index 3d577be..58f8cdd 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/WarehouseAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/WarehouseAdapter.kt @@ -22,7 +22,7 @@ class WarehouseAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) { MapFragment() } else -> { - NullObjectFragment() + NullFragment() } } } diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/WebTemplateAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/WebTemplateAdapter.kt new file mode 100644 index 0000000..146e11a --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/WebTemplateAdapter.kt @@ -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) : + BaseAdapter(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, + 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() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt b/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt index 6def4a4..a50cbd4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt @@ -5,6 +5,7 @@ import android.content.res.Configuration import androidx.appcompat.app.AppCompatActivity import com.coldmint.rust.pro.tool.AppSettings import android.os.Bundle +import android.view.LayoutInflater import android.view.MenuItem import android.view.View import android.view.inputmethod.InputMethodManager @@ -33,16 +34,13 @@ abstract class BaseActivity : abstract fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) - abstract fun getViewBindingObject(): ViewBingType + abstract fun getViewBindingObject(layoutInflater: LayoutInflater): ViewBingType 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 { getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager } diff --git a/app/src/main/java/com/coldmint/rust/pro/base/BaseFragment.kt b/app/src/main/java/com/coldmint/rust/pro/base/BaseFragment.kt index 0dc9bc2..85b0fc8 100644 --- a/app/src/main/java/com/coldmint/rust/pro/base/BaseFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/base/BaseFragment.kt @@ -10,12 +10,12 @@ import androidx.viewbinding.ViewBinding import com.coldmint.rust.pro.tool.AppSettings abstract class BaseFragment : Fragment() { - protected lateinit var appSettings: AppSettings val viewBinding: T by lazy { - getViewBindingObject() + getViewBindingObject(layoutInflater) } + /** * 显示Toast * @param text String @@ -39,7 +39,7 @@ abstract class BaseFragment : Fragment() { /** * 获取视图绑定对象 */ - abstract fun getViewBindingObject(): T + abstract fun getViewBindingObject(layoutInflater: LayoutInflater): T override fun onCreateView( @@ -47,7 +47,6 @@ abstract class BaseFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - appSettings = AppSettings.getInstance(requireContext()) return viewBinding.root } diff --git a/app/src/main/java/com/coldmint/rust/pro/databean/ErrorInfo.kt b/app/src/main/java/com/coldmint/rust/pro/databean/ErrorInfo.kt index ae81ed9..d66eb6d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/databean/ErrorInfo.kt +++ b/app/src/main/java/com/coldmint/rust/pro/databean/ErrorInfo.kt @@ -22,10 +22,10 @@ data class ErrorInfo( val id: String = UUID.randomUUID().toString(), var allErrorDetails: String = "", var activityLog: String? = null, - var describe: String? = null, - var autoSave: Boolean = true + var autoSave: Boolean = true, ) { + /** * 保存ErrorInfo * @return Boolean diff --git a/app/src/main/java/com/coldmint/rust/pro/edit/RustAutoComplete2.kt b/app/src/main/java/com/coldmint/rust/pro/edit/RustAutoComplete2.kt index 7629126..77887fe 100644 --- a/app/src/main/java/com/coldmint/rust/pro/edit/RustAutoComplete2.kt +++ b/app/src/main/java/com/coldmint/rust/pro/edit/RustAutoComplete2.kt @@ -42,7 +42,7 @@ class RustAutoComplete2(val context: Context) : AutoCompleteProvider, EnglishMod tem } private val identifiersPromptNumber: Int by lazy { - AppSettings.getInstance(context).getValue(AppSettings.Setting.IdentifiersPromptNumber, 40) + AppSettings.getValue(AppSettings.Setting.IdentifiersPromptNumber, 40) } //类型转换器 diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt index 066a472..5e0a4e6 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt @@ -89,7 +89,7 @@ class AllUnitsFragment( val funData: () -> Unit = { val path = file.file.absolutePath val name = file.getName( - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.AppLanguage, Locale.getDefault().language ) @@ -240,7 +240,7 @@ class AllUnitsFragment( dataList.clear() val data = modClass.modConfigurationManager?.readData() val sourceFileFilteringRule = data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template" - val language = AppSettings.getInstance(requireContext()) + val language = AppSettings .getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) val fileFinder2 = FileFinder2(file) fileFinder2.findMode = true @@ -332,7 +332,7 @@ class AllUnitsFragment( notFindUnits(handler) } else { val newList = ArrayList() - val language = AppSettings.getInstance(requireContext()) + val language = AppSettings .getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) dataList.forEach { 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) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/CommunityFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/CommunityFragment.kt index 7fcc36d..22bce99 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/CommunityFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/CommunityFragment.kt @@ -51,7 +51,7 @@ class CommunityFragment : BaseFragment() { } - override fun getViewBindingObject(): CommunityFragmentBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): CommunityFragmentBinding { return CommunityFragmentBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/DatabaseFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/DatabaseFragment.kt index f937acb..2344ae7 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/DatabaseFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/DatabaseFragment.kt @@ -34,7 +34,7 @@ class DatabaseFragment : BaseFragment() { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { viewBinding.databaseList.layoutManager = LinearLayoutManager(requireContext()) - val database_directory = appSettings.getValue( + val database_directory = AppSettings.getValue( AppSettings.Setting.DatabaseDirectory, requireContext().filesDir.absolutePath + "/database/" ) @@ -151,7 +151,7 @@ class DatabaseFragment : BaseFragment() { } - override fun getViewBindingObject(): DatabaseFragmentBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): DatabaseFragmentBinding { return DatabaseFragmentBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/DynamicFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/DynamicFragment.kt index 5f73a82..1062a2e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/DynamicFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/DynamicFragment.kt @@ -52,7 +52,7 @@ class DynamicFragment(val userId: String) : BaseFragment } - override fun getViewBindingObject(): FragmentDynamicBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentDynamicBinding { return FragmentDynamicBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/FollowFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/FollowFragment.kt index bb33343..1c91e44 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/FollowFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/FollowFragment.kt @@ -29,7 +29,7 @@ import com.coldmint.rust.pro.tool.AppSettings */ class FollowFragment : BaseFragment() { val selfAccount by lazy { - appSettings.getValue(AppSettings.Setting.Account, "") + AppSettings.getValue(AppSettings.Setting.Account, "") } var oldSize: Int = 0 var lastIndex = 0 @@ -212,7 +212,7 @@ class FollowFragment : BaseFragment() { } } - override fun getViewBindingObject(): FragmentFollowBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentFollowBinding { return FragmentFollowBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/HistoryUnitFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/HistoryUnitFragment.kt index bbf3846..4331138 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/HistoryUnitFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/HistoryUnitFragment.kt @@ -111,7 +111,7 @@ class HistoryUnitFragment( val bundle = Bundle() val path = file.file.absolutePath // val name = fileClass.getName( -// appSettings.getValue( +// AppSettings.getValue( // AppSettings.Setting.AppLanguage, // Locale.getDefault().language // ) @@ -140,7 +140,7 @@ class HistoryUnitFragment( } } - override fun getViewBindingObject(): FragmentHistoryBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentHistoryBinding { return FragmentHistoryBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt new file mode 100644 index 0000000..dd6f365 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt @@ -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() { + 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(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) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/MapFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/MapFragment.kt index 631731e..26116f6 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/MapFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/MapFragment.kt @@ -131,7 +131,7 @@ class MapFragment : BaseFragment() { viewBinding.mapErrorIcon.isVisible = true } - override fun getViewBindingObject(): FragmentMapBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentMapBinding { return FragmentMapBinding.inflate(layoutInflater) } @@ -143,7 +143,7 @@ class MapFragment : BaseFragment() { DividerItemDecoration.VERTICAL ) ) - val path = appSettings.getValue(AppSettings.Setting.MapFolder, "") + val path = AppSettings.getValue(AppSettings.Setting.MapFolder, "") if (path.isNotBlank()) { loadPath(File(path)) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt index 75cae96..2d5d5a6 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt @@ -41,7 +41,7 @@ class ModFragment : BaseFragment() { lateinit var modAdapter: ModAdapter val needRecycling by lazy { if (GlobalMethod.isActive) { - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.EnableRecoveryStation, true ) @@ -64,7 +64,7 @@ class ModFragment : BaseFragment() { 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()) { mod_directory.mkdirs() } @@ -93,6 +93,7 @@ class ModFragment : BaseFragment() { handler.post { loadMods() } } } +// modAdapter. modAdapter.setItemEvent { i, modListItemBinding, viewHolder, modClass -> modListItemBinding.root.setOnClickListener { onClickItemWork(modListItemBinding, modClass) @@ -167,7 +168,7 @@ class ModFragment : BaseFragment() { val removePath: String val removeFile: File if (targetFile.isDirectory) { - removePath = appSettings.getValue( + removePath = AppSettings.getValue( AppSettings.Setting.RecoveryStationFolder, requireContext().filesDir.absolutePath + "/backup/" ).toString() + targetFile.name + "/" @@ -176,7 +177,7 @@ class ModFragment : BaseFragment() { removeFile.mkdirs() } } else { - removePath = appSettings.getValue( + removePath = AppSettings.getValue( AppSettings.Setting.RecoveryStationFolder, requireContext().filesDir.absolutePath + "/backup/" ).toString() + targetFile.name @@ -269,7 +270,7 @@ class ModFragment : BaseFragment() { configurationManager?.readData() val works: MutableList = ArrayList() if (modClass.modFile.isDirectory) { - val developerMode = appSettings.getValue(AppSettings.Setting.DeveloperMode, false) + val developerMode = AppSettings.getValue(AppSettings.Setting.DeveloperMode, false) if (developerMode) { works.add(getString(R.string.generate_error_report)) } @@ -356,7 +357,7 @@ class ModFragment : BaseFragment() { viewBinding.progressBar.isVisible = false } - override fun getViewBindingObject(): ModFragmentBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): ModFragmentBinding { return ModFragmentBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/NullObjectFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/NullFragment.kt similarity index 66% rename from app/src/main/java/com/coldmint/rust/pro/fragments/NullObjectFragment.kt rename to app/src/main/java/com/coldmint/rust/pro/fragments/NullFragment.kt index 3df9c66..626d783 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/NullObjectFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/NullFragment.kt @@ -6,10 +6,12 @@ import com.coldmint.rust.pro.base.BaseFragment import com.coldmint.rust.pro.databinding.FragmentNullBinding -//该类的实例是表示集合中单个对象的片段。 -class NullObjectFragment : BaseFragment() { +/** + * 没有内容的碎片 + */ +class NullFragment : BaseFragment() { - override fun getViewBindingObject(): FragmentNullBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentNullBinding { return FragmentNullBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/PersonalHomeFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/PersonalHomeFragment.kt index 89578a4..f963853 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/PersonalHomeFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/PersonalHomeFragment.kt @@ -23,7 +23,7 @@ import com.coldmint.rust.pro.databinding.FragmentPersonalHomeBinding */ class PersonalHomeFragment(val userId: String) : BaseFragment() { - override fun getViewBindingObject(): FragmentPersonalHomeBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentPersonalHomeBinding { return FragmentPersonalHomeBinding.inflate(LayoutInflater.from(requireContext())) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/RankingFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/RankingFragment.kt index f4a885d..2581afb 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/RankingFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/RankingFragment.kt @@ -123,7 +123,7 @@ class RankingFragment : BaseFragment() { } - override fun getViewBindingObject(): FragmentRankingBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentRankingBinding { return FragmentRankingBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt index fb9eeea..cff248e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt @@ -97,7 +97,7 @@ class RecommendedFragment : BaseFragment() { fun loadSoleRecommended() { viewBinding.soleRecommendedCardView.isVisible = false viewBinding.soleRecommendedProgressIndicator.isVisible = true - val account = appSettings.getValue(AppSettings.Setting.Account, "") + val account = AppSettings.getValue(AppSettings.Setting.Account, "") if (account.isNotBlank()) { WebMod.instance.soleRecommended(account, object : ApiCallBack { override fun onResponse(t: WebModListData) { @@ -132,7 +132,7 @@ class RecommendedFragment : BaseFragment() { val dataList = t.data if (dataList != null && dataList.isNotEmpty()) { val forever = - appSettings.getValue( + AppSettings.getValue( AppSettings.Setting.ExpirationTime, 0.toLong() ) == (-2).toLong() @@ -221,7 +221,7 @@ class RecommendedFragment : BaseFragment() { loadBannerData() } - override fun getViewBindingObject(): RecommendedFragmentBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): RecommendedFragmentBinding { return RecommendedFragmentBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/SearchResultFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/SearchResultFragment.kt index 7f018d8..cf06823 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/SearchResultFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/SearchResultFragment.kt @@ -44,7 +44,7 @@ class SearchResultFragment( return list } - override fun getViewBindingObject(): FragmentSearchResultBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentSearchResultBinding { return FragmentSearchResultBinding.inflate(layoutInflater) } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateCommunityFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateCommunityFragment.kt new file mode 100644 index 0000000..1800f16 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateCommunityFragment.kt @@ -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() { + 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 { + 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) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateFragment.kt index b1b84c7..5dbcd37 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateFragment.kt @@ -6,8 +6,7 @@ import android.os.Bundle import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager import com.coldmint.rust.pro.tool.AppSettings -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener -import com.coldmint.rust.core.TemplatePackage +import com.coldmint.rust.core.LocalTemplatePackage import com.coldmint.rust.pro.adapters.TemplateListAdapter import com.coldmint.rust.pro.base.BaseFragment import com.coldmint.rust.pro.databinding.TemplateFragemntBinding @@ -21,7 +20,7 @@ class TemplateFragment : BaseFragment() { override fun onResume() { super.onResume() if (!first) { - val directent = appSettings.getValue( + val directent = AppSettings.getValue( AppSettings.Setting.TemplateDirectory, requireContext().filesDir.absolutePath + "/template/" ) @@ -33,13 +32,13 @@ class TemplateFragment : BaseFragment() { fun loadList(path: String) { val language = - appSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) + AppSettings.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) val file = File(path) if (file.exists() && file.isDirectory) { val files = file.listFiles() - val mutableList: ArrayList = ArrayList() + val mutableList: ArrayList = ArrayList() for (f in files) { - val tem = TemplatePackage(f) + val tem = LocalTemplatePackage(f) if (tem.isTemplate) { mutableList.add(tem) } @@ -60,12 +59,12 @@ class TemplateFragment : BaseFragment() { } } - override fun getViewBindingObject(): TemplateFragemntBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): TemplateFragemntBinding { return TemplateFragemntBinding.inflate(layoutInflater) } override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { - val directent = appSettings.getValue( + val directent = AppSettings.getValue( AppSettings.Setting.TemplateDirectory, requireContext().filesDir.absolutePath + "/template/" ) diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt index eaa498e..038145e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt @@ -95,14 +95,14 @@ class UserInfoFragment : BaseFragment() { startActivity(intent) } - override fun getViewBindingObject(): FragmentUserInfoBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentUserInfoBinding { return FragmentUserInfoBinding.inflate(layoutInflater) } override fun onResume() { super.onResume() - val token = appSettings.getValue(AppSettings.Setting.Token, "") + val token = AppSettings.getValue(AppSettings.Setting.Token, "") if (token.isNotBlank()) { User.getUserActivationInfo(token, object : ApiCallBack { @@ -110,7 +110,7 @@ class UserInfoFragment : BaseFragment() { viewBinding.nameView.text = account loadRecyclerView(3) // val localTime = -// appSettings.getValue(AppSettings.Setting.ExpirationTime, 0.toLong()) +// AppSettings.getValue(AppSettings.Setting.ExpirationTime, 0.toLong()) // viewBinding.expirationTimeView.text = // ServerConfiguration.toStringTime(localTime) } @@ -138,7 +138,7 @@ class UserInfoFragment : BaseFragment() { } override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { - account = appSettings.getValue(AppSettings.Setting.Account, "") + account = AppSettings.getValue(AppSettings.Setting.Account, "") viewBinding.myHomeView.setOnClickListener { val intent = Intent( requireActivity(), @@ -151,7 +151,7 @@ class UserInfoFragment : BaseFragment() { } viewBinding.logOutButton.setOnClickListener { - appSettings.setValue(AppSettings.Setting.LoginStatus, false) + AppSettings.setValue(AppSettings.Setting.LoginStatus, false) startActivity(Intent(requireContext(), LoginActivity::class.java)) } } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/WarehouseFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/WarehouseFragment.kt index f1049d8..6378980 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/WarehouseFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/WarehouseFragment.kt @@ -43,7 +43,7 @@ class WarehouseFragment : BaseFragment() { } } - override fun getViewBindingObject(): FragmentWarehouseBinding { + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentWarehouseBinding { return FragmentWarehouseBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/tool/AppSettings.kt b/app/src/main/java/com/coldmint/rust/pro/tool/AppSettings.kt index 3f11971..ed5052c 100644 --- a/app/src/main/java/com/coldmint/rust/pro/tool/AppSettings.kt +++ b/app/src/main/java/com/coldmint/rust/pro/tool/AppSettings.kt @@ -1,6 +1,7 @@ package com.coldmint.rust.pro.tool import android.annotation.SuppressLint +import android.app.Application import android.content.Context import android.content.SharedPreferences import com.coldmint.rust.pro.R @@ -15,33 +16,25 @@ import java.util.* * 程序设置类 * 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 + val dataRootDirectory = + Environment.getExternalStorageDirectory().absolutePath + "/rustAssistant" + val Locale_Russia = Locale("RU", "ru", "") - @JvmField - val dataRootDirectory = - Environment.getExternalStorageDirectory().absolutePath + "/rustAssistant" - val Locale_Russia = Locale("RU", "ru", "") + private val mFileName: String by lazy { + mApplication.packageName + "_preferences" + } + private val sharedPreferences: SharedPreferences by lazy { + mApplication.getSharedPreferences(mFileName, Context.MODE_PRIVATE) + } + private val editor: SharedPreferences.Editor by lazy { + sharedPreferences.edit() } - - private val mFileName: String = mContext.packageName + "_preferences" - private val sharedPreferences: SharedPreferences = - mContext.getSharedPreferences(mFileName, Context.MODE_PRIVATE) - private val editor: SharedPreferences.Editor = sharedPreferences.edit() 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 @@ -71,6 +64,71 @@ class AppSettings private constructor(val mContext: Context) { 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. @@ -106,7 +164,7 @@ class AppSettings private constructor(val mContext: Context) { * @return Boolean 是否需要重启App */ 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 } - - /** - * 构造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" - } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/tool/TextStyleMaker.kt b/app/src/main/java/com/coldmint/rust/pro/tool/TextStyleMaker.kt index e7054e2..d1777fe 100644 --- a/app/src/main/java/com/coldmint/rust/pro/tool/TextStyleMaker.kt +++ b/app/src/main/java/com/coldmint/rust/pro/tool/TextStyleMaker.kt @@ -297,7 +297,7 @@ class TextStyleMaker private constructor() { } "activate" -> { val time = ServerConfiguration.toStringTime( - AppSettings.getInstance(context) + AppSettings .getValue(AppSettings.Setting.ExpirationTime, 0.toLong()) ) if (time == ServerConfiguration.ForeverTime) { diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/EditViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/EditViewModel.kt index 849f4fc..c60ecfb 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/EditViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/EditViewModel.kt @@ -60,7 +60,7 @@ class EditViewModel(application: Application) : BaseAndroidViewModel(application */ val apkFolder by lazy { GameSynchronizer.getPackAgeFolder( - getApplication(), AppSettings.getInstance(getApplication()).getValue( + getApplication(), AppSettings.getValue( AppSettings.Setting.GamePackage, GlobalMethod.DEFAULT_GAME_PACKAGE ) @@ -504,7 +504,7 @@ class EditViewModel(application: Application) : BaseAndroidViewModel(application if (fileDataBase != null) { val path = file.file.absolutePath val name = file.getName( - AppSettings.getInstance(getApplication()).getValue( + AppSettings.getValue( AppSettings.Setting.AppLanguage, Locale.getDefault().language ) @@ -573,7 +573,7 @@ class EditViewModel(application: Application) : BaseAndroidViewModel(application * 加载数据 */ fun loadData() { - val english = AppSettings.getInstance(getApplication()) + val english = AppSettings .getValue(AppSettings.Setting.EnglishEditingMode, false) setEnglish(english) } diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt index 9fa38b1..077789a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt @@ -85,9 +85,8 @@ class FileManagerViewModel : BaseViewModel() { * 从设置中读取排序方式 */ fun loadSortType(context: Context) { - val appSettings = AppSettings.getInstance(context) //从设置中读取排序方式 - val sortType = appSettings.getValue( + val sortType = AppSettings.getValue( AppSettings.Setting.FileSortType, context.getString(R.string.setting_file_list_action_sort_by_name) ) @@ -116,7 +115,6 @@ class FileManagerViewModel : BaseViewModel() { * @return Boolean */ fun saveSortType(context: Context): Boolean { - val appSettings = AppSettings.getInstance(context) val value = sortTypeLiveData.value ?: SortType.BY_NAME val text = when (value) { @@ -136,7 +134,7 @@ class FileManagerViewModel : BaseViewModel() { 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) } /** diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/InstalledTemplateViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/InstalledTemplateViewModel.kt new file mode 100644 index 0000000..b401ae4 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/InstalledTemplateViewModel.kt @@ -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 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? + */ + fun setLoadCallBack(callBack: (() -> Unit)? = null) { + loadCallBack = callBack + } + + var mRootPath: String? = null + + private val groupList: ArrayList by lazy { + ArrayList() + } + private val itemList: ArrayList> by lazy { + ArrayList() + } + + /** + * 获取组 + * @return ArrayList + */ + fun getGroupData(): ArrayList { + return groupList + } + + /** + * 获取组 + * @return ArrayList + */ + fun getItemData(): ArrayList> { + 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