Skip to content

Commit

Permalink
- added a badge if there's an update
Browse files Browse the repository at this point in the history
  • Loading branch information
jakepurple13 committed Apr 9, 2021
1 parent 588ff6d commit e9fef28
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<BottomNavigationView>(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,
Expand Down

0 comments on commit e9fef28

Please sign in to comment.