From 01715baa99794a0f5873b6b347b57ea24d1115c7 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Mon, 26 Jun 2023 20:27:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=89=AA=E5=88=87=E6=9D=BF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=BC=80=E5=85=B3=EF=BC=8C=E5=9C=A8=E5=AE=89?= =?UTF-8?q?=E5=8D=9313=E5=8F=AF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 - .../com/coldmint/rust/pro/SettingsActivity.kt | 6 ++ .../rust/pro/adapters/CodeTableAdapter.kt | 14 +++- .../com/coldmint/rust/pro/tool/AppSettings.kt | 13 +++- .../coldmint/rust/pro/tool/GlobalMethod.kt | 29 +++++--- .../rust/pro/viewmodel/StartViewModel.kt | 2 + .../res/drawable/baseline_help_outline_24.xml | 14 +++- app/src/main/res/layout/code_table_item.xml | 74 ++++++++++--------- app/src/main/res/values/strings.xml | 4 + app/src/main/res/xml/root_preferences.xml | 6 ++ 10 files changed, 109 insertions(+), 55 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 82868c7..7b3ec8a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -101,10 +101,8 @@ dependencies { implementation 'com.github.promeg:tinypinyin:2.0.3' implementation 'io.github.youth5201314:banner:2.2.2' implementation 'androidx.core:core-ktx:1.8.0' -// implementation 'com.github.deano2390:MaterialShowcaseView:1.3.4' implementation 'com.google.code.gson:gson:2.9.1' implementation 'com.github.yalantis:ucrop:2.2.8-native' -// implementation 'com.kongzue.stacklabel:stacklabelview:1.1.9' implementation 'io.github.Rosemoe.sora-editor:editor:0.16.5' implementation project(path: ':assistantCoreLibrary') implementation project(path: ':dialog') 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 bb4448e..8bfd43b 100644 --- a/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt @@ -62,6 +62,12 @@ class SettingsActivity : BaseActivity() { true } + val clipboardCue = manager.findPreference(requireContext().getString(R.string.setting_clipboard_cue)) + // Only show a toast for Android 12 and lower. + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2){ + //如果是安卓12或更低 + clipboardCue?.isEnabled = false + } val dynamicColor = manager.findPreference(requireContext().getString(R.string.setting_dynamic_color)) if (!DynamicColors.isDynamicColorAvailable()) { 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 a4b6170..5cdcc28 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 @@ -11,6 +11,7 @@ import android.view.View import android.widget.Toast import androidx.core.view.isVisible import com.afollestad.materialdialogs.MaterialDialog +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.database.code.CodeDataBase import com.coldmint.rust.core.database.code.CodeInfo import com.coldmint.rust.core.database.code.SectionInfo @@ -20,6 +21,7 @@ import com.coldmint.rust.pro.databinding.CodeTableItemBinding import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod import com.google.android.material.chip.Chip +import com.google.android.material.dialog.MaterialAlertDialogBuilder import java.util.concurrent.Executors class CodeTableAdapter( @@ -144,8 +146,16 @@ class CodeTableAdapter( } val demo = codeInfo.demo - resultView.demoView.isVisible = demo.isNotBlank() - resultView.demoView.text = demo + resultView.imageView.isVisible = demo.isNotBlank() + resultView.imageView.setOnClickListener { + val dialog = MaterialAlertDialogBuilder(context); + dialog.setTitle(R.string.code_demo) + dialog.setMessage(demo) + dialog.setPositiveButton(R.string.dialog_ok){ + v,a-> + } + dialog.show() + } resultView.subTitleView.text = codeInfo.code resultView.subTitleView.setOnClickListener { 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 fa1023d..48002de 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 @@ -38,7 +38,7 @@ object AppSettings { } enum class Setting { - DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeywordColor, KeywordColorDark, AnnotationColor, AnnotationColorDark, TextColor, TextColorDark, SectionColor, SectionColorDark, 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, CodeEditBackGroundEnable, BlurTransformationValue, CodeEditBackGroundPath, SimpleDisplayOfAutoCompleteMenu, SourceFileType + DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeywordColor, KeywordColorDark, AnnotationColor, AnnotationColorDark, TextColor, TextColorDark, SectionColor, SectionColorDark, 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, CodeEditBackGroundEnable, BlurTransformationValue, CodeEditBackGroundPath, SimpleDisplayOfAutoCompleteMenu, SourceFileType, ClipboardCue } @@ -135,6 +135,7 @@ object AppSettings { mApplication.getString(R.string.setting_simple_display_of_auto_complete_menu) //setting_source_file_type map[Setting.SourceFileType] = mApplication.getString(R.string.setting_source_file_type) + map[Setting.ClipboardCue] = mApplication.getString(R.string.setting_clipboard_cue) //仅保存不可显示 map[Setting.SetGameStorage] = "SetGameStorage" map[Setting.AppID] = "AppId" @@ -235,18 +236,23 @@ object AppSettings { is String -> { editor.putString(name, value as String) } + is Boolean -> { editor.putBoolean(name, value as Boolean) } + is Int -> { editor.putInt(name, value as Int) } + is Float -> { editor.putFloat(name, value as Float) } + is Long -> { editor.putLong(name, value as Long) } + else -> { return false } @@ -271,18 +277,23 @@ object AppSettings { is String -> { editor.putString(name, value as String) } + is Boolean -> { editor.putBoolean(name, value as Boolean) } + is Int -> { editor.putInt(name, value as Int) } + is Float -> { editor.putFloat(name, value as Float) } + is Long -> { editor.putLong(name, value as Long) } + else -> { return false } diff --git a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt index 7ef209d..c3d6101 100644 --- a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt +++ b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt @@ -4,6 +4,7 @@ import android.Manifest import android.content.ClipData import android.content.ClipboardManager import android.content.Context +import android.content.Context.CLIPBOARD_SERVICE import android.content.res.ColorStateList import android.content.res.Resources import android.graphics.Bitmap @@ -20,6 +21,7 @@ import android.view.View import android.widget.PopupMenu import android.widget.TextView import android.widget.Toast +import androidx.core.content.ContextCompat.getSystemService import androidx.core.graphics.drawable.DrawableCompat import androidx.fragment.app.FragmentActivity import com.bumptech.glide.load.MultiTransformation @@ -49,7 +51,6 @@ object GlobalMethod { const val RELEASE_SIGN = "5320b24894fe7ed449842a81a2dfceda" - /** * 转dp * @param i Int @@ -300,7 +301,8 @@ object GlobalMethod { scope.showRequestReasonDialog( deniedList, activity.getString(R.string.dialog_title), - activity.getString(R.string.dialog_confirm),activity.getString(R.string.dialog_cancel) + activity.getString(R.string.dialog_confirm), + activity.getString(R.string.dialog_cancel) ) } .request { allGranted, grantedList, deniedList -> @@ -335,16 +337,21 @@ object GlobalMethod { * @param showView 展示的视图(设置为null则不展示提示) */ fun copyText(context: Context, text: String, showView: View? = null) { - val clipboardManager = - context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - val clipData = ClipData.newPlainText(text, text) - clipboardManager.setPrimaryClip(clipData) + val clipboardManager = context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager + // When setting the clip board text. + clipboardManager.setPrimaryClip(ClipData.newPlainText("", text)) if (showView != null) { - Snackbar.make( - showView, - String.format(context.getText(R.string.copy_complete).toString(), text), - Snackbar.LENGTH_SHORT - ).show() + if (AppSettings.getValue( + 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 + ).show() + } } } diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/StartViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/StartViewModel.kt index 1a40716..b443778 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/StartViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/StartViewModel.kt @@ -258,6 +258,8 @@ class StartViewModel(application: Application) : BaseAndroidViewModel(applicatio AppSettings.Setting.DynamicColor, DynamicColors.isDynamicColorAvailable() ) + //如果是安卓12或更低,那么默认启用。安卓13默认关闭 + AppSettings.initSetting(AppSettings.Setting.ClipboardCue,Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) AppSettings.initSetting(AppSettings.Setting.KeywordColor, "#2196f3") AppSettings.initSetting(AppSettings.Setting.SectionColor, "#e91e63") AppSettings.initSetting(AppSettings.Setting.TextColor, "#212121") diff --git a/app/src/main/res/drawable/baseline_help_outline_24.xml b/app/src/main/res/drawable/baseline_help_outline_24.xml index d2f9639..bce47f8 100644 --- a/app/src/main/res/drawable/baseline_help_outline_24.xml +++ b/app/src/main/res/drawable/baseline_help_outline_24.xml @@ -1,5 +1,11 @@ - - + + diff --git a/app/src/main/res/layout/code_table_item.xml b/app/src/main/res/layout/code_table_item.xml index 59ea631..fac7972 100644 --- a/app/src/main/res/layout/code_table_item.xml +++ b/app/src/main/res/layout/code_table_item.xml @@ -1,12 +1,14 @@ - + + + + + + + + + + + + + + + + + + + + + + - - - - + android:layout_marginTop="8dp" + app:singleLine="false"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e20215b..fe75a50 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -880,6 +880,7 @@ 显示源代码 动态颜色 DynamicColor + ClipboardCue 跟随设备壁纸更换主题色。 此设备不支持动态颜色。 不支持的文件格式%1$s。 @@ -967,4 +968,7 @@ GitHub DataBaseManifest.json不存在,无法加载信息。 此数据集仅适用于旧版本助手。 + 示例代码 + 剪切板提示 + 在安卓13及以上系统,应用将内容复制到剪贴板时,弹出提示。 \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 6fa14c5..68237a8 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -12,6 +12,12 @@ app:title="@string/reply_title" app:useSimpleSummaryProvider="true" /> +