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.
This commit is contained in:
parent
a0dc66abe7
commit
5fea12d8eb
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue