Skip to content

Commit

Permalink
Fixes Android Studio Warnings under Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
awanishyadav967 authored and lukstbit committed Mar 9, 2024
1 parent 2d4985c commit 7858251
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,7 @@ abstract class AbstractFlashcardViewer :

/** #6141 - blocks clicking links from executing "touch" gestures.
* COULD_BE_BETTER: Make base class static and move this out of the CardViewer */
internal inner class LinkDetectingGestureDetector() :
internal inner class LinkDetectingGestureDetector :
MyGestureDetector(), ShakeDetector.Listener {
private var shakeDetector: ShakeDetector? = null

Expand Down
3 changes: 1 addition & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ open class CardBrowser :

// convenience method for updateCardsInList(...)
private fun updateCardInList(card: Card) {
val cards: MutableList<Card> = java.util.ArrayList(1)
val cards: MutableList<Card> = ArrayList(1)
cards.add(card)
updateCardsInList(cards)
}
Expand Down Expand Up @@ -1743,7 +1743,6 @@ open class CardBrowser :
return v
}

@Suppress("UNCHECKED_CAST")
@KotlinCleanup("Unchecked cast")
private fun bindView(position: Int, v: View) {
// Draw the content in the columns
Expand Down
4 changes: 0 additions & 4 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ import timber.log.Timber
import java.io.File
import java.lang.Runnable
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.ExperimentalTime
import kotlin.time.measureTimedValue

const val MIGRATION_WAS_LAST_POSTPONED_AT_SECONDS = "secondWhenMigrationWasPostponedLast"
Expand Down Expand Up @@ -1221,7 +1220,6 @@ open class DeckPicker :
}
}

@Suppress("DEPRECATION") // onBackPressed
@Deprecated("Deprecated in Java")
override fun onBackPressed() {
val preferences = baseContext.sharedPrefs()
Expand Down Expand Up @@ -1848,7 +1846,6 @@ open class DeckPicker :
}
negativeButton(R.string.dialog_cancel)
if (AdaptionUtil.hasWebBrowser(this@DeckPicker)) {
@Suppress("DEPRECATION")
neutralButton(text = getColUnsafe.tr.schedulingUpdateMoreInfoButton()) {
this@DeckPicker.openUrl(Uri.parse("https://faqs.ankiweb.net/the-anki-2.1-scheduler.html#updating"))
}
Expand Down Expand Up @@ -2344,7 +2341,6 @@ open class DeckPicker :
MigrationService.start(baseContext)
}

@OptIn(ExperimentalTime::class)
private fun launchShowingHidingEssentialFileMigrationProgressDialog() = lifecycleScope.launch {
while (true) {
MigrationService.flowOfProgress
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/ModelFieldEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class ModelFieldEditor : AnkiActivity(), LocaleSelectionDialogHandler {

private suspend fun changeSortField(notetype: NotetypeJson, idx: Int) {
withProgress(resources.getString(R.string.model_field_editor_changing)) {
CollectionManager.withCol {
withCol {
Timber.d("doInBackgroundChangeSortField")
notetypes.set_sort_index(notetype, idx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ open class DeckSelectionDialog : AnalyticsDialogFragment() {
isCancelable = true
}

@Suppress("Deprecation") // Material dialog neutral button deprecation
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialogView = LayoutInflater.from(activity)
.inflate(R.layout.deck_picker_dialog, null, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class TtsVoicesDialogFragment : DialogFragment() {
}

// inner allows access to viewModel/openTtsSettings
inner class TtsVoiceAdapter() : ListAdapter<AndroidTtsVoice, TtsVoiceAdapter.TtsViewHolder>(TtsVoiceDiffCallback()) {
inner class TtsVoiceAdapter : ListAdapter<AndroidTtsVoice, TtsVoiceAdapter.TtsViewHolder>(TtsVoiceDiffCallback()) {
inner class TtsViewHolder(private val voiceView: View) : RecyclerView.ViewHolder(voiceView) {
private val textViewTop = voiceView.findViewById<TextView>(R.id.mtrl_list_item_secondary_text)
private val textViewBottom = voiceView.findViewById<TextView>(R.id.mtrl_list_item_text)
Expand Down
1 change: 0 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/libanki/DB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class DB(val database: SupportSQLiteDatabase) {
*/
@KotlinCleanup("""Use Kotlin string. Change split so that there is no empty string after last ";".""")
fun executeScript(@Language("SQL") sql: String) {
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
val queries = java.lang.String(sql).split(";")
for (query in queries) {
database.execSQL(query)
Expand Down
22 changes: 11 additions & 11 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Notetypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ class Notetypes(val col: Collection) {
* [ConfirmModSchemaException]
*/
@RustCleanup("Since Kotlin doesn't have throws, this may not be needed")
fun addFieldInNewModel(m: com.ichi2.libanki.NotetypeJson, field: JSONObject) {
Assert.that(Notetypes.isModelNew(m), "Model was assumed to be new, but is not")
fun addFieldInNewModel(m: NotetypeJson, field: JSONObject) {
Assert.that(isModelNew(m), "Model was assumed to be new, but is not")
try {
_addField(m, field)
} catch (e: ConfirmModSchemaException) {
Expand All @@ -399,10 +399,10 @@ class Notetypes(val col: Collection) {
}
}

fun addTemplateInNewModel(m: com.ichi2.libanki.NotetypeJson, template: JSONObject) {
fun addTemplateInNewModel(m: NotetypeJson, template: JSONObject) {
// similar to addTemplate, but doesn't throw exception;
// asserting the model is new.
Assert.that(Notetypes.isModelNew(m), "Model was assumed to be new, but is not")
Assert.that(isModelNew(m), "Model was assumed to be new, but is not")

try {
_addTemplate(m, template)
Expand All @@ -413,15 +413,15 @@ class Notetypes(val col: Collection) {
}
}

fun addFieldModChanged(m: com.ichi2.libanki.NotetypeJson, field: JSONObject) {
fun addFieldModChanged(m: NotetypeJson, field: JSONObject) {
// similar to Anki's addField; but thanks to assumption that
// mod is already changed, it never has to throw
// ConfirmModSchemaException.
Assert.that(col.schemaChanged(), "Mod was assumed to be already changed, but is not")
_addField(m, field)
}

fun addTemplateModChanged(m: com.ichi2.libanki.NotetypeJson, template: JSONObject) {
fun addTemplateModChanged(m: NotetypeJson, template: JSONObject) {
// similar to addTemplate, but doesn't throw exception;
// asserting the model is new.
Assert.that(col.schemaChanged(), "Mod was assumed to be already changed, but is not")
Expand Down Expand Up @@ -573,11 +573,11 @@ class Notetypes(val col: Collection) {
return all_names_and_ids().count()
}

fun _addTemplate(m: com.ichi2.libanki.NotetypeJson, template: JSONObject) {
fun _addTemplate(m: NotetypeJson, template: JSONObject) {
addTemplate(m, template)
}

fun _addField(m: com.ichi2.libanki.NotetypeJson, field: JSONObject) {
fun _addField(m: NotetypeJson, field: JSONObject) {
addField(m, field)
}

Expand Down Expand Up @@ -629,7 +629,7 @@ class Notetypes(val col: Collection) {
)

/** "Mapping of field name -> (ord, field). */
fun fieldMap(m: com.ichi2.libanki.NotetypeJson): Map<String, Pair<Int, JSONObject>> {
fun fieldMap(m: NotetypeJson): Map<String, Pair<Int, JSONObject>> {
val flds = m.getJSONArray("flds")
// TreeMap<Integer, String> map = new TreeMap<Integer, String>();
val result: MutableMap<String, Pair<Int, JSONObject>> = HashUtil.hashMapInit(flds.length())
Expand All @@ -640,11 +640,11 @@ class Notetypes(val col: Collection) {
}

// not in anki
fun isModelNew(m: com.ichi2.libanki.NotetypeJson): Boolean {
fun isModelNew(m: NotetypeJson): Boolean {
return m.getLong("id") == 0L
}

fun _updateTemplOrds(m: com.ichi2.libanki.NotetypeJson) {
fun _updateTemplOrds(m: NotetypeJson) {
val tmpls = m.getJSONArray("tmpls")
for (i in 0 until tmpls.length()) {
val f = tmpls.getJSONObject(i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fun Note.toBackendNote(): anki.notes.Note {
id = note.id
guid = note.guId!!
notetypeId = note.mid
mtimeSecs = note.mod.toInt() // this is worrying, 2038 problem
mtimeSecs = note.mod
usn = note.usn
tags.addAll(note.tags.asIterable())
fields.addAll(note.fields.asIterable())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.ichi2.anki.reviewer
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.anki.RobolectricTest
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.not
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.ichi2.anki.servicelayer.scopedstorage

import com.ichi2.anki.servicelayer.scopedstorage.migrateuserdata.MigrateUserData.*
import com.ichi2.anki.servicelayer.scopedstorage.migrateuserdata.MigrateUserData.MigrationContext
import com.ichi2.anki.servicelayer.scopedstorage.migrateuserdata.MigrateUserData.Operation
import com.ichi2.anki.servicelayer.scopedstorage.migrateuserdata.NumberOfBytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.ichi2.anki.servicelayer.NoteService
import com.ichi2.libanki.Consts
import com.ichi2.libanki.Note
import com.ichi2.libanki.NotetypeJson
import com.ichi2.libanki.utils.set
import com.ichi2.testutils.createTransientFile
import org.hamcrest.CoreMatchers.*
import org.hamcrest.MatcherAssert.assertThat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import org.mockito.Mockito
/** Test helper:
* causes getCol to emulate an exception caused by having another AnkiDroid instance open on the same collection
*/
class BackendEmulatingOpenConflict() : Backend() {
@Suppress("UNUSED_PARAMETER")
class BackendEmulatingOpenConflict : Backend() {
override fun openCollection(
collectionPath: String,
mediaFolderPath: String,
Expand Down
1 change: 0 additions & 1 deletion AnkiDroid/src/test/java/com/ichi2/utils/FileOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package com.ichi2.utils

import java.io.File
import java.io.RandomAccessFile
import java.util.*

class FileOperation {
companion object {
Expand Down

0 comments on commit 7858251

Please sign in to comment.