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,
@@ -87,7 +129,7 @@ object AppUpdateHelper {
appContext: Context,
currentVersionName: String,
gitRepoUrl: String
- ){
+ ) {
try {
val versionList = requestVersionsSync(gitRepoUrl)
@@ -111,6 +153,37 @@ object AppUpdateHelper {
return client.github.getGithubVersions(gitRepoUrl.user(), gitRepoUrl.repo()).execute()
}
+ 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) {
+ val repositories = artifactory.repositories()
+
+// val allBuilds = artifactory.builds().allBuilds
+// Log.d("allBuilds", allBuilds.toString())
+
+ val localRepoList = repositories.list(LOCAL)
+ val remoteRepoList = repositories.list(REMOTE)
+ val virtualRepoList = repositories.list(VIRTUAL)
+ val federatedRepoList = repositories.list(FEDERATED)
+
+ Log.d("data", localRepoList.toString())
+// val list = artifactory.storage().storageInfo.repositoriesSummaryList
+// Log.d("list", list.toString())
+ val dataA = artifactory.repository("AppStore")
+ .download("/AppStore/AutonomousCar/app/1.2/app-1.2.pom")
+ .doDownload()
+ Log.d("dataA", dataA.toString())
+ Log.d("data", repositories.toString())
+ Log.d("data", repositories.replicationApi)
+ }
+ Log.d("data", versionList.toString())
+ return null
+ }
+
private suspend fun requestGithubVersions(gitRepoUrl: String): Response> {
val versionList = withContext(Dispatchers.Default) {
val client = GithubClient(HttpLoggingInterceptor.Level.BODY)
diff --git a/githubAppUpdate/src/test/java/info/hannes/github/AppUpdateHelperTest.kt b/githubAppUpdate/src/test/java/info/hannes/github/AppUpdateHelperTest.kt
new file mode 100644
index 0000000..41a0804
--- /dev/null
+++ b/githubAppUpdate/src/test/java/info/hannes/github/AppUpdateHelperTest.kt
@@ -0,0 +1,41 @@
+package info.hannes.github
+
+import junit.framework.Assert.assertEquals
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+
+@OptIn(ExperimentalCoroutinesApi::class)
+class AppUpdateHelperTest {
+
+ @org.junit.Before
+ fun setUp() {
+ }
+
+ @org.junit.After
+ fun tearDown() {
+ }
+
+ @org.junit.Test
+ fun getPackageInfo() {
+ }
+
+ @org.junit.Test
+ fun requestArtifactoryVersions() = runTest {
+ val data = AppUpdateHelper.requestArtifactoryVersions("https://artifactory.mxtracks.info")
+ assertEquals("Hello world", data)
+ }
+
+ @Test
+ fun dataShouldBeHelloWorld() = runTest {
+ val data = fetchData()
+ assertEquals("Hello world", data)
+ }
+
+ suspend fun fetchData(): String {
+ delay(1000L)
+ return "Hello world"
+ }
+
+}
\ No newline at end of file