Skip to content

Commit

Permalink
[1.121.*] Pre-release merge (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
tramline-github[bot] authored Apr 13, 2024
2 parents 93857c2 + d36c3eb commit fc7f635
Show file tree
Hide file tree
Showing 45 changed files with 988 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import kotlinx.datetime.Instant

@Immutable
data class Feed(
override val id: String,
val name: String,
val icon: String,
val description: String,
val link: String,
val homepageLink: String,
val createdAt: Instant,
val link: String,
val pinnedAt: Instant?,
val lastCleanUpAt: Instant? = null,
val numberOfUnreadPosts: Long = 0L,
val alwaysFetchSourceArticle: Boolean = false,
)
override val sourceType: SourceType = SourceType.Feed
) : Source
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 Sasikanth Miriyampalli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.sasikanth.rss.reader.core.model.local

import kotlinx.datetime.Instant

data class FeedGroup(
override val id: String,
val name: String,
val feedIds: Set<String>,
val feedIcons: Set<String>,
val createdAt: Instant,
val updatedAt: Instant,
override val sourceType: SourceType = SourceType.FeedGroup
) : Source
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package dev.sasikanth.rss.reader.core.model.local
import kotlinx.datetime.Instant

data class Post(
val id: String,
val sourceId: String,
val title: String,
val description: String,
val rawContent: String?,
val imageUrl: String?,
val date: Instant,
val feedLink: String,
val link: String,
val bookmarked: Boolean,
val commentsLink: String?,
val bookmarked: Boolean,
val read: Boolean,
val rawContent: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ import kotlinx.datetime.Instant

@Immutable
data class PostWithMetadata(
val id: String,
val sourceId: String,
val title: String,
val description: String,
val imageUrl: String?,
val date: Instant,
val link: String,
val commentsLink: String?,
val bookmarked: Boolean,
val read: Boolean,
val feedName: String,
val feedIcon: String,
val feedLink: String,
val commentsLink: String?,
val read: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Sasikanth Miriyampalli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.sasikanth.rss.reader.core.model.local

interface Source {
val id: String
val sourceType: SourceType
}

enum class SourceType {
Feed,
FeedGroup
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package dev.sasikanth.rss.reader.database

import android.content.Context
import androidx.sqlite.db.SupportSQLiteDatabase
import app.cash.sqldelight.db.AfterVersion
import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
import dev.sasikanth.rss.reader.di.scopes.AppScope
Expand All @@ -25,15 +26,18 @@ import me.tatarka.inject.annotations.Inject

@Inject
@AppScope
actual class DriverFactory(private val context: Context) {
actual class DriverFactory(
private val context: Context,
private val codeMigrations: Array<AfterVersion>,
) {

actual fun createDriver(): SqlDriver {
return AndroidSqliteDriver(
schema = ReaderDatabase.Schema,
context = context,
name = DB_NAME,
callback =
object : AndroidSqliteDriver.Callback(ReaderDatabase.Schema) {
object : AndroidSqliteDriver.Callback(ReaderDatabase.Schema, callbacks = codeMigrations) {
override fun onOpen(db: SupportSQLiteDatabase) {
db.setForeignKeyConstraintsEnabled(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.arkivanov.essenty.lifecycle.coroutines.coroutineScope
import com.arkivanov.essenty.lifecycle.doOnStart
import dev.sasikanth.rss.reader.about.AboutPresenterFactory
import dev.sasikanth.rss.reader.bookmarks.BookmarksPresenterFactory
import dev.sasikanth.rss.reader.core.model.local.PostWithMetadata
import dev.sasikanth.rss.reader.di.scopes.ActivityScope
import dev.sasikanth.rss.reader.feed.FeedPresenterFactory
import dev.sasikanth.rss.reader.home.HomePresenterFactory
Expand Down Expand Up @@ -115,7 +116,7 @@ class AppPresenter(
is ModalConfig.FeedInfo -> {
Modals.FeedInfo(
presenter =
feedPresenter(modalConfig.feedLink, componentContext) { modalNavigation.dismiss() }
feedPresenter(modalConfig.feedId, componentContext) { modalNavigation.dismiss() }
)
}
}
Expand Down Expand Up @@ -160,21 +161,21 @@ class AppPresenter(
}
is Config.Reader -> {
Screen.Reader(
presenter = readerPresenter(config.postLink, componentContext) { navigation.pop() }
presenter = readerPresenter(config.postId, componentContext) { navigation.pop() }
)
}
}

private fun openPost(postLink: String) {
private fun openPost(post: PostWithMetadata) {
scope.launch {
val showReaderView =
withContext(dispatchersProvider.io) { settingsRepository.showReaderView.first() }

if (showReaderView) {
navigation.push(Config.Reader(postLink))
navigation.push(Config.Reader(post.id))
} else {
linkHandler.openLink(postLink)
rssRepository.updatePostReadStatus(read = true, link = postLink)
linkHandler.openLink(post.link)
rssRepository.updatePostReadStatus(read = true, id = post.id)
}
}
}
Expand Down Expand Up @@ -214,11 +215,11 @@ class AppPresenter(

@Serializable data object About : Config

@Serializable data class Reader(val postLink: String) : Config
@Serializable data class Reader(val postId: String) : Config
}

@Serializable
sealed interface ModalConfig {
@Serializable data class FeedInfo(val feedLink: String) : ModalConfig
@Serializable data class FeedInfo(val feedId: String) : ModalConfig
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ sealed interface BookmarksEvent {

data class OnPostClicked(val post: PostWithMetadata) : BookmarksEvent

data class TogglePostReadStatus(val postLink: String, val postRead: Boolean) : BookmarksEvent
data class TogglePostReadStatus(val postId: String, val postRead: Boolean) : BookmarksEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal typealias BookmarksPresenterFactory =
(
ComponentContext,
goBack: () -> Unit,
openReaderView: (String) -> Unit,
openReaderView: (PostWithMetadata) -> Unit,
) -> BookmarksPresenter

@Inject
Expand All @@ -52,7 +52,7 @@ class BookmarksPresenter(
private val rssRepository: RssRepository,
@Assisted componentContext: ComponentContext,
@Assisted private val goBack: () -> Unit,
@Assisted private val openReaderView: (postLink: String) -> Unit,
@Assisted private val openReaderView: (post: PostWithMetadata) -> Unit,
) : ComponentContext by componentContext {

private val presenterInstance =
Expand Down Expand Up @@ -110,28 +110,25 @@ class BookmarksPresenter(
is BookmarksEvent.OnPostClicked -> {
// no-op
}
is BookmarksEvent.TogglePostReadStatus ->
togglePostReadStatus(event.postLink, event.postRead)
is BookmarksEvent.TogglePostReadStatus -> togglePostReadStatus(event.postId, event.postRead)
}
}

private fun togglePostReadStatus(postLink: String, postRead: Boolean) {
coroutineScope.launch {
rssRepository.updatePostReadStatus(read = !postRead, link = postLink)
}
private fun togglePostReadStatus(postId: String, postRead: Boolean) {
coroutineScope.launch { rssRepository.updatePostReadStatus(read = !postRead, id = postId) }
}

fun onPostClicked(
post: PostWithMetadata,
openReaderView: (postLink: String) -> Unit,
openReaderView: (post: PostWithMetadata) -> Unit,
openLink: (postLink: String) -> Unit
) {
coroutineScope.launch {
val hasPost = rssRepository.hasPost(post.link)
val hasFeed = rssRepository.hasFeed(post.feedLink)
val hasPost = rssRepository.hasPost(post.id)
val hasFeed = rssRepository.hasFeed(post.sourceId)

if (hasPost && hasFeed) {
openReaderView(post.link)
openReaderView(post)
} else {
openLink(post.link)
}
Expand All @@ -140,10 +137,10 @@ class BookmarksPresenter(

private fun onPostBookmarkClicked(post: PostWithMetadata) {
coroutineScope.launch {
if (rssRepository.hasFeed(post.feedLink)) {
rssRepository.updateBookmarkStatus(bookmarked = !post.bookmarked, link = post.link)
if (rssRepository.hasFeed(post.sourceId)) {
rssRepository.updateBookmarkStatus(bookmarked = !post.bookmarked, id = post.id)
} else {
rssRepository.deleteBookmark(link = post.link)
rssRepository.deleteBookmark(id = post.id)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal fun BookmarksScreen(
},
togglePostReadClick = {
bookmarksPresenter.dispatch(
BookmarksEvent.TogglePostReadStatus(post.link, post.read)
BookmarksEvent.TogglePostReadStatus(post.id, post.read)
)
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 Sasikanth Miriyampalli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.sasikanth.rss.reader.database

import app.cash.sqldelight.ColumnAdapter

internal object ListToStringAdapter : ColumnAdapter<List<String>, String> {

override fun decode(databaseValue: String): List<String> {
return databaseValue.split(", ")
}

override fun encode(value: List<String>): String {
return value.joinToString()
}
}
Loading

0 comments on commit fc7f635

Please sign in to comment.