Skip to content

Commit

Permalink
cleanup: CompatV26
Browse files Browse the repository at this point in the history
the KotlinCleanup seemed wrong: 0e43472
already handled `Context.VIBRATOR_SERVICE` deprecation

* Use `as?` to allow the lookup to fail gracefully
  • Loading branch information
david-allison authored and BrayanDSO committed Nov 2, 2023
1 parent e4ca43b commit 158b259
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions AnkiDroid/src/main/java/com/ichi2/compat/CompatV26.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import android.os.Vibrator
import android.view.View
import androidx.annotation.VisibleForTesting
import com.ichi2.anki.NotificationChannels
import com.ichi2.utils.KotlinCleanup
import java.io.*
import java.nio.file.*

Expand All @@ -44,11 +43,9 @@ open class CompatV26 : CompatV24(), Compat {
override fun setTooltipTextByContentDescription(view: View) { /* Nothing to do API26+ */
}

@Suppress("DEPRECATION")
@KotlinCleanup("when solving the deprecation of Context.VIBRATOR_SERVICE fix the SENSELESS_COMPARISON warning")
@Suppress("DEPRECATION") // VIBRATOR_SERVICE => VIBRATOR_MANAGER_SERVICE handled in CompatV31
override fun vibrate(context: Context, durationMillis: Long) {
val vibratorManager = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
@Suppress("SENSELESS_COMPARISON")
val vibratorManager = context.getSystemService(Context.VIBRATOR_SERVICE) as? Vibrator
if (vibratorManager != null) {
val effect = VibrationEffect.createOneShot(durationMillis, VibrationEffect.DEFAULT_AMPLITUDE)
vibratorManager.vibrate(effect)
Expand Down

0 comments on commit 158b259

Please sign in to comment.