From e9fef28e85f2e88e20a8f03c0f90b4c62fa7fea1 Mon Sep 17 00:00:00 2001 From: jakepurple13 Date: Fri, 9 Apr 2021 06:31:46 -0400 Subject: [PATCH] - added a badge if there's an update --- .../uiviews/BaseMainActivity.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt b/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt index ff4e5725b..71414fda2 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt @@ -5,10 +5,15 @@ import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.LiveData import androidx.navigation.NavController import com.google.android.material.bottomnavigation.BottomNavigationView +import com.programmersbox.helpfulutils.runOnUIThread import com.programmersbox.models.sourcePublish import com.programmersbox.uiviews.utils.currentService import com.programmersbox.uiviews.utils.setupWithNavController +import com.squareup.okhttp.OkHttpClient +import com.squareup.okhttp.Request import io.reactivex.disposables.CompositeDisposable +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import kotlin.properties.Delegates abstract class BaseMainActivity : AppCompatActivity(), GenericInfo { @@ -42,6 +47,21 @@ abstract class BaseMainActivity : AppCompatActivity(), GenericInfo { val navGraphIds = listOf(R.navigation.recent_nav, R.navigation.all_nav, R.navigation.setting_nav) val controller = findViewById(R.id.navLayout2) + .also { + GlobalScope.launch { + val request = Request.Builder() + .url("https://github.com/jakepurple13/OtakuWorld/releases/latest") + .get() + .build() + @Suppress("BlockingMethodInNonBlockingContext") val response = OkHttpClient().newCall(request).execute() + val f = response.request().url().path.split("/").lastOrNull()?.toDoubleOrNull() + runOnUIThread { + if (packageManager?.getPackageInfo(packageName, 0)?.versionName?.toDoubleOrNull() ?: 0.0 < f ?: 0.0) { + it.getOrCreateBadge(R.id.setting_nav).number = 1 + } + } + } + } .setupWithNavController( navGraphIds = navGraphIds, fragmentManager = supportFragmentManager,