diff --git a/app/build.gradle b/app/build.gradle index ff9d514..e4af4a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.nareshkumarrao.eiweblog" minSdkVersion 16 targetSdkVersion 30 - versionCode 3 - versionName "0.9.2" + versionCode 4 + versionName "0.9.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/release/app-release.apk b/app/release/app-release.apk index 55e07aa..6e7cb04 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index e4bcfe9..ed7cac1 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -10,8 +10,8 @@ { "type": "SINGLE", "filters": [], - "versionCode": 3, - "versionName": "0.9.2", + "versionCode": 4, + "versionName": "0.9.3", "outputFile": "app-release.apk" } ] diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt index 6e34284..839c1e7 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt @@ -1,10 +1,13 @@ package com.nareshkumarrao.eiweblog import android.content.Intent +import android.content.pm.PackageInfo +import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View +import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.viewpager.widget.ViewPager @@ -38,10 +41,48 @@ class MainActivity : AppCompatActivity() { .build() WorkManager.getInstance(this).enqueue(uploadWorkRequest) + Utilities.fetchRepoReleaseInformation(this, ::repoReleaseCallback) } + private fun repoReleaseCallback(version: String, log: String, url: String?){ + var version = version + val url = url ?: getString(R.string.github_repository) + val log = "Changelog $version: \n\n$log" + + if(version.substring(0,1) == "v"){ + version = version.substring(1) + } + + val pInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0) + val pVersion = pInfo.versionName + + if( version != pVersion){ + val builder = AlertDialog.Builder(this) + + builder.apply { + setPositiveButton(getString(R.string.download)) { _, _ -> + startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse(url) + ) + ) + } + setNegativeButton(getString(R.string.cancel)){ dialog, _ -> + dialog.dismiss() + } + } + builder.setMessage(log) + .setTitle(getString(R.string.update_dialog)) + + + builder.create().show() + + } + } + override fun onCreateOptionsMenu(menu: Menu?): Boolean { menuInflater.inflate(R.menu.toolbar_menu, menu) return true diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt index 4ad466f..74646c3 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt @@ -3,8 +3,8 @@ package com.nareshkumarrao.eiweblog import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent -import android.content.Intent import android.content.Context +import android.content.Intent import android.os.Build import android.util.Log import android.util.Xml @@ -12,6 +12,7 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.core.text.HtmlCompat import com.android.volley.Request +import com.android.volley.toolbox.JsonArrayRequest import com.android.volley.toolbox.StringRequest import com.android.volley.toolbox.Volley import com.nareshkumarrao.eiweblog.ui.main.Article @@ -177,4 +178,31 @@ internal object Utilities { } return null } + + fun fetchRepoReleaseInformation(context: Context?, callback: (v: String, log:String, url:String?) -> Unit){ + val queue = Volley.newRequestQueue(context) + val url = context?.getString(R.string.github_api_releases) + val jsonObjectRequest = JsonArrayRequest(Request.Method.GET, url, null, + { response -> + val latestRelease = response.getJSONObject(0) + val releaseVersion = latestRelease.getString("tag_name") + val releaseLog = latestRelease.getString("body") + val releaseAssets = latestRelease.getJSONArray("assets") + var releaseAPK: String? = null + for(i in 0 until releaseAssets.length()){ + val asset = releaseAssets.getJSONObject(0) + val contentType = asset.getString("content_type") + if( contentType == "application/vnd.android.package-archive" ){ + releaseAPK = asset.getString("browser_download_url") + break + } + } + Log.d("RESTAPI", "v: $releaseVersion, log: $releaseLog, apk: $releaseAPK") + callback(releaseVersion, releaseLog, releaseAPK) + }, + { error -> Log.e("RESTAPI", error.toString()) + } + ) + queue.add(jsonObjectRequest) + } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index b69748a..78eda5d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -17,4 +17,7 @@ Diese sind in der GPLv3-Lizenz dieses Projekts geregelt. Du kannst mehr über den Lizenz und auch die Quellecode auf dem GitHub-Repository finden. + Herunterladen + Abbrechen + Neues App-Version verfügbar \ No newline at end of file diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index f40b444..6a8cfff 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -18,4 +18,7 @@ \nI put too many hours of work into this app, and if you like it and found it useful, I would really appreciate it if you bought me a beer, or maybe a tasty döner. + Download + Cancel + New version of app available \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 239dbdc..1ed5774 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -31,4 +31,8 @@ Notify me when new updates are posted to the weblog com.nareshkumarrao.notifications.key GitHub Repository + https://api.github.com/repos/naresh97/ei-weblog-android/releases + New version of app available + Download + Cancel \ No newline at end of file