mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-23 12:41:50 +01:00
Add badge to notify when update is available
This commit is contained in:
parent
411b79ed9e
commit
68b0abfa91
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -4,5 +4,5 @@
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path android:fillColor="#000" android:pathData="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z" />
|
||||
<path android:fillColor="?attr/colorOnSecondary" android:pathData="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z" />
|
||||
</vector>
|
Loading…
Reference in New Issue
Block a user