Skip to content

Commit

Permalink
Small code improvements
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Stypox committed Feb 26, 2022
1 parent a0dc66a commit 5fea12d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,7 @@ class NotificationsSettingsFragment : BasePreferenceFragment(), OnSharedPreferen
private fun updateSubscriptions(subscriptions: List<SubscriptionEntity>) {
val notified = subscriptions.count { it.notificationMode != NotificationMode.DISABLED }
val preference = findPreference<Preference>(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) {
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ public static void cancelTag(final Object tag) {
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
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,5 @@
<string name="get_notified">Get notified</string>
<string name="you_successfully_subscribed">You now subscribed to this channel</string>
<string name="enumeration_comma">,</string>
<string name="notification_title_pattern" translatable="false">%s • %s</string>
<string name="streams_notifications_channels_summary" translatable="false">%d/%d</string>
<string name="toggle_all">Toggle all</string>
</resources>

0 comments on commit 5fea12d

Please sign in to comment.