Browse Source

implemented github update checking

pull/1/head
Nareshkumar Rao 4 years ago
parent
commit
cdb5fe2c11
  1. 4
      app/build.gradle
  2. BIN
      app/release/app-release.apk
  3. 4
      app/release/output-metadata.json
  4. 41
      app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt
  5. 30
      app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt
  6. 3
      app/src/main/res/values-de/strings.xml
  7. 3
      app/src/main/res/values-en/strings.xml
  8. 4
      app/src/main/res/values/strings.xml

4
app/build.gradle

@ -11,8 +11,8 @@ android {
applicationId "com.nareshkumarrao.eiweblog" applicationId "com.nareshkumarrao.eiweblog"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 30 targetSdkVersion 30
versionCode 3
versionName "0.9.2"
versionCode 4
versionName "0.9.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

BIN
app/release/app-release.apk

Binary file not shown.

4
app/release/output-metadata.json

@ -10,8 +10,8 @@
{ {
"type": "SINGLE", "type": "SINGLE",
"filters": [], "filters": [],
"versionCode": 3,
"versionName": "0.9.2",
"versionCode": 4,
"versionName": "0.9.3",
"outputFile": "app-release.apk" "outputFile": "app-release.apk"
} }
] ]

41
app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt

@ -1,10 +1,13 @@
package com.nareshkumarrao.eiweblog package com.nareshkumarrao.eiweblog
import android.content.Intent import android.content.Intent
import android.content.pm.PackageInfo
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
@ -38,10 +41,48 @@ class MainActivity : AppCompatActivity() {
.build() .build()
WorkManager.getInstance(this).enqueue(uploadWorkRequest) 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 { override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.toolbar_menu, menu) menuInflater.inflate(R.menu.toolbar_menu, menu)
return true return true

30
app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt

@ -3,8 +3,8 @@ package com.nareshkumarrao.eiweblog
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Intent
import android.content.Context import android.content.Context
import android.content.Intent
import android.os.Build import android.os.Build
import android.util.Log import android.util.Log
import android.util.Xml import android.util.Xml
@ -12,6 +12,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.core.text.HtmlCompat import androidx.core.text.HtmlCompat
import com.android.volley.Request import com.android.volley.Request
import com.android.volley.toolbox.JsonArrayRequest
import com.android.volley.toolbox.StringRequest import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley import com.android.volley.toolbox.Volley
import com.nareshkumarrao.eiweblog.ui.main.Article import com.nareshkumarrao.eiweblog.ui.main.Article
@ -177,4 +178,31 @@ internal object Utilities {
} }
return null 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)
}
} }

3
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 Diese sind in der GPLv3-Lizenz dieses Projekts geregelt. Du kannst mehr über den Lizenz und auch
die Quellecode auf dem GitHub-Repository finden. die Quellecode auf dem GitHub-Repository finden.
</string> </string>
<string name="download">Herunterladen</string>
<string name="cancel">Abbrechen</string>
<string name="update_dialog">Neues App-Version verfügbar</string>
</resources> </resources>

3
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 \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. appreciate it if you bought me a beer, or maybe a tasty döner.
</string> </string>
<string name="download">Download</string>
<string name="cancel">Cancel</string>
<string name="update_dialog">New version of app available</string>
</resources> </resources>

4
app/src/main/res/values/strings.xml

@ -31,4 +31,8 @@
<string name="enable_notifications">Notify me when new updates are posted to the weblog</string> <string name="enable_notifications">Notify me when new updates are posted to the weblog</string>
<string name="enable_notifications_key" translatable="false">com.nareshkumarrao.notifications.key</string> <string name="enable_notifications_key" translatable="false">com.nareshkumarrao.notifications.key</string>
<string name="github_repository" translatable="false">GitHub Repository</string> <string name="github_repository" translatable="false">GitHub Repository</string>
<string name="github_api_releases" translatable="false">https://api.github.com/repos/naresh97/ei-weblog-android/releases</string>
<string name="update_dialog">New version of app available</string>
<string name="download">Download</string>
<string name="cancel">Cancel</string>
</resources> </resources>
Loading…
Cancel
Save