Skip to content

Commit

Permalink
feat(freshrss): support fresh rss api
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashinch committed Jan 18, 2024
1 parent c579c01 commit 1d4883f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.supervisorScope
import me.ash.reader.domain.model.account.Account
import me.ash.reader.domain.model.article.ArticleWithFeed
import me.ash.reader.domain.model.feed.Feed
import me.ash.reader.domain.model.feed.FeedWithArticle
Expand Down Expand Up @@ -49,7 +50,7 @@ abstract class AbstractRssRepository(
open val deleteSubscription: Boolean = true
open val updateSubscription: Boolean = true

open suspend fun validCredentials(): Boolean = true
open suspend fun validCredentials(account: Account): Boolean = true

open suspend fun clearAuthorization() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.supervisorScope
import kotlinx.coroutines.withContext
import me.ash.reader.R
import me.ash.reader.domain.model.account.Account
import me.ash.reader.domain.model.account.security.FeverSecurityKey
import me.ash.reader.domain.model.article.Article
import me.ash.reader.domain.model.article.ArticleMeta
Expand Down Expand Up @@ -73,7 +74,8 @@ class FeverRssService @Inject constructor(
)
}

override suspend fun validCredentials(): Boolean = getFeverAPI().validCredentials() > 0
override suspend fun validCredentials(account: Account): Boolean =
getFeverAPI().validCredentials() > 0

override suspend fun clearAuthorization() {
FeverAPI.clearInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.supervisorScope
import kotlinx.coroutines.withContext
import me.ash.reader.R
import me.ash.reader.domain.model.account.Account
import me.ash.reader.domain.model.account.security.GoogleReaderSecurityKey
import me.ash.reader.domain.model.article.Article
import me.ash.reader.domain.model.article.ArticleMeta
Expand Down Expand Up @@ -75,7 +76,16 @@ class GoogleReaderRssService @Inject constructor(
)
}

override suspend fun validCredentials(): Boolean = getGoogleReaderAPI().validCredentials()
override suspend fun validCredentials(account: Account): Boolean {
return getGoogleReaderAPI().validCredentials().also { success ->
if (success) try {
getGoogleReaderAPI().getUserInfo().userName?.let {
accountDao.update(account.copy(name = it))
}
} catch (ignore: Exception) {
}
}
}

override suspend fun clearAuthorization() {
GoogleReaderAPI.clearInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AccountViewModel @Inject constructor(
viewModelScope.launch(ioDispatcher) {
val addAccount = accountService.addAccount(account)
try {
if (rssService.get(addAccount.type.id).validCredentials()) {
if (rssService.get(addAccount.type.id).validCredentials(account)) {
withContext(mainDispatcher) {
callback(addAccount, null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ fun AddAccountsPage(
text = stringResource(R.string.self_hosted),
)
SettingItem(
enable = false,
title = stringResource(R.string.fresh_rss),
desc = stringResource(R.string.fresh_rss_desc),
iconPainter = painterResource(id = R.drawable.ic_freshrss),
onClick = {

additionViewModel.showAddGoogleReaderAccountDialog()
},
) {}
SettingItem(
Expand Down

0 comments on commit 1d4883f

Please sign in to comment.