diff --git a/app/src/main/java/emu/skyline/AppUpdater.kt b/app/src/main/java/emu/skyline/AppUpdater.kt index 7c13494a..022ac862 100644 --- a/app/src/main/java/emu/skyline/AppUpdater.kt +++ b/app/src/main/java/emu/skyline/AppUpdater.kt @@ -14,10 +14,14 @@ import android.net.Uri import android.os.Handler import android.os.Looper import android.text.Html +import android.widget.ImageView import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat.startActivity +import com.google.android.material.badge.BadgeDrawable +import com.google.android.material.badge.BadgeDrawable.BOTTOM_END +import com.google.android.material.badge.BadgeUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -121,5 +125,36 @@ class AppUpdater : BroadcastReceiver() { } } } + + @JvmStatic + @com.google.android.material.badge.ExperimentalBadgeUtils + fun checkForUpdates2(context : Context, icon: ImageView) { + CoroutineScope(Dispatchers.IO).launch { + val url = URL("$baseUrl/builds") + try { + val response = url.readText() + val jsonBuilds = JSONTokener(response).nextValue() as JSONArray + + var ftx1Index = 0 + while (ftx1Index < jsonBuilds.length() && !jsonBuilds.getJSONObject(ftx1Index).get("branch").equals(branch)) { + ftx1Index++ + } + if (ftx1Index >= jsonBuilds.length()) + ftx1Index = 0 + + val remoteBuildGitHash = jsonBuilds.getJSONObject(ftx1Index).getJSONObject("commit").getString("id") + if(!BuildConfig.GIT_HASH.equals(remoteBuildGitHash)){ + val badge = BadgeDrawable.create(context) + badge.badgeGravity = BOTTOM_END + badge.verticalOffset = 25 + badge.horizontalOffset = 25 + badge.backgroundColor = context.getResources().getColor(R.color.colorPrimary) + BadgeUtils.attachBadgeDrawable(badge, icon) + } + } catch (e : IOException) { + e.printStackTrace() + } + } + } } } diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index afcc33f8..e904f2a5 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -154,6 +154,7 @@ class MainActivity : AppCompatActivity() { if (BuildConfig.FLAVOR.equals("edge")) { binding.checkUpdatesIcon.visibility = View.GONE } else { + AppUpdater.checkForUpdates2(context, binding.checkUpdatesIcon) binding.checkUpdatesIcon.setOnClickListener { AppUpdater.checkForUpdates(context) } diff --git a/app/src/main/res/drawable/ic_check_updates.xml b/app/src/main/res/drawable/ic_check_updates.xml index 74fd5fd2..6346d876 100644 --- a/app/src/main/res/drawable/ic_check_updates.xml +++ b/app/src/main/res/drawable/ic_check_updates.xml @@ -4,5 +4,5 @@ android:width="24dp" android:viewportWidth="24" android:viewportHeight="24"> - + \ No newline at end of file