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

added collapse keyboard function #215

Merged
merged 5 commits into from
Oct 17, 2020
Merged

added collapse keyboard function #215

merged 5 commits into from
Oct 17, 2020

Conversation

mrwhoknows55
Copy link
Contributor

Closes #84

Added collapseKeyboardOnOutsideTap function in helper module, which can be used in future code also

How has it been tested?

I manually tested it with each edittext and it works fine

Screenshots

collapseKeyboardIssue

@aniri
Copy link
Member

aniri commented Oct 14, 2020

hey @mrwhoknows55 ! thanks for your contribution!! the code looks neat, but there seems to be a small glitch when switching the focus from one input to another. for example on the login screen. Could you please check?

Screen_Recording_20201014-213955

@mrwhoknows55
Copy link
Contributor Author

@aniri will check and fix it

@mrwhoknows55
Copy link
Contributor Author

@aniri I couldn't find how to solve that, do you have any suggestions?

@aniri
Copy link
Member

aniri commented Oct 17, 2020

@mrwhoknows55 I'll also investigate and see if I can come up with something :/

@DeKaN maybe you have a suggestion of how we could fix this? :D we're trying to hide the keyboard when the user presses outside an input area. but on the login screen, if the user switches between inputs for phone and password, the keyboard collapses and then opens again :/

@DeKaN
Copy link
Contributor

DeKaN commented Oct 17, 2020

@aniri This snippet works well in BaseActivity

    override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
        if (ev.action == MotionEvent.ACTION_UP) {
            currentFocus?.let { oldView ->
                val consumed = super.dispatchTouchEvent(ev)
                val newView = currentFocus ?: oldView
                if (newView == oldView) {
                    val coords = IntArray(2)
                    oldView.getLocationOnScreen(coords)
                    val rect = Rect(coords[0], coords[1], coords[0] + oldView.width, coords[1] + oldView.height)
                    if (rect.contains(ev.x.toInt(), ev.y.toInt()))
                        return consumed
                } else if (newView is EditText) {
                    return consumed
                }

                ContextCompat.getSystemService(this, InputMethodManager::class.java)
                    ?.hideSoftInputFromWindow(newView.windowToken, 0)
                return consumed
            }
        }
        return super.dispatchTouchEvent(ev)
    }

@aniri
Copy link
Member

aniri commented Oct 17, 2020

@mrwhoknows55 could you please check the suggestion? ⬆️

@mrwhoknows55
Copy link
Contributor Author

@aniri it is fixed now, thank you so much @DeKaN 🙏

@aniri
Copy link
Member

aniri commented Oct 17, 2020

woooh! looks good now! thanks @mrwhoknows55 & @DeKaN 🚀

just one more nitpick :/ I think we could move the collapseKeyboardIfFocusOutsideEditText method to helper/Utils.kt. It doesn't need to be in a separate file :D

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@mrwhoknows55
Copy link
Contributor Author

@aniri done!

@aniri
Copy link
Member

aniri commented Oct 17, 2020

@mrwhoknows55 awesome! thank you!!

@mrwhoknows55
Copy link
Contributor Author

@aniri and @DeKaN thank you so much 🙏

@aniri aniri merged commit b881b50 into code4romania:develop Oct 17, 2020
currentFocus?.let { oldFocus ->
super.dispatchTouchEvent(motionEvent)
val newFocus = currentFocus ?: oldFocus
collapseKeyboardIfFocusOutsideEditText(motionEvent, oldFocus, newFocus)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to return result from line 139 here instead of calling the super method again

Copy link
Member

Choose a reason for hiding this comment

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

good catch! we'll have to fix this in a new PR

aniri added a commit that referenced this pull request Dec 12, 2020
* fix send note on question

* Add simple usage for values from remote config at "About page"

* Use values from remote config for menu

* Copy files to cache instead of using directly. Fixes #178

* Remove file from cache after sending in any sync case

* Fix null string property

* Made font for selected item in the menu bold (#195)

* added collapse keyboard function (#215)

* added collapse keyboard function

* fix: keyboard collapse and opens again while switching multiple inputs

* refactor: collapseKeyboardIfFocusOutsideEditText() to Utils.kt

* Use the orderNumber field for sorting (#222)

* Use the orderNumber field for sorting

* Remove duplication for sonar

* Fix sorting for forms (#227)

* Sending firebase token on the login call (#225)

* Use filesDir instead of cacheDir (#230)

* Enable upload of multiple files with note (#231)

* Enable uploading multiple files with note

* Allow user to select multiple files

* Improve error strings for note files

* Update app/src/main/res/values-ro-rRO/strings.xml

Co-authored-by: Irina Borozan <anirib@gmail.com>

* replace: `this` with appropriate lifecycle owner (#224)

Co-authored-by: Irina Borozan <anirib@gmail.com>

* check db reset remote config flag on startup

* cleanups and add default value for remote config param

* Add sync related UI changes (#233)

* Add sync related UI changes

* small layout adjustments

* Add latest changes

Co-authored-by: Irina Borozan <anirib@gmail.com>

* removed extra activate

* Allow user to delete note files (#237)

* Allow user to delete note files

* Handle file deletion failure

* Send count of unsynced items to analytics (#244)

* Send count of unsynced items to analytics

* renamed variable to keep it consistent

Co-authored-by: Irina Borozan <anirib@gmail.com>

* fixed remote config init error and add min interval setting (#245)

* Fix RxJava null values usage (#240)

* Fix incorrect selection of counties (#247)

* Enable screen for visited polling stations (#241)

* Enable screen for visited polling stations

* Enable selecting from previously visited stations

* added visited stations icon from figma

* Implement requested changes

* Hide station selection on first run

Co-authored-by: Irina Borozan <anirib@gmail.com>

* Enable details screen for user's notes (#242)

* Enable details screen for user's notes

* Implement UI requested changes

* Fix issues with form-question codes

* Fix adding notes directly from forms list

* Tweak UI and save codes for note into database

* Update app/src/main/java/ro/code4/monitorizarevot/ui/notes/NoteDetailsFragment.kt

* Update app/src/main/res/values/strings.xml

* Apply suggestions from code review

Co-authored-by: Irina Borozan <anirib@gmail.com>

* Add info for visited stations screen (#256)

* Fix UI for notes after changing stations (#254)

* Bugfix/cleanups on app update (#257)

* refactored has selected stations shared pref

* fixed db cleanups after app update

* Add checks for empty answers list to sync (#252)

* added new link in menu and new guide (#259)

* changed logout display in menu and default safety link (#260)

Co-authored-by: Dmitriy <dekanszn@gmail.com>
Co-authored-by: caldareanda <61616802+caldareanda@users.noreply.github.com>
Co-authored-by: Avadhut Tanugade <30384908+mrwhoknows55@users.noreply.github.com>
Co-authored-by: lukstbit <52494258+lukstbit@users.noreply.github.com>
Co-authored-by: Pedro Francisco de Sousa Neto <pedrokra@gmail.com>
Co-authored-by: AlexandraDaraban <AlexandraDaraban@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] Collapse the keyboard when the user taps outside the input area
3 participants