Add comments and improve code formatting
This commit is contained in:
parent
77aaa15082
commit
2d2b96420f
3 changed files with 54 additions and 14 deletions
|
@ -413,10 +413,12 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo>
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNotify(final boolean isEnabled) {
|
private void setNotify(final boolean isEnabled) {
|
||||||
final int mode = isEnabled ? NotificationMode.ENABLED : NotificationMode.DISABLED;
|
|
||||||
disposables.add(
|
disposables.add(
|
||||||
subscriptionManager.updateNotificationMode(currentInfo.getServiceId(),
|
subscriptionManager
|
||||||
currentInfo.getUrl(), mode)
|
.updateNotificationMode(
|
||||||
|
currentInfo.getServiceId(),
|
||||||
|
currentInfo.getUrl(),
|
||||||
|
isEnabled ? NotificationMode.ENABLED : NotificationMode.DISABLED)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe()
|
.subscribe()
|
||||||
|
|
|
@ -81,9 +81,8 @@ class NotificationHelper(val context: Context) {
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
context,
|
context,
|
||||||
data.pseudoId,
|
data.pseudoId,
|
||||||
NavigationHelper.getChannelIntent(
|
NavigationHelper
|
||||||
context, data.listInfo.serviceId, data.listInfo.url
|
.getChannelIntent(context, data.listInfo.serviceId, data.listInfo.url)
|
||||||
)
|
|
||||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
|
@ -129,10 +128,10 @@ class NotificationHelper(val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
/**
|
/**
|
||||||
* Whether the user enabled the notifications for new streams in the app settings.
|
* Whether the user enabled the notifications for new streams in the app settings.
|
||||||
*/
|
*/
|
||||||
|
@JvmStatic
|
||||||
fun areNewStreamsNotificationsEnabled(context: Context): Boolean {
|
fun areNewStreamsNotificationsEnabled(context: Context): Boolean {
|
||||||
return (
|
return (
|
||||||
PreferenceManager.getDefaultSharedPreferences(context)
|
PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
|
@ -37,6 +37,15 @@ class FeedLoadManager(private val context: Context) {
|
||||||
FeedLoadState(description, maxProgress.get(), currentProgress.get())
|
FeedLoadState(description, maxProgress.get(), currentProgress.get())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
fun startLoading(
|
fun startLoading(
|
||||||
groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
|
groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
|
||||||
ignoreOutdatedThreshold: Boolean = false,
|
ignoreOutdatedThreshold: Boolean = false,
|
||||||
|
@ -59,12 +68,15 @@ class FeedLoadManager(private val context: Context) {
|
||||||
OffsetDateTime.now(ZoneOffset.UTC).minusSeconds(thresholdOutdatedSeconds.toLong())
|
OffsetDateTime.now(ZoneOffset.UTC).minusSeconds(thresholdOutdatedSeconds.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
val subscriptions = when (groupId) {
|
/**
|
||||||
|
* subscriptions which have not been updated within the feed updated threshold
|
||||||
|
*/
|
||||||
|
val outdatedSubscriptions = when (groupId) {
|
||||||
FeedGroupEntity.GROUP_ALL_ID -> feedDatabaseManager.outdatedSubscriptions(outdatedThreshold)
|
FeedGroupEntity.GROUP_ALL_ID -> feedDatabaseManager.outdatedSubscriptions(outdatedThreshold)
|
||||||
else -> feedDatabaseManager.outdatedSubscriptionsForGroup(groupId, outdatedThreshold)
|
else -> feedDatabaseManager.outdatedSubscriptionsForGroup(groupId, outdatedThreshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
return subscriptions
|
return outdatedSubscriptions
|
||||||
.take(1)
|
.take(1)
|
||||||
|
|
||||||
.doOnNext {
|
.doOnNext {
|
||||||
|
@ -90,9 +102,14 @@ class FeedLoadManager(private val context: Context) {
|
||||||
.map { subscriptionEntity ->
|
.map { subscriptionEntity ->
|
||||||
var error: Throwable? = null
|
var error: Throwable? = null
|
||||||
try {
|
try {
|
||||||
|
// check for and load new streams
|
||||||
|
// either by using the dedicated feed method or by getting the channel info
|
||||||
val listInfo = if (useFeedExtractor) {
|
val listInfo = if (useFeedExtractor) {
|
||||||
ExtractorHelper
|
ExtractorHelper
|
||||||
.getFeedInfoFallbackToChannelInfo(subscriptionEntity.serviceId, subscriptionEntity.url)
|
.getFeedInfoFallbackToChannelInfo(
|
||||||
|
subscriptionEntity.serviceId,
|
||||||
|
subscriptionEntity.url
|
||||||
|
)
|
||||||
.onErrorReturn {
|
.onErrorReturn {
|
||||||
error = it // store error, otherwise wrapped into RuntimeException
|
error = it // store error, otherwise wrapped into RuntimeException
|
||||||
throw it
|
throw it
|
||||||
|
@ -100,7 +117,11 @@ class FeedLoadManager(private val context: Context) {
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
} else {
|
} else {
|
||||||
ExtractorHelper
|
ExtractorHelper
|
||||||
.getChannelInfo(subscriptionEntity.serviceId, subscriptionEntity.url, true)
|
.getChannelInfo(
|
||||||
|
subscriptionEntity.serviceId,
|
||||||
|
subscriptionEntity.url,
|
||||||
|
true
|
||||||
|
)
|
||||||
.onErrorReturn {
|
.onErrorReturn {
|
||||||
error = it // store error, otherwise wrapped into RuntimeException
|
error = it // store error, otherwise wrapped into RuntimeException
|
||||||
throw it
|
throw it
|
||||||
|
@ -108,7 +129,12 @@ class FeedLoadManager(private val context: Context) {
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
} as ListInfo<StreamInfoItem>
|
} as ListInfo<StreamInfoItem>
|
||||||
|
|
||||||
return@map Notification.createOnNext(FeedUpdateInfo(subscriptionEntity, listInfo))
|
return@map Notification.createOnNext(
|
||||||
|
FeedUpdateInfo(
|
||||||
|
subscriptionEntity,
|
||||||
|
listInfo
|
||||||
|
)
|
||||||
|
)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
// do this to prevent blockingGet() from wrapping into RuntimeException
|
// do this to prevent blockingGet() from wrapping into RuntimeException
|
||||||
|
@ -116,7 +142,8 @@ class FeedLoadManager(private val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val request = "${subscriptionEntity.serviceId}:${subscriptionEntity.url}"
|
val request = "${subscriptionEntity.serviceId}:${subscriptionEntity.url}"
|
||||||
val wrapper = FeedLoadService.RequestException(subscriptionEntity.uid, request, error!!)
|
val wrapper =
|
||||||
|
FeedLoadService.RequestException(subscriptionEntity.uid, request, error!!)
|
||||||
return@map Notification.createOnError<FeedUpdateInfo>(wrapper)
|
return@map Notification.createOnError<FeedUpdateInfo>(wrapper)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +169,13 @@ class FeedLoadManager(private val context: Context) {
|
||||||
FeedEventManager.postEvent(FeedEventManager.Event.ProgressEvent(currentProgress.get(), maxProgress.get()))
|
FeedEventManager.postEvent(FeedEventManager.Event.ProgressEvent(currentProgress.get(), maxProgress.get()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep the feed and the stream tables small
|
||||||
|
* to reduce loading times when trying to display the feed.
|
||||||
|
* <br>
|
||||||
|
* Remove streams from the feed which are older than [FeedDatabaseManager.FEED_OLDEST_ALLOWED_DATE].
|
||||||
|
* Remove streams from the database which are not linked / used by any table.
|
||||||
|
*/
|
||||||
private fun postProcessFeed() = Completable.fromRunnable {
|
private fun postProcessFeed() = Completable.fromRunnable {
|
||||||
FeedEventManager.postEvent(FeedEventManager.Event.ProgressEvent(R.string.feed_processing_message))
|
FeedEventManager.postEvent(FeedEventManager.Event.ProgressEvent(R.string.feed_processing_message))
|
||||||
feedDatabaseManager.removeOrphansOrOlderStreams()
|
feedDatabaseManager.removeOrphansOrOlderStreams()
|
||||||
|
@ -179,7 +213,12 @@ class FeedLoadManager(private val context: Context) {
|
||||||
subscriptionManager.updateFromInfo(subscriptionId, info)
|
subscriptionManager.updateFromInfo(subscriptionId, info)
|
||||||
|
|
||||||
if (info.errors.isNotEmpty()) {
|
if (info.errors.isNotEmpty()) {
|
||||||
feedResultsHolder.addErrors(FeedLoadService.RequestException.wrapList(subscriptionId, info))
|
feedResultsHolder.addErrors(
|
||||||
|
FeedLoadService.RequestException.wrapList(
|
||||||
|
subscriptionId,
|
||||||
|
info
|
||||||
|
)
|
||||||
|
)
|
||||||
feedDatabaseManager.markAsOutdated(subscriptionId)
|
feedDatabaseManager.markAsOutdated(subscriptionId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue