This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter emojis in RAT profile fields (EXPOSUREAPP-8108) (#3597)
* Create a custom view * Use extension function instead * Some Tests Co-authored-by: harambasicluka <64483219+harambasicluka@users.noreply.github.com> Co-authored-by: Juraj Kusnier <jurajkusnier@users.noreply.github.com>
- Loading branch information
1 parent
31ed88f
commit 61b8e18
Showing
3 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/view/EmojiFilterTest.kt
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.rki.coronawarnapp.ui.view | ||
|
||
import android.text.SpannableString | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
|
||
@RunWith(JUnit4::class) | ||
class EmojiFilterTest { | ||
|
||
private val testData = mapOf<CharSequence, CharSequence?>( | ||
"Pneumonoultramicroscopicsilicovolcanoconiosis" to null, // English | ||
"Donaudampfschifffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft" to null, // German | ||
"Muvaffakiyetsizleştiricileştiriveremeyebileceklerimizdenmişsinizcesine" to null, // Turkish | ||
"Рентгеноэлектрокардиографический" to null, // Russian | ||
"speciallægepraksisplanlægningsstabiliseringsperiode" to null, // Danish | ||
"Непротивоконституционствувателствувайте" to null, // Bulgarian | ||
"Dziewięćsetdziewięćdziesięciodziewięcionarodowościowego" to null, // Polish | ||
"Pneumoultramicroscopicossilicovulcanoconiótico" to null, // Portuguese | ||
"paraskevidékatriaphobie" to null, // French | ||
"peruspalveluliikelaitoskuntayhtymä" to null, // Finnish | ||
"Arquitectónicamente" to null, // Spanish | ||
"znajneprekryštalizovávateľnejšievajúcimi" to null, // Slovak | ||
// Swedish | ||
"Spårvagnsaktiebolagsskensmutsskjutarefackföreningspersonalbeklädnadsmagasinsförråd-sförvaltarens" to null, | ||
// Hungarian | ||
"legösszetettebbszóhosszúságvilágrekorddöntéskényszerneurózistünetegyüttesmegnyilvá-nulásfejleszthetőségvizsgálataitokként" to null, | ||
"nebeprisikiškiakopūstlapiaujančiuosiuose" to null, // Lithuanian | ||
"וכשבהשתעשעויותיהם" to null, // Hebrew | ||
"ηλεκτροεγκεφαλογραφήματος" to null, // Greek | ||
"prijestolonasljednikovičičinima" to null, // Croatian | ||
"Sünnipäevanädalalõpupeopärastlõunaväsimatus" to null, // Estonian | ||
"أفاستسقيناكموها" to null, // Arabic, | ||
"✌️✌️✌️✌️✌️✌️✌️✌️✌️️" to "", // Emoji, | ||
"☕☕☕☕☕☕☕☕☕" to "", // Emoji, | ||
) | ||
|
||
@Test | ||
fun filter() { | ||
testData.forEach { (input, output) -> | ||
EmojiFilter().filter( | ||
input, | ||
0, | ||
input.length, | ||
SpannableString(input), | ||
0, | ||
input.length | ||
) shouldBe output | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/EmojiFilter.kt
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.rki.coronawarnapp.ui.view | ||
|
||
import android.text.InputFilter | ||
import android.text.Spanned | ||
import com.google.android.material.textfield.TextInputEditText | ||
import java.lang.Character.OTHER_SYMBOL | ||
import java.lang.Character.SURROGATE | ||
|
||
/** | ||
* Adds [InputFilter] of emojis ,returns same [TextInputEditText] | ||
*/ | ||
fun TextInputEditText.addEmojiFilter(): TextInputEditText { | ||
filters += EmojiFilter() | ||
return this | ||
} | ||
|
||
class EmojiFilter : InputFilter { | ||
override fun filter( | ||
source: CharSequence, | ||
sStart: Int, | ||
sEnd: Int, | ||
destination: Spanned, | ||
dStart: Int, | ||
dEnd: Int | ||
): CharSequence? { | ||
for (index in sStart until sEnd) { | ||
val type = Character.getType(source[index]).toByte() | ||
if (type in listOf(SURROGATE, OTHER_SYMBOL)) return "" | ||
} | ||
return null | ||
} | ||
} |