Created
January 11, 2025 18:04
-
-
Save limkhashing/546b8a75e7709f20632cfde9a700ca70 to your computer and use it in GitHub Desktop.
Mask phone number
This file contains hidden or 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
| fun maskPhoneNumber(input: String): String { | |
| fun removeNonNumericalChar(input: String): String { | |
| val result = StringBuilder() | |
| for (char in input) { | |
| if (char.isDigit()) { | |
| result.append(char) | |
| } | |
| } | |
| return result.toString() | |
| } | |
| val digits = removeNonNumericalChar(input) | |
| val length = digits.length | |
| val maskedDigit = when (length) { | |
| 10 -> digits.substring(0, 2) + "****" + digits.substring(6) | |
| 11 -> digits.substring(0, 3) + "****" + digits.substring(7) | |
| 12 -> digits.substring(0, 4) + "****" + digits.substring(8) | |
| else -> return input | |
| } | |
| return maskedDigit | |
| } |
This file contains hidden or 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
| fun main() { | |
| binding.recyclerView.adapter = RecyclerViewAdapter | |
| binding.recyclerView.addOnScrollListener(EndlessRecyclerViewScroll()) | |
| } | |
| class RecyclerView: Adapter { | |
| } | |
| class EndlessRecyclerViewScroll: RecyclerView.OnScrollListener() { | |
| val page = 1 | |
| override fun onScrollStateChanged(recyclerView: RecyclerView) { | |
| recyclerView.layoutDirection // View.Layout_Direction.RTL | |
| if (!recyclerView.canScrollHorizontal(direction = -1)) { // can scroll left | |
| page ++ | |
| onLoadMore(page) | |
| } | |
| if (!recyclerView.canScrollHorizontal(direction = 1)) { // can scroll right | |
| page ++ | |
| onLoadMore(page) | |
| } | |
| } | |
| abstract fun onLoadMore(page: Int) | |
| } |
limkhashing
commented
Jan 11, 2025
Author
- Write a function to mask the middle 4 digital of the Malaysia phone number, it should support different phone number type ,for example
Author
- RecyclerView support Right to Left scrolling, and pagination
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment