From 31084d479394e3a4fdf1c73badc59e87831a81f1 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Sat, 8 Feb 2025 22:59:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(tool):=20=E6=B7=BB=E5=8A=A0=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E6=9D=83=E9=99=90=E8=AF=B7=E6=B1=82=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 GlobalMethod.kt 中添加了请求存储权限的功能 - 优化了代码格式,调整了部分缩进和换行 - 移除了 shortcuts.xml 文件 - 在 strings.xml 中添加了权限请求相关的字符串资源 --- app/src/main/AndroidManifest.xml | 3 - .../coldmint/rust/pro/tool/GlobalMethod.kt | 99 ++++++++++--------- app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml-v25/shortcuts.xml | 16 --- 4 files changed, 57 insertions(+), 63 deletions(-) delete mode 100644 app/src/main/res/xml-v25/shortcuts.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 75e501e..59a68d7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -89,9 +89,6 @@ - ( - transformations + transformations ) RequestOptions.bitmapTransform(multi) } else { RequestOptions() } requestOptions.placeholder(R.drawable.image) - .error(R.drawable.image_not_supported) + .error(R.drawable.image_not_supported) return requestOptions } @@ -131,10 +132,10 @@ object GlobalMethod { val context = view.context; return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { PopupMenu( - context, - view, - Gravity.NO_GRAVITY, - 0, com.google.android.material.R.style.Widget_Material3_PopupMenu + context, + view, + Gravity.NO_GRAVITY, + 0, com.google.android.material.R.style.Widget_Material3_PopupMenu ) } else { PopupMenu(context, view) @@ -165,24 +166,24 @@ object GlobalMethod { * @param func Function1 */ fun showColorPickerDialog( - context: Context, - useARGB: Boolean = false, func: ((String) -> Unit) + context: Context, + useARGB: Boolean = false, func: ((String) -> Unit) ) { ColorPickerDialogBuilder - .with(context).showAlphaSlider(useARGB) - .setTitle(context.getString(R.string.choose_color)) - .initialColor(Color.WHITE) - .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER) - .density(12) - .setOnColorSelectedListener { - //toast("onColorSelected: 0x" + Integer.toHexString(selectedColor)); - } - .setPositiveButton(R.string.dialog_ok) { dialog, selectedColor, allColors -> - func.invoke(colorToString(selectedColor, useARGB)) - } - .setNegativeButton(R.string.dialog_cancel) { dialog, which -> } - .build() - .show() + .with(context).showAlphaSlider(useARGB) + .setTitle(context.getString(R.string.choose_color)) + .initialColor(Color.WHITE) + .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER) + .density(12) + .setOnColorSelectedListener { + //toast("onColorSelected: 0x" + Integer.toHexString(selectedColor)); + } + .setPositiveButton(R.string.dialog_ok) { dialog, selectedColor, allColors -> + func.invoke(colorToString(selectedColor, useARGB)) + } + .setNegativeButton(R.string.dialog_cancel) { dialog, which -> } + .build() + .show() } /** @@ -243,11 +244,11 @@ object GlobalMethod { stringBuilder.append("\n\n------\n\n") } val title = - context.getString(R.string.update_record) + "(" + data.size + ")" + context.getString(R.string.update_record) + "(" + data.size + ")" MaterialAlertDialogBuilder(context).setTitle(title) - .setMessage(stringBuilder.toString()).setCancelable(false) - .setPositiveButton(R.string.dialog_ok) { i, i2 -> - }.show() + .setMessage(stringBuilder.toString()).setCancelable(false) + .setPositiveButton(R.string.dialog_ok) { i, i2 -> + }.show() } else { Toast.makeText(context, t.message, Toast.LENGTH_SHORT).show() } @@ -261,9 +262,9 @@ object GlobalMethod { override fun onFailure(e: Exception) { Toast.makeText( - context, - context.getString(R.string.network_error), - Toast.LENGTH_SHORT + context, + context.getString(R.string.network_error), + Toast.LENGTH_SHORT ).show() } @@ -278,19 +279,29 @@ object GlobalMethod { fun requestStoragePermissions(activity: FragmentActivity, requestCompleted: (Boolean) -> Unit) { val list = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { listOf( - Manifest.permission.MANAGE_EXTERNAL_STORAGE + Manifest.permission.MANAGE_EXTERNAL_STORAGE ) } else { listOf( - Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE ) } - XXPermissions.with(activity).permission( - list - ).request { _, allGranted -> - requestCompleted.invoke(allGranted) + if (XXPermissions.isGranted(activity, list)) { + return } + MaterialAlertDialogBuilder(activity).setTitle(R.string.permission_request_title) + .setMessage(R.string.permission_request_message) + .setPositiveButton( + R.string.dialog_ok + ) { _, _ -> + XXPermissions.with(activity).permission( + list + ).request { _, allGranted -> + requestCompleted.invoke(allGranted) + } + }.setNegativeButton(R.string.dialog_cancel, null).setCancelable(false).show() + } @@ -325,14 +336,14 @@ object GlobalMethod { clipboardManager.setPrimaryClip(ClipData.newPlainText("", text)) if (showView != null) { if (AppSettings.getValue( - AppSettings.Setting.ClipboardCue, - Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2 - ) + AppSettings.Setting.ClipboardCue, + Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2 + ) ) { Snackbar.make( - showView, - String.format(context.getText(R.string.copy_complete).toString(), text), - Snackbar.LENGTH_SHORT + showView, + String.format(context.getText(R.string.copy_complete).toString(), text), + Snackbar.LENGTH_SHORT ).show() } } @@ -350,8 +361,8 @@ object GlobalMethod { // When setting the clip board text. clipboardManager.setPrimaryClip(ClipData.newPlainText("", text)) Toast.makeText( - context, - "已复制", Toast.LENGTH_SHORT + context, + "已复制", Toast.LENGTH_SHORT ).show() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6cee8ec..399e209 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -616,4 +616,6 @@ 在安卓13及以上系统,应用将内容复制到剪贴板时,弹出提示。 分享 变量名 + 请求权限 + 我们需要存储权限以访问您的模组。 \ No newline at end of file diff --git a/app/src/main/res/xml-v25/shortcuts.xml b/app/src/main/res/xml-v25/shortcuts.xml deleted file mode 100644 index f37f981..0000000 --- a/app/src/main/res/xml-v25/shortcuts.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - -