mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
add the notification bell UI
This commit is contained in:
parent
b3f52f9a18
commit
861e319aeb
@ -0,0 +1,18 @@
|
||||
package com.github.libretube.extensions
|
||||
|
||||
import android.util.Log
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.google.android.material.button.MaterialButton
|
||||
|
||||
fun MaterialButton.setupNotificationBell(channelId: String) {
|
||||
var isIgnorable = PreferenceHelper.isChannelNotificationIgnorable(channelId)
|
||||
Log.e(channelId, isIgnorable.toString())
|
||||
setIconResource(if (isIgnorable) R.drawable.ic_bell else R.drawable.ic_notification)
|
||||
|
||||
setOnClickListener {
|
||||
isIgnorable = !isIgnorable
|
||||
PreferenceHelper.toggleIgnorableNotificationChannel(channelId)
|
||||
setIconResource(if (isIgnorable) R.drawable.ic_bell else R.drawable.ic_notification)
|
||||
}
|
||||
}
|
@ -5,14 +5,17 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.SubscriptionHelper
|
||||
import com.github.libretube.api.obj.Subscription
|
||||
import com.github.libretube.databinding.ChannelSubscriptionRowBinding
|
||||
import com.github.libretube.extensions.setupNotificationBell
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.ui.viewholders.SubscriptionChannelViewHolder
|
||||
import com.github.libretube.util.ImageHelper
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
|
||||
class SubscriptionChannelAdapter(private val subscriptions: MutableList<com.github.libretube.api.obj.Subscription>) :
|
||||
RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
||||
class SubscriptionChannelAdapter(
|
||||
private val subscriptions: MutableList<Subscription>
|
||||
) : RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return subscriptions.size
|
||||
@ -32,6 +35,9 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<com.gith
|
||||
holder.binding.apply {
|
||||
subscriptionChannelName.text = subscription.name
|
||||
ImageHelper.loadImage(subscription.avatar, subscriptionChannelImage)
|
||||
|
||||
subscription.url?.toID()?.let { notificationBell.setupNotificationBell(it) }
|
||||
|
||||
root.setOnClickListener {
|
||||
NavigationHelper.navigateChannel(root.context, subscription.url)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import com.github.libretube.databinding.FragmentChannelBinding
|
||||
import com.github.libretube.enums.ShareObjectType
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.formatShort
|
||||
import com.github.libretube.extensions.setupNotificationBell
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.obj.ShareData
|
||||
import com.github.libretube.ui.adapters.SearchAdapter
|
||||
@ -128,6 +129,8 @@ class ChannelFragment : BaseFragment() {
|
||||
binding.channelSubscribe.text = getString(R.string.unsubscribe)
|
||||
}
|
||||
|
||||
channelId?.let { binding.notificationBell.setupNotificationBell(it) }
|
||||
|
||||
binding.channelSubscribe.setOnClickListener {
|
||||
if (isSubscribed == true) {
|
||||
SubscriptionHelper.handleUnsubscribe(requireContext(), channelId!!, channelName) {
|
||||
|
@ -99,7 +99,7 @@ object PreferenceHelper {
|
||||
editor.putString(
|
||||
PreferenceKeys.IGNORED_NOTIFICATION_CHANNELS,
|
||||
ignorableChannels.joinToString(",")
|
||||
)
|
||||
).apply()
|
||||
}
|
||||
|
||||
private fun getDefaultSharedPreferences(context: Context): SharedPreferences {
|
||||
|
10
app/src/main/res/drawable/ic_bell.xml
Normal file
10
app/src/main/res/drawable/ic_bell.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="M8,38v-3h4.2L12.2,19.7q0,-4.2 2.475,-7.475Q17.15,8.95 21.2,8.1L21.2,6.65q0,-1.15 0.825,-1.9T24,4q1.15,0 1.975,0.75 0.825,0.75 0.825,1.9L26.8,8.1q4.05,0.85 6.55,4.125t2.5,7.475L35.85,35L40,35v3ZM24,23.25ZM24,44q-1.6,0 -2.8,-1.175Q20,41.65 20,40h8q0,1.65 -1.175,2.825Q25.65,44 24,44ZM15.2,35h17.65L32.85,19.7q0,-3.7 -2.55,-6.3 -2.55,-2.6 -6.25,-2.6t-6.275,2.6Q15.2,16 15.2,19.7Z" />
|
||||
</vector>
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
@ -12,32 +12,38 @@
|
||||
android:id="@+id/subscription_channel_image"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subscription_channel_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_toEndOf="@id/subscription_channel_image"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textSize="16sp"
|
||||
tools:text="Channel Name" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/notification_bell"
|
||||
style="@style/ElevatedIconButton"
|
||||
android:layout_gravity="center"
|
||||
app:icon="@drawable/ic_notification"
|
||||
tools:targetApi="m" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/subscription_subscribe"
|
||||
style="@style/Widget.Material3.Button.ElevatedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:stateListAnimator="@null"
|
||||
android:text="@string/unsubscribe"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="12sp"
|
||||
app:cornerRadius="20dp" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
@ -45,25 +45,19 @@
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="3.5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/channel_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:drawablePadding="3dip"
|
||||
android:layout_marginTop="3.5dp"
|
||||
android:drawablePadding="3dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="Channel Name" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/channel_subs"
|
||||
android:layout_width="wrap_content"
|
||||
@ -75,19 +69,17 @@
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
style="@style/ElevatedIconButton"
|
||||
android:id="@+id/channel_share"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:drawableTint="?android:attr/textColorPrimary"
|
||||
android:paddingHorizontal="15dp"
|
||||
android:stateListAnimator="@null"
|
||||
app:cornerRadius="20dp"
|
||||
app:elevation="20dp"
|
||||
app:icon="@drawable/ic_share"
|
||||
tools:targetApi="m" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/notification_bell"
|
||||
style="@style/ElevatedIconButton"
|
||||
app:icon="@drawable/ic_notification"
|
||||
tools:targetApi="m" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/channel_subscribe"
|
||||
style="@style/Widget.Material3.Button.ElevatedButton"
|
||||
|
@ -195,4 +195,15 @@
|
||||
|
||||
</style>
|
||||
|
||||
<style name="ElevatedIconButton" parent="@style/Widget.Material3.Button.IconButton.Filled.Tonal">
|
||||
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:paddingStart">15dp</item>
|
||||
<item name="android:paddingEnd">15dp</item>
|
||||
<item name="android:stateListAnimator">@null</item>
|
||||
<item name="cardCornerRadius">25dp</item>
|
||||
<item name="android:drawableTint" tools:targetApi="m">?android:attr/textColorPrimary</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user