Skip to content

Commit

Permalink
[Cleanup]: Fix Android Studio Warnings in various Kotlin files ankidr…
Browse files Browse the repository at this point in the history
…oid#13282 (ankidroid#16095)

* Fixed some Kotlin Android Studio Warnings

* Reverted import changes

* Update OperationTest.kt code legibility improved

---------

Co-authored-by: Bernardo Galante <ba@MacBook-Air-de-Bernardo.local>
  • Loading branch information
2 people authored and henriqueccmac committed May 27, 2024
1 parent ba70fd7 commit c0cd3b5
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PeripheralKeymapTest : InstrumentedTest() {
)
}

protected fun getNumpadEvent(keycode: Int): KeyEvent {
private fun getNumpadEvent(keycode: Int): KeyEvent {
return KeyEvent(0, 0, KeyEvent.ACTION_UP, keycode, 0, KeyEvent.META_NUM_LOCK_ON)
}
}
2 changes: 0 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2191,8 +2191,6 @@ open class CardBrowser :
return s
}

const val CARD_NOT_AVAILABLE = -1

fun dueString(col: Collection, card: Card): String {
var t = nextDue(col, card)
if (card.queue < 0) {
Expand Down
24 changes: 12 additions & 12 deletions AnkiDroid/src/main/java/com/ichi2/anki/MetaDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ object MetaDB {
}

/** Reset the widget status. */
fun resetWidget(context: Context): Boolean {
private fun resetWidget(context: Context): Boolean {
openDBIfClosed(context)
try {
Timber.i("MetaDB:: Resetting widget status")
Expand Down Expand Up @@ -249,9 +249,9 @@ object MetaDB {
mMetaDb!!.rawQuery(
query,
arrayOf(
java.lang.Long.toString(did),
Integer.toString(ord),
Integer.toString(qa.int)
did.toString(),
ord.toString(),
qa.int.toString()
)
).use { cur ->
Timber.v("getLanguage: %s", query)
Expand All @@ -275,7 +275,7 @@ object MetaDB {
try {
mMetaDb!!.rawQuery(
"SELECT state FROM whiteboardState WHERE did = ?",
arrayOf(java.lang.Long.toString(did))
arrayOf(did.toString())
).use { cur -> return DatabaseUtil.getScalarBoolean(cur) }
} catch (e: Exception) {
Timber.e(e, "Error retrieving whiteboard state from MetaDB ")
Expand All @@ -296,7 +296,7 @@ object MetaDB {
val metaDb = mMetaDb!!
metaDb.rawQuery(
"SELECT _id FROM whiteboardState WHERE did = ?",
arrayOf(java.lang.Long.toString(did))
arrayOf(did.toString())
).use { cur ->
if (cur.moveToNext()) {
metaDb.execSQL(
Expand Down Expand Up @@ -327,7 +327,7 @@ object MetaDB {
try {
mMetaDb!!.rawQuery(
"SELECT stylus FROM whiteboardState WHERE did = ?",
arrayOf(java.lang.Long.toString(did))
arrayOf(did.toString())
).use { cur -> return DatabaseUtil.getScalarBoolean(cur) }
} catch (e: Exception) {
Timber.e(e, "Error retrieving whiteboard stylus mode state from MetaDB ")
Expand All @@ -348,7 +348,7 @@ object MetaDB {
val metaDb = mMetaDb!!
metaDb.rawQuery(
"SELECT _id FROM whiteboardState WHERE did = ?",
arrayOf(java.lang.Long.toString(did))
arrayOf(did.toString())
).use { cur ->
if (cur.moveToNext()) {
metaDb.execSQL(
Expand Down Expand Up @@ -379,7 +379,7 @@ object MetaDB {
try {
mMetaDb!!.rawQuery(
"SELECT visible FROM whiteboardState WHERE did = ?",
arrayOf(java.lang.Long.toString(did))
arrayOf(did.toString())
).use { cur -> return DatabaseUtil.getScalarBoolean(cur) }
} catch (e: Exception) {
Timber.e(e, "Error retrieving whiteboard state from MetaDB ")
Expand All @@ -400,7 +400,7 @@ object MetaDB {
val metaDb = mMetaDb!!
metaDb.rawQuery(
"SELECT _id FROM whiteboardState WHERE did = ?",
arrayOf(java.lang.Long.toString(did))
arrayOf(did.toString())
).use { cur ->
if (cur.moveToNext()) {
metaDb.execSQL(
Expand Down Expand Up @@ -429,7 +429,7 @@ object MetaDB {
try {
mMetaDb!!.rawQuery(
"SELECT lightpencolor, darkpencolor FROM whiteboardState WHERE did = ?",
arrayOf(java.lang.Long.toString(did))
arrayOf(did.toString())
).use { cur ->
cur.moveToFirst()
val light = DatabaseUtil.getInteger(cur, 0)
Expand All @@ -456,7 +456,7 @@ object MetaDB {
val metaDb = mMetaDb!!
metaDb.rawQuery(
"SELECT _id FROM whiteboardState WHERE did = ?",
arrayOf(java.lang.Long.toString(did))
arrayOf(did.toString())
).use { cur ->
if (cur.moveToNext()) {
metaDb.execSQL(
Expand Down
6 changes: 3 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,9 @@ class NoteEditor : AnkiActivity(), DeckSelectionListener, SubtitleListener, Tags
}
}

private fun addFromAedict(extra_text: String?): Boolean {
private fun addFromAedict(extraText: String?): Boolean {
var category: String
val notepadLines = extra_text!!.split("\n".toRegex()).toTypedArray()
val notepadLines = extraText!!.split("\n".toRegex()).toTypedArray()
for (i in notepadLines.indices) {
if (notepadLines[i].startsWith("[") && notepadLines[i].endsWith("]")) {
category = notepadLines[i].substring(1, notepadLines[i].length - 1)
Expand Down Expand Up @@ -1189,7 +1189,7 @@ class NoteEditor : AnkiActivity(), DeckSelectionListener, SubtitleListener, Tags
return sp.roundToInt().toString()
}

fun addNewNote() {
private fun addNewNote() {
openNewNoteEditor { }
}

Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/ReadText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ object ReadText {
showDialogAfterDelay(dialog, 500)
}

internal fun showDialogAfterDelay(dialog: AlertDialog.Builder, delayMillis: Int) {
private fun showDialogAfterDelay(dialog: AlertDialog.Builder, delayMillis: Int) {
postDelayedOnNewHandler({
try {
dialog.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class FieldState private constructor(private val editor: NoteEditor) {
return editLines
}

protected fun createFields(type: FieldChangeType): List<FieldEditLine> {
private fun createFields(type: FieldChangeType): List<FieldEditLine> {
val fields = getFields(type)
val editLines: MutableList<FieldEditLine> = ArrayList(fields.size)
for (i in fields.indices) {
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/libanki/Notetypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Notetypes(val col: Collection) {
}

private fun _get_cached(ntid: int): NotetypeJson? {
return _cache.get(ntid)
return _cache[ntid]
}

@NeedsTest("14827: styles are updated after syncing style changes")
Expand Down
14 changes: 7 additions & 7 deletions AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ open class Scheduler(val col: Collection) {
var revTime: Double
var relrnRate: Double
var relrnTime: Double
if (reload || etaCache.get(0) == -1.0) {
if (reload || etaCache[0] == -1.0) {
col
.db
.query(
Expand Down Expand Up @@ -574,12 +574,12 @@ open class Scheduler(val col: Collection) {
etaCache[4] = relrnRate
etaCache[5] = relrnTime
} else {
newRate = etaCache.get(0)
newTime = etaCache.get(1)
revRate = etaCache.get(2)
revTime = etaCache.get(3)
relrnRate = etaCache.get(4)
relrnTime = etaCache.get(5)
newRate = etaCache[0]
newTime = etaCache[1]
revRate = etaCache[2]
revTime = etaCache[3]
relrnRate = etaCache[4]
relrnTime = etaCache[5]
}

// Calculate the total time for each queue based on the historical average duration per rep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ class TagsDialogTest {
val returnedOption = AtomicReference<CardStateFilter>()
f.parentFragmentManager.setFragmentResultListener(
TagsDialogListener.ON_SELECTED_TAGS_KEY,
mockLifecycleOwner(),
{ _: String?, bundle: Bundle ->
returnedList.set(bundle.getStringArrayList(TagsDialogListener.ON_SELECTED_TAGS__SELECTED_TAGS))
returnedOption.set(bundle.getSerializableCompat<CardStateFilter>(TagsDialogListener.ON_SELECTED_TAGS__OPTION))
}
)
mockLifecycleOwner()
) { _: String?, bundle: Bundle ->
returnedList.set(bundle.getStringArrayList(TagsDialogListener.ON_SELECTED_TAGS__SELECTED_TAGS))
returnedOption.set(bundle.getSerializableCompat<CardStateFilter>(TagsDialogListener.ON_SELECTED_TAGS__OPTION))
}
val body = dialog!!.getCustomView()
val optionsGroup = body.findViewById<RadioGroup>(R.id.tags_dialog_options_radiogroup)
Assert.assertEquals(optionsGroup.visibility.toLong(), View.VISIBLE.toLong())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.ichi2.libanki.Collection
import com.ichi2.testutils.ShadowStatFs
import com.ichi2.testutils.assertFalse
import com.ichi2.testutils.createTransientDirectory
import io.mockk.*
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.*
import org.robolectric.shadows.ShadowStatFs
import java.io.File
import kotlin.io.path.Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ interface OperationTest {
* The [MoveDirectoryContent] that performs the action mentioned in the class description.
*/
val spy: MoveDirectoryContent
get() = spy(moveDirectoryContent) {
doAnswer { toMoveOperation(it) }.whenever(it).toMoveOperation(any())
get() = spy(moveDirectoryContent) { moveDirectoryContent ->
doAnswer { toMoveOperation(it) }.whenever(moveDirectoryContent).toMoveOperation(any())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private constructor(source: Directory, destination: Directory, val filesToMigrat
companion object {
// media DB created on demand, and no -journal file in new backend
// collection.log no longer exists
val INTEGRATION_INTENDED_REMAINING_FILE_COUNT: Int = 2
const val INTEGRATION_INTENDED_REMAINING_FILE_COUNT: Int = 2

/**
* A MigrateUserDataTest from inputSource to inputDestination (or transient directories if not provided)
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ open class SchedulerTest : JvmTest() {
note2.setItem("Back", "two")
col.addNote(note2)
Assert.assertEquals(Counts(2, 0, 0), col.sched.counts())
var c = col.sched.card!!
val c = col.sched.card!!
// getCard does not decrement counts
Assert.assertEquals(Counts(2, 0, 0), col.sched.counts())
Assert.assertEquals(Counts.Queue.NEW, col.sched.countIdx())
Expand Down
1 change: 0 additions & 1 deletion AnkiDroid/src/test/java/com/ichi2/libanki/UtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import java.util.*

@RunWith(AndroidJUnit4::class)
class UtilsTest {
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/test/java/com/ichi2/testutils/JvmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ open class JvmTest : TestClass {
return
}
// use println(): Timber may not work under the Jvm
System.out.println(tag + ": " + message)
println("$tag: $message")
t?.printStackTrace()
}
})
Expand Down
1 change: 0 additions & 1 deletion AnkiDroid/src/test/java/com/ichi2/utils/JSONObjectTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.ichi2.utils
import android.annotation.SuppressLint
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.testutils.EmptyApplication
import junit.framework.TestCase.*
import org.json.JSONObject
import org.junit.Assert
import org.junit.Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.hamcrest.Matchers
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
import java.util.*

@RunWith(AndroidJUnit4::class)
@Config(application = EmptyApplication::class)
Expand Down
1 change: 0 additions & 1 deletion AnkiDroid/src/test/java/com/ichi2/utils/TagsUtilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.junit.Test
import org.junit.experimental.runners.Enclosed
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.util.*

@RunWith(Enclosed::class)
class TagsUtilTest {
Expand Down

0 comments on commit c0cd3b5

Please sign in to comment.