From 5fea12d8ebb95a8f6a14777e7fa5c5d7a0a3ed0e Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 23 Feb 2022 19:45:49 +0100 Subject: [PATCH] Small code improvements Removed some non-translatable strings and just hardcoded them in the code, like it's being done for other string separators. This also deduplicates some code by using Localization. Used some Kotlin feature to reduce code. --- .../local/feed/notifications/NotificationHelper.kt | 13 +++---------- .../newpipe/local/feed/service/FeedLoadManager.kt | 14 +++++++------- .../local/subscription/SubscriptionManager.kt | 9 +++++++-- .../settings/NotificationsSettingsFragment.kt | 8 +------- .../org/schabi/newpipe/util/PicassoHelper.java | 4 ---- app/src/main/res/values/strings.xml | 2 -- 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt index 8ce59b14a..3a08b3e4a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt @@ -14,6 +14,7 @@ import androidx.preference.PreferenceManager import org.schabi.newpipe.R import org.schabi.newpipe.extractor.stream.StreamInfoItem import org.schabi.newpipe.local.feed.service.FeedUpdateInfo +import org.schabi.newpipe.util.Localization import org.schabi.newpipe.util.NavigationHelper import org.schabi.newpipe.util.PicassoHelper @@ -39,13 +40,7 @@ class NotificationHelper(val context: Context) { context, context.getString(R.string.streams_notification_channel_id) ) - .setContentTitle( - context.getString( - R.string.notification_title_pattern, - data.name, - summary - ) - ) + .setContentTitle(Localization.concatenateStrings(data.name, summary)) .setContentText( data.listInfo.relatedItems.joinToString( context.getString(R.string.enumeration_comma) @@ -62,9 +57,7 @@ class NotificationHelper(val context: Context) { // Build style val style = NotificationCompat.InboxStyle() - for (stream in newStreams) { - style.addLine(stream.name) - } + newStreams.forEach { style.addLine(it.name) } style.setSummaryText(summary) style.setBigContentTitle(data.name) builder.setStyle(style) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt index 8c608eb0e..fec50a579 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt @@ -40,14 +40,14 @@ class FeedLoadManager(private val context: Context) { /** * Start checking for new streams of a subscription group. - * @param groupId The ID of the subscription group to load. - * When using [FeedGroupEntity.GROUP_ALL_ID], all subscriptions are loaded. - * When using [GROUP_NOTIFICATION_ENABLED], only subscriptions with enabled notifications - * for new streams are loaded. + * @param groupId The ID of the subscription group to load. When using + * [FeedGroupEntity.GROUP_ALL_ID], all subscriptions are loaded. When using + * [GROUP_NOTIFICATION_ENABLED], only subscriptions with enabled notifications for new streams + * are loaded. Using an id of a group created by the user results in that specific group to be + * loaded. * @param ignoreOutdatedThreshold When `false`, only subscriptions which have not been updated - * within the `feed_update_threshold` are checked for updates. - * This threshold can be set by the user in the app settings. - * When `true`, all subscriptions are checked for new streams. + * within the `feed_update_threshold` are checked for updates. This threshold can be set by + * the user in the app settings. When `true`, all subscriptions are checked for new streams. */ fun startLoading( groupId: Long = FeedGroupEntity.GROUP_ALL_ID, diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt index e4af6e0ac..b17f49801 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt @@ -90,7 +90,12 @@ class SubscriptionManager(context: Context) { if (info is FeedInfo) { subscriptionEntity.name = info.name } else if (info is ChannelInfo) { - subscriptionEntity.setData(info.name, info.avatarUrl, info.description, info.subscriberCount) + subscriptionEntity.setData( + info.name, + info.avatarUrl, + info.description, + info.subscriberCount + ) } subscriptionTable.update(subscriptionEntity) @@ -115,7 +120,7 @@ class SubscriptionManager(context: Context) { /** * Fetches the list of videos for the provided channel and saves them in the database, so that - * they will be considered as "old"/"already seen" streams and the user will never notified + * they will be considered as "old"/"already seen" streams and the user will never be notified * about any one of them. */ private fun rememberAllStreams(subscription: SubscriptionEntity): Completable { diff --git a/app/src/main/java/org/schabi/newpipe/settings/NotificationsSettingsFragment.kt b/app/src/main/java/org/schabi/newpipe/settings/NotificationsSettingsFragment.kt index 4340e7ce8..e823c2fcf 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/NotificationsSettingsFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/NotificationsSettingsFragment.kt @@ -108,13 +108,7 @@ class NotificationsSettingsFragment : BasePreferenceFragment(), OnSharedPreferen private fun updateSubscriptions(subscriptions: List) { val notified = subscriptions.count { it.notificationMode != NotificationMode.DISABLED } val preference = findPreference(getString(R.string.streams_notifications_channels_key)) - if (preference != null) { - preference.summary = preference.context.getString( - R.string.streams_notifications_channels_summary, - notified, - subscriptions.size - ) - } + preference?.apply { summary = "$notified/${subscriptions.size}" } } private fun onError(e: Throwable) { diff --git a/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java b/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java index 1690f7223..da86ab1a4 100644 --- a/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java @@ -81,10 +81,6 @@ public final class PicassoHelper { picassoInstance.cancelTag(tag); } - public static void cancelRequest(final Target target) { - picassoInstance.cancelRequest(target); - } - public static void setIndicatorsEnabled(final boolean enabled) { picassoInstance.setIndicatorsEnabled(enabled); // useful for debugging } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c9a3f705..a92849ed7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -721,7 +721,5 @@ Get notified You now subscribed to this channel , - %s • %s - %d/%d Toggle all \ No newline at end of file