From 0d5bd9a156c8dd0f419ea84aea41c265bd138058 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Tue, 7 Apr 2026 06:26:56 +0200 Subject: [PATCH] Lint warnings --- .../info/hannes/github/AppUpdateHelper.kt | 11 +++++---- .../main/java/info/hannes/github/Notify.kt | 24 ++++++++----------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/githubAppUpdate/src/main/java/info/hannes/github/AppUpdateHelper.kt b/githubAppUpdate/src/main/java/info/hannes/github/AppUpdateHelper.kt index 9ebe15b..07f97ca 100644 --- a/githubAppUpdate/src/main/java/info/hannes/github/AppUpdateHelper.kt +++ b/githubAppUpdate/src/main/java/info/hannes/github/AppUpdateHelper.kt @@ -7,7 +7,6 @@ import android.content.Intent import android.content.pm.ApplicationInfo import android.content.pm.PackageInfo import android.content.pm.PackageManager -import android.net.Uri import android.os.Build import android.util.Log import android.widget.Toast @@ -24,13 +23,15 @@ import retrofit2.Response import java.lang.RuntimeException import java.net.HttpURLConnection import java.util.concurrent.TimeUnit +import androidx.core.net.toUri +import androidx.core.content.edit object AppUpdateHelper { private fun Activity.getVersionName(): String = try { this.getPackageInfo().versionName ?: "" - } catch (e: PackageManager.NameNotFoundException) { + } catch (_: PackageManager.NameNotFoundException) { "" } @@ -64,7 +65,7 @@ object AppUpdateHelper { if (force || prefs.getLong(key, 0) < System.currentTimeMillis() - 1000 * 3600 * 24 / 24 / 60 * 5) { try { val versionList = requestGithubVersions(gitRepoUrl, token) - prefs.edit().putLong(key, System.currentTimeMillis()).apply() + prefs.edit { putLong(key, System.currentTimeMillis()) } versionList.body()?.firstOrNull()?.let { release -> val assetApk = release.assets.find { it.name.endsWith("release.apk") } @@ -146,7 +147,7 @@ object AppUpdateHelper { dialog.dismiss() } .setPositiveButton(activity.getString(R.string.showRelease)) { dialog, _ -> - val uriUrl = Uri.parse(release.htmlUrl) + val uriUrl = release.htmlUrl.toUri() Log.d("open", uriUrl.toString()) activity.startActivity(Intent(Intent.ACTION_VIEW, uriUrl)) dialog.dismiss() @@ -154,7 +155,7 @@ object AppUpdateHelper { assetApk?.let { dialog.setNeutralButton(activity.getString(R.string.directDownload)) { dialog, _ -> - val uriUrl = Uri.parse(it.browserDownloadUrl) + val uriUrl = it.browserDownloadUrl.toUri() Log.d("open", uriUrl.toString()) activity.startActivity(Intent(Intent.ACTION_VIEW, uriUrl)) dialog.dismiss() diff --git a/githubAppUpdate/src/main/java/info/hannes/github/Notify.kt b/githubAppUpdate/src/main/java/info/hannes/github/Notify.kt index ab93293..193f60b 100755 --- a/githubAppUpdate/src/main/java/info/hannes/github/Notify.kt +++ b/githubAppUpdate/src/main/java/info/hannes/github/Notify.kt @@ -6,23 +6,19 @@ import android.app.PendingIntent import android.content.Context import android.content.Intent import android.graphics.Color -import android.net.Uri import android.os.Build import androidx.core.app.NotificationCompat +import androidx.core.net.toUri import info.hannes.github.model.Asset import info.hannes.github.model.GithubVersion internal object Notify { private var MessageID = 120 - private const val channelId = "channelAppUpdate" - private const val channelFireBaseMsg = "Channel appUpdate" + private const val CHANNEL_ID = "channelAppUpdate" + private const val CHANNEL_FIREBASE_MSG = "Channel appUpdate" - private val pendingIntentFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT - } else { - PendingIntent.FLAG_UPDATE_CURRENT - } + private const val PENDING_INTENT_FLAGS = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT fun notification(context: Context, messageString: String, notificationTitle: String, assetApk: Asset?, release: GithubVersion) { @@ -31,7 +27,7 @@ internal object Notify { val notificationManager = context.getSystemService(ns) as NotificationManager if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val notificationChannel = NotificationChannel(channelId, channelFireBaseMsg, NotificationManager.IMPORTANCE_LOW) + val notificationChannel = NotificationChannel(CHANNEL_ID, CHANNEL_FIREBASE_MSG, NotificationManager.IMPORTANCE_LOW) notificationChannel.enableLights(true) notificationChannel.lightColor = Color.RED notificationChannel.enableVibration(true) @@ -46,11 +42,11 @@ internal object Notify { //the message that will be displayed as the ticker val ticker = "$contentTitle $messageString" - val showUrl = Uri.parse(release.htmlUrl) - val showPendingIntent = PendingIntent.getActivity(context, 0, Intent(Intent.ACTION_VIEW, showUrl), pendingIntentFlags) + val showUrl = release.htmlUrl.toUri() + val showPendingIntent = PendingIntent.getActivity(context, 0, Intent(Intent.ACTION_VIEW, showUrl), PENDING_INTENT_FLAGS) //build the notification - val notificationCompat = NotificationCompat.Builder(context, channelId) + val notificationCompat = NotificationCompat.Builder(context, CHANNEL_ID) .setAutoCancel(true) .setContentTitle(contentTitle) .setContentIntent(showPendingIntent) @@ -62,8 +58,8 @@ internal object Notify { .addAction(R.drawable.githib_logo, context.getString(R.string.showRelease), showPendingIntent) assetApk?.let { - val uriUrl = Uri.parse(it.browserDownloadUrl) - val directPendingIntent = PendingIntent.getActivity(context, 0, Intent(Intent.ACTION_VIEW, uriUrl), pendingIntentFlags) + val uriUrl = it.browserDownloadUrl.toUri() + val directPendingIntent = PendingIntent.getActivity(context, 0, Intent(Intent.ACTION_VIEW, uriUrl), PENDING_INTENT_FLAGS) notificationCompat.addAction(R.drawable.githib_logo, context.getString(R.string.directDownload), directPendingIntent) }