switched to update API
This commit is contained in:
parent
b21d28f251
commit
f90cc8fe8f
3 changed files with 18 additions and 6 deletions
|
@ -37,6 +37,8 @@ dependencies {
|
||||||
implementation 'com.google.android.material:material:1.12.0'
|
implementation 'com.google.android.material:material:1.12.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.activity:activity:1.9.1'
|
implementation 'androidx.activity:activity:1.9.1'
|
||||||
|
implementation 'com.google.code.gson:gson:2.9.0'
|
||||||
|
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
|
||||||
implementation 'com.android.volley:volley:1.2.1'
|
implementation 'com.android.volley:volley:1.2.1'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,6 @@ import android.os.StrictMode.ThreadPolicy
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.View.VISIBLE
|
import android.view.View.VISIBLE
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.webkit.CookieManager
|
|
||||||
import android.webkit.CookieSyncManager
|
|
||||||
import android.webkit.ValueCallback
|
import android.webkit.ValueCallback
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
@ -22,32 +20,43 @@ import com.android.volley.Request
|
||||||
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.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import com.google.gson.Gson
|
||||||
import com.nin0dev.vendroid.HttpClient.fetchVencord
|
import com.nin0dev.vendroid.HttpClient.fetchVencord
|
||||||
import com.nin0dev.vendroid.Logger.e
|
import com.nin0dev.vendroid.Logger.e
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.decodeFromString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import pl.droidsonroids.gif.GifImageView
|
import pl.droidsonroids.gif.GifImageView
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class UpdateData(val version: Int, val changelog: String)
|
||||||
|
|
||||||
class MainActivity : Activity() {
|
class MainActivity : Activity() {
|
||||||
private var wvInitialized = false
|
private var wvInitialized = false
|
||||||
private var wv: WebView? = null
|
private var wv: WebView? = null
|
||||||
@JvmField
|
@JvmField
|
||||||
var filePathCallback: ValueCallback<Array<Uri?>?>? = null
|
var filePathCallback: ValueCallback<Array<Uri?>?>? = null
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
fun checkUpdates(ignoreSetting: Boolean = false)
|
fun checkUpdates(ignoreSetting: Boolean = false)
|
||||||
{
|
{
|
||||||
val sPrefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
val sPrefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||||
if(sPrefs.getBoolean("checkVendroidUpdates", false) || ignoreSetting) {
|
if(sPrefs.getBoolean("checkVendroidUpdates", false) || ignoreSetting) {
|
||||||
val queue = Volley.newRequestQueue(this)
|
val queue = Volley.newRequestQueue(this)
|
||||||
val url = "https://raw.githubusercontent.com/VendroidEnhanced/UpdateTracker/main/vendroid"
|
val url = "https://vendroid.nin0.dev/api/updates"
|
||||||
val stringRequest = StringRequest(
|
val stringRequest = StringRequest(
|
||||||
Request.Method.GET, url,
|
Request.Method.GET, url,
|
||||||
{ response ->
|
{ response ->
|
||||||
if(Integer.parseInt(response.trim()) != BuildConfig.VERSION_CODE)
|
val gson = Gson()
|
||||||
|
val updateData = gson.fromJson<UpdateData>(response, UpdateData::class.java)
|
||||||
|
if(updateData.version != BuildConfig.VERSION_CODE)
|
||||||
{
|
{
|
||||||
val madb = MaterialAlertDialogBuilder(this)
|
val madb = MaterialAlertDialogBuilder(this)
|
||||||
madb.setTitle(getString(R.string.vendroid_update_available))
|
madb.setTitle(getString(R.string.vendroid_update_available))
|
||||||
madb.setMessage("To make sure that no unexpected bugs happen, it is recommended to update.")
|
madb.setMessage("Changelog:\n" + updateData.changelog)
|
||||||
madb.setPositiveButton(getString(R.string.update), DialogInterface.OnClickListener { dialogInterface, i ->
|
madb.setPositiveButton(getString(R.string.update), DialogInterface.OnClickListener { dialogInterface, i ->
|
||||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/VendroidEnhanced/Vendroid/releases/latest/download/app-release.apk"))
|
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/VendroidEnhanced/Vendroid/releases/latest/download/app-release.apk"))
|
||||||
startActivity(browserIntent)
|
startActivity(browserIntent)
|
||||||
|
@ -55,7 +64,7 @@ class MainActivity : Activity() {
|
||||||
madb.setNegativeButton(getString(R.string.later), DialogInterface.OnClickListener { _, _ -> })
|
madb.setNegativeButton(getString(R.string.later), DialogInterface.OnClickListener { _, _ -> })
|
||||||
madb.show()
|
madb.show()
|
||||||
}
|
}
|
||||||
if(ignoreSetting && Integer.parseInt(response.trim()) == BuildConfig.VERSION_CODE) {
|
if(ignoreSetting && updateData.version == BuildConfig.VERSION_CODE) {
|
||||||
showDiscordToast("No updates available", "MESSAGE")
|
showDiscordToast("No updates available", "MESSAGE")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,4 +3,5 @@ plugins {
|
||||||
id 'com.android.application' version '8.5.2' apply false
|
id 'com.android.application' version '8.5.2' apply false
|
||||||
id 'com.android.library' version '8.5.2' apply false
|
id 'com.android.library' version '8.5.2' apply false
|
||||||
id 'org.jetbrains.kotlin.android' version '1.9.25' apply false
|
id 'org.jetbrains.kotlin.android' version '1.9.25' apply false
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization" version "2.0.20" apply true
|
||||||
}
|
}
|
Loading…
Reference in a new issue