From c7ea22cb7b2434f151a280fd52e1d78a6d33557e Mon Sep 17 00:00:00 2001 From: Linfye <3158203624@qq.com> Date: Mon, 9 Sep 2024 17:02:59 +0800 Subject: [PATCH 1/2] Fix property naming issues --- .editorconfig | 2 +- .../be/scri/activities/BaseSimpleActivity.kt | 25 ++++++----- .../be/scri/extensions/Context-storage.kt | 11 ++--- app/src/main/java/be/scri/extensions/Int.kt | 8 ++-- .../main/java/be/scri/extensions/String.kt | 4 +- .../java/be/scri/fragments/AboutFragment.kt | 12 +++--- .../be/scri/services/SimpleKeyboardIME.kt | 42 ++++++++++--------- 7 files changed, 54 insertions(+), 50 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0a96eec7..a3b8416a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,7 +20,7 @@ continuation_indent_size = 4 wildcard_import_limit = 999 ij_kotlin_name_count_to_use_star_import = 999 ij_kotlin_name_count_to_use_star_import_for_members = 999 -ktlint_standard_property-naming = disabled +#ktlint_standard_property-naming = disabled ktlint_standard_no-wildcard-imports = disabled ktlint_standard_backing-property-naming = disabled ktlint_standard_filename = disabled diff --git a/app/src/main/java/be/scri/activities/BaseSimpleActivity.kt b/app/src/main/java/be/scri/activities/BaseSimpleActivity.kt index 2b67968a..670af3d1 100644 --- a/app/src/main/java/be/scri/activities/BaseSimpleActivity.kt +++ b/app/src/main/java/be/scri/activities/BaseSimpleActivity.kt @@ -44,16 +44,15 @@ abstract class BaseSimpleActivity : AppCompatActivity() { var checkedDocumentPath = "" var configItemsToExport = LinkedHashMap() - private val GENERIC_PERM_HANDLER = 100 - private val DELETE_FILE_SDK_30_HANDLER = 300 - private val RECOVERABLE_SECURITY_HANDLER = 301 - private val UPDATE_FILE_SDK_30_HANDLER = 302 - companion object { var funAfterSAFPermission: ((success: Boolean) -> Unit)? = null var funAfterSdk30Action: ((success: Boolean) -> Unit)? = null var funAfterUpdate30File: ((success: Boolean) -> Unit)? = null var funRecoverableSecurity: ((success: Boolean) -> Unit)? = null + private const val GENERIC_PERM_HANDLER = 100 + private const val DELETE_FILE_SDK_30_HANDLER = 300 + private const val RECOVERABLE_SECURITY_HANDLER = 301 + private const val UPDATE_FILE_SDK_30_HANDLER = 302 } abstract fun getAppIconIDs(): ArrayList @@ -393,12 +392,12 @@ abstract class BaseSimpleActivity : AppCompatActivity() { } else { funAfterSAFPermission?.invoke(false) } - } else if (requestCode == DELETE_FILE_SDK_30_HANDLER) { + } else if (requestCode == Companion.DELETE_FILE_SDK_30_HANDLER) { funAfterSdk30Action?.invoke(resultCode == Activity.RESULT_OK) - } else if (requestCode == RECOVERABLE_SECURITY_HANDLER) { + } else if (requestCode == Companion.RECOVERABLE_SECURITY_HANDLER) { funRecoverableSecurity?.invoke(resultCode == Activity.RESULT_OK) funRecoverableSecurity = null - } else if (requestCode == UPDATE_FILE_SDK_30_HANDLER) { + } else if (requestCode == Companion.UPDATE_FILE_SDK_30_HANDLER) { funAfterUpdate30File?.invoke(resultCode == Activity.RESULT_OK) } } @@ -576,7 +575,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() { funAfterSdk30Action = callback try { val deleteRequest = MediaStore.createDeleteRequest(contentResolver, uris).intentSender - startIntentSenderForResult(deleteRequest, DELETE_FILE_SDK_30_HANDLER, null, 0, 0, 0) + startIntentSenderForResult(deleteRequest, Companion.DELETE_FILE_SDK_30_HANDLER, null, 0, 0, 0) } catch (e: Exception) { showErrorToast(e) } @@ -595,7 +594,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() { funAfterUpdate30File = callback try { val writeRequest = MediaStore.createWriteRequest(contentResolver, uris).intentSender - startIntentSenderForResult(writeRequest, UPDATE_FILE_SDK_30_HANDLER, null, 0, 0, 0) + startIntentSenderForResult(writeRequest, Companion.UPDATE_FILE_SDK_30_HANDLER, null, 0, 0, 0) } catch (e: Exception) { showErrorToast(e) } @@ -613,7 +612,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() { funRecoverableSecurity = callback val recoverableSecurityException = securityException as? RecoverableSecurityException ?: throw securityException val intentSender = recoverableSecurityException.userAction.actionIntent.intentSender - startIntentSenderForResult(intentSender, RECOVERABLE_SECURITY_HANDLER, null, 0, 0, 0) + startIntentSenderForResult(intentSender, Companion.RECOVERABLE_SECURITY_HANDLER, null, 0, 0, 0) } else { callback(false) } @@ -630,7 +629,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() { } else { isAskingPermissions = true actionOnPermission = callback - ActivityCompat.requestPermissions(this, arrayOf(getPermissionString(permissionId)), GENERIC_PERM_HANDLER) + ActivityCompat.requestPermissions(this, arrayOf(getPermissionString(permissionId)), Companion.GENERIC_PERM_HANDLER) } } @@ -641,7 +640,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() { ) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) isAskingPermissions = false - if (requestCode == GENERIC_PERM_HANDLER && grantResults.isNotEmpty()) { + if (requestCode == Companion.GENERIC_PERM_HANDLER && grantResults.isNotEmpty()) { actionOnPermission?.invoke(grantResults[0] == 0) } } diff --git a/app/src/main/java/be/scri/extensions/Context-storage.kt b/app/src/main/java/be/scri/extensions/Context-storage.kt index c6fc42bb..35851c07 100644 --- a/app/src/main/java/be/scri/extensions/Context-storage.kt +++ b/app/src/main/java/be/scri/extensions/Context-storage.kt @@ -63,10 +63,10 @@ fun Context.getSDCardPath(): String { } if (sdCardPath.isEmpty()) { - val SDpattern = Pattern.compile(SD_OTG_SHORT) + val sdPattern = Pattern.compile(SD_OTG_SHORT) try { File("/storage").listFiles()?.forEach { - if (SDpattern.matcher(it.name).matches()) { + if (sdPattern.matcher(it.name).matches()) { sdCardPath = "/storage/${it.name}" } } @@ -456,11 +456,12 @@ fun Context.deleteFromMediaStore( } } +const val SCAN_FILE_MAX_DURATION = 1000L + fun Context.rescanAndDeletePath( path: String, callback: () -> Unit, ) { - val SCAN_FILE_MAX_DURATION = 1000L val scanFileHandler = Handler(Looper.getMainLooper()) scanFileHandler.postDelayed({ callback() @@ -524,10 +525,10 @@ fun Context.getOTGItems( callback: (ArrayList) -> Unit, ) { val items = ArrayList() - val OTGTreeUri = baseConfig.OTGTreeUri + val otgTreeUri = baseConfig.OTGTreeUri var rootUri = try { - DocumentFile.fromTreeUri(applicationContext, Uri.parse(OTGTreeUri)) + DocumentFile.fromTreeUri(applicationContext, Uri.parse(otgTreeUri)) } catch (e: Exception) { showErrorToast(e) baseConfig.OTGPath = "" diff --git a/app/src/main/java/be/scri/extensions/Int.kt b/app/src/main/java/be/scri/extensions/Int.kt index 5fbe3e6f..7d45e846 100644 --- a/app/src/main/java/be/scri/extensions/Int.kt +++ b/app/src/main/java/be/scri/extensions/Int.kt @@ -129,11 +129,11 @@ fun Int.darkenColor(factor: Int = 8): Int { return this } - val DARK_FACTOR = factor + val darkFactor = factor var hsv = FloatArray(3) Color.colorToHSV(this, hsv) val hsl = hsv2hsl(hsv) - hsl[2] -= DARK_FACTOR / 100f + hsl[2] -= darkFactor / 100f if (hsl[2] < 0) { hsl[2] = 0f } @@ -146,11 +146,11 @@ fun Int.lightenColor(factor: Int = 8): Int { return this } - val LIGHT_FACTOR = factor + val lightFactor = factor var hsv = FloatArray(3) Color.colorToHSV(this, hsv) val hsl = hsv2hsl(hsv) - hsl[2] += LIGHT_FACTOR / 100f + hsl[2] += lightFactor / 100f if (hsl[2] < 0) { hsl[2] = 0f } diff --git a/app/src/main/java/be/scri/extensions/String.kt b/app/src/main/java/be/scri/extensions/String.kt index 085d8102..85a63aa5 100644 --- a/app/src/main/java/be/scri/extensions/String.kt +++ b/app/src/main/java/be/scri/extensions/String.kt @@ -77,8 +77,8 @@ fun String.getFirstParentPath( } fun String.isAValidFilename(): Boolean { - val ILLEGAL_CHARACTERS = charArrayOf('/', '\n', '\r', '\t', '\u0000', '`', '?', '*', '\\', '<', '>', '|', '\"', ':') - ILLEGAL_CHARACTERS.forEach { + val illegalCharacters = charArrayOf('/', '\n', '\r', '\t', '\u0000', '`', '?', '*', '\\', '<', '>', '|', '\"', ':') + illegalCharacters.forEach { if (contains(it)) { return false } diff --git a/app/src/main/java/be/scri/fragments/AboutFragment.kt b/app/src/main/java/be/scri/fragments/AboutFragment.kt index 0cf37978..3182694d 100644 --- a/app/src/main/java/be/scri/fragments/AboutFragment.kt +++ b/app/src/main/java/be/scri/fragments/AboutFragment.kt @@ -19,11 +19,6 @@ class AboutFragment : Fragment() { private var appName = "" private var primaryColor = 0 - private val EASTER_EGG_TIME_LIMIT = 3000L - private val EASTER_EGG_REQUIRED_CLICKS = 7 - private val SWIPE_THRESHOLD = 100 - private val SWIPE_VELOCITY_THRESHOLD = 100 - private lateinit var binding: FragmentAboutBinding private lateinit var gestureDetector: GestureDetector @@ -231,4 +226,11 @@ class AboutFragment : Fragment() { fragmentTransaction.addToBackStack(null) fragmentTransaction.commit() } + + companion object { + private const val EASTER_EGG_TIME_LIMIT = 3000L + private const val EASTER_EGG_REQUIRED_CLICKS = 7 + private const val SWIPE_THRESHOLD = 100 + private const val SWIPE_VELOCITY_THRESHOLD = 100 + } } diff --git a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt index 6658f89f..2faaaf63 100644 --- a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt @@ -26,15 +26,10 @@ abstract class SimpleKeyboardIME : MyKeyboardView.OnKeyboardActionListener { abstract fun getKeyboardLayoutXML(): Int - private var SHIFT_PERM_TOGGLE_SPEED = 500 // how quickly do we have to doubletap shift to enable permanent caps lock - private val KEYBOARD_LETTERS = 0 - private val KEYBOARD_SYMBOLS = 1 - private val KEYBOARD_SYMBOLS_SHIFT = 2 - private var keyboard: MyKeyboard? = null private var keyboardView: MyKeyboardView? = null private var lastShiftPressTS = 0L - private var keyboardMode = KEYBOARD_LETTERS + private var keyboardMode = Companion.KEYBOARD_LETTERS private var inputTypeClass = InputType.TYPE_CLASS_TEXT private var enterKeyType = IME_ACTION_NONE private var switchToLetters = false @@ -92,11 +87,11 @@ abstract class SimpleKeyboardIME : val keyboardXml = when (inputTypeClass) { TYPE_CLASS_NUMBER, TYPE_CLASS_DATETIME, TYPE_CLASS_PHONE -> { - keyboardMode = KEYBOARD_SYMBOLS + keyboardMode = Companion.KEYBOARD_SYMBOLS R.xml.keys_symbols } else -> { - keyboardMode = KEYBOARD_LETTERS + keyboardMode = Companion.KEYBOARD_LETTERS getKeyboardLayoutXML() } } @@ -107,7 +102,7 @@ abstract class SimpleKeyboardIME : } private fun updateShiftKeyState() { - if (keyboardMode == KEYBOARD_LETTERS) { + if (keyboardMode == Companion.KEYBOARD_LETTERS) { val editorInfo = currentInputEditorInfo if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL && keyboard?.mShiftState != SHIFT_ON_PERMANENT) { if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) { @@ -143,10 +138,10 @@ abstract class SimpleKeyboardIME : keyboardView!!.invalidateAllKeys() } MyKeyboard.KEYCODE_SHIFT -> { - if (keyboardMode == KEYBOARD_LETTERS) { + if (keyboardMode == Companion.KEYBOARD_LETTERS) { when { keyboard!!.mShiftState == SHIFT_ON_PERMANENT -> keyboard!!.mShiftState = SHIFT_OFF - System.currentTimeMillis() - lastShiftPressTS < SHIFT_PERM_TOGGLE_SPEED -> keyboard!!.mShiftState = SHIFT_ON_PERMANENT + System.currentTimeMillis() - lastShiftPressTS < Companion.SHIFT_PERM_TOGGLE_SPEED -> keyboard!!.mShiftState = SHIFT_ON_PERMANENT keyboard!!.mShiftState == SHIFT_ON_ONE_CHAR -> keyboard!!.mShiftState = SHIFT_OFF keyboard!!.mShiftState == SHIFT_OFF -> keyboard!!.mShiftState = SHIFT_ON_ONE_CHAR } @@ -154,11 +149,11 @@ abstract class SimpleKeyboardIME : lastShiftPressTS = System.currentTimeMillis() } else { val keyboardXml = - if (keyboardMode == KEYBOARD_SYMBOLS) { - keyboardMode = KEYBOARD_SYMBOLS_SHIFT + if (keyboardMode == Companion.KEYBOARD_SYMBOLS) { + keyboardMode = Companion.KEYBOARD_SYMBOLS_SHIFT R.xml.keys_symbols_shift } else { - keyboardMode = KEYBOARD_SYMBOLS + keyboardMode = Companion.KEYBOARD_SYMBOLS R.xml.keys_symbols } keyboard = MyKeyboard(this, keyboardXml, enterKeyType) @@ -177,11 +172,11 @@ abstract class SimpleKeyboardIME : } MyKeyboard.KEYCODE_MODE_CHANGE -> { val keyboardXml = - if (keyboardMode == KEYBOARD_LETTERS) { - keyboardMode = KEYBOARD_SYMBOLS + if (keyboardMode == Companion.KEYBOARD_LETTERS) { + keyboardMode = Companion.KEYBOARD_SYMBOLS R.xml.keys_symbols } else { - keyboardMode = KEYBOARD_LETTERS + keyboardMode = Companion.KEYBOARD_LETTERS getKeyboardLayoutXML() } keyboard = MyKeyboard(this, keyboardXml, enterKeyType) @@ -196,7 +191,7 @@ abstract class SimpleKeyboardIME : // If the keyboard is set to symbols and the user presses space, we usually should switch back to the letters keyboard. // However, avoid doing that in cases when the EditText for example requires numbers as the input. // We can detect that by the text not changing on pressing Space. - if (keyboardMode != KEYBOARD_LETTERS && code == MyKeyboard.KEYCODE_SPACE) { + if (keyboardMode != Companion.KEYBOARD_LETTERS && code == MyKeyboard.KEYCODE_SPACE) { val originalText = inputConnection.getExtractedText(ExtractedTextRequest(), 0).text inputConnection.commitText(codeChar.toString(), 1) val newText = inputConnection.getExtractedText(ExtractedTextRequest(), 0).text @@ -205,7 +200,7 @@ abstract class SimpleKeyboardIME : inputConnection.commitText(codeChar.toString(), 1) } - if (keyboard!!.mShiftState == SHIFT_ON_ONE_CHAR && keyboardMode == KEYBOARD_LETTERS) { + if (keyboard!!.mShiftState == SHIFT_ON_ONE_CHAR && keyboardMode == Companion.KEYBOARD_LETTERS) { keyboard!!.mShiftState = SHIFT_OFF keyboardView!!.invalidateAllKeys() } @@ -219,7 +214,7 @@ abstract class SimpleKeyboardIME : override fun onActionUp() { if (switchToLetters) { - keyboardMode = KEYBOARD_LETTERS + keyboardMode = Companion.KEYBOARD_LETTERS keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType) val editorInfo = currentInputEditorInfo @@ -265,4 +260,11 @@ abstract class SimpleKeyboardIME : } else { currentInputEditorInfo.imeOptions and IME_MASK_ACTION } + + companion object { + private const val SHIFT_PERM_TOGGLE_SPEED = 500 // how quickly do we have to doubletap shift to enable permanent caps lock + private const val KEYBOARD_LETTERS = 0 + private const val KEYBOARD_SYMBOLS = 1 + private const val KEYBOARD_SYMBOLS_SHIFT = 2 + } } From e4de02409d210b00745c1dd2d5387ee43f11ffa9 Mon Sep 17 00:00:00 2001 From: Andrew Tavis McAllister Date: Mon, 9 Sep 2024 22:21:50 +0200 Subject: [PATCH 2/2] Delete disabled linting rule --- .editorconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index a3b8416a..01a0bff0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,13 +20,10 @@ continuation_indent_size = 4 wildcard_import_limit = 999 ij_kotlin_name_count_to_use_star_import = 999 ij_kotlin_name_count_to_use_star_import_for_members = 999 -#ktlint_standard_property-naming = disabled ktlint_standard_no-wildcard-imports = disabled ktlint_standard_backing-property-naming = disabled ktlint_standard_filename = disabled - - ktlint_code_style = ktlint_official ktlint_standard = enabled ktlint_standard_final-newline = enabled