@@ -7,6 +7,9 @@ import io.reactivex.Flowable
7
7
import io.reactivex.Maybe
8
8
import io.reactivex.android.schedulers.AndroidSchedulers
9
9
import io.reactivex.schedulers.Schedulers
10
+ import java.time.LocalDate
11
+ import java.time.ZoneId
12
+ import java.time.ZonedDateTime
10
13
import java.util.Calendar
11
14
import java.util.Date
12
15
import org.schabi.newpipe.MainActivity.DEBUG
@@ -17,6 +20,7 @@ import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity
17
20
import org.schabi.newpipe.database.stream.model.StreamEntity
18
21
import org.schabi.newpipe.extractor.stream.StreamInfoItem
19
22
import org.schabi.newpipe.extractor.stream.StreamType
23
+ import org.schabi.newpipe.ktx.toLegacyDate
20
24
import org.schabi.newpipe.local.subscription.FeedGroupIcon
21
25
22
26
class FeedDatabaseManager (context : Context ) {
@@ -29,13 +33,8 @@ class FeedDatabaseManager(context: Context) {
29
33
/* *
30
34
* Only items that are newer than this will be saved.
31
35
*/
32
- val FEED_OLDEST_ALLOWED_DATE : Calendar = Calendar .getInstance().apply {
33
- add(Calendar .WEEK_OF_YEAR , - 13 )
34
- set(Calendar .HOUR_OF_DAY , 0 )
35
- set(Calendar .MINUTE , 0 )
36
- set(Calendar .SECOND , 0 )
37
- set(Calendar .MILLISECOND , 0 )
38
- }
36
+ val FEED_OLDEST_ALLOWED_DATE : ZonedDateTime =
37
+ LocalDate .now().minusWeeks(13 ).atStartOfDay(ZoneId .systemDefault())
39
38
}
40
39
41
40
fun groups () = feedGroupTable.getAll()
@@ -73,7 +72,7 @@ class FeedDatabaseManager(context: Context) {
73
72
fun upsertAll (
74
73
subscriptionId : Long ,
75
74
items : List <StreamInfoItem >,
76
- oldestAllowedDate : Date = FEED_OLDEST_ALLOWED_DATE .time
75
+ oldestAllowedDate : Date = FEED_OLDEST_ALLOWED_DATE .toLegacyDate()
77
76
) {
78
77
val itemsToInsert = ArrayList <StreamInfoItem >()
79
78
loop@ for (streamItem in items) {
@@ -99,7 +98,7 @@ class FeedDatabaseManager(context: Context) {
99
98
feedTable.setLastUpdatedForSubscription(FeedLastUpdatedEntity (subscriptionId, Calendar .getInstance().time))
100
99
}
101
100
102
- fun removeOrphansOrOlderStreams (oldestAllowedDate : Date = FEED_OLDEST_ALLOWED_DATE .time ) {
101
+ fun removeOrphansOrOlderStreams (oldestAllowedDate : Date = FEED_OLDEST_ALLOWED_DATE .toLegacyDate() ) {
103
102
feedTable.unlinkStreamsOlderThan(oldestAllowedDate)
104
103
streamTable.deleteOrphans()
105
104
}
0 commit comments