mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Merge pull request #1283 from Bnyro/master
Indicator for amount of new videos
This commit is contained in:
commit
eafc7e3d42
@ -30,9 +30,11 @@ 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.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 +140,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 +160,8 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
setupBreakReminder()
|
||||
|
||||
setupSubscriptionsBadge()
|
||||
|
||||
// new way of handling back presses
|
||||
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
@ -223,6 +228,31 @@ class MainActivity : BaseActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the notification badge showing the amount of new videos
|
||||
*/
|
||||
private fun setupSubscriptionsBadge() {
|
||||
if (!PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.NEW_VIDEOS_BADGE,
|
||||
false
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
val subscriptionsViewModel = ViewModelProvider(this)[SubscriptionsViewModel::class.java]
|
||||
subscriptionsViewModel.fetchSubscriptions()
|
||||
|
||||
subscriptionsViewModel.videoFeed.observe(this) {
|
||||
val lastSeenVideoId = PreferenceHelper.getLastSeenVideoId()
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ object PreferenceKeys {
|
||||
const val LEGACY_SUBSCRIPTIONS = "legacy_subscriptions"
|
||||
const val LEGACY_SUBSCRIPTIONS_COLUMNS = "legacy_subscriptions_columns"
|
||||
const val ALTERNATIVE_TRENDING_LAYOUT = "trending_layout"
|
||||
const val NEW_VIDEOS_BADGE = "new_videos_badge"
|
||||
|
||||
/**
|
||||
* Instance
|
||||
|
@ -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, "")
|
||||
}
|
||||
|
||||
|
10
app/src/main/res/drawable/ic_badge.xml
Normal file
10
app/src/main/res/drawable/ic_badge.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="48"
|
||||
android:viewportHeight="48">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m17.3,45 l-3.8,-6.5 -7.55,-1.55 0.85,-7.35L2,24l4.8,-5.55 -0.85,-7.35 7.55,-1.55L17.3,3 24,6.1 30.7,3l3.85,6.55 7.5,1.55 -0.85,7.35L46,24l-4.8,5.6 0.85,7.35 -7.5,1.55L30.7,45 24,41.9ZM21.85,30.65L33.2,19.4l-2.25,-2.05 -9.1,9 -4.75,-4.95 -2.3,2.25Z" />
|
||||
</vector>
|
@ -319,4 +319,6 @@
|
||||
<string name="renamePlaylist">Rename playlist</string>
|
||||
<string name="wifi">WiFi</string>
|
||||
<string name="mobile_data">Mobile data</string>
|
||||
<string name="new_videos_badge">Indicator for new videos</string>
|
||||
<string name="new_videos_badge_summary">Show a badge with the amount of new videos if there are some.</string>
|
||||
</resources>
|
||||
|
@ -24,6 +24,12 @@
|
||||
app:key="reset_settings"
|
||||
app:title="@string/reset" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:icon="@drawable/ic_badge"
|
||||
android:summary="@string/new_videos_badge_summary"
|
||||
app:key="new_videos_badge"
|
||||
app:title="@string/new_videos_badge" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/backup_restore">
|
||||
|
Loading…
Reference in New Issue
Block a user