-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into displaying_connect…
…ing_label_in_call # Conflicts: # app/src/main/res/values/strings.xml
- Loading branch information
Showing
34 changed files
with
1,682 additions
and
162 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
app/src/androidTest/java/com/wire/android/LinkSpannableStringTest.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,103 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android | ||
|
||
import android.text.style.URLSpan | ||
import android.text.util.Linkify | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.wire.android.ui.common.LinkSpannableString | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class LinkSpannableStringTest { | ||
|
||
lateinit var linkSpannableString: LinkSpannableString | ||
|
||
@Before | ||
fun setUp() { | ||
linkSpannableString = LinkSpannableString("Hello, world!") | ||
} | ||
|
||
@Test | ||
fun givenValidIndices_whenSetSpanIsCalled_thenSpanIsSet() { | ||
// Given | ||
val start = 0 | ||
val end = 5 | ||
|
||
// When | ||
linkSpannableString.setSpan(URLSpan("http://example.com"), start, end, 0) | ||
|
||
// Then | ||
assert(linkSpannableString.getSpans(start, end, URLSpan::class.java).isNotEmpty()) | ||
} | ||
|
||
@Test | ||
fun givenInvalidStartIndex_whenSetSpanIsCalled_thenSpanIsNotSet() { | ||
// Given | ||
val start = -1 | ||
val end = 5 | ||
|
||
// When | ||
linkSpannableString.setSpan(URLSpan("http://example.com"), start, end, 0) | ||
|
||
// Then | ||
assert(linkSpannableString.getSpans(start, end, URLSpan::class.java).isEmpty()) | ||
} | ||
|
||
@Test | ||
fun givenInvalidEndIndex_whenSetSpanIsCalled_thenSpanIsNotSet() { | ||
// Given | ||
val start = 0 | ||
val end = 20 | ||
|
||
// When | ||
linkSpannableString.setSpan(URLSpan("http://example.com"), start, end, 0) | ||
|
||
// Then | ||
assert(linkSpannableString.getSpans(start, end, URLSpan::class.java).isEmpty()) | ||
} | ||
|
||
@Test | ||
fun givenASetSpan_whenRemoveSpanIsCalled_thenSpanIsRemoved() { | ||
// Given | ||
val urlSpan = URLSpan("http://example.com") | ||
linkSpannableString.setSpan(urlSpan, 0, 5, 0) | ||
|
||
// When | ||
linkSpannableString.removeSpan(urlSpan) | ||
|
||
// Then | ||
assert(linkSpannableString.getSpans(0, 5, URLSpan::class.java).isEmpty()) | ||
} | ||
|
||
@Test | ||
fun givenATextWithLink_whenGetLinkInfosIsCalled_thenLinkInfoIsReturned() { | ||
// Given | ||
val text = "Visit http://example.com for more info." | ||
val mask = Linkify.WEB_URLS | ||
|
||
// When | ||
val linkInfos = LinkSpannableString.getLinkInfos(text, mask) | ||
|
||
// Then | ||
assert(linkInfos.size == 1) | ||
assert(linkInfos[0].url == "http://example.com") | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/main/kotlin/com/wire/android/feature/GenerateRandomPasswordUseCase.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,59 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.feature | ||
|
||
import androidx.annotation.VisibleForTesting | ||
import dagger.hilt.android.scopes.ViewModelScoped | ||
import java.security.SecureRandom | ||
import javax.inject.Inject | ||
|
||
@ViewModelScoped | ||
class GenerateRandomPasswordUseCase @Inject constructor() { | ||
|
||
operator fun invoke(): String { | ||
|
||
val secureRandom = SecureRandom() | ||
|
||
val passwordLength = secureRandom.nextInt(MAX_LENGTH - MIN_LENGTH + 1) + MIN_LENGTH | ||
|
||
return buildList<Char> { | ||
add(lowercase[secureRandom.nextInt(lowercase.size)]) | ||
add(uppercase[secureRandom.nextInt(uppercase.size)]) | ||
add(digits[secureRandom.nextInt(digits.size)]) | ||
add(specialChars[secureRandom.nextInt(specialChars.size)]) | ||
|
||
repeat(passwordLength - FIXED_CHAR_COUNT) { | ||
add(allCharacters[secureRandom.nextInt(allCharacters.size)]) | ||
} | ||
}.shuffled(secureRandom).joinToString("") | ||
} | ||
|
||
@VisibleForTesting | ||
companion object { | ||
val lowercase: List<Char> = ('a'..'z').shuffled() | ||
val uppercase: List<Char> = ('A'..'Z').shuffled() | ||
val digits: List<Char> = ('0'..'9').shuffled() | ||
val specialChars: List<Char> = "!@#$%^&*()_+[]{}|;:,.<>?-".toList().shuffled() | ||
|
||
val allCharacters: List<Char> = (lowercase + uppercase + digits + specialChars).shuffled() | ||
|
||
const val MIN_LENGTH = 15 | ||
const val MAX_LENGTH = 20 | ||
const val FIXED_CHAR_COUNT = 4 | ||
} | ||
} |
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
Oops, something went wrong.