Add @ChecksSdkIntAtLeast annotation.

This commit is contained in:
Benoit Marty 2022-09-15 15:51:27 +02:00 committed by Benoit Marty
parent 1ff4a5f212
commit bb2eb56ee6
3 changed files with 7 additions and 1 deletions

View file

@ -16,6 +16,8 @@
package org.matrix.android.sdk.api.util
import androidx.annotation.ChecksSdkIntAtLeast
interface BuildVersionSdkIntProvider {
/**
* Return the current version of the Android SDK.
@ -26,6 +28,7 @@ interface BuildVersionSdkIntProvider {
* Checks the if the current OS version is equal or greater than [version].
* @return A `non-null` result if true, `null` otherwise.
*/
@ChecksSdkIntAtLeast(parameter = 0, lambda = 1)
fun <T> whenAtLeast(version: Int, result: () -> T): T? {
return if (get() >= version) {
result()

View file

@ -20,6 +20,7 @@ import android.content.Context
import android.content.pm.ShortcutInfo
import android.graphics.Bitmap
import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.annotation.WorkerThread
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
@ -32,6 +33,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.util.toMatrixItem
import javax.inject.Inject
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
private val useAdaptiveIcon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
private const val adaptiveIconSizeDp = 108
private const val adaptiveIconOuterSidesDp = 18

View file

@ -34,6 +34,7 @@ import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import androidx.annotation.AttrRes
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat
@ -102,6 +103,7 @@ class NotificationUtils @Inject constructor(
const val SILENT_NOTIFICATION_CHANNEL_ID = "DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID_V2"
private const val CALL_NOTIFICATION_CHANNEL_ID = "CALL_NOTIFICATION_CHANNEL_ID_V2"
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
fun supportNotificationChannels() = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
fun openSystemSettingsForSilentCategory(fragment: Fragment) {
@ -126,7 +128,6 @@ class NotificationUtils @Inject constructor(
/**
* Create notification channels.
*/
@TargetApi(Build.VERSION_CODES.O)
fun createNotificationChannels() {
if (!supportNotificationChannels()) {
return