diff --git a/app/build.gradle b/app/build.gradle
index 2ca08cb..0deb75e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -10,14 +10,14 @@ android {
versionCode getGitCommitCount()
versionName "1.0"
- minSdkVersion 21
+ minSdkVersion 26
targetSdkVersion 33
buildConfigField "String", 'GIT_REPOSITORY', "\"" + getGitOriginRemote() + "\""
}
packagingOptions {
resources {
- pickFirsts += ['META-INF/atomicfu.kotlin_module']
+ pickFirsts += ['META-INF/atomicfu.kotlin_module', 'META-INF/DEPENDENCIES']
}
}
diff --git a/app/src/main/java/info/hannes/github/sample/MainActivity.kt b/app/src/main/java/info/hannes/github/sample/MainActivity.kt
index 2b8c883..b64254f 100644
--- a/app/src/main/java/info/hannes/github/sample/MainActivity.kt
+++ b/app/src/main/java/info/hannes/github/sample/MainActivity.kt
@@ -27,7 +27,7 @@ class MainActivity : AppCompatActivity() {
BuildConfig.GIT_REPOSITORY
)
- binding.button.setOnClickListener {
+ binding.buttonGithub.setOnClickListener {
AppUpdateHelper.checkWithDialog(
this,
BuildConfig.GIT_REPOSITORY,
@@ -35,6 +35,15 @@ class MainActivity : AppCompatActivity() {
force = true // just to enable debugging, without you can only debug once a day
)
}
+
+ binding.buttonArtifactory.setOnClickListener {
+ AppUpdateHelper.checkArtifactoryDialog(
+ this,
+ "https://artifactory.myserver.info",
+ { msg -> Log.d("result", msg) },
+ force = true // just to enable debugging, without you can only debug once a day
+ )
+ }
}
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 746ee3a..7c09803 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -6,19 +6,28 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
-
-
+
+
+
Unit)? = null,
+ force: Boolean = false
+ ) = activity.lifecycle.coroutineScope.launch(Dispatchers.Main) {
+
+ val currentVersionName = activity.getVersionName()
+
+ val key = "LAST_VERSION_CHECK"
+ val prefs = PreferenceManager.getDefaultSharedPreferences(activity)
+
+ if (force || prefs.getLong(key, 0) < System.currentTimeMillis() - 1000 * 3600 * 24 / 24 / 60 * 5) {
+ try {
+ val versionList = requestArtifactoryVersions(gitRepoUrl)
+ prefs.edit().putLong(key, System.currentTimeMillis()).apply()
+
+ versionList?.body()?.firstOrNull()?.let { release ->
+ val assetApk = release.assets.find { it.name.endsWith("release.apk") }
+
+ Log.d("AppUpdateHelper", release.tagName + " > " + currentVersionName + " " + (release.tagName > currentVersionName))
+ callback?.invoke(release.tagName)
+ if (release.tagName > currentVersionName) {
+ askUser(activity, currentVersionName, release, assetApk)
+ } else {
+ callback?.invoke("Nothing to do with ${release.tagName}")
+ }
+ }
+ } catch (e: Exception) {
+ Log.e("AppUpdateHelper", "git check deliver: ${e.message}")
+ Toast.makeText(activity, "git check delivers: ${e.message}", Toast.LENGTH_LONG).show()
+ }
+ }
+ }
+
fun checkWithDialog(
activity: AppCompatActivity,
gitRepoUrl: String,
@@ -111,6 +148,18 @@ object AppUpdateHelper {
return client.github.getGithubVersions(gitRepoUrl.user(), gitRepoUrl.repo()).execute()
}
+ private suspend fun requestArtifactoryVersions(artifactoryRepoUrl: String): Response>? {
+ val artifactory: Artifactory = ArtifactoryClientBuilder.create()
+ .setUrl(artifactoryRepoUrl)
+ //.setUsername("username")
+ //.setPassword("password")
+ .build() // TODO runtime error with "No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier"
+ val versionList = withContext(Dispatchers.Default) {
+ artifactory.repositories()
+ }
+ return null
+ }
+
private suspend fun requestGithubVersions(gitRepoUrl: String): Response> {
val versionList = withContext(Dispatchers.Default) {
val client = GithubClient(HttpLoggingInterceptor.Level.BODY)