-
Notifications
You must be signed in to change notification settings - Fork 38
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
Refactor: Reduce Return Statements Across Multiple Functions #191
Open
KesharwaniArpita
wants to merge
39
commits into
scribe-org:main
Choose a base branch
from
KesharwaniArpita:AK-return-statement-lint-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
f5da3d1
Update detekt.yml remove return count
KesharwaniArpita 708eb08
Update Activity.kt to remove return statement >2
KesharwaniArpita dfa59e1
Update CommonsContext.kt to resolve the return statement lint error
KesharwaniArpita c81646c
Update ContextStorage.kt
KesharwaniArpita 99934c2
Update String.kt
KesharwaniArpita 724c2e6
Update LanguageSettingsFragment.kt
KesharwaniArpita fa4ab51
Update AlphanumericComparator.kt
KesharwaniArpita f9a912c
Update ExternalStorageProviderHack.kt
KesharwaniArpita 058f414
Update SimpleKeyboardIME.kt
KesharwaniArpita ebe4395
Update MyKeyboardView.kt
KesharwaniArpita e05376d
Update BaseSimpleActivity.kt
KesharwaniArpita 5b18e59
Merge branch 'main' into AK-return-statement-lint-error
KesharwaniArpita eb81b04
Merge branch 'scribe-org:main' into AK-return-statement-lint-error
KesharwaniArpita ec4d7d4
Update BaseSimpleActivity.kt
KesharwaniArpita b38fc71
Update ContextStorage.kt
KesharwaniArpita b74957c
Update Activity.kt
KesharwaniArpita 1673d15
Delete app/src/main/java/be/scri/activities directory
KesharwaniArpita f097cd0
Create MainActivity.kt
KesharwaniArpita 8765001
Delete app/src/main/java/be/scri/extensions/Activity.kt
KesharwaniArpita 2902980
Delete app/src/main/java/be/scri/extensions directory
KesharwaniArpita de5d41f
Create CommonsContext.kt
KesharwaniArpita f642bc2
Create Context.kt
KesharwaniArpita 6562407
Create ContextStyling.kt
KesharwaniArpita b6b22c5
Create Drawable.kt
KesharwaniArpita 0dd7d59
Create Int.kt
KesharwaniArpita 6ae90c8
Create View.kt
KesharwaniArpita 6a0c879
Delete app/src/main/java/be/scri/helpers/ExternalStorageProviderHack.kt
KesharwaniArpita 469c4ef
Merge branch 'scribe-org:main' into AK-return-statement-lint-error
KesharwaniArpita ec10daa
Update AlphanumericComparator.kt
KesharwaniArpita 16be181
Merge branch 'scribe-org:main' into AK-return-statement-lint-error
KesharwaniArpita e0d368a
Update LanguageSettingsFragment.kt
KesharwaniArpita 3bd1bb1
Update AlphanumericComparator.kt Modified Compare function to reduce …
KesharwaniArpita e18a51b
Update SimpleKeyboardIME.kt fun hastextbeforecursor
KesharwaniArpita 59011cc
Update MyKeyboardView.kt
KesharwaniArpita c9b24c0
Merge branch 'main' into AK-return-statement-lint-error
KesharwaniArpita 7c27fbd
Updating the detekt.yml as the current code doesn't have the return s…
KesharwaniArpita be4f564
Merge branch 'main' into AK-return-statement-lint-error
andrewtavis 25eb8c1
Run ktlint formatting
andrewtavis b642a7f
Remove unneeded added spacing
andrewtavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -967,29 +967,18 @@ class MyKeyboardView | |
) | ||
} | ||
|
||
private fun openPopupIfRequired(me: MotionEvent): Boolean { | ||
// Check if we have a popup layout specified first. | ||
if (mPopupLayout == 0) { | ||
return false | ||
} | ||
|
||
if (mCurrentKey < 0 || mCurrentKey >= mKeys.size) { | ||
return false | ||
} | ||
|
||
val popupKey = mKeys[mCurrentKey] | ||
val result = onLongPress(popupKey, me) | ||
if (result) { | ||
mAbortKey = true | ||
showPreview(NOT_A_KEY) | ||
} | ||
private fun openPopupIfRequired(me: MotionEvent): Boolean { | ||
if (mPopupLayout == 0 || mCurrentKey !in mKeys.indices) { | ||
return false | ||
} | ||
|
||
return result | ||
val popupKey = mKeys[mCurrentKey] | ||
val result = onLongPress(popupKey, me) | ||
if (result) { | ||
mAbortKey = true | ||
showPreview(NOT_A_KEY) | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the comment be opened and closed properly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll fix this and the above and we'll see what the state of it all is :) |
||
* Called when a key is long pressed. | ||
* By default this will open any popup keyboard associated with this key through the attributes | ||
* popupLayout and popupCharacters. | ||
* @param popupKey the key that was long pressed | ||
* @return true if the long press is handled, false otherwise. | ||
|
@@ -1197,36 +1186,37 @@ class MyKeyboardView | |
return onModifiedTouchEvent(me) | ||
} | ||
|
||
private fun onModifiedTouchEvent(me: MotionEvent): Boolean { | ||
var touchX = me.x.toInt() | ||
var touchY = me.y.toInt() | ||
if (touchY >= -mVerticalCorrection) { | ||
touchY += mVerticalCorrection | ||
} | ||
@Suppress("ReturnCount") | ||
private fun onModifiedTouchEvent(me: MotionEvent): Boolean { | ||
var touchX = me.x.toInt() | ||
var touchY = me.y.toInt() | ||
if (touchY >= -mVerticalCorrection) { | ||
touchY += mVerticalCorrection | ||
} | ||
|
||
val action = me.actionMasked | ||
val eventTime = me.eventTime | ||
val keyIndex = getPressedKeyIndex(touchX, touchY) | ||
val action = me.actionMasked | ||
val eventTime = me.eventTime | ||
val keyIndex = getPressedKeyIndex(touchX, touchY) | ||
|
||
// Ignore all motion events until a DOWN. | ||
if (mAbortKey && action != MotionEvent.ACTION_DOWN && action != MotionEvent.ACTION_CANCEL) { | ||
return true | ||
} | ||
var handled = false | ||
|
||
// Needs to be called after the gesture detector gets a turn, as it may have displayed the mini keyboard | ||
if (mMiniKeyboardOnScreen && action != MotionEvent.ACTION_CANCEL) { | ||
return true | ||
} | ||
// Ignore all motion events until a DOWN. | ||
if (mAbortKey && action != MotionEvent.ACTION_DOWN && action != MotionEvent.ACTION_CANCEL) { | ||
handled = true | ||
} | ||
|
||
// Handle mini keyboard case | ||
if (mMiniKeyboardOnScreen && action != MotionEvent.ACTION_CANCEL) { | ||
handled = true | ||
} | ||
|
||
if (!handled) { | ||
when (action) { | ||
MotionEvent.ACTION_POINTER_DOWN -> { | ||
// if the user presses a key while still holding down the previous, | ||
// type in both chars and ignore the later gestures | ||
// can happen at fast typing, easier to reproduce by increasing LONGPRESS_TIMEOUT | ||
ignoreTouches = true | ||
mHandler!!.removeMessages(MSG_LONGPRESS) | ||
dismissPopupKeyboard() | ||
detectAndSendKey(keyIndex, me.x.toInt(), me.y.toInt(), eventTime) | ||
detectAndSendKey(keyIndex, touchX, touchY, eventTime) | ||
|
||
val newPointerX = me.getX(1).toInt() | ||
val newPointerY = me.getY(1).toInt() | ||
|
@@ -1235,13 +1225,11 @@ class MyKeyboardView | |
detectAndSendKey(secondKeyIndex, newPointerX, newPointerY, eventTime) | ||
|
||
val secondKeyCode = mKeys.getOrNull(secondKeyIndex)?.code | ||
if (secondKeyCode != null) { | ||
mOnKeyboardActionListener!!.onPress(secondKeyCode) | ||
} | ||
secondKeyCode?.let { mOnKeyboardActionListener!!.onPress(it) } | ||
|
||
showPreview(NOT_A_KEY) | ||
invalidateKey(mCurrentKey) | ||
return true | ||
handled = true | ||
} | ||
MotionEvent.ACTION_DOWN -> { | ||
mAbortKey = false | ||
|
@@ -1251,39 +1239,30 @@ class MyKeyboardView | |
mCurrentKeyTime = 0 | ||
mLastKey = NOT_A_KEY | ||
mCurrentKey = keyIndex | ||
mDownTime = me.eventTime | ||
mLastMoveTime = mDownTime | ||
|
||
val onPressKey = | ||
if (keyIndex != NOT_A_KEY) { | ||
mKeys[keyIndex].code | ||
} else { | ||
0 | ||
} | ||
mDownTime = eventTime | ||
mLastMoveTime = eventTime | ||
|
||
val onPressKey = if (keyIndex != NOT_A_KEY) mKeys[keyIndex].code else 0 | ||
mOnKeyboardActionListener!!.onPress(onPressKey) | ||
|
||
var wasHandled = false | ||
if (mCurrentKey >= 0 && mKeys[mCurrentKey].repeatable) { | ||
mRepeatKeyIndex = mCurrentKey | ||
|
||
val msg = mHandler!!.obtainMessage(MSG_REPEAT) | ||
mHandler!!.sendMessageDelayed(msg, REPEAT_START_DELAY.toLong()) | ||
// if the user long presses Space, move the cursor after swipine left/right | ||
|
||
if (mKeys[mCurrentKey].code == KEYCODE_SPACE) { | ||
mLastSpaceMoveX = -1 | ||
} else { | ||
repeatKey(true) | ||
} | ||
|
||
// Delivering the key could have caused an abort | ||
if (mAbortKey) { | ||
mRepeatKeyIndex = NOT_A_KEY | ||
wasHandled = true | ||
handled = true | ||
} | ||
} | ||
|
||
if (!wasHandled && mCurrentKey != NOT_A_KEY) { | ||
if (!handled && mCurrentKey != NOT_A_KEY) { | ||
val msg = mHandler!!.obtainMessage(MSG_LONGPRESS, me) | ||
mHandler!!.sendMessageDelayed(msg, LONGPRESS_TIMEOUT.toLong()) | ||
} | ||
|
@@ -1331,9 +1310,7 @@ class MyKeyboardView | |
mLastSpaceMoveX = mLastX | ||
} | ||
} else if (!continueLongPress) { | ||
// Cancel old longpress | ||
mHandler!!.removeMessages(MSG_LONGPRESS) | ||
// Start new longpress if key has changed | ||
if (keyIndex != NOT_A_KEY) { | ||
val msg = mHandler!!.obtainMessage(MSG_LONGPRESS, me) | ||
mHandler!!.sendMessageDelayed(msg, LONGPRESS_TIMEOUT.toLong()) | ||
|
@@ -1362,9 +1339,10 @@ class MyKeyboardView | |
touchX = mLastCodeX | ||
touchY = mLastCodeY | ||
} | ||
|
||
showPreview(NOT_A_KEY) | ||
Arrays.fill(mKeyIndices, NOT_A_KEY) | ||
// If we're not on a repeating key (which sends on a DOWN event) | ||
|
||
if (mRepeatKeyIndex == NOT_A_KEY && !mMiniKeyboardOnScreen && !mAbortKey) { | ||
detectAndSendKey(mCurrentKey, touchX, touchY, eventTime) | ||
} | ||
|
@@ -1381,6 +1359,7 @@ class MyKeyboardView | |
} | ||
lastSpaceBarTapTime = currentTime | ||
} | ||
|
||
invalidateKey(keyIndex) | ||
mRepeatKeyIndex = NOT_A_KEY | ||
mOnKeyboardActionListener!!.onActionUp() | ||
|
@@ -1396,13 +1375,17 @@ class MyKeyboardView | |
invalidateKey(mCurrentKey) | ||
} | ||
} | ||
|
||
mLastX = touchX | ||
mLastY = touchY | ||
return true | ||
} | ||
|
||
private fun repeatKey(initialCall: Boolean): Boolean { | ||
mLastX = touchX | ||
mLastY = touchY | ||
|
||
return handled || true | ||
} | ||
|
||
|
||
|
||
private fun repeatKey(initialCall: Boolean): Boolean { | ||
val key = mKeys[mRepeatKeyIndex] | ||
if (!initialCall && key.code == KEYCODE_SPACE) { | ||
if (!mIsLongPressingSpace) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using
isEmpty()
, I recommend performing a simple null check in the return statement. This adjustment should help avoid any errors.Additionally, I suggest running the application in Android Studio or following the steps outlined in the new PR template, specifically
./gradlew lintKotlin detekt test
. This could help catch potential issues early on. If you are facing any difficulties in running the application do tell. Happy to help :)Thank you!