Skip to content

Commit

Permalink
Changed so articles don't disappear immediately when they are read
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Aug 9, 2023
1 parent 2a11651 commit 6e629e1
Show file tree
Hide file tree
Showing 23 changed files with 1,097 additions and 209 deletions.
725 changes: 725 additions & 0 deletions app/schemas/com.nononsenseapps.feeder.db.room.AppDatabase/27.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.nononsenseapps.feeder.db.room

import androidx.room.testing.MigrationTestHelper
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry
import com.nononsenseapps.feeder.FeederApplication
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.android.closestDI

@RunWith(AndroidJUnit4::class)
@LargeTest
class TestMigrationFrom26To27 : DIAware {
private val dbName = "testDb"
private val feederApplication: FeederApplication = ApplicationProvider.getApplicationContext()
override val di: DI by closestDI(feederApplication)

@Rule
@JvmField
val testHelper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
AppDatabase::class.java,
emptyList(),
FrameworkSQLiteOpenHelperFactory(),
)

@Test
fun migrate() {
testHelper.createDatabase(dbName, 26).let { oldDB ->
oldDB.execSQL(
"""
INSERT INTO feeds(id, title, url, custom_title, tag, notify, last_sync, response_hash, fulltext_by_default, open_articles_with, alternate_id, currently_syncing, when_modified)
VALUES(1, 'feed', 'http://url', '', '', 0, 0, 666, 0, '', 0, 0, 0)
""".trimIndent(),
)
oldDB.execSQL(
"""
INSERT INTO feed_items(id, guid, title, plain_title, plain_snippet, unread, notified, feed_id, first_synced_time, primary_sort_time, pinned, bookmarked, fulltext_downloaded)
VALUES(8, 'http://item1', 'title', 'ptitle', 'psnippet', 1, 0, 1, 0, 0, 1, 0, 0)
""".trimIndent(),
)
oldDB.execSQL(
"""
INSERT INTO feed_items(id, guid, title, plain_title, plain_snippet, unread, notified, feed_id, first_synced_time, primary_sort_time, pinned, bookmarked, fulltext_downloaded)
VALUES(9, 'http://item2', 'title', 'ptitle', 'psnippet', 0, 0, 1, 0, 0, 1, 0, 0)
""".trimIndent(),
)
}
val db = testHelper.runMigrationsAndValidate(dbName, 27, true, MigrationFrom26To27(di))

db.query(
"""
SELECT read_time FROM feed_items
""".trimIndent(),
).use {
assert(it.count == 2)
assert(it.moveToFirst())
assertTrue {
it.isNull(0)
}
assert(it.moveToLast())
assertEquals(1690317917000, it.getLong(0))
}
}
}
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@
android:launchMode="singleInstance"
android:taskAffinity="${applicationId}.OpenLinkTask" />

<service
android:name=".model.FeederService"
android:exported="true" />

<provider
android:name=".contentprovider.RSSContentProvider"
android:authorities="com.nononsenseapps.feeder.rssprovider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.map
import com.nononsenseapps.feeder.db.FAR_FUTURE
import com.nononsenseapps.feeder.db.room.FeedItem
import com.nononsenseapps.feeder.db.room.FeedItemCursor
import com.nononsenseapps.feeder.db.room.FeedItemDao
Expand All @@ -21,40 +22,41 @@ import kotlinx.coroutines.flow.map
import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.instance
import org.threeten.bp.Instant

class FeedItemStore(override val di: DI) : DIAware {
private val dao: FeedItemDao by instance()

fun getFeedItemCount(
feedId: Long,
tag: String,
onlyUnread: Boolean,
minReadTime: Instant?,
): Flow<Int> =
when {
feedId > ID_UNSET -> dao.getFeedItemCount(
feedId = feedId,
unread = onlyUnread,
minReadTime = minReadTime ?: FAR_FUTURE,
bookmarked = false,
)

tag.isNotEmpty() -> dao.getFeedItemCount(
tag = tag,
unread = onlyUnread,
minReadTime = minReadTime ?: FAR_FUTURE,
bookmarked = false,
)

feedId == ID_SAVED_ARTICLES -> dao.getFeedItemCount(
unread = onlyUnread,
minReadTime = minReadTime ?: FAR_FUTURE,
bookmarked = true,
)

else -> dao.getFeedItemCount(unread = onlyUnread, bookmarked = false)
else -> dao.getFeedItemCount(minReadTime = minReadTime ?: FAR_FUTURE, bookmarked = false)
}

fun getPagedFeedItems(
feedId: Long,
tag: String,
onlyUnread: Boolean,
minReadTime: Instant,
newestFirst: Boolean,
): Flow<PagingData<FeedListItem>> =
Pager(
Expand All @@ -69,18 +71,18 @@ class FeedItemStore(override val di: DI) : DIAware {
when {
feedId > ID_UNSET -> dao.pagingUnreadPreviewsDesc(
feedId = feedId,
unread = onlyUnread,
minReadTime = minReadTime,
bookmarked = onlyBookmarks,
)

tag.isNotEmpty() -> dao.pagingUnreadPreviewsDesc(
tag = tag,
unread = onlyUnread,
minReadTime = minReadTime,
bookmarked = onlyBookmarks,
)

else -> dao.pagingUnreadPreviewsDesc(
unread = onlyUnread,
minReadTime = minReadTime,
bookmarked = onlyBookmarks,
)
}
Expand All @@ -90,18 +92,18 @@ class FeedItemStore(override val di: DI) : DIAware {
when {
feedId > ID_UNSET -> dao.pagingUnreadPreviewsAsc(
feedId = feedId,
unread = onlyUnread,
minReadTime = minReadTime,
bookmarked = onlyBookmarks,
)

tag.isNotEmpty() -> dao.pagingUnreadPreviewsAsc(
tag = tag,
unread = onlyUnread,
minReadTime = minReadTime,
bookmarked = onlyBookmarks,
)

else -> dao.pagingUnreadPreviewsAsc(
unread = onlyUnread,
minReadTime = minReadTime,
bookmarked = onlyBookmarks,
)
}
Expand All @@ -124,8 +126,8 @@ class FeedItemStore(override val di: DI) : DIAware {
dao.markAsReadAndNotified(itemId)
}

suspend fun markAsUnread(itemId: Long, unread: Boolean) {
dao.markAsRead(itemId, unread)
suspend fun markAsUnread(itemId: Long) {
dao.markAsUnread(itemId)
}

suspend fun setBookmarked(itemId: Long, bookmarked: Boolean) {
Expand Down Expand Up @@ -167,7 +169,7 @@ class FeedItemStore(override val di: DI) : DIAware {
suspend fun markAsRead(
feedId: Long,
tag: String,
onlyUnread: Boolean,
queryReadTime: Instant,
descending: Boolean,
cursor: FeedItemCursor,
) {
Expand All @@ -180,7 +182,7 @@ class FeedItemStore(override val di: DI) : DIAware {
pubDate = cursor.pubDate,
id = cursor.id,
feedId = feedId,
onlyUnread = onlyUnread,
queryReadTime = queryReadTime,
onlyBookmarked = onlyBookmarks,
)

Expand All @@ -189,15 +191,15 @@ class FeedItemStore(override val di: DI) : DIAware {
pubDate = cursor.pubDate,
id = cursor.id,
tag = tag,
onlyUnread = onlyUnread,
queryReadTime = queryReadTime,
onlyBookmarked = onlyBookmarks,
)

else -> dao.markAsReadDesc(
primarySortTime = cursor.primarySortTime,
pubDate = cursor.pubDate,
id = cursor.id,
onlyUnread = onlyUnread,
queryReadTime = queryReadTime,
onlyBookmarked = onlyBookmarks,
)
}
Expand All @@ -210,7 +212,7 @@ class FeedItemStore(override val di: DI) : DIAware {
pubDate = cursor.pubDate,
id = cursor.id,
feedId = feedId,
onlyUnread = onlyUnread,
queryReadTime = queryReadTime,
onlyBookmarked = onlyBookmarks,
)

Expand All @@ -219,15 +221,15 @@ class FeedItemStore(override val di: DI) : DIAware {
pubDate = cursor.pubDate,
id = cursor.id,
tag = tag,
onlyUnread = onlyUnread,
queryReadTime = queryReadTime,
onlyBookmarked = onlyBookmarks,
)

else -> dao.markAsReadAsc(
primarySortTime = cursor.primarySortTime,
pubDate = cursor.pubDate,
id = cursor.id,
onlyUnread = onlyUnread,
queryReadTime = queryReadTime,
onlyBookmarked = onlyBookmarks,
)
}
Expand Down Expand Up @@ -273,7 +275,7 @@ private fun PreviewItem.toFeedListItem() =
title = plainTitle,
snippet = plainSnippet,
feedTitle = feedDisplayTitle,
unread = unread,
unread = readTime == null,
pubDate = pubDate?.toLocalDate()?.format(shortDateTimeFormat) ?: "",
imageUrl = imageUrl,
link = link,
Expand Down
Loading

0 comments on commit 6e629e1

Please sign in to comment.