Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ open class AnkiDroidJsAPI(
"setCardDue" -> {
try {
val days = apiParams.toInt()
if (days < 0 || days > 9999) {
if (days !in 0..9999) {
showDeveloperContact(ANKI_JS_ERROR_CODE_SET_DUE, apiContract.cardSuppliedDeveloperContact)
return@withContext convertToByteArray(apiContract, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,8 @@ class StudyOptionsFragment :
Timber.e("StudyOptionsFragment.mRefreshFragmentListener :: can't refresh")
return
}
val studyOptionsView = view
// #5506 If we have no view, short circuit all UI logic
Comment thread
lukstbit marked this conversation as resolved.
if (studyOptionsView == null) {
return
}
val studyOptionsView = view ?: return

val col =
col
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CardTemplate(
val classIndex = template.indexOf(classDelim)
val contentIndex = template.indexOf(contentDelim)
try {
preStyle = template.substring(0, styleIndex)
preStyle = template.take(styleIndex)
preScript = template.substring(styleIndex + styleDelim.length, scriptIndex)
preClass = template.substring(scriptIndex + scriptDelim.length, classIndex)
preContent = template.substring(classIndex + classDelim.length, contentIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class TypeAnswer(
val colonColonIndex = groupOne.indexOf("::")
if (colonColonIndex > -1) {
// Cut out the hint.
groupOne = groupOne.substring(0, colonColonIndex)
groupOne = groupOne.take(colonColonIndex)
}
matches.add(groupOne)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,7 @@ class DeckPickerViewModel :
*/
suspend fun fetchSyncIconState(): SyncIconState {
if (!Prefs.displaySyncStatus) return SyncIconState.Normal
val auth = syncAuth()
if (auth == null) return SyncIconState.NotLoggedIn
val auth = syncAuth() ?: return SyncIconState.NotLoggedIn
return try {
// Use CollectionManager to ensure that this doesn't block 'deck count' tasks
// throws if a .colpkg import or similar occurs just before this call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class ChangeNoteTypeViewModel(
keysToMapToNothing.forEach { updatedMap[it] = null }
}

updatedMap.put(outputTemplateIndex, updatedValue)
updatedMap[outputTemplateIndex] = updatedValue

templateChangeMapFlow.value = updatedMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class TagsDialog : AnalyticsDialogFragment {
}
var previousColonsCnt = 0
if (dest != null) {
val previousPart = dest.substring(0, destStart)
val previousPart = dest.take(destStart)
if (previousPart.endsWith("::")) {
previousColonsCnt = 2
} else if (previousPart.endsWith(":")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class InstantNoteEditorActivity :

if (start != -1 && end != -1) {
val newText =
text.substring(0, start) + "{{c$incrementNumber::$word}}" + text.substring(end)
text.take(start) + "{{c$incrementNumber::$word}}" + text.substring(end)

textBox.setText(newText)
textBox.setSelection(start + "{{c$incrementNumber::".length)
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/reviewer/Binding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ sealed interface Binding {
*/
fun parse(s: String): Pair<ModifierKeys, String> {
val plusIndex = s.lastIndexOfOrNull('+') ?: return Pair(none(), s)
val modifiers = fromString(s.substring(0, plusIndex + 1))
val modifiers = fromString(s.take(plusIndex + 1))
return Pair(modifiers, s.substring(plusIndex + 1))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ class AddEditReminderDialog : DialogFragment() {
Pair(Consts.DEFAULT_DECK_ID, withCol { decks.name(Consts.DEFAULT_DECK_ID) })
}

val currentlySelectedDeckID = viewModel.deckSelected.value
return when (currentlySelectedDeckID) {
return when (val currentlySelectedDeckID = viewModel.deckSelected.value) {
ALL_DECKS_ID -> Pair(ALL_DECKS_ID, getString(R.string.card_browser_all_decks))
Consts.DEFAULT_DECK_ID -> getFallbackSelection()
null -> getFallbackSelection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ fun String.toSentenceCase(
): String {
val resString = context.getString(resId)
// lowercase both for the comparison: sentence case doesn't mean all words are lowercase
if (this.lowercase() == resString.lowercase()) return resString
if (this.equals(resString, ignoreCase = true)) return resString
return this
}
4 changes: 2 additions & 2 deletions AnkiDroid/src/test/java/com/ichi2/anki/MyAccountTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import junit.framework.TestCase.assertFalse
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.test.assertTrue
import kotlin.test.assertEquals

@RunWith(AndroidJUnit4::class)
class MyAccountTest : RobolectricTest() {
Expand All @@ -49,7 +49,7 @@ class MyAccountTest : RobolectricTest() {
fragment.view?.findViewById<TextInputEditText>(R.id.password)?.setText(testPassword)

val loginButton = fragment.view?.findViewById<Button>(R.id.login_button)
assertTrue(loginButton?.isEnabled == true)
assertEquals(loginButton?.isEnabled, true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/test/java/com/ichi2/utils/ImportUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ImportUtilsTest : RobolectricTest() {
assertThat(actualFilePath, containsString("..."))
// Obtain the filename from the path
assertThat(actualFilePath, containsString("%E5%A5%BD"))
val fileName = actualFilePath.substring(actualFilePath.indexOf("%E5%A5%BD"))
val fileName = actualFilePath.substringAfter("%E5%A5%BD")
assertThat(fileName.length, lessThanOrEqualTo(100))
}

Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/com/ichi2/anki/api/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ internal object Utils {
// pad checksum to 40 bytes, as is done in the main AnkiDroid code
if (result.length < 40) {
val zeroes = "0000000000000000000000000000000000000000"
result = zeroes.substring(0, zeroes.length - result.length) + result
result = zeroes.take(zeroes.length - result.length) + result
}
java.lang.Long.valueOf(result.substring(0, 8), 16)
java.lang.Long.valueOf(result.take(8), 16)
} catch (e: Exception) {
// This is guaranteed to never happen
throw IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object StringUtils {
if (s == null) return null
if (s.isBlank()) return s

return s.substring(0, 1).uppercase(Locale.getDefault()) + s.substring(1).lowercase(Locale.getDefault())
return s[0].uppercase(Locale.getDefault()) + s.substring(1).lowercase(Locale.getDefault())
}
}

Expand Down
2 changes: 1 addition & 1 deletion libanki/src/main/java/com/ichi2/anki/libanki/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ object Utils {
// not 32.
if (result.length < 40) {
val zeroes = "0000000000000000000000000000000000000000"
result = zeroes.substring(0, zeroes.length - result.length) + result
result = zeroes.take(zeroes.length - result.length) + result
}
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import net.ankiweb.rsdroid.RustCleanup
import timber.log.Timber
import kotlin.math.ceil
import kotlin.math.max
import kotlin.math.roundToLong

/**
* A parameter for [Scheduler.setDueDate]
Expand Down Expand Up @@ -650,7 +651,7 @@ open class Scheduler(
toRelrn = failures
} while (toRelrn > 1)
val futureRelrnTotal = relrnTime * futureReps
return Math.round((newTotal + relrnTotal + revTotal + futureRelrnTotal) / 60000).toInt()
return ((newTotal + relrnTotal + revTotal + futureRelrnTotal) / 60000).roundToLong().toInt()
}

/** Used only by V1/V2, and unit tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ fun <T : JSONObjectHolder> JSONContainer<T>.insert(
fun <T : JSONObjectHolder> len(templates: JSONContainer<T>) = templates.jsonArray.length()

// Changed signature from `copy.deepcopy(clone_from)`
fun DeckConfig.deepClone() = this.copy(this.jsonObject.deepClone())
fun DeckConfig.deepClone() = this.copy(jsonObject = this.jsonObject.deepClone())
Loading