Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Property Naming Issues #96

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 12 additions & 13 deletions app/src/main/java/be/scri/activities/BaseSimpleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
var checkedDocumentPath = ""
var configItemsToExport = LinkedHashMap<String, Any>()

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<Int>
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :) Great work and thoughts on this, both of you!

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)
}
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
}

Expand All @@ -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)
}
}
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/be/scri/extensions/Context-storage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -524,10 +525,10 @@ fun Context.getOTGItems(
callback: (ArrayList<FileDirItem>) -> Unit,
) {
val items = ArrayList<FileDirItem>()
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 = ""
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/be/scri/extensions/Int.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/be/scri/extensions/String.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/be/scri/fragments/AboutFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}
42 changes: 22 additions & 20 deletions app/src/main/java/be/scri/services/SimpleKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -143,22 +138,22 @@ 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
}

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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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()
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}