Skip to content

Commit

Permalink
Fix Android Studio warnings for redundant constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
aarushis18 authored and BrayanDSO committed Jan 2, 2024
1 parent 1d1aa78 commit e38bfe4
Show file tree
Hide file tree
Showing 27 changed files with 33 additions and 47 deletions.
5 changes: 3 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/BackendBackups.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package com.ichi2.anki

import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.libanki.awaitBackupCompletion
import com.ichi2.libanki.createBackup
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext

fun DeckPicker.performBackupInBackground() {
launchCatchingTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class IntroductionActivity : AnkiActivity() {

handleCollectionSetupOption { option ->
when (option) {
CollectionSetupOption.DeckPickerWithNewCollection -> startDeckPicker(RESULT_START_NEW)
CollectionSetupOption.DeckPickerWithNewCollection -> startDeckPicker()
CollectionSetupOption.SyncFromExistingAccount -> openLoginDialog()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class TypeAnswer(
*/
fun updateInfo(card: Card, res: Resources) {
correct = null
val q = card.question(false)
val q = card.question()
val m = PATTERN.matcher(q)
var clozeIdx = 0
if (!m.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.util.*
* @param checkedTags a list containing the currently selected tags. Any duplicates will be ignored.
* @param uncheckedTags a list containing the currently unselected tags. Any duplicates will be ignored.
*/
class TagsList constructor(
class TagsList(
allTags: List<String>,
checkedTags: List<String>,
uncheckedTags: List<String>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.ichi2.anki.exception

class StorageAccessException constructor(
class StorageAccessException(
msg: String? = null,
e: Throwable? = null
) : Exception(msg, e)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import java.net.HttpCookie
* because android doesn't have a non-private getter for its MediaPlayer state
*/
class MediaPlayer :
android.media.MediaPlayer(),
MediaPlayer(),
OnPreparedListener,
MediaPlayer.OnErrorListener,
MediaPlayer.OnCompletionListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,6 @@ class MultimediaEditFieldActivity : AnkiActivity(), OnRequestPermissionsResultCa
}

private fun createControllerForField(field: IField): IFieldController {
@Suppress("WHEN_ENUM_CAN_BE_NULL_IN_JAVA")
// the return of field.type is non nullable
return when (field.type) {
EFieldType.TEXT -> BasicTextFieldController()
EFieldType.IMAGE -> BasicImageFieldController()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CustomButtonsSettingsFragment : SettingsFragment() {
// #9263: refresh the screen to display the changes
refreshScreen()
}
negativeButton(R.string.dialog_cancel, null)
negativeButton(R.string.dialog_cancel)
}
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ import com.bytehamster.lib.preferencesearch.SearchPreferenceResult
import com.bytehamster.lib.preferencesearch.SearchPreferenceResultListener
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.CollapsingToolbarLayout
import com.ichi2.anki.*
import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.DeckPicker
import com.ichi2.anki.R
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.services.BootService.Companion.scheduleNotification
import com.ichi2.libanki.utils.TimeManager
import com.ichi2.themes.setTransparentStatusBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.ichi2.anki.reviewer.Binding.Companion.possibleKeyBindings
import com.ichi2.anki.reviewer.CardSide.Companion.fromAnswer
import com.ichi2.anki.reviewer.MappableBinding.*
import com.ichi2.anki.reviewer.MappableBinding.Companion.fromPreference
import java.util.HashMap

/** Accepts peripheral input, mapping via various keybinding strategies,
* and converting them to commands for the Reviewer. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ open class MigrateUserData protected constructor(val source: Directory, val dest
* If the number of retries was exceeded when resolving a file conflict via moving it to the
* /conflict/ folder.
*/
class FileConflictResolutionFailedException(val sourceFile: DiskFile, private val attemptedDestination: File) : MigrationException("Failed to move $sourceFile to $attemptedDestination")
class FileConflictResolutionFailedException(val sourceFile: DiskFile, attemptedDestination: File) : MigrationException("Failed to move $sourceFile to $attemptedDestination")

/**
* Context for an [Operation], allowing a change of execution behavior and
Expand Down Expand Up @@ -600,11 +600,7 @@ open class MigrateUserData protected constructor(val source: Directory, val dest
}

// don't move the "conflict" directory
if (file.name == MoveConflictedFile.CONFLICT_DIRECTORY) {
return false
}

return true
return file.name != MoveConflictedFile.CONFLICT_DIRECTORY
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import android.os.Binder
import android.os.IBinder
import androidx.annotation.CallSuper
import androidx.lifecycle.LifecycleCoroutineScope
import com.ichi2.anki.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import com.drakeet.drawer.FullDraggableContainer
* and finger travel distance is usually much higher than the usual threshold of about 8 dp.)
*/

class FullDraggableContainerFix constructor(context: Context, attrs: AttributeSet? = null) :
class FullDraggableContainerFix(context: Context, attrs: AttributeSet? = null) :
FullDraggableContainer(context, attrs) {

private var childRequestedNoTouchInterception = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,6 @@ fun saveModel(
// required for Rust: the modified time can't go backwards, and we updated the model by adding fields
// This could be done better
notetype.put("mod", oldModel!!.getLong("mod"))
col.notetypes.save(notetype, true)
col.notetypes.save(notetype)
col.notetypes.update(notetype)
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ fun Collection.exportCollectionPackage(
includeMedia: Boolean,
legacy: Boolean = true
) {
close(downgrade = false, forFullSync = true)
close(forFullSync = true)
backend.exportCollectionPackage(
outPath = outPath,
includeMedia = includeMedia,
legacy = legacy
)
reopen(afterFullSync = false)
reopen()
}

fun Collection.importAnkiPackageRaw(input: ByteArray): ByteArray {
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ open class Card : Cloneable {
* ***********************************************************
*/
fun qSimple(): String {
return renderOutput(false).questionText
return renderOutput().questionText
}

/*
* Returns the answer with anything before the <hr id=answer> tag removed
*/
val pureAnswer: String
get() {
val s = renderOutput(false).answerText
val s = renderOutput().answerText
for (target in arrayOf("<hr id=answer>", "<hr id=\"answer\">")) {
val pos = s.indexOf(target)
if (pos == -1) continue
Expand Down
5 changes: 2 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ package com.ichi2.libanki
import androidx.annotation.WorkerThread
import anki.collection.OpChangesWithCount
import com.ichi2.libanki.utils.join
import com.ichi2.libanki.utils.set
import java.util.*
import java.util.AbstractSet

/**
* Anki maintains a cache of used tags so it can quickly present a list of tags
Expand Down Expand Up @@ -93,7 +92,7 @@ class Tags(private val col: Collection) {
/** {@inheritDoc} */

// this is now a no-op - the tags are canonified when the note is saved
fun canonify(tagList: List<String>): java.util.AbstractSet<String> {
fun canonify(tagList: List<String>): AbstractSet<String> {
// libAnki difference: tagList was returned directly
return HashSet(tagList)
}
Expand Down
4 changes: 1 addition & 3 deletions AnkiDroid/src/main/java/com/ichi2/libanki/TemplateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,13 @@ class TemplateManager {
aoutText = LaTeX.mungeQA(aoutText, _col, svg)
}

val output = TemplateRenderOutput(
return TemplateRenderOutput(
questionText = qoutText,
answerText = aoutText,
questionAvTags = avTagsToNative(qout.avTagsList),
answerAvTags = avTagsToNative(aout.avTagsList),
css = noteType().getString("css")
)

return output
}

fun partiallyRender(): PartiallyRenderedCard {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

@file:Suppress("deprecation") // BuiltinSortKind - is a valid choice

package com.ichi2.libanki.backend.model

import com.ichi2.libanki.SortOrder
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/libanki/sched/Counts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.annotation.CheckResult
/**
* Represents the three counts shown in deck picker and reviewer. Semantically more meaningful than int[]
*/
class Counts constructor(var new: Int = 0, var lrn: Int = 0, var rev: Int = 0) {
class Counts(var new: Int = 0, var lrn: Int = 0, var rev: Int = 0) {
enum class Queue {
NEW, LRN, REV
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IncrementerNumberRangePreferenceCompat : NumberRangePreferenceCompat, Dial
@Suppress("unused")
constructor(context: Context) : super(context)

class IncrementerNumberRangeDialogFragmentCompat : NumberRangePreferenceCompat.NumberRangeDialogFragmentCompat() {
class IncrementerNumberRangeDialogFragmentCompat : NumberRangeDialogFragmentCompat() {
private var mLastValidEntry = 0

/**
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/ui/ButtonItemAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ButtonItemAdapter(

override fun getItemCount() = items.size

inner class ButtonVH constructor(itemView: View, private val adapter: ButtonItemAdapter) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
inner class ButtonVH(itemView: View, private val adapter: ButtonItemAdapter) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
val title: TextView = itemView.findViewById(R.id.card_browser_my_search_name_textview)
val button: ImageButton = itemView.findViewById<ImageButton?>(R.id.card_browser_my_search_remove_button).apply {
setOnClickListener(this@ButtonVH)
Expand Down
7 changes: 2 additions & 5 deletions AnkiDroid/src/main/java/com/ichi2/ui/GesturePicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import timber.log.Timber
* Current use is via [com.ichi2.anki.dialogs.GestureSelectionDialogBuilder]
*/
// This class exists as elements resized when adding in the spinner to GestureDisplay.kt
class GesturePicker
constructor(ctx: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0) :
class GesturePicker(ctx: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0) :
ConstraintLayout(ctx, attributeSet, defStyleAttr) {

private val mGestureSpinner: Spinner
Expand Down Expand Up @@ -97,9 +96,7 @@ constructor(ctx: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int

other as GestureWrapper

if (gesture != other.gesture) return false

return true
return gesture == other.gesture
}

override fun hashCode() = gesture?.hashCode() ?: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import android.widget.ImageButton
import androidx.annotation.VisibleForTesting
import androidx.appcompat.widget.TooltipCompat
import com.ichi2.anki.ActionProviderCompat
import com.ichi2.anki.R

/**
* An Rtl version of a normal action view, where the drawable is mirrored
Expand Down
3 changes: 2 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/utils/LanguageUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import com.ichi2.anki.AnkiDroidApp
import com.ichi2.anki.preferences.sharedPrefs
import net.ankiweb.rsdroid.BackendFactory
import java.text.DateFormat
import java.util.*
import java.util.Date
import java.util.Locale

/**
* Utility call for proving language related functionality.
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/utils/NetworkUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object NetworkUtils {
/**
* @return whether is possible to access the internet
*/
@Suppress("DEPRECATION") // activeNetworkInfo deprecation, only used for SDK < 23
// activeNetworkInfo deprecation, only used for SDK < 23
val isOnline: Boolean
get() {
val cm = connectivityManager ?: return false
Expand Down
2 changes: 0 additions & 2 deletions api/src/main/java/com/ichi2/anki/api/AddContentApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ public class AddContentApi(context: Context) {
*
* @return the spec version number or -1 if AnkiDroid is not installed.
*/
@Suppress("deprecation") // API33 symbol required until minSdkVersion >= 33
public val apiHostSpecVersion: Int
get() {
// PackageManager#resolveContentProvider docs suggest flags should be 0 (but that gives null metadata)
Expand Down Expand Up @@ -767,7 +766,6 @@ public class AddContentApi(context: Context) {
* @param context a Context that can be used to get the PackageManager
* @return packageId of AnkiDroid if a supported version is not installed, otherwise null
*/
@Suppress("deprecation") // deprecated symbol until minSdkVersion >= 33
@JvmStatic // required for API
public fun getAnkiDroidPackageName(context: Context): String? {
val manager = context.packageManager
Expand Down

0 comments on commit e38bfe4

Please sign in to comment.