mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
add badge for amount of new videos
This commit is contained in:
parent
c10672f837
commit
c1120ab487
@ -7,6 +7,7 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
@ -30,9 +31,12 @@ import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.databinding.ActivityMainBinding
|
||||
import com.github.libretube.dialogs.ErrorDialog
|
||||
import com.github.libretube.extensions.BaseActivity
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.fragments.PlayerFragment
|
||||
import com.github.libretube.models.PlayerViewModel
|
||||
import com.github.libretube.models.SearchViewModel
|
||||
import com.github.libretube.models.SubscriptionsViewModel
|
||||
import com.github.libretube.services.ClosingService
|
||||
import com.github.libretube.util.NetworkHelper
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
@ -138,6 +142,7 @@ class MainActivity : BaseActivity() {
|
||||
navController.navigate(R.id.homeFragment)
|
||||
}
|
||||
R.id.subscriptionsFragment -> {
|
||||
binding.bottomNav.removeBadge(R.id.subscriptionsFragment)
|
||||
navController.navigate(R.id.subscriptionsFragment)
|
||||
}
|
||||
R.id.libraryFragment -> {
|
||||
@ -157,6 +162,8 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
setupBreakReminder()
|
||||
|
||||
setupSubscriptionsBadge()
|
||||
|
||||
// new way of handling back presses
|
||||
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
@ -223,6 +230,23 @@ class MainActivity : BaseActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the notification badge showing the amount of new videos
|
||||
*/
|
||||
private fun setupSubscriptionsBadge() {
|
||||
val subscriptionsViewModel = ViewModelProvider(this)[SubscriptionsViewModel::class.java]
|
||||
subscriptionsViewModel.fetchSubscriptions()
|
||||
|
||||
val lastSeenVideoId = PreferenceHelper.getLastSeenVideoId()
|
||||
subscriptionsViewModel.videoFeed.observe(this) {
|
||||
val lastSeenVideoIndex = subscriptionsViewModel.videoFeed.value?.indexOfFirst {
|
||||
lastSeenVideoId == it.url?.toID()
|
||||
} ?: return@observe
|
||||
if (lastSeenVideoIndex < 1) return@observe
|
||||
binding.bottomNav.getOrCreateBadge(R.id.subscriptionsFragment).number = lastSeenVideoIndex
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the focus of the search view in the toolbar
|
||||
*/
|
||||
|
@ -31,12 +31,14 @@ class BottomSheetAdapter(
|
||||
}
|
||||
|
||||
// increase padding if there's no drawable
|
||||
if (item.drawable == null) root.setPadding(
|
||||
root.paddingLeft * 2,
|
||||
root.paddingTop,
|
||||
root.paddingRight,
|
||||
root.paddingBottom
|
||||
)
|
||||
if (item.drawable == null) {
|
||||
root.setPadding(
|
||||
root.paddingLeft * 2,
|
||||
root.paddingTop,
|
||||
root.paddingRight,
|
||||
root.paddingBottom
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ class NotificationHelper(
|
||||
return@runBlocking
|
||||
}
|
||||
|
||||
val lastSeenStreamId = PreferenceHelper.getLatestVideoId()
|
||||
val lastSeenStreamId = PreferenceHelper.getLastSeenVideoId()
|
||||
val latestFeedStreamId = videoFeed[0].url!!.toID()
|
||||
|
||||
// first time notifications enabled or no new video available
|
||||
|
@ -76,7 +76,7 @@ object PreferenceHelper {
|
||||
editor.putString(PreferenceKeys.LAST_STREAM_VIDEO_ID, videoId).commit()
|
||||
}
|
||||
|
||||
fun getLatestVideoId(): String {
|
||||
fun getLastSeenVideoId(): String {
|
||||
return getString(PreferenceKeys.LAST_STREAM_VIDEO_ID, "")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user