1
0
Fork 0

switched to update API

This commit is contained in:
nin0dev 2024-08-28 15:50:12 -04:00
parent b21d28f251
commit f90cc8fe8f
3 changed files with 18 additions and 6 deletions

View file

@ -37,6 +37,8 @@ dependencies {
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.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 'androidx.constraintlayout:constraintlayout:2.1.4'
}

View file

@ -13,8 +13,6 @@ import android.os.StrictMode.ThreadPolicy
import android.view.KeyEvent
import android.view.View.VISIBLE
import android.view.WindowManager
import android.webkit.CookieManager
import android.webkit.CookieSyncManager
import android.webkit.ValueCallback
import android.webkit.WebView
import android.widget.Toast
@ -22,32 +20,43 @@ import com.android.volley.Request
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.gson.Gson
import com.nin0dev.vendroid.HttpClient.fetchVencord
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 java.io.IOException
@Serializable
data class UpdateData(val version: Int, val changelog: String)
class MainActivity : Activity() {
private var wvInitialized = false
private var wv: WebView? = null
@JvmField
var filePathCallback: ValueCallback<Array<Uri?>?>? = null
@OptIn(ExperimentalSerializationApi::class)
fun checkUpdates(ignoreSetting: Boolean = false)
{
val sPrefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
if(sPrefs.getBoolean("checkVendroidUpdates", false) || ignoreSetting) {
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(
Request.Method.GET, url,
{ 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)
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 ->
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/VendroidEnhanced/Vendroid/releases/latest/download/app-release.apk"))
startActivity(browserIntent)
@ -55,7 +64,7 @@ class MainActivity : Activity() {
madb.setNegativeButton(getString(R.string.later), DialogInterface.OnClickListener { _, _ -> })
madb.show()
}
if(ignoreSetting && Integer.parseInt(response.trim()) == BuildConfig.VERSION_CODE) {
if(ignoreSetting && updateData.version == BuildConfig.VERSION_CODE) {
showDiscordToast("No updates available", "MESSAGE")
}
},

View file

@ -3,4 +3,5 @@ plugins {
id 'com.android.application' 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.plugin.serialization" version "2.0.20" apply true
}