Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions githubAppUpdate/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
id("com.android.library")
id("maven-publish")
kotlin("plugin.serialization") version "2.3.20"
}

android {
namespace = "info.hannes.github"
compileSdk = 36
defaultConfig {
minSdk = 23
consumerProguardFiles("proguard-rules.pro")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
Expand All @@ -31,12 +33,12 @@ base {

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.3.20")
implementation("com.google.code.gson:gson:2.13.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1")
implementation("androidx.work:work-runtime-ktx:2.11.2")

implementation("com.squareup.retrofit2:retrofit:3.0.0")
implementation("androidx.appcompat:appcompat:1.7.1")
implementation("com.squareup.retrofit2:converter-gson:3.0.0")
implementation("com.squareup.retrofit2:converter-kotlinx-serialization:3.0.0")
implementation("androidx.preference:preference-ktx:1.2.1")
api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2")
api("androidx.lifecycle:lifecycle-runtime-ktx:2.10.0")
Expand Down
35 changes: 33 additions & 2 deletions githubAppUpdate/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Keep Kotlin metadata for coroutines
-keep class kotlin.Metadata { *; }
-keepattributes RuntimeVisibleAnnotations
-keepattributes *Annotation*
-keepattributes *Annotation*,InnerClasses,AnnotationDefault

# Keep coroutine related classes
-keepclassmembernames class kotlinx.** {
Expand All @@ -14,7 +14,6 @@

# Don't obfuscate Kotlin metadata
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile

# Keep synthetic methods for Kotlin coroutines
-keepclassmembers class ** {
Expand All @@ -31,3 +30,35 @@
# Keep lifecycle coroutine scope
-keep class androidx.lifecycle.** { *; }
-keepclassmembers class androidx.lifecycle.** { *; }

##------------------ kotlinx.serialization ------------------

# Keep @Serializable companion objects and their serializer() methods
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
static <1>$Companion Companion;
}

# Keep serializer() on named companion objects of serializable classes
-if @kotlinx.serialization.Serializable class ** {
static **$* *;
}
-keepclassmembers class <2>$<3> {
kotlinx.serialization.KSerializer serializer(...);
}

# Keep INSTANCE.serializer() for serializable objects
-if @kotlinx.serialization.Serializable class ** {
public static ** INSTANCE;
}
-keepclassmembers class <1> {
public static <1> INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}

# Keep serialization descriptor fields
-keepclassmembers class kotlinx.serialization.internal.** { *; }

# Suppress notes about kotlinx.serialization internals
-dontnote kotlinx.serialization.**
-dontwarn kotlinx.serialization.**
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object AppUpdateHelper {
prefs.edit { putLong(key, System.currentTimeMillis()) }

versionList.body()?.firstOrNull()?.let { release ->
val assetApk = release.assets.find { it.name.endsWith("release.apk") }
val assetApk = release.assets.find { it.name?.endsWith("release.apk") == true }

Log.d("AppUpdateHelper", release.tagName + " > " + currentVersionName + " " + (release.tagName > currentVersionName))
if (release.tagName > currentVersionName) {
Expand Down Expand Up @@ -96,7 +96,7 @@ object AppUpdateHelper {
val versionList = requestVersionsSync(gitRepoUrl, token)

versionList.body()?.firstOrNull()?.let { release ->
val assetApk = release.assets.find { it.name.endsWith("release.apk") }
val assetApk = release.assets.find { it.name?.endsWith("release.apk") == true }

Log.d("AppUpdateHelper", release.tagName + " > " + currentVersionName + " " + (release.tagName > currentVersionName))
val text = "You use version $currentVersionName\n" +
Expand All @@ -112,12 +112,12 @@ object AppUpdateHelper {
}
}

private fun requestVersionsSync(gitRepoUrl: String, token: String? = null): Response<MutableList<GithubVersion>> {
private fun requestVersionsSync(gitRepoUrl: String, token: String? = null): Response<List<GithubVersion>> {
val client = GithubClient(HttpLoggingInterceptor.Level.BODY, token)
return client.github.getGithubVersions(gitRepoUrl.user(), gitRepoUrl.repo()).execute()
}

private suspend fun requestGithubVersions(gitRepoUrl: String, token: String? = null): Response<MutableList<GithubVersion>> {
private suspend fun requestGithubVersions(gitRepoUrl: String, token: String? = null): Response<List<GithubVersion>> {
val versionList = withContext(Dispatchers.Default) {
val client = GithubClient(HttpLoggingInterceptor.Level.BODY, token)
client.github.getGithubVersions(gitRepoUrl.user(), gitRepoUrl.repo()).execute()
Expand Down Expand Up @@ -147,15 +147,15 @@ object AppUpdateHelper {
dialog.dismiss()
}
.setPositiveButton(activity.getString(R.string.showRelease)) { dialog, _ ->
val uriUrl = release.htmlUrl.toUri()
val uriUrl = release.htmlUrl.orEmpty().toUri()
Log.d("open", uriUrl.toString())
activity.startActivity(Intent(Intent.ACTION_VIEW, uriUrl))
dialog.dismiss()
}

assetApk?.let {
dialog.setNeutralButton(activity.getString(R.string.directDownload)) { dialog, _ ->
val uriUrl = it.browserDownloadUrl.toUri()
val uriUrl = it.browserDownloadUrl.orEmpty().toUri()
Log.d("open", uriUrl.toString())
activity.startActivity(Intent(Intent.ACTION_VIEW, uriUrl))
dialog.dismiss()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package info.hannes.github

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.kotlinx.serialization.asConverterFactory

internal object GithubRestServiceCreationHelper {

private var httpLoggingInterceptor: HttpLoggingInterceptor = HttpLoggingInterceptor()

init {
httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.NONE
private val json = Json {
ignoreUnknownKeys = true
coerceInputValues = true
}

private fun createGson(): Gson {
return GsonBuilder().serializeNulls()
.create()
init {
httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.NONE
}

fun <T> createGithubService(retrofitInterface: Class<T>, logLevel: HttpLoggingInterceptor.Level, token: String? = null): T {
Expand All @@ -34,11 +34,10 @@ internal object GithubRestServiceCreationHelper {
val client = clientHttp
.build()

val gson = createGson()
val retrofit = Retrofit.Builder()
.baseUrl("https://api.github.com")
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(json.asConverterFactory("application/json; charset=UTF-8".toMediaType()))
.build()

return retrofit.create(retrofitInterface)
Expand Down
19 changes: 0 additions & 19 deletions githubAppUpdate/src/main/java/info/hannes/github/IGithub.java

This file was deleted.

16 changes: 16 additions & 0 deletions githubAppUpdate/src/main/java/info/hannes/github/IGithub.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package info.hannes.github

import info.hannes.github.model.GithubVersion
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Path

interface IGithub {
@GET("/repos/{githubUser}/{githubRepo}/releases")
@Headers("Accept: application/json")
fun getGithubVersions(
@Path("githubUser") githubUser: String,
@Path("githubRepo") githubRepo: String
): Call<List<GithubVersion>>
}
4 changes: 2 additions & 2 deletions githubAppUpdate/src/main/java/info/hannes/github/Notify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal object Notify {
//the message that will be displayed as the ticker
val ticker = "$contentTitle $messageString"

val showUrl = release.htmlUrl.toUri()
val showUrl = release.htmlUrl.orEmpty().toUri()
val showPendingIntent = PendingIntent.getActivity(context, 0, Intent(Intent.ACTION_VIEW, showUrl), PENDING_INTENT_FLAGS)

//build the notification
Expand All @@ -58,7 +58,7 @@ internal object Notify {
.addAction(R.drawable.githib_logo, context.getString(R.string.showRelease), showPendingIntent)

assetApk?.let {
val uriUrl = it.browserDownloadUrl.toUri()
val uriUrl = it.browserDownloadUrl.orEmpty().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)
}
Expand Down
152 changes: 0 additions & 152 deletions githubAppUpdate/src/main/java/info/hannes/github/model/Asset.java

This file was deleted.

Loading
Loading