From ef95908cd4b5dbcb78db9d0da0f85f9001bb44e6 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Sat, 2 Mar 2024 15:25:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E5=8A=A9=E6=89=8B=E6=97=B6=EF=BC=8C=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=B8=B8=E6=88=8F=E7=9B=AE=E5=BD=95=EF=BC=8C=E6=B2=A1?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=97=A0=E6=B3=95=E5=88=9B=E5=BB=BA=E6=A8=A1?= =?UTF-8?q?=E7=BB=84=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coldmint/rust/pro/CreateModActivity.kt | 85 ++++++++++--------- 1 file changed, 43 insertions(+), 42 deletions(-) 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 1f959de..3bf6f6a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/CreateModActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/CreateModActivity.kt @@ -12,6 +12,7 @@ import android.view.inputmethod.InputMethodManager import android.widget.Toast import androidx.core.widget.addTextChangedListener import com.coldmint.rust.pro.databinding.ActivityCreateModBinding +import com.coldmint.rust.pro.tool.GlobalMethod import java.io.File import java.io.FileWriter import java.io.IOException @@ -32,22 +33,22 @@ class CreateModActivity : BaseActivity() { val name = it.toString() if (name.isBlank()) { setErrorAndInput( - viewBinding.modNameEdit, - String.format( - getString(R.string.please_input_value), - viewBinding.modDescribeInputLayout.hint.toString() - ), - viewBinding.modNameInputLayout, false + viewBinding.modNameEdit, + String.format( + getString(R.string.please_input_value), + viewBinding.modDescribeInputLayout.hint.toString() + ), + viewBinding.modNameInputLayout, false ) return@addTextChangedListener } val mod_directory = - File(Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + name) + File(Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + name) if (mod_directory.exists()) { setErrorAndInput( - viewBinding.modNameEdit, - getString(R.string.directory_error), - viewBinding.modNameInputLayout, false + viewBinding.modNameEdit, + getString(R.string.directory_error), + viewBinding.modNameInputLayout, false ) } else { viewBinding.modNameInputLayout.isErrorEnabled = false @@ -67,9 +68,9 @@ class CreateModActivity : BaseActivity() { override fun afterTextChanged(s: Editable) { if (s.toString().contains("\n")) { setErrorAndInput( - viewBinding.modDescribeEdit, - getString(R.string.describe_error2), - viewBinding.modDescribeInputLayout + viewBinding.modDescribeEdit, + getString(R.string.describe_error2), + viewBinding.modDescribeInputLayout ) } } @@ -78,28 +79,28 @@ class CreateModActivity : BaseActivity() { val name: String = viewBinding.modNameEdit.text.toString() if (name.isBlank()) { setErrorAndInput( - viewBinding.modNameEdit, - String.format( - getString(R.string.please_input_value), - viewBinding.modNameInputLayout.hint.toString() - ), - viewBinding.modNameInputLayout + viewBinding.modNameEdit, + String.format( + getString(R.string.please_input_value), + viewBinding.modNameInputLayout.hint.toString() + ), + viewBinding.modNameInputLayout ) return@OnClickListener } val describe: String = viewBinding.modDescribeEdit.text.toString() if (describe.isEmpty()) { setErrorAndInput( - viewBinding.modDescribeEdit, - getString(R.string.describe_error), - viewBinding.modDescribeInputLayout + viewBinding.modDescribeEdit, + getString(R.string.describe_error), + viewBinding.modDescribeInputLayout ) return@OnClickListener } else if (describe.contains("\n")) { setErrorAndInput( - viewBinding.modDescribeEdit, - getString(R.string.describe_error2), - viewBinding.modDescribeInputLayout + viewBinding.modDescribeEdit, + getString(R.string.describe_error2), + viewBinding.modDescribeInputLayout ) return@OnClickListener } @@ -108,34 +109,34 @@ class CreateModActivity : BaseActivity() { stringBuilder.append(name) stringBuilder.append("\ndescription: ") stringBuilder.append(describe) - val minVersion:String = viewBinding.minVersionEdit.text.toString() - if (minVersion.isNotBlank()){ + val minVersion: String = viewBinding.minVersionEdit.text.toString() + if (minVersion.isNotBlank()) { stringBuilder.append("\nminVersion: ") stringBuilder.append(minVersion) } - val mod_directory = - File(Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + name) - if (mod_directory.exists()) { - setErrorAndInput( - viewBinding.modNameEdit, - getString(R.string.directory_error), - viewBinding.modNameInputLayout - ) - } else { - if (mod_directory.mkdirs()) { - try { + GlobalMethod.requestStoragePermissions(this@CreateModActivity) { + if (!it) { + return@requestStoragePermissions + } + val mod_directory = + File(Environment.getExternalStorageDirectory().absolutePath + "/rustedWarfare/units/" + name) + if (mod_directory.exists()) { + setErrorAndInput( + viewBinding.modNameEdit, + getString(R.string.directory_error), + viewBinding.modNameInputLayout + ) + } else { + if (mod_directory.mkdirs()) { val fileWriter = FileWriter(mod_directory.absolutePath + "/mod-info.txt") fileWriter.write(stringBuilder.toString()) fileWriter.close() setResult(RESULT_OK) finish() - } catch (e: IOException) { - e.printStackTrace() } - } else { - Toast.makeText(this@CreateModActivity, "你的手机拒绝创建目录", Toast.LENGTH_SHORT).show() } } + }) }