From 8707059d6ed8f1ecad0442c88e74163cbe81f2e3 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 6 Nov 2022 10:21:37 +0100 Subject: [PATCH 1/5] notifications cleanup --- .../java/com/github/libretube/LibreTubeApp.kt | 3 +- .../ui/preferences/NotificationSettings.kt | 3 +- .../libretube/util/NotificationHelper.kt | 140 +----------------- .../libretube/util/NotificationWorker.kt | 138 ++++++++++++++++- 4 files changed, 142 insertions(+), 142 deletions(-) diff --git a/app/src/main/java/com/github/libretube/LibreTubeApp.kt b/app/src/main/java/com/github/libretube/LibreTubeApp.kt index 77212a998..9c75cae9b 100644 --- a/app/src/main/java/com/github/libretube/LibreTubeApp.kt +++ b/app/src/main/java/com/github/libretube/LibreTubeApp.kt @@ -52,7 +52,8 @@ class LibreTubeApp : Application() { /** * Initialize the notification listener in the background */ - NotificationHelper(this).enqueueWork( + NotificationHelper.enqueueWork( + context = this, existingPeriodicWorkPolicy = ExistingPeriodicWorkPolicy.KEEP ) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/NotificationSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/NotificationSettings.kt index 80b87bb87..3a1f20cd0 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/NotificationSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/NotificationSettings.kt @@ -45,8 +45,9 @@ class NotificationSettings : BasePreferenceFragment() { private fun updateNotificationPrefs() { // replace the previous queued work request - NotificationHelper(requireContext()) + NotificationHelper .enqueueWork( + context = requireContext(), existingPeriodicWorkPolicy = ExistingPeriodicWorkPolicy.REPLACE ) } diff --git a/app/src/main/java/com/github/libretube/util/NotificationHelper.kt b/app/src/main/java/com/github/libretube/util/NotificationHelper.kt index 7780cfbb0..ec467e9fb 100644 --- a/app/src/main/java/com/github/libretube/util/NotificationHelper.kt +++ b/app/src/main/java/com/github/libretube/util/NotificationHelper.kt @@ -1,46 +1,21 @@ package com.github.libretube.util -import android.app.NotificationManager -import android.app.PendingIntent import android.content.Context -import android.content.Intent -import android.os.Build -import androidx.core.app.NotificationCompat -import androidx.core.app.NotificationManagerCompat import androidx.work.Constraints import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.NetworkType import androidx.work.PeriodicWorkRequest import androidx.work.WorkManager -import com.github.libretube.R -import com.github.libretube.api.RetrofitInstance -import com.github.libretube.api.SubscriptionHelper import com.github.libretube.constants.NOTIFICATION_WORK_NAME -import com.github.libretube.constants.PUSH_CHANNEL_ID import com.github.libretube.constants.PreferenceKeys -import com.github.libretube.extensions.toID -import com.github.libretube.ui.activities.MainActivity -import kotlinx.coroutines.async -import kotlinx.coroutines.runBlocking import java.util.concurrent.TimeUnit -class NotificationHelper( - private val context: Context -) { - val NotificationManager = - context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - - // the id where notification channels start - private var notificationId = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - NotificationManager.activeNotifications.size + 5 - } else { - 5 - } - +object NotificationHelper { /** * Enqueue the work manager task */ fun enqueueWork( + context: Context, existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy ) { // get the notification preferences @@ -95,115 +70,4 @@ class NotificationHelper( .cancelUniqueWork(NOTIFICATION_WORK_NAME) } } - - /** - * check whether new streams are available in subscriptions - */ - fun checkForNewStreams(): Boolean { - var success = true - - val token = PreferenceHelper.getToken() - runBlocking { - val task = async { - if (token != "") { - RetrofitInstance.authApi.getFeed(token) - } else { - RetrofitInstance.authApi.getUnauthenticatedFeed( - SubscriptionHelper.getFormattedLocalSubscriptions() - ) - } - } - // fetch the users feed - val videoFeed = try { - task.await() - } catch (e: Exception) { - success = false - return@runBlocking - } - - val lastSeenStreamId = PreferenceHelper.getLastSeenVideoId() - val latestFeedStreamId = videoFeed[0].url!!.toID() - - // first time notifications enabled or no new video available - if (lastSeenStreamId == "" || lastSeenStreamId == latestFeedStreamId) { - PreferenceHelper.setLatestVideoId(lastSeenStreamId) - return@runBlocking - } - - // filter the new videos out - val lastSeenStreamItem = videoFeed.filter { it.url!!.toID() == lastSeenStreamId } - - // previous video not found - if (lastSeenStreamItem.isEmpty()) return@runBlocking - - val lastStreamIndex = videoFeed.indexOf(lastSeenStreamItem[0]) - val newVideos = videoFeed.filterIndexed { index, _ -> - index < lastStreamIndex - } - - // group the new streams by the uploader - val channelGroups = newVideos.groupBy { it.uploaderUrl } - // create a notification for each new stream - channelGroups.forEach { (_, streams) -> - createNotification( - group = streams[0].uploaderUrl!!.toID(), - title = streams[0].uploaderName.toString(), - isSummary = true - ) - - streams.forEach { streamItem -> - notificationId += 1 - createNotification( - title = streamItem.title.toString(), - description = streamItem.uploaderName.toString(), - group = streamItem.uploaderUrl!!.toID() - ) - } - } - // save the latest streams that got notified about - PreferenceHelper.setLatestVideoId(videoFeed[0].url!!.toID()) - } - // return whether the work succeeded - return success - } - - /** - * Notification that is created when new streams are found - */ - private fun createNotification( - title: String, - group: String, - description: String? = null, - isSummary: Boolean = false - ) { - val intent = Intent(context, MainActivity::class.java).apply { - flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - } - val pendingIntent: PendingIntent = PendingIntent.getActivity( - context, - 0, - intent, - PendingIntent.FLAG_IMMUTABLE - ) - - val builder = NotificationCompat.Builder(context, PUSH_CHANNEL_ID) - .setContentTitle(title) - .setGroup(group) - .setSmallIcon(R.drawable.ic_notification) - .setPriority(NotificationCompat.PRIORITY_DEFAULT) - // Set the intent that will fire when the user taps the notification - .setContentIntent(pendingIntent) - .setAutoCancel(true) - - if (isSummary) { - builder.setGroupSummary(true) - } else { - builder.setContentText(description) - } - - with(NotificationManagerCompat.from(context)) { - // notificationId is a unique int for each notification that you must define - notify(notificationId, builder.build()) - } - } } diff --git a/app/src/main/java/com/github/libretube/util/NotificationWorker.kt b/app/src/main/java/com/github/libretube/util/NotificationWorker.kt index ea7e06da2..b3cfc46e6 100644 --- a/app/src/main/java/com/github/libretube/util/NotificationWorker.kt +++ b/app/src/main/java/com/github/libretube/util/NotificationWorker.kt @@ -1,8 +1,22 @@ package com.github.libretube.util +import android.app.NotificationManager +import android.app.PendingIntent import android.content.Context +import android.content.Intent +import android.os.Build +import androidx.core.app.NotificationCompat +import androidx.core.app.NotificationManagerCompat import androidx.work.Worker import androidx.work.WorkerParameters +import com.github.libretube.R +import com.github.libretube.api.RetrofitInstance +import com.github.libretube.api.SubscriptionHelper +import com.github.libretube.constants.PUSH_CHANNEL_ID +import com.github.libretube.extensions.toID +import com.github.libretube.ui.activities.MainActivity +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking /** * The notification worker which checks for new streams in a certain frequency @@ -10,11 +24,131 @@ import androidx.work.WorkerParameters class NotificationWorker(appContext: Context, parameters: WorkerParameters) : Worker(appContext, parameters) { + val NotificationManager = + appContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + + // the id where notification channels start + private var notificationId = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + NotificationManager.activeNotifications.size + 5 + } else { + 5 + } + override fun doWork(): Result { // check whether there are new streams and notify if there are some - val result = NotificationHelper(applicationContext) - .checkForNewStreams() + val result = checkForNewStreams() // return success if the API request succeeded return if (result) Result.success() else Result.retry() } + + /** + * check whether new streams are available in subscriptions + */ + fun checkForNewStreams(): Boolean { + var success = true + + val token = PreferenceHelper.getToken() + runBlocking { + val task = async { + if (token != "") { + RetrofitInstance.authApi.getFeed(token) + } else { + RetrofitInstance.authApi.getUnauthenticatedFeed( + SubscriptionHelper.getFormattedLocalSubscriptions() + ) + } + } + // fetch the users feed + val videoFeed = try { + task.await() + } catch (e: Exception) { + success = false + return@runBlocking + } + + val lastSeenStreamId = PreferenceHelper.getLastSeenVideoId() + val latestFeedStreamId = videoFeed[0].url!!.toID() + + // first time notifications enabled or no new video available + if (lastSeenStreamId == "" || lastSeenStreamId == latestFeedStreamId) { + PreferenceHelper.setLatestVideoId(lastSeenStreamId) + return@runBlocking + } + + // filter the new videos out + val lastSeenStreamItem = videoFeed.filter { it.url!!.toID() == lastSeenStreamId } + + // previous video not found + if (lastSeenStreamItem.isEmpty()) return@runBlocking + + val lastStreamIndex = videoFeed.indexOf(lastSeenStreamItem[0]) + val newVideos = videoFeed.filterIndexed { index, _ -> + index < lastStreamIndex + } + + // group the new streams by the uploader + val channelGroups = newVideos.groupBy { it.uploaderUrl } + // create a notification for each new stream + channelGroups.forEach { (_, streams) -> + createNotification( + group = streams[0].uploaderUrl!!.toID(), + title = streams[0].uploaderName.toString(), + isSummary = true + ) + + streams.forEach { streamItem -> + notificationId += 1 + createNotification( + title = streamItem.title.toString(), + description = streamItem.uploaderName.toString(), + group = streamItem.uploaderUrl!!.toID() + ) + } + } + // save the latest streams that got notified about + PreferenceHelper.setLatestVideoId(videoFeed[0].url!!.toID()) + } + // return whether the work succeeded + return success + } + + /** + * Notification that is created when new streams are found + */ + private fun createNotification( + title: String, + group: String, + description: String? = null, + isSummary: Boolean = false + ) { + val intent = Intent(applicationContext, MainActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + } + val pendingIntent: PendingIntent = PendingIntent.getActivity( + applicationContext, + 0, + intent, + PendingIntent.FLAG_IMMUTABLE + ) + + val builder = NotificationCompat.Builder(applicationContext, PUSH_CHANNEL_ID) + .setContentTitle(title) + .setGroup(group) + .setSmallIcon(R.drawable.ic_notification) + .setPriority(NotificationCompat.PRIORITY_DEFAULT) + // Set the intent that will fire when the user taps the notification + .setContentIntent(pendingIntent) + .setAutoCancel(true) + + if (isSummary) { + builder.setGroupSummary(true) + } else { + builder.setContentText(description) + } + + with(NotificationManagerCompat.from(applicationContext)) { + // notificationId is a unique int for each notification that you must define + notify(notificationId, builder.build()) + } + } } From 1808bbceee798d20be861dbe8551687c982115d9 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 6 Nov 2022 10:27:53 +0100 Subject: [PATCH 2/5] fix warnings --- .../libretube/ui/adapters/CommentsAdapter.kt | 62 ++++++++++--------- .../libretube/ui/sheets/PlaybackSpeedSheet.kt | 4 +- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt index 941b1ded9..1c612dd39 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt @@ -5,6 +5,7 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Button import android.widget.Toast import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -71,8 +72,7 @@ class CommentsAdapter( if (comment.hearted == true) heartedImageView.visibility = View.VISIBLE if (comment.repliesPage != null) repliesAvailable.visibility = View.VISIBLE if ((comment.replyCount ?: -1L) > 0L) { - repliesCount.text = - comment.replyCount?.formatShort() + repliesCount.text = comment.replyCount?.formatShort() } commentorImage.setOnClickListener { @@ -89,33 +89,7 @@ class CommentsAdapter( repliesRecView.adapter = repliesAdapter if (!isRepliesAdapter && comment.repliesPage != null) { root.setOnClickListener { - when { - repliesAdapter.itemCount.equals(0) -> { - fetchReplies(comment.repliesPage) { - repliesAdapter.updateItems(it.comments) - if (repliesPage.nextpage == null) { - showMore.visibility = View.GONE - return@fetchReplies - } - showMore.visibility = View.VISIBLE - showMore.setOnClickListener { - if (repliesPage.nextpage == null) { - it.visibility = View.GONE - return@setOnClickListener - } - fetchReplies( - repliesPage.nextpage!! - ) { - repliesAdapter.updateItems(repliesPage.comments) - } - } - } - } - else -> { - repliesAdapter.clear() - showMore.visibility = View.GONE - } - } + showMoreReplies(comment.repliesPage, showMore, repliesAdapter) } } @@ -127,6 +101,36 @@ class CommentsAdapter( } } + private fun showMoreReplies(nextPage: String, showMoreBtn: Button, repliesAdapter: CommentsAdapter) { + when { + repliesAdapter.itemCount.equals(0) -> { + fetchReplies(nextPage) { + repliesAdapter.updateItems(it.comments) + if (repliesPage.nextpage == null) { + showMoreBtn.visibility = View.GONE + return@fetchReplies + } + showMoreBtn.visibility = View.VISIBLE + showMoreBtn.setOnClickListener { + if (repliesPage.nextpage == null) { + it.visibility = View.GONE + return@setOnClickListener + } + fetchReplies( + repliesPage.nextpage!! + ) { + repliesAdapter.updateItems(repliesPage.comments) + } + } + } + } + else -> { + repliesAdapter.clear() + showMoreBtn.visibility = View.GONE + } + } + } + override fun getItemCount(): Int { return comments.size } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt index 6583fca95..0e5149316 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt @@ -30,11 +30,11 @@ class PlaybackSpeedSheet( binding.speed.value = player.playbackParameters.speed binding.pitch.value = player.playbackParameters.pitch - binding.speed.addOnChangeListener { _, value, _ -> + binding.speed.addOnChangeListener { _, _, _ -> onChange() } - binding.pitch.addOnChangeListener { _, value, _ -> + binding.pitch.addOnChangeListener { _, _, _ -> onChange() } From b3f52f9a18e856262e2029d1cec77607588d4280 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 6 Nov 2022 10:47:18 +0100 Subject: [PATCH 3/5] ignore notification channels logic --- .../libretube/constants/PreferenceKeys.kt | 1 + .../github/libretube/util/NotificationWorker.kt | 16 ++++++++++++---- .../github/libretube/util/PreferenceHelper.kt | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt index f29f5716b..3675ac171 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -93,6 +93,7 @@ object PreferenceKeys { const val CHECKING_FREQUENCY = "checking_frequency" const val REQUIRED_NETWORK = "required_network" const val LAST_STREAM_VIDEO_ID = "last_stream_video_id" + const val IGNORED_NOTIFICATION_CHANNELS = "ignored_notification_channels" /** * Advanced diff --git a/app/src/main/java/com/github/libretube/util/NotificationWorker.kt b/app/src/main/java/com/github/libretube/util/NotificationWorker.kt index b3cfc46e6..351918cad 100644 --- a/app/src/main/java/com/github/libretube/util/NotificationWorker.kt +++ b/app/src/main/java/com/github/libretube/util/NotificationWorker.kt @@ -24,12 +24,12 @@ import kotlinx.coroutines.runBlocking class NotificationWorker(appContext: Context, parameters: WorkerParameters) : Worker(appContext, parameters) { - val NotificationManager = + private val notificationManager = appContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager // the id where notification channels start private var notificationId = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - NotificationManager.activeNotifications.size + 5 + notificationManager.activeNotifications.size + 5 } else { 5 } @@ -44,7 +44,7 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) : /** * check whether new streams are available in subscriptions */ - fun checkForNewStreams(): Boolean { + private fun checkForNewStreams(): Boolean { var success = true val token = PreferenceHelper.getToken() @@ -86,8 +86,16 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) : index < lastStreamIndex } + // hide for notifications unsubscribed channels + val channelsToIgnore = PreferenceHelper.getIgnorableNotificationChannels() + val filteredVideos = newVideos.filter { + channelsToIgnore.none { channelId -> + channelId == it.uploaderUrl?.toID() + } + } + // group the new streams by the uploader - val channelGroups = newVideos.groupBy { it.uploaderUrl } + val channelGroups = filteredVideos.groupBy { it.uploaderUrl } // create a notification for each new stream channelGroups.forEach { (_, streams) -> createNotification( diff --git a/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt index 0861bc555..77fdc6c99 100644 --- a/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt @@ -85,6 +85,23 @@ object PreferenceHelper { return getString(PreferenceKeys.ERROR_LOG, "") } + fun getIgnorableNotificationChannels(): List { + return getString(PreferenceKeys.IGNORED_NOTIFICATION_CHANNELS, "").split(",") + } + + fun isChannelNotificationIgnorable(channelId: String): Boolean { + return getIgnorableNotificationChannels().any { it == channelId } + } + + fun toggleIgnorableNotificationChannel(channelId: String) { + val ignorableChannels = getIgnorableNotificationChannels().toMutableList() + if (ignorableChannels.contains(channelId)) ignorableChannels.remove(channelId) else ignorableChannels.add(channelId) + editor.putString( + PreferenceKeys.IGNORED_NOTIFICATION_CHANNELS, + ignorableChannels.joinToString(",") + ) + } + private fun getDefaultSharedPreferences(context: Context): SharedPreferences { return PreferenceManager.getDefaultSharedPreferences(context) } From 861e319aebf5eef77108f3993fd7b392138729da Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 6 Nov 2022 11:26:24 +0100 Subject: [PATCH 4/5] add the notification bell UI --- .../extensions/SetupNotificationBell.kt | 18 ++++++++ .../ui/adapters/SubscriptionChannelAdapter.kt | 10 ++++- .../libretube/ui/fragments/ChannelFragment.kt | 3 ++ .../github/libretube/util/PreferenceHelper.kt | 2 +- app/src/main/res/drawable/ic_bell.xml | 10 +++++ .../res/layout/channel_subscription_row.xml | 24 +++++++---- app/src/main/res/layout/fragment_channel.xml | 42 ++++++++----------- app/src/main/res/values/style.xml | 11 +++++ 8 files changed, 83 insertions(+), 37 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/extensions/SetupNotificationBell.kt create mode 100644 app/src/main/res/drawable/ic_bell.xml diff --git a/app/src/main/java/com/github/libretube/extensions/SetupNotificationBell.kt b/app/src/main/java/com/github/libretube/extensions/SetupNotificationBell.kt new file mode 100644 index 000000000..8cd60a5d4 --- /dev/null +++ b/app/src/main/java/com/github/libretube/extensions/SetupNotificationBell.kt @@ -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) + } +} diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt index 029131b03..2fe7277f7 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt @@ -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) : - RecyclerView.Adapter() { +class SubscriptionChannelAdapter( + private val subscriptions: MutableList +) : RecyclerView.Adapter() { override fun getItemCount(): Int { return subscriptions.size @@ -32,6 +35,9 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList + + diff --git a/app/src/main/res/layout/channel_subscription_row.xml b/app/src/main/res/layout/channel_subscription_row.xml index 2fefef887..b82b9a477 100644 --- a/app/src/main/res/layout/channel_subscription_row.xml +++ b/app/src/main/res/layout/channel_subscription_row.xml @@ -1,5 +1,5 @@ - + + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index f3197e338..afbb9e879 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -45,24 +45,18 @@ android:layout_weight="1" android:orientation="vertical"> - - - - - + android:layout_gravity="start" + android:layout_marginTop="3.5dp" + android:drawablePadding="3dp" + android:ellipsize="end" + android:maxLines="1" + android:textSize="16sp" + android:textStyle="bold" + tools:text="Channel Name" /> + + + + \ No newline at end of file From d18e0dfc1f5bb28ea3f3ec427c4d3ef6df6f8ba8 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 6 Nov 2022 11:30:38 +0100 Subject: [PATCH 5/5] hide when not subscribed --- .../ui/adapters/SubscriptionChannelAdapter.kt | 11 +++++++---- .../github/libretube/ui/fragments/ChannelFragment.kt | 3 +++ app/src/main/res/layout/fragment_channel.xml | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt index 2fe7277f7..feb47d1a0 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt @@ -1,6 +1,7 @@ package com.github.libretube.ui.adapters import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.github.libretube.R @@ -30,7 +31,7 @@ class SubscriptionChannelAdapter( override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) { val subscription = subscriptions[position] - var subscribed = true + var isSubscribed = true holder.binding.apply { subscriptionChannelName.text = subscription.name @@ -43,15 +44,17 @@ class SubscriptionChannelAdapter( } subscriptionSubscribe.setOnClickListener { val channelId = subscription.url!!.toID() - if (subscribed) { + if (isSubscribed) { SubscriptionHelper.handleUnsubscribe(root.context, channelId, subscription.name ?: "") { subscriptionSubscribe.text = root.context.getString(R.string.subscribe) - subscribed = false + notificationBell.visibility = View.GONE + isSubscribed = false } } else { SubscriptionHelper.subscribe(channelId) subscriptionSubscribe.text = root.context.getString(R.string.unsubscribe) - subscribed = true + notificationBell.visibility = View.VISIBLE + isSubscribed = true } } } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt index f3ea8b1ca..0cc63d135 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt @@ -130,17 +130,20 @@ class ChannelFragment : BaseFragment() { } channelId?.let { binding.notificationBell.setupNotificationBell(it) } + if (isSubscribed == false) binding.notificationBell.visibility = View.GONE binding.channelSubscribe.setOnClickListener { if (isSubscribed == true) { SubscriptionHelper.handleUnsubscribe(requireContext(), channelId!!, channelName) { isSubscribed = false binding.channelSubscribe.text = getString(R.string.subscribe) + binding.notificationBell.visibility = View.GONE } } else { SubscriptionHelper.subscribe(channelId!!) isSubscribed = true binding.channelSubscribe.text = getString(R.string.unsubscribe) + binding.notificationBell.visibility = View.VISIBLE } } diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index afbb9e879..25f028b28 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -63,14 +63,15 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="start" + android:maxLines="1" android:text="@string/app_name" android:textSize="12sp" />