diff --git a/app/schemas/me.ash.reader.infrastructure.db.AndroidDatabase/5.json b/app/schemas/me.ash.reader.infrastructure.db.AndroidDatabase/5.json new file mode 100644 index 000000000..1f1a26eb6 --- /dev/null +++ b/app/schemas/me.ash.reader.infrastructure.db.AndroidDatabase/5.json @@ -0,0 +1,377 @@ +{ + "formatVersion": 1, + "database": { + "version": 5, + "identityHash": "2b86f20200ed2c56f5ae8d0565cf0f26", + "entities": [ + { + "tableName": "account", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `type` INTEGER NOT NULL, `updateAt` INTEGER, `lastArticleId` TEXT, `syncInterval` INTEGER NOT NULL DEFAULT 30, `syncOnStart` INTEGER NOT NULL DEFAULT 0, `syncOnlyOnWiFi` INTEGER NOT NULL DEFAULT 0, `syncOnlyWhenCharging` INTEGER NOT NULL DEFAULT 0, `keepArchived` INTEGER NOT NULL DEFAULT 2592000000, `syncBlockList` TEXT NOT NULL DEFAULT '', `securityKey` TEXT DEFAULT 'CvJ1PKM8EW8=')", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updateAt", + "columnName": "updateAt", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "lastArticleId", + "columnName": "lastArticleId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "syncInterval", + "columnName": "syncInterval", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "30" + }, + { + "fieldPath": "syncOnStart", + "columnName": "syncOnStart", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "syncOnlyOnWiFi", + "columnName": "syncOnlyOnWiFi", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "syncOnlyWhenCharging", + "columnName": "syncOnlyWhenCharging", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "keepArchived", + "columnName": "keepArchived", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "2592000000" + }, + { + "fieldPath": "syncBlockList", + "columnName": "syncBlockList", + "affinity": "TEXT", + "notNull": true, + "defaultValue": "''" + }, + { + "fieldPath": "securityKey", + "columnName": "securityKey", + "affinity": "TEXT", + "notNull": false, + "defaultValue": "'CvJ1PKM8EW8='" + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "feed", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `icon` TEXT, `url` TEXT NOT NULL, `groupId` TEXT NOT NULL, `accountId` INTEGER NOT NULL, `isNotification` INTEGER NOT NULL, `isFullContent` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`groupId`) REFERENCES `group`(`id`) ON UPDATE CASCADE ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "url", + "columnName": "url", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "groupId", + "columnName": "groupId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isNotification", + "columnName": "isNotification", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isFullContent", + "columnName": "isFullContent", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_feed_groupId", + "unique": false, + "columnNames": [ + "groupId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_groupId` ON `${TABLE_NAME}` (`groupId`)" + }, + { + "name": "index_feed_accountId", + "unique": false, + "columnNames": [ + "accountId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_accountId` ON `${TABLE_NAME}` (`accountId`)" + } + ], + "foreignKeys": [ + { + "table": "group", + "onDelete": "CASCADE", + "onUpdate": "CASCADE", + "columns": [ + "groupId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "article", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `date` INTEGER NOT NULL, `title` TEXT NOT NULL, `author` TEXT, `rawDescription` TEXT NOT NULL, `shortDescription` TEXT NOT NULL, `fullContent` TEXT, `img` TEXT, `link` TEXT NOT NULL, `feedId` TEXT NOT NULL, `accountId` INTEGER NOT NULL, `isUnread` INTEGER NOT NULL, `isStarred` INTEGER NOT NULL, `isReadLater` INTEGER NOT NULL, `updateAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`feedId`) REFERENCES `feed`(`id`) ON UPDATE CASCADE ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "date", + "columnName": "date", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "author", + "columnName": "author", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "rawDescription", + "columnName": "rawDescription", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "shortDescription", + "columnName": "shortDescription", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "fullContent", + "columnName": "fullContent", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "img", + "columnName": "img", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "link", + "columnName": "link", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "feedId", + "columnName": "feedId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isUnread", + "columnName": "isUnread", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isStarred", + "columnName": "isStarred", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isReadLater", + "columnName": "isReadLater", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updateAt", + "columnName": "updateAt", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_article_feedId", + "unique": false, + "columnNames": [ + "feedId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_article_feedId` ON `${TABLE_NAME}` (`feedId`)" + }, + { + "name": "index_article_accountId", + "unique": false, + "columnNames": [ + "accountId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_article_accountId` ON `${TABLE_NAME}` (`accountId`)" + } + ], + "foreignKeys": [ + { + "table": "feed", + "onDelete": "CASCADE", + "onUpdate": "CASCADE", + "columns": [ + "feedId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "group", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `accountId` INTEGER NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_group_accountId", + "unique": false, + "columnNames": [ + "accountId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_group_accountId` ON `${TABLE_NAME}` (`accountId`)" + } + ], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2b86f20200ed2c56f5ae8d0565cf0f26')" + ] + } +} \ No newline at end of file diff --git a/app/schemas/me.ash.reader.infrastructure.db.RYDatabase/5.json b/app/schemas/me.ash.reader.infrastructure.db.RYDatabase/5.json new file mode 100644 index 000000000..1f1a26eb6 --- /dev/null +++ b/app/schemas/me.ash.reader.infrastructure.db.RYDatabase/5.json @@ -0,0 +1,377 @@ +{ + "formatVersion": 1, + "database": { + "version": 5, + "identityHash": "2b86f20200ed2c56f5ae8d0565cf0f26", + "entities": [ + { + "tableName": "account", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `type` INTEGER NOT NULL, `updateAt` INTEGER, `lastArticleId` TEXT, `syncInterval` INTEGER NOT NULL DEFAULT 30, `syncOnStart` INTEGER NOT NULL DEFAULT 0, `syncOnlyOnWiFi` INTEGER NOT NULL DEFAULT 0, `syncOnlyWhenCharging` INTEGER NOT NULL DEFAULT 0, `keepArchived` INTEGER NOT NULL DEFAULT 2592000000, `syncBlockList` TEXT NOT NULL DEFAULT '', `securityKey` TEXT DEFAULT 'CvJ1PKM8EW8=')", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updateAt", + "columnName": "updateAt", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "lastArticleId", + "columnName": "lastArticleId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "syncInterval", + "columnName": "syncInterval", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "30" + }, + { + "fieldPath": "syncOnStart", + "columnName": "syncOnStart", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "syncOnlyOnWiFi", + "columnName": "syncOnlyOnWiFi", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "syncOnlyWhenCharging", + "columnName": "syncOnlyWhenCharging", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "keepArchived", + "columnName": "keepArchived", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "2592000000" + }, + { + "fieldPath": "syncBlockList", + "columnName": "syncBlockList", + "affinity": "TEXT", + "notNull": true, + "defaultValue": "''" + }, + { + "fieldPath": "securityKey", + "columnName": "securityKey", + "affinity": "TEXT", + "notNull": false, + "defaultValue": "'CvJ1PKM8EW8='" + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "feed", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `icon` TEXT, `url` TEXT NOT NULL, `groupId` TEXT NOT NULL, `accountId` INTEGER NOT NULL, `isNotification` INTEGER NOT NULL, `isFullContent` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`groupId`) REFERENCES `group`(`id`) ON UPDATE CASCADE ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "url", + "columnName": "url", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "groupId", + "columnName": "groupId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isNotification", + "columnName": "isNotification", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isFullContent", + "columnName": "isFullContent", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_feed_groupId", + "unique": false, + "columnNames": [ + "groupId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_groupId` ON `${TABLE_NAME}` (`groupId`)" + }, + { + "name": "index_feed_accountId", + "unique": false, + "columnNames": [ + "accountId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_accountId` ON `${TABLE_NAME}` (`accountId`)" + } + ], + "foreignKeys": [ + { + "table": "group", + "onDelete": "CASCADE", + "onUpdate": "CASCADE", + "columns": [ + "groupId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "article", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `date` INTEGER NOT NULL, `title` TEXT NOT NULL, `author` TEXT, `rawDescription` TEXT NOT NULL, `shortDescription` TEXT NOT NULL, `fullContent` TEXT, `img` TEXT, `link` TEXT NOT NULL, `feedId` TEXT NOT NULL, `accountId` INTEGER NOT NULL, `isUnread` INTEGER NOT NULL, `isStarred` INTEGER NOT NULL, `isReadLater` INTEGER NOT NULL, `updateAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`feedId`) REFERENCES `feed`(`id`) ON UPDATE CASCADE ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "date", + "columnName": "date", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "author", + "columnName": "author", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "rawDescription", + "columnName": "rawDescription", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "shortDescription", + "columnName": "shortDescription", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "fullContent", + "columnName": "fullContent", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "img", + "columnName": "img", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "link", + "columnName": "link", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "feedId", + "columnName": "feedId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isUnread", + "columnName": "isUnread", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isStarred", + "columnName": "isStarred", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isReadLater", + "columnName": "isReadLater", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updateAt", + "columnName": "updateAt", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_article_feedId", + "unique": false, + "columnNames": [ + "feedId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_article_feedId` ON `${TABLE_NAME}` (`feedId`)" + }, + { + "name": "index_article_accountId", + "unique": false, + "columnNames": [ + "accountId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_article_accountId` ON `${TABLE_NAME}` (`accountId`)" + } + ], + "foreignKeys": [ + { + "table": "feed", + "onDelete": "CASCADE", + "onUpdate": "CASCADE", + "columns": [ + "feedId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "group", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `accountId` INTEGER NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_group_accountId", + "unique": false, + "columnNames": [ + "accountId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_group_accountId` ON `${TABLE_NAME}` (`accountId`)" + } + ], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2b86f20200ed2c56f5ae8d0565cf0f26')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ed0debf76..4641be3e8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ diff --git a/app/src/main/java/me/ash/reader/domain/model/article/ArticleFlowItem.kt b/app/src/main/java/me/ash/reader/domain/model/article/ArticleFlowItem.kt index 423433bd8..a0cf051b9 100644 --- a/app/src/main/java/me/ash/reader/domain/model/article/ArticleFlowItem.kt +++ b/app/src/main/java/me/ash/reader/domain/model/article/ArticleFlowItem.kt @@ -3,7 +3,7 @@ package me.ash.reader.domain.model.article import androidx.paging.PagingData import androidx.paging.insertSeparators import androidx.paging.map -import me.ash.reader.domain.service.StringsRepository +import me.ash.reader.infrastructure.android.AndroidStringsHelper /** * Provide paginated and inserted separator data types for article list view. @@ -30,19 +30,19 @@ sealed class ArticleFlowItem { /** * Mapping [ArticleWithFeed] list to [ArticleFlowItem] list. */ -fun PagingData.mapPagingFlowItem(stringsRepository: StringsRepository): PagingData = +fun PagingData.mapPagingFlowItem(androidStringsHelper: AndroidStringsHelper): PagingData = map { ArticleFlowItem.Article(it.apply { - article.dateString = stringsRepository.formatAsString( + article.dateString = androidStringsHelper.formatAsString( date = article.date, onlyHourMinute = true ) }) }.insertSeparators { before, after -> val beforeDate = - stringsRepository.formatAsString(before?.articleWithFeed?.article?.date) + androidStringsHelper.formatAsString(before?.articleWithFeed?.article?.date) val afterDate = - stringsRepository.formatAsString(after?.articleWithFeed?.article?.date) + androidStringsHelper.formatAsString(after?.articleWithFeed?.article?.date) if (beforeDate != afterDate) { afterDate?.let { ArticleFlowItem.Date(it, beforeDate != null) } } else { diff --git a/app/src/main/java/me/ash/reader/domain/service/AbstractRssRepository.kt b/app/src/main/java/me/ash/reader/domain/service/AbstractRssRepository.kt index e193e9186..99ea86a40 100644 --- a/app/src/main/java/me/ash/reader/domain/service/AbstractRssRepository.kt +++ b/app/src/main/java/me/ash/reader/domain/service/AbstractRssRepository.kt @@ -25,6 +25,8 @@ import me.ash.reader.domain.repository.FeedDao import me.ash.reader.domain.repository.GroupDao import me.ash.reader.infrastructure.preference.KeepArchivedPreference import me.ash.reader.infrastructure.preference.SyncIntervalPreference +import me.ash.reader.infrastructure.rss.RssHelper +import me.ash.reader.infrastructure.android.NotificationHelper import me.ash.reader.ui.ext.currentAccountId import me.ash.reader.ui.ext.spacerDollar import java.util.* diff --git a/app/src/main/java/me/ash/reader/domain/service/AccountRepository.kt b/app/src/main/java/me/ash/reader/domain/service/AccountService.kt similarity index 96% rename from app/src/main/java/me/ash/reader/domain/service/AccountRepository.kt rename to app/src/main/java/me/ash/reader/domain/service/AccountService.kt index ee002357c..7e1943479 100644 --- a/app/src/main/java/me/ash/reader/domain/service/AccountRepository.kt +++ b/app/src/main/java/me/ash/reader/domain/service/AccountService.kt @@ -15,14 +15,14 @@ import me.ash.reader.domain.repository.GroupDao import me.ash.reader.ui.ext.* import javax.inject.Inject -class AccountRepository @Inject constructor( +class AccountService @Inject constructor( @ApplicationContext private val context: Context, private val accountDao: AccountDao, private val groupDao: GroupDao, private val feedDao: FeedDao, private val articleDao: ArticleDao, - private val rssRepository: RssRepository, + private val rssService: RssService, ) { fun getAccounts(): Flow> = accountDao.queryAllAsFlow() @@ -85,7 +85,7 @@ class AccountRepository @Inject constructor( } suspend fun switch(account: Account) { - rssRepository.get().cancelSync() + rssService.get().cancelSync() context.dataStore.put(DataStoreKeys.CurrentAccountId, account.id!!) context.dataStore.put(DataStoreKeys.CurrentAccountType, account.type.id) diff --git a/app/src/main/java/me/ash/reader/domain/service/RYRepository.kt b/app/src/main/java/me/ash/reader/domain/service/AppService.kt similarity index 93% rename from app/src/main/java/me/ash/reader/domain/service/RYRepository.kt rename to app/src/main/java/me/ash/reader/domain/service/AppService.kt index 6156014eb..60ec6f101 100644 --- a/app/src/main/java/me/ash/reader/domain/service/RYRepository.kt +++ b/app/src/main/java/me/ash/reader/domain/service/AppService.kt @@ -11,21 +11,21 @@ import me.ash.reader.R import me.ash.reader.domain.model.general.toVersion import me.ash.reader.infrastructure.di.IODispatcher import me.ash.reader.infrastructure.di.MainDispatcher +import me.ash.reader.infrastructure.net.Download +import me.ash.reader.infrastructure.net.NetworkDataSource +import me.ash.reader.infrastructure.net.downloadToFileWithProgress import me.ash.reader.infrastructure.preference.* import me.ash.reader.infrastructure.preference.NewVersionSizePreference.formatSize -import me.ash.reader.infrastructure.source.Download -import me.ash.reader.infrastructure.source.RYNetworkDataSource -import me.ash.reader.infrastructure.source.downloadToFileWithProgress import me.ash.reader.ui.ext.getCurrentVersion import me.ash.reader.ui.ext.getLatestApk import me.ash.reader.ui.ext.showToast import me.ash.reader.ui.ext.skipVersionNumber import javax.inject.Inject -class RYRepository @Inject constructor( +class AppService @Inject constructor( @ApplicationContext private val context: Context, - private val networkDataSource: RYNetworkDataSource, + private val networkDataSource: NetworkDataSource, @IODispatcher private val ioDispatcher: CoroutineDispatcher, @MainDispatcher diff --git a/app/src/main/java/me/ash/reader/domain/service/FeverRssRepository.kt b/app/src/main/java/me/ash/reader/domain/service/FeverRssService.kt similarity index 97% rename from app/src/main/java/me/ash/reader/domain/service/FeverRssRepository.kt rename to app/src/main/java/me/ash/reader/domain/service/FeverRssService.kt index 7ce55dcc7..e2cf7ca5e 100644 --- a/app/src/main/java/me/ash/reader/domain/service/FeverRssRepository.kt +++ b/app/src/main/java/me/ash/reader/domain/service/FeverRssService.kt @@ -20,11 +20,13 @@ import me.ash.reader.domain.repository.AccountDao import me.ash.reader.domain.repository.ArticleDao import me.ash.reader.domain.repository.FeedDao import me.ash.reader.domain.repository.GroupDao +import me.ash.reader.infrastructure.android.NotificationHelper import me.ash.reader.infrastructure.di.DefaultDispatcher import me.ash.reader.infrastructure.di.IODispatcher import me.ash.reader.infrastructure.di.MainDispatcher -import me.ash.reader.infrastructure.provider.fever.FeverAPI -import me.ash.reader.infrastructure.provider.fever.FeverDTO +import me.ash.reader.infrastructure.rss.RssHelper +import me.ash.reader.infrastructure.rss.provider.fever.FeverAPI +import me.ash.reader.infrastructure.rss.provider.fever.FeverDTO import me.ash.reader.ui.ext.currentAccountId import me.ash.reader.ui.ext.dollarLast import me.ash.reader.ui.ext.showToast @@ -33,7 +35,7 @@ import net.dankito.readability4j.extended.Readability4JExtended import java.util.* import javax.inject.Inject -class FeverRssRepository @Inject constructor( +class FeverRssService @Inject constructor( @ApplicationContext private val context: Context, private val articleDao: ArticleDao, diff --git a/app/src/main/java/me/ash/reader/domain/service/LocalRssRepository.kt b/app/src/main/java/me/ash/reader/domain/service/LocalRssService.kt similarity index 88% rename from app/src/main/java/me/ash/reader/domain/service/LocalRssRepository.kt rename to app/src/main/java/me/ash/reader/domain/service/LocalRssService.kt index 34d4f7e3c..2ff2a57c7 100644 --- a/app/src/main/java/me/ash/reader/domain/service/LocalRssRepository.kt +++ b/app/src/main/java/me/ash/reader/domain/service/LocalRssService.kt @@ -10,9 +10,11 @@ import me.ash.reader.domain.repository.FeedDao import me.ash.reader.domain.repository.GroupDao import me.ash.reader.infrastructure.di.DefaultDispatcher import me.ash.reader.infrastructure.di.IODispatcher +import me.ash.reader.infrastructure.rss.RssHelper +import me.ash.reader.infrastructure.android.NotificationHelper import javax.inject.Inject -class LocalRssRepository @Inject constructor( +class LocalRssService @Inject constructor( @ApplicationContext private val context: Context, private val articleDao: ArticleDao, diff --git a/app/src/main/java/me/ash/reader/domain/service/OpmlRepository.kt b/app/src/main/java/me/ash/reader/domain/service/OpmlService.kt similarity index 94% rename from app/src/main/java/me/ash/reader/domain/service/OpmlRepository.kt rename to app/src/main/java/me/ash/reader/domain/service/OpmlService.kt index 238ec2225..9e08d7c45 100644 --- a/app/src/main/java/me/ash/reader/domain/service/OpmlRepository.kt +++ b/app/src/main/java/me/ash/reader/domain/service/OpmlService.kt @@ -11,7 +11,7 @@ import me.ash.reader.domain.model.feed.Feed import me.ash.reader.domain.repository.AccountDao import me.ash.reader.domain.repository.FeedDao import me.ash.reader.domain.repository.GroupDao -import me.ash.reader.infrastructure.source.OPMLDataSource +import me.ash.reader.infrastructure.rss.OPMLDataSource import me.ash.reader.ui.ext.currentAccountId import me.ash.reader.ui.ext.getDefaultGroupId import java.io.InputStream @@ -21,13 +21,13 @@ import javax.inject.Inject /** * Supports import and export from OPML files. */ -class OpmlRepository @Inject constructor( +class OpmlService @Inject constructor( @ApplicationContext private val context: Context, private val groupDao: GroupDao, private val feedDao: FeedDao, private val accountDao: AccountDao, - private val rssRepository: RssRepository, + private val rssService: RssService, private val OPMLDataSource: OPMLDataSource, ) { @@ -48,7 +48,7 @@ class OpmlRepository @Inject constructor( val repeatList = mutableListOf() groupWithFeed.feeds.forEach { it.groupId = groupWithFeed.group.id - if (rssRepository.get().isFeedExist(it.url)) { + if (rssService.get().isFeedExist(it.url)) { repeatList.add(it) } } diff --git a/app/src/main/java/me/ash/reader/domain/service/RssRepository.kt b/app/src/main/java/me/ash/reader/domain/service/RssService.kt similarity index 52% rename from app/src/main/java/me/ash/reader/domain/service/RssRepository.kt rename to app/src/main/java/me/ash/reader/domain/service/RssService.kt index 98716fe5b..1cb64009b 100644 --- a/app/src/main/java/me/ash/reader/domain/service/RssRepository.kt +++ b/app/src/main/java/me/ash/reader/domain/service/RssService.kt @@ -6,22 +6,22 @@ import me.ash.reader.domain.model.account.AccountType import me.ash.reader.ui.ext.currentAccountType import javax.inject.Inject -class RssRepository @Inject constructor( +class RssService @Inject constructor( @ApplicationContext private val context: Context, - private val localRssRepository: LocalRssRepository, - private val feverRssRepository: FeverRssRepository, + private val localRssService: LocalRssService, + private val feverRssService: FeverRssService, // private val googleReaderRssRepository: GoogleReaderRssRepository, ) { fun get() = get(context.currentAccountType) fun get(accountTypeId: Int) = when (accountTypeId) { - AccountType.Local.id -> localRssRepository - AccountType.Fever.id -> feverRssRepository - AccountType.GoogleReader.id -> localRssRepository - AccountType.Inoreader.id -> localRssRepository - AccountType.Feedly.id -> localRssRepository - else -> localRssRepository + AccountType.Local.id -> localRssService + AccountType.Fever.id -> feverRssService + AccountType.GoogleReader.id -> localRssService + AccountType.Inoreader.id -> localRssService + AccountType.Feedly.id -> localRssService + else -> localRssService } } diff --git a/app/src/main/java/me/ash/reader/domain/service/SyncWorker.kt b/app/src/main/java/me/ash/reader/domain/service/SyncWorker.kt index 9e2f8603d..38d3405c6 100644 --- a/app/src/main/java/me/ash/reader/domain/service/SyncWorker.kt +++ b/app/src/main/java/me/ash/reader/domain/service/SyncWorker.kt @@ -18,15 +18,15 @@ import java.util.concurrent.TimeUnit class SyncWorker @AssistedInject constructor( @Assisted context: Context, @Assisted workerParams: WorkerParameters, - private val accountRepository: AccountRepository, - private val rssRepository: RssRepository, + private val accountService: AccountService, + private val rssService: RssService, ) : CoroutineWorker(context, workerParams) { override suspend fun doWork(): Result = withContext(Dispatchers.Default) { Log.i("RLog", "doWork: ") - rssRepository.get().sync(this@SyncWorker).also { - rssRepository.get().clearKeepArchivedArticles() + rssService.get().sync(this@SyncWorker).also { + rssService.get().clearKeepArchivedArticles() } } diff --git a/app/src/main/java/me/ash/reader/RYApp.kt b/app/src/main/java/me/ash/reader/infrastructure/android/AndroidApp.kt similarity index 75% rename from app/src/main/java/me/ash/reader/RYApp.kt rename to app/src/main/java/me/ash/reader/infrastructure/android/AndroidApp.kt index 57442255b..82bfa2e00 100644 --- a/app/src/main/java/me/ash/reader/RYApp.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/android/AndroidApp.kt @@ -1,4 +1,4 @@ -package me.ash.reader +package me.ash.reader.infrastructure.android import android.app.Application import androidx.hilt.work.HiltWorkerFactory @@ -11,11 +11,12 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import me.ash.reader.domain.service.* +import me.ash.reader.infrastructure.db.AndroidDatabase import me.ash.reader.infrastructure.di.ApplicationScope import me.ash.reader.infrastructure.di.IODispatcher -import me.ash.reader.infrastructure.source.OPMLDataSource -import me.ash.reader.infrastructure.source.RYDatabase -import me.ash.reader.infrastructure.source.RYNetworkDataSource +import me.ash.reader.infrastructure.net.NetworkDataSource +import me.ash.reader.infrastructure.rss.OPMLDataSource +import me.ash.reader.infrastructure.rss.RssHelper import me.ash.reader.ui.ext.del import me.ash.reader.ui.ext.getLatestApk import me.ash.reader.ui.ext.isFdroid @@ -26,7 +27,7 @@ import javax.inject.Inject * The Application class, where the Dagger components is generated. */ @HiltAndroidApp -class RYApp : Application(), Configuration.Provider { +class AndroidApp : Application(), Configuration.Provider { /** * From: [Feeder](https://gitlab.com/spacecowboy/Feeder). @@ -39,7 +40,7 @@ class RYApp : Application(), Configuration.Provider { } @Inject - lateinit var ryDatabase: RYDatabase + lateinit var androidDatabase: AndroidDatabase @Inject lateinit var workerFactory: HiltWorkerFactory @@ -48,7 +49,7 @@ class RYApp : Application(), Configuration.Provider { lateinit var workManager: WorkManager @Inject - lateinit var ryNetworkDataSource: RYNetworkDataSource + lateinit var networkDataSource: NetworkDataSource @Inject lateinit var OPMLDataSource: OPMLDataSource @@ -60,22 +61,22 @@ class RYApp : Application(), Configuration.Provider { lateinit var notificationHelper: NotificationHelper @Inject - lateinit var ryRepository: RYRepository + lateinit var appService: AppService @Inject - lateinit var stringsRepository: StringsRepository + lateinit var androidStringsHelper: AndroidStringsHelper @Inject - lateinit var accountRepository: AccountRepository + lateinit var accountService: AccountService @Inject - lateinit var localRssRepository: LocalRssRepository + lateinit var localRssService: LocalRssService @Inject - lateinit var opmlRepository: OpmlRepository + lateinit var opmlService: OpmlService @Inject - lateinit var rssRepository: RssRepository + lateinit var rssService: RssService @Inject @ApplicationScope @@ -120,14 +121,14 @@ class RYApp : Application(), Configuration.Provider { private suspend fun accountInit() { withContext(ioDispatcher) { - if (accountRepository.isNoAccount()) { - accountRepository.addDefaultAccount() + if (accountService.isNoAccount()) { + accountService.addDefaultAccount() } } } private suspend fun workerInit() { - rssRepository.get().doSync(isOnStart = true) + rssService.get().doSync(isOnStart = true) } private suspend fun checkUpdate() { @@ -137,6 +138,6 @@ class RYApp : Application(), Configuration.Provider { if (it.exists()) it.del() } } - ryRepository.checkUpdate(showToast = false) + appService.checkUpdate(showToast = false) } } diff --git a/app/src/main/java/me/ash/reader/domain/service/StringsRepository.kt b/app/src/main/java/me/ash/reader/infrastructure/android/AndroidStringsHelper.kt similarity index 88% rename from app/src/main/java/me/ash/reader/domain/service/StringsRepository.kt rename to app/src/main/java/me/ash/reader/infrastructure/android/AndroidStringsHelper.kt index 24d83232f..aeac8afab 100644 --- a/app/src/main/java/me/ash/reader/domain/service/StringsRepository.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/android/AndroidStringsHelper.kt @@ -1,4 +1,4 @@ -package me.ash.reader.domain.service +package me.ash.reader.infrastructure.android import android.content.Context import dagger.hilt.android.qualifiers.ApplicationContext @@ -6,7 +6,7 @@ import me.ash.reader.ui.ext.formatAsString import java.util.* import javax.inject.Inject -class StringsRepository @Inject constructor( +class AndroidStringsHelper @Inject constructor( @ApplicationContext private val context: Context, ) { diff --git a/app/src/main/java/me/ash/reader/CrashHandler.kt b/app/src/main/java/me/ash/reader/infrastructure/android/CrashHandler.kt similarity index 96% rename from app/src/main/java/me/ash/reader/CrashHandler.kt rename to app/src/main/java/me/ash/reader/infrastructure/android/CrashHandler.kt index b57fcae1c..b8dd6fdec 100644 --- a/app/src/main/java/me/ash/reader/CrashHandler.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/android/CrashHandler.kt @@ -1,4 +1,4 @@ -package me.ash.reader +package me.ash.reader.infrastructure.android import android.content.Context import android.os.Looper diff --git a/app/src/main/java/me/ash/reader/MainActivity.kt b/app/src/main/java/me/ash/reader/infrastructure/android/MainActivity.kt similarity index 97% rename from app/src/main/java/me/ash/reader/MainActivity.kt rename to app/src/main/java/me/ash/reader/infrastructure/android/MainActivity.kt index e0966629b..95c06abac 100644 --- a/app/src/main/java/me/ash/reader/MainActivity.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/android/MainActivity.kt @@ -1,4 +1,4 @@ -package me.ash.reader +package me.ash.reader.infrastructure.android import android.os.Build import android.os.Bundle diff --git a/app/src/main/java/me/ash/reader/domain/service/NotificationHelper.kt b/app/src/main/java/me/ash/reader/infrastructure/android/NotificationHelper.kt similarity index 98% rename from app/src/main/java/me/ash/reader/domain/service/NotificationHelper.kt rename to app/src/main/java/me/ash/reader/infrastructure/android/NotificationHelper.kt index a75a303dc..669611ef7 100644 --- a/app/src/main/java/me/ash/reader/domain/service/NotificationHelper.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/android/NotificationHelper.kt @@ -1,4 +1,4 @@ -package me.ash.reader.domain.service +package me.ash.reader.infrastructure.android import android.app.* import android.content.Context @@ -7,7 +7,6 @@ import android.graphics.BitmapFactory import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import dagger.hilt.android.qualifiers.ApplicationContext -import me.ash.reader.MainActivity import me.ash.reader.R import me.ash.reader.domain.model.feed.FeedWithArticle import me.ash.reader.ui.page.common.ExtraName diff --git a/app/src/main/java/me/ash/reader/infrastructure/source/RYDatabase.kt b/app/src/main/java/me/ash/reader/infrastructure/db/AndroidDatabase.kt similarity index 93% rename from app/src/main/java/me/ash/reader/infrastructure/source/RYDatabase.kt rename to app/src/main/java/me/ash/reader/infrastructure/db/AndroidDatabase.kt index 6fdc5b004..d28d8edf3 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/source/RYDatabase.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/db/AndroidDatabase.kt @@ -1,4 +1,4 @@ -package me.ash.reader.infrastructure.source +package me.ash.reader.infrastructure.db import android.content.Context import androidx.room.* @@ -22,7 +22,7 @@ import java.util.* version = 5 ) @TypeConverters( - RYDatabase.DateConverters::class, + AndroidDatabase.DateConverters::class, AccountTypeConverters::class, SyncIntervalConverters::class, SyncOnStartConverters::class, @@ -31,7 +31,7 @@ import java.util.* KeepArchivedConverters::class, SyncBlockListConverters::class, ) -abstract class RYDatabase : RoomDatabase() { +abstract class AndroidDatabase : RoomDatabase() { abstract fun accountDao(): AccountDao abstract fun feedDao(): FeedDao @@ -40,13 +40,13 @@ abstract class RYDatabase : RoomDatabase() { companion object { - private var instance: RYDatabase? = null + private var instance: AndroidDatabase? = null - fun getInstance(context: Context): RYDatabase { + fun getInstance(context: Context): AndroidDatabase { return instance ?: synchronized(this) { instance ?: Room.databaseBuilder( context.applicationContext, - RYDatabase::class.java, + AndroidDatabase::class.java, "Reader" ).addMigrations(*allMigrations).build().also { instance = it diff --git a/app/src/main/java/me/ash/reader/infrastructure/di/DatabaseModule.kt b/app/src/main/java/me/ash/reader/infrastructure/di/DatabaseModule.kt index f73c2fe40..98e4dc522 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/di/DatabaseModule.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/di/DatabaseModule.kt @@ -10,7 +10,7 @@ import me.ash.reader.domain.repository.AccountDao import me.ash.reader.domain.repository.ArticleDao import me.ash.reader.domain.repository.FeedDao import me.ash.reader.domain.repository.GroupDao -import me.ash.reader.infrastructure.source.RYDatabase +import me.ash.reader.infrastructure.db.AndroidDatabase import javax.inject.Singleton /** @@ -27,26 +27,26 @@ object DatabaseModule { @Provides @Singleton - fun provideArticleDao(ryDatabase: RYDatabase): ArticleDao = - ryDatabase.articleDao() + fun provideArticleDao(androidDatabase: AndroidDatabase): ArticleDao = + androidDatabase.articleDao() @Provides @Singleton - fun provideFeedDao(ryDatabase: RYDatabase): FeedDao = - ryDatabase.feedDao() + fun provideFeedDao(androidDatabase: AndroidDatabase): FeedDao = + androidDatabase.feedDao() @Provides @Singleton - fun provideGroupDao(ryDatabase: RYDatabase): GroupDao = - ryDatabase.groupDao() + fun provideGroupDao(androidDatabase: AndroidDatabase): GroupDao = + androidDatabase.groupDao() @Provides @Singleton - fun provideAccountDao(ryDatabase: RYDatabase): AccountDao = - ryDatabase.accountDao() + fun provideAccountDao(androidDatabase: AndroidDatabase): AccountDao = + androidDatabase.accountDao() @Provides @Singleton - fun provideReaderDatabase(@ApplicationContext context: Context): RYDatabase = - RYDatabase.getInstance(context) + fun provideReaderDatabase(@ApplicationContext context: Context): AndroidDatabase = + AndroidDatabase.getInstance(context) } diff --git a/app/src/main/java/me/ash/reader/infrastructure/di/RetrofitModule.kt b/app/src/main/java/me/ash/reader/infrastructure/di/RetrofitModule.kt index eea7d9329..771cf80d7 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/di/RetrofitModule.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/di/RetrofitModule.kt @@ -4,13 +4,13 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import me.ash.reader.infrastructure.source.RYNetworkDataSource +import me.ash.reader.infrastructure.net.NetworkDataSource import javax.inject.Singleton /** * Provides network requests for Retrofit. * - * - [RYNetworkDataSource]: For network requests within the application + * - [NetworkDataSource]: For network requests within the application */ @Module @InstallIn(SingletonComponent::class) @@ -18,6 +18,6 @@ object RetrofitModule { @Provides @Singleton - fun provideAppNetworkDataSource(): RYNetworkDataSource = - RYNetworkDataSource.getInstance() + fun provideAppNetworkDataSource(): NetworkDataSource = + NetworkDataSource.getInstance() } diff --git a/app/src/main/java/me/ash/reader/infrastructure/source/RYNetworkDataSource.kt b/app/src/main/java/me/ash/reader/infrastructure/net/NetworkDataSource.kt similarity index 92% rename from app/src/main/java/me/ash/reader/infrastructure/source/RYNetworkDataSource.kt rename to app/src/main/java/me/ash/reader/infrastructure/net/NetworkDataSource.kt index 3c49c34f3..1f0f99687 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/source/RYNetworkDataSource.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/net/NetworkDataSource.kt @@ -1,4 +1,4 @@ -package me.ash.reader.infrastructure.source +package me.ash.reader.infrastructure.net import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow @@ -14,7 +14,7 @@ import retrofit2.http.Streaming import retrofit2.http.Url import java.io.File -interface RYNetworkDataSource { +interface NetworkDataSource { @GET suspend fun getReleaseLatest(@Url url: String): Response @@ -25,14 +25,14 @@ interface RYNetworkDataSource { companion object { - private var instance: RYNetworkDataSource? = null + private var instance: NetworkDataSource? = null - fun getInstance(): RYNetworkDataSource { + fun getInstance(): NetworkDataSource { return instance ?: synchronized(this) { instance ?: Retrofit.Builder() .baseUrl("https://github.com/") .addConverterFactory(GsonConverterFactory.create()) - .build().create(RYNetworkDataSource::class.java).also { + .build().create(NetworkDataSource::class.java).also { instance = it } } diff --git a/app/src/main/java/me/ash/reader/infrastructure/source/OPMLDataSource.kt b/app/src/main/java/me/ash/reader/infrastructure/rss/OPMLDataSource.kt similarity index 99% rename from app/src/main/java/me/ash/reader/infrastructure/source/OPMLDataSource.kt rename to app/src/main/java/me/ash/reader/infrastructure/rss/OPMLDataSource.kt index 67290420f..d0b34a91e 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/source/OPMLDataSource.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/rss/OPMLDataSource.kt @@ -1,4 +1,4 @@ -package me.ash.reader.infrastructure.source +package me.ash.reader.infrastructure.rss import android.content.Context import be.ceau.opml.OpmlParser diff --git a/app/src/main/java/me/ash/reader/domain/service/RssHelper.kt b/app/src/main/java/me/ash/reader/infrastructure/rss/RssHelper.kt similarity index 99% rename from app/src/main/java/me/ash/reader/domain/service/RssHelper.kt rename to app/src/main/java/me/ash/reader/infrastructure/rss/RssHelper.kt index cdc546bef..eff98a3f8 100644 --- a/app/src/main/java/me/ash/reader/domain/service/RssHelper.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/rss/RssHelper.kt @@ -1,4 +1,4 @@ -package me.ash.reader.domain.service +package me.ash.reader.infrastructure.rss import android.content.Context import android.text.Html diff --git a/app/src/main/java/me/ash/reader/infrastructure/provider/BaseAPI.kt b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/ProviderAPI.kt similarity index 87% rename from app/src/main/java/me/ash/reader/infrastructure/provider/BaseAPI.kt rename to app/src/main/java/me/ash/reader/infrastructure/rss/provider/ProviderAPI.kt index 77117fc63..d393b099d 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/provider/BaseAPI.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/ProviderAPI.kt @@ -1,4 +1,4 @@ -package me.ash.reader.infrastructure.provider +package me.ash.reader.infrastructure.rss.provider import com.google.gson.Gson import com.google.gson.GsonBuilder @@ -6,7 +6,7 @@ import me.ash.reader.infrastructure.di.UserAgentInterceptor import me.ash.reader.infrastructure.di.cachingHttpClient import okhttp3.OkHttpClient -abstract class BaseAPI { +abstract class ProviderAPI { protected val client: OkHttpClient = cachingHttpClient() .newBuilder() diff --git a/app/src/main/java/me/ash/reader/infrastructure/provider/fever/FeverAPI.kt b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverAPI.kt similarity index 97% rename from app/src/main/java/me/ash/reader/infrastructure/provider/fever/FeverAPI.kt rename to app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverAPI.kt index dc7c4893b..ba9e7b135 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/provider/fever/FeverAPI.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverAPI.kt @@ -1,6 +1,6 @@ -package me.ash.reader.infrastructure.provider.fever +package me.ash.reader.infrastructure.rss.provider.fever -import me.ash.reader.infrastructure.provider.BaseAPI +import me.ash.reader.infrastructure.rss.provider.ProviderAPI import me.ash.reader.ui.ext.encodeBase64 import me.ash.reader.ui.ext.md5 import okhttp3.FormBody @@ -13,7 +13,7 @@ class FeverAPI private constructor( private val apiKey: String, private val httpUsername: String? = null, private val httpPassword: String? = null, -) : BaseAPI() { +) : ProviderAPI() { private suspend inline fun postRequest(query: String?): T { val response = client.newCall( diff --git a/app/src/main/java/me/ash/reader/infrastructure/provider/fever/FeverDTO.kt b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverDTO.kt similarity index 98% rename from app/src/main/java/me/ash/reader/infrastructure/provider/fever/FeverDTO.kt rename to app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverDTO.kt index f9f274e82..ffe7f9864 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/provider/fever/FeverDTO.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverDTO.kt @@ -1,4 +1,4 @@ -package me.ash.reader.infrastructure.provider.fever +package me.ash.reader.infrastructure.rss.provider.fever object FeverDTO { diff --git a/app/src/main/java/me/ash/reader/infrastructure/source/GoogleReaderApiDto.kt b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/greader/GoogleReaderApiDto.kt similarity index 97% rename from app/src/main/java/me/ash/reader/infrastructure/source/GoogleReaderApiDto.kt rename to app/src/main/java/me/ash/reader/infrastructure/rss/provider/greader/GoogleReaderApiDto.kt index 706f43a90..6a5de97d9 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/source/GoogleReaderApiDto.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/greader/GoogleReaderApiDto.kt @@ -1,4 +1,4 @@ -package me.ash.reader.infrastructure.source +package me.ash.reader.infrastructure.rss.provider.greader object GoogleReaderApiDto { // subscription/list?output=json diff --git a/app/src/main/java/me/ash/reader/ui/page/home/HomeViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/HomeViewModel.kt index 2ac6ad77a..83ac2b61a 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/HomeViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/HomeViewModel.kt @@ -17,8 +17,8 @@ import me.ash.reader.domain.model.article.mapPagingFlowItem import me.ash.reader.domain.model.feed.Feed import me.ash.reader.domain.model.general.Filter import me.ash.reader.domain.model.group.Group -import me.ash.reader.domain.service.RssRepository -import me.ash.reader.domain.service.StringsRepository +import me.ash.reader.domain.service.RssService +import me.ash.reader.infrastructure.android.AndroidStringsHelper import me.ash.reader.domain.service.SyncWorker import me.ash.reader.infrastructure.di.ApplicationScope import me.ash.reader.infrastructure.di.IODispatcher @@ -26,8 +26,8 @@ import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( - private val rssRepository: RssRepository, - private val stringsRepository: StringsRepository, + private val rssService: RssService, + private val androidStringsHelper: AndroidStringsHelper, @ApplicationScope private val applicationScope: CoroutineScope, private val workManager: WorkManager, @@ -45,7 +45,7 @@ class HomeViewModel @Inject constructor( fun sync() { viewModelScope.launch(ioDispatcher) { - rssRepository.get().doSync() + rssService.get().doSync() } } @@ -70,7 +70,7 @@ class HomeViewModel @Inject constructor( ) ) { if (_homeUiState.value.searchContent.isNotBlank()) { - rssRepository.get().searchArticles( + rssService.get().searchArticles( content = _homeUiState.value.searchContent.trim(), groupId = _filterUiState.value.group?.id, feedId = _filterUiState.value.feed?.id, @@ -78,7 +78,7 @@ class HomeViewModel @Inject constructor( isUnread = _filterUiState.value.filter.isUnread(), ) } else { - rssRepository.get().pullArticles( + rssService.get().pullArticles( groupId = _filterUiState.value.group?.id, feedId = _filterUiState.value.feed?.id, isStarred = _filterUiState.value.filter.isStarred(), @@ -86,7 +86,7 @@ class HomeViewModel @Inject constructor( ) } }.flow.map { - it.mapPagingFlowItem(stringsRepository) + it.mapPagingFlowItem(androidStringsHelper) }.cachedIn(applicationScope) ) } diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt index 8deec82fc..94ef8d916 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt @@ -146,7 +146,7 @@ fun FeedsPage( ) { if (!isSyncing) homeViewModel.sync() } - if (subscribeViewModel.rssRepository.get().subscribe) { + if (subscribeViewModel.rssService.get().subscribe) { FeedbackIconButton( imageVector = Icons.Rounded.Add, contentDescription = stringResource(R.string.subscribe), diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsViewModel.kt index d480d3b83..866f0d48e 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsViewModel.kt @@ -11,9 +11,9 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import me.ash.reader.R import me.ash.reader.domain.model.account.Account -import me.ash.reader.domain.service.AccountRepository -import me.ash.reader.domain.service.RssRepository -import me.ash.reader.domain.service.StringsRepository +import me.ash.reader.domain.service.AccountService +import me.ash.reader.domain.service.RssService +import me.ash.reader.infrastructure.android.AndroidStringsHelper import me.ash.reader.infrastructure.di.DefaultDispatcher import me.ash.reader.infrastructure.di.IODispatcher import me.ash.reader.ui.page.home.FilterState @@ -21,9 +21,9 @@ import javax.inject.Inject @HiltViewModel class FeedsViewModel @Inject constructor( - private val accountRepository: AccountRepository, - private val rssRepository: RssRepository, - private val stringsRepository: StringsRepository, + private val accountService: AccountService, + private val rssService: RssService, + private val androidStringsHelper: AndroidStringsHelper, @DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher, @IODispatcher @@ -35,7 +35,7 @@ class FeedsViewModel @Inject constructor( fun fetchAccount() { viewModelScope.launch(ioDispatcher) { - _feedsUiState.update { it.copy(account = accountRepository.getCurrentAccount()) } + _feedsUiState.update { it.copy(account = accountService.getCurrentAccount()) } } } @@ -44,10 +44,10 @@ class FeedsViewModel @Inject constructor( val isUnread = filterState.filter.isUnread() _feedsUiState.update { it.copy( - importantSum = rssRepository.get().pullImportant(isStarred, isUnread) + importantSum = rssService.get().pullImportant(isStarred, isUnread) .mapLatest { (it["sum"] ?: 0).run { - stringsRepository.getQuantityString( + androidStringsHelper.getQuantityString( when { isStarred -> R.plurals.starred_desc isUnread -> R.plurals.unread_desc @@ -59,8 +59,8 @@ class FeedsViewModel @Inject constructor( } }.flowOn(defaultDispatcher), groupWithFeedList = combine( - rssRepository.get().pullImportant(isStarred, isUnread), - rssRepository.get().pullFeeds() + rssService.get().pullImportant(isStarred, isUnread), + rssService.get().pullFeeds() ) { importantMap, groupWithFeedList -> val groupIterator = groupWithFeedList.iterator() while (groupIterator.hasNext()) { diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/feed/FeedOptionDrawer.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/feed/FeedOptionDrawer.kt index bf3570f43..2e76b7b90 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/feed/FeedOptionDrawer.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/feed/FeedOptionDrawer.kt @@ -73,7 +73,7 @@ fun FeedOptionDrawer( Spacer(modifier = Modifier.height(16.dp)) Text( modifier = Modifier.roundClick { - if (feedOptionViewModel.rssRepository.get().update) { + if (feedOptionViewModel.rssService.get().update) { feedOptionViewModel.showRenameDialog() } }, @@ -92,8 +92,8 @@ fun FeedOptionDrawer( ?: false, selectedParseFullContentPreset = feedOptionUiState.feed?.isFullContent ?: false, isMoveToGroup = true, - showGroup = feedOptionViewModel.rssRepository.get().move, - showUnsubscribe = feedOptionViewModel.rssRepository.get().delete, + showGroup = feedOptionViewModel.rssService.get().move, + showUnsubscribe = feedOptionViewModel.rssService.get().delete, notSubscribeMode = true, selectedGroupId = feedOptionUiState.feed?.groupId ?: "", allowNotificationPresetOnClick = { @@ -118,7 +118,7 @@ fun FeedOptionDrawer( context.openURL(feed?.url, openLink, openLinkSpecificBrowser) }, onFeedUrlLongClick = { - if (feedOptionViewModel.rssRepository.get().update) { + if (feedOptionViewModel.rssService.get().update) { view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) feedOptionViewModel.showFeedUrlDialog() } diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/feed/FeedOptionViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/feed/FeedOptionViewModel.kt index 3a909ab34..098f9f12f 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/feed/FeedOptionViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/feed/FeedOptionViewModel.kt @@ -16,7 +16,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import me.ash.reader.domain.model.feed.Feed import me.ash.reader.domain.model.group.Group -import me.ash.reader.domain.service.RssRepository +import me.ash.reader.domain.service.RssService import me.ash.reader.infrastructure.di.IODispatcher import me.ash.reader.infrastructure.di.MainDispatcher import javax.inject.Inject @@ -24,7 +24,7 @@ import javax.inject.Inject @OptIn(ExperimentalMaterialApi::class) @HiltViewModel class FeedOptionViewModel @Inject constructor( - val rssRepository: RssRepository, + val rssService: RssService, @MainDispatcher private val mainDispatcher: CoroutineDispatcher, @IODispatcher @@ -36,14 +36,14 @@ class FeedOptionViewModel @Inject constructor( init { viewModelScope.launch(ioDispatcher) { - rssRepository.get().pullGroups().collect { groups -> + rssService.get().pullGroups().collect { groups -> _feedOptionUiState.update { it.copy(groups = groups) } } } } private suspend fun fetchFeed(feedId: String) { - val feed = rssRepository.get().findFeedById(feedId) + val feed = rssService.get().findFeedById(feedId) _feedOptionUiState.update { it.copy( feed = feed, @@ -88,7 +88,7 @@ class FeedOptionViewModel @Inject constructor( fun addNewGroup() { if (_feedOptionUiState.value.newGroupContent.isNotBlank()) { viewModelScope.launch { - selectedGroup(rssRepository.get().addGroup(_feedOptionUiState.value.newGroupContent)) + selectedGroup(rssService.get().addGroup(_feedOptionUiState.value.newGroupContent)) hideNewGroupDialog() } } @@ -97,7 +97,7 @@ class FeedOptionViewModel @Inject constructor( fun selectedGroup(groupId: String) { viewModelScope.launch(ioDispatcher) { _feedOptionUiState.value.feed?.let { - rssRepository.get().updateFeed(it.copy(groupId = groupId)) + rssService.get().updateFeed(it.copy(groupId = groupId)) fetchFeed(it.id) } } @@ -106,7 +106,7 @@ class FeedOptionViewModel @Inject constructor( fun changeParseFullContentPreset() { viewModelScope.launch(ioDispatcher) { _feedOptionUiState.value.feed?.let { - rssRepository.get().updateFeed(it.copy(isFullContent = !it.isFullContent)) + rssService.get().updateFeed(it.copy(isFullContent = !it.isFullContent)) fetchFeed(it.id) } } @@ -115,7 +115,7 @@ class FeedOptionViewModel @Inject constructor( fun changeAllowNotificationPreset() { viewModelScope.launch(ioDispatcher) { _feedOptionUiState.value.feed?.let { - rssRepository.get().updateFeed(it.copy(isNotification = !it.isNotification)) + rssService.get().updateFeed(it.copy(isNotification = !it.isNotification)) fetchFeed(it.id) } } @@ -124,7 +124,7 @@ class FeedOptionViewModel @Inject constructor( fun delete(callback: () -> Unit = {}) { _feedOptionUiState.value.feed?.let { viewModelScope.launch(ioDispatcher) { - rssRepository.get().deleteFeed(it) + rssService.get().deleteFeed(it) withContext(mainDispatcher) { callback() } @@ -151,7 +151,7 @@ class FeedOptionViewModel @Inject constructor( fun clearFeed(callback: () -> Unit = {}) { _feedOptionUiState.value.feed?.let { viewModelScope.launch(ioDispatcher) { - rssRepository.get().deleteArticles(feed = it) + rssService.get().deleteArticles(feed = it) withContext(mainDispatcher) { callback() } @@ -162,7 +162,7 @@ class FeedOptionViewModel @Inject constructor( fun renameFeed() { _feedOptionUiState.value.feed?.let { viewModelScope.launch { - rssRepository.get().updateFeed(it.copy(name = _feedOptionUiState.value.newName)) + rssService.get().updateFeed(it.copy(name = _feedOptionUiState.value.newName)) _feedOptionUiState.update { it.copy(renameDialogVisible = false) } } } @@ -215,7 +215,7 @@ class FeedOptionViewModel @Inject constructor( fun changeFeedUrl() { _feedOptionUiState.value.feed?.let { viewModelScope.launch { - rssRepository.get().updateFeed(it.copy(url = _feedOptionUiState.value.newUrl)) + rssService.get().updateFeed(it.copy(url = _feedOptionUiState.value.newUrl)) _feedOptionUiState.update { it.copy(changeUrlDialogVisible = false) } } } diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/group/GroupOptionDrawer.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/group/GroupOptionDrawer.kt index efa5d89d5..9b1449677 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/group/GroupOptionDrawer.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/group/GroupOptionDrawer.kt @@ -73,7 +73,7 @@ fun GroupOptionDrawer( Spacer(modifier = Modifier.height(16.dp)) Text( modifier = Modifier.roundClick { - if (viewModel.rssRepository.get().update) { + if (viewModel.rssService.get().update) { viewModel.showRenameDialog() } }, @@ -106,7 +106,7 @@ fun GroupOptionDrawer( Spacer(modifier = Modifier.height(10.dp)) Preset(viewModel, group, context) - if (viewModel.rssRepository.get().move && groupOptionUiState.groups.size != 1) { + if (viewModel.rssService.get().move && groupOptionUiState.groups.size != 1) { Spacer(modifier = Modifier.height(26.dp)) Subtitle(text = stringResource(R.string.move_to_group)) Spacer(modifier = Modifier.height(10.dp)) @@ -199,7 +199,7 @@ private fun Preset( ) { viewModel.showClearDialog() } - if (viewModel.rssRepository.get().delete && group?.id != context.currentAccountId.getDefaultGroupId()) { + if (viewModel.rssService.get().delete && group?.id != context.currentAccountId.getDefaultGroupId()) { RYSelectionChip( modifier = Modifier.animateContentSize(), content = stringResource(R.string.delete_group), diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/group/GroupOptionViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/group/GroupOptionViewModel.kt index 356cab07a..2ae8ea11b 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/group/GroupOptionViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/drawer/group/GroupOptionViewModel.kt @@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import me.ash.reader.domain.model.group.Group -import me.ash.reader.domain.service.RssRepository +import me.ash.reader.domain.service.RssService import me.ash.reader.infrastructure.di.IODispatcher import me.ash.reader.infrastructure.di.MainDispatcher import javax.inject.Inject @@ -23,7 +23,7 @@ import javax.inject.Inject @OptIn(ExperimentalMaterialApi::class) @HiltViewModel class GroupOptionViewModel @Inject constructor( - val rssRepository: RssRepository, + val rssService: RssService, @MainDispatcher private val mainDispatcher: CoroutineDispatcher, @IODispatcher @@ -35,7 +35,7 @@ class GroupOptionViewModel @Inject constructor( init { viewModelScope.launch(ioDispatcher) { - rssRepository.get().pullGroups().collect { groups -> + rssService.get().pullGroups().collect { groups -> _groupOptionUiState.update { it.copy(groups = groups) } } } @@ -43,7 +43,7 @@ class GroupOptionViewModel @Inject constructor( fun showDrawer(scope: CoroutineScope, groupId: String) { scope.launch { - _groupOptionUiState.update { it.copy(group = rssRepository.get().findGroupById(groupId)) } + _groupOptionUiState.update { it.copy(group = rssService.get().findGroupById(groupId)) } _groupOptionUiState.value.drawerState.show() } } @@ -55,7 +55,7 @@ class GroupOptionViewModel @Inject constructor( fun allAllowNotification(isNotification: Boolean, callback: () -> Unit = {}) { _groupOptionUiState.value.group?.let { viewModelScope.launch(ioDispatcher) { - rssRepository.get().groupAllowNotification(it, isNotification) + rssService.get().groupAllowNotification(it, isNotification) withContext(mainDispatcher) { callback() } @@ -74,7 +74,7 @@ class GroupOptionViewModel @Inject constructor( fun allParseFullContent(isFullContent: Boolean, callback: () -> Unit = {}) { _groupOptionUiState.value.group?.let { viewModelScope.launch(ioDispatcher) { - rssRepository.get().groupParseFullContent(it, isFullContent) + rssService.get().groupParseFullContent(it, isFullContent) withContext(mainDispatcher) { callback() } @@ -93,7 +93,7 @@ class GroupOptionViewModel @Inject constructor( fun delete(callback: () -> Unit = {}) { _groupOptionUiState.value.group?.let { viewModelScope.launch(ioDispatcher) { - rssRepository.get().deleteGroup(it) + rssService.get().deleteGroup(it) withContext(mainDispatcher) { callback() } @@ -120,7 +120,7 @@ class GroupOptionViewModel @Inject constructor( fun clear(callback: () -> Unit = {}) { _groupOptionUiState.value.group?.let { viewModelScope.launch(ioDispatcher) { - rssRepository.get().deleteArticles(group = it) + rssService.get().deleteArticles(group = it) withContext(mainDispatcher) { callback() } @@ -132,7 +132,7 @@ class GroupOptionViewModel @Inject constructor( _groupOptionUiState.value.group?.let { group -> _groupOptionUiState.value.targetGroup?.let { targetGroup -> viewModelScope.launch(ioDispatcher) { - rssRepository.get().groupMoveToTargetGroup(group, targetGroup) + rssService.get().groupMoveToTargetGroup(group, targetGroup) withContext(mainDispatcher) { callback() } @@ -162,7 +162,7 @@ class GroupOptionViewModel @Inject constructor( fun rename() { _groupOptionUiState.value.group?.let { viewModelScope.launch { - rssRepository.get().updateGroup(it.copy(name = _groupOptionUiState.value.newName)) + rssService.get().updateGroup(it.copy(name = _groupOptionUiState.value.newName)) _groupOptionUiState.update { it.copy(renameDialogVisible = false) } } } diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeViewModel.kt index 5fe53c556..9f470b503 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeViewModel.kt @@ -11,20 +11,20 @@ import me.ash.reader.R import me.ash.reader.domain.model.article.Article import me.ash.reader.domain.model.feed.Feed import me.ash.reader.domain.model.group.Group -import me.ash.reader.domain.service.OpmlRepository -import me.ash.reader.domain.service.RssHelper -import me.ash.reader.domain.service.RssRepository -import me.ash.reader.domain.service.StringsRepository +import me.ash.reader.infrastructure.android.AndroidStringsHelper +import me.ash.reader.domain.service.OpmlService +import me.ash.reader.domain.service.RssService +import me.ash.reader.infrastructure.rss.RssHelper import me.ash.reader.ui.ext.formatUrl import java.io.InputStream import javax.inject.Inject @HiltViewModel class SubscribeViewModel @Inject constructor( - private val opmlRepository: OpmlRepository, - val rssRepository: RssRepository, + private val opmlService: OpmlService, + val rssService: RssService, private val rssHelper: RssHelper, - private val stringsRepository: StringsRepository, + private val androidStringsHelper: AndroidStringsHelper, ) : ViewModel() { private val _subscribeUiState = MutableStateFlow(SubscribeUiState()) @@ -34,8 +34,8 @@ class SubscribeViewModel @Inject constructor( fun init() { _subscribeUiState.update { it.copy( - title = stringsRepository.getString(R.string.subscribe), - groups = rssRepository.get().pullGroups(), + title = androidStringsHelper.getString(R.string.subscribe), + groups = rssService.get().pullGroups(), ) } } @@ -44,15 +44,15 @@ class SubscribeViewModel @Inject constructor( searchJob?.cancel() searchJob = null _subscribeUiState.update { - SubscribeUiState().copy(title = stringsRepository.getString(R.string.subscribe)) + SubscribeUiState().copy(title = androidStringsHelper.getString(R.string.subscribe)) } } fun importFromInputStream(inputStream: InputStream) { viewModelScope.launch { try { - opmlRepository.saveToDatabase(inputStream) - rssRepository.get().doSync() + opmlService.saveToDatabase(inputStream) + rssService.get().doSync() } catch (e: Exception) { Log.e("FeedsViewModel", "importFromInputStream: ", e) } @@ -66,7 +66,7 @@ class SubscribeViewModel @Inject constructor( fun addNewGroup() { if (_subscribeUiState.value.newGroupContent.isNotBlank()) { viewModelScope.launch { - selectedGroup(rssRepository.get().addGroup(_subscribeUiState.value.newGroupContent)) + selectedGroup(rssService.get().addGroup(_subscribeUiState.value.newGroupContent)) hideNewGroupDialog() _subscribeUiState.update { it.copy(newGroupContent = "") } } @@ -105,15 +105,15 @@ class SubscribeViewModel @Inject constructor( } _subscribeUiState.update { it.copy( - title = stringsRepository.getString(R.string.searching), + title = androidStringsHelper.getString(R.string.searching), lockLinkInput = true, ) } - if (rssRepository.get().isFeedExist(_subscribeUiState.value.linkContent)) { + if (rssService.get().isFeedExist(_subscribeUiState.value.linkContent)) { _subscribeUiState.update { it.copy( - title = stringsRepository.getString(R.string.subscribe), - errorMessage = stringsRepository.getString(R.string.already_subscribed), + title = androidStringsHelper.getString(R.string.subscribe), + errorMessage = androidStringsHelper.getString(R.string.already_subscribed), lockLinkInput = false, ) } @@ -131,8 +131,8 @@ class SubscribeViewModel @Inject constructor( e.printStackTrace() _subscribeUiState.update { it.copy( - title = stringsRepository.getString(R.string.subscribe), - errorMessage = e.message ?: stringsRepository.getString(R.string.unknown), + title = androidStringsHelper.getString(R.string.subscribe), + errorMessage = e.message ?: androidStringsHelper.getString(R.string.unknown), lockLinkInput = false, ) } @@ -146,7 +146,7 @@ class SubscribeViewModel @Inject constructor( val feed = _subscribeUiState.value.feed ?: return val articles = _subscribeUiState.value.articles viewModelScope.launch { - rssRepository.get().subscribe( + rssService.get().subscribe( feed.copy( groupId = _subscribeUiState.value.selectedGroupId, isNotification = _subscribeUiState.value.allowNotificationPreset, diff --git a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowViewModel.kt index 1cea8eb1c..06f981999 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowViewModel.kt @@ -10,13 +10,13 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import me.ash.reader.domain.model.general.MarkAsReadConditions -import me.ash.reader.domain.service.RssRepository +import me.ash.reader.domain.service.RssService import me.ash.reader.infrastructure.di.IODispatcher import javax.inject.Inject @HiltViewModel class FlowViewModel @Inject constructor( - private val rssRepository: RssRepository, + private val rssService: RssService, @IODispatcher private val ioDispatcher: CoroutineDispatcher, ) : ViewModel() { @@ -26,7 +26,7 @@ class FlowViewModel @Inject constructor( fun sync() { viewModelScope.launch(ioDispatcher) { - rssRepository.get().doSync() + rssService.get().doSync() } } @@ -37,7 +37,7 @@ class FlowViewModel @Inject constructor( conditions: MarkAsReadConditions, ) { viewModelScope.launch { - rssRepository.get().markAsRead( + rssService.get().markAsRead( groupId = groupId, feedId = feedId, articleId = articleId, diff --git a/app/src/main/java/me/ash/reader/ui/page/home/reading/ReadingViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/reading/ReadingViewModel.kt index da5e00214..c5b920571 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/reading/ReadingViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/reading/ReadingViewModel.kt @@ -14,13 +14,13 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import me.ash.reader.domain.model.article.ArticleFlowItem import me.ash.reader.domain.model.article.ArticleWithFeed -import me.ash.reader.domain.service.RssHelper -import me.ash.reader.domain.service.RssRepository +import me.ash.reader.infrastructure.rss.RssHelper +import me.ash.reader.domain.service.RssService import javax.inject.Inject @HiltViewModel class ReadingViewModel @Inject constructor( - private val rssRepository: RssRepository, + private val rssService: RssService, private val rssHelper: RssHelper, ) : ViewModel() { @@ -31,7 +31,7 @@ class ReadingViewModel @Inject constructor( showLoading() viewModelScope.launch { _readingUiState.update { - it.copy(articleWithFeed = rssRepository.get().findArticleById(articleId)) + it.copy(articleWithFeed = rssService.get().findArticleById(articleId)) } _readingUiState.value.articleWithFeed?.let { if (it.feed.isFullContent) internalRenderFullContent() @@ -94,7 +94,7 @@ class ReadingViewModel @Inject constructor( ) ) } - rssRepository.get().markAsRead( + rssService.get().markAsRead( groupId = null, feedId = null, articleId = _readingUiState.value.articleWithFeed!!.article.id, @@ -116,7 +116,7 @@ class ReadingViewModel @Inject constructor( ) ) } - rssRepository.get().markAsStarred( + rssService.get().markAsStarred( articleId = articleWithFeed.article.id, isStarred = isStarred, ) diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/accounts/AccountViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/settings/accounts/AccountViewModel.kt index f585a90fa..e7524aa19 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/accounts/AccountViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/accounts/AccountViewModel.kt @@ -9,9 +9,9 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import me.ash.reader.domain.model.account.Account -import me.ash.reader.domain.service.AccountRepository -import me.ash.reader.domain.service.OpmlRepository -import me.ash.reader.domain.service.RssRepository +import me.ash.reader.domain.service.AccountService +import me.ash.reader.domain.service.OpmlService +import me.ash.reader.domain.service.RssService import me.ash.reader.infrastructure.di.DefaultDispatcher import me.ash.reader.infrastructure.di.IODispatcher import me.ash.reader.infrastructure.di.MainDispatcher @@ -19,9 +19,9 @@ import javax.inject.Inject @HiltViewModel class AccountViewModel @Inject constructor( - private val accountRepository: AccountRepository, - private val rssRepository: RssRepository, - private val opmlRepository: OpmlRepository, + private val accountService: AccountService, + private val rssService: RssService, + private val opmlService: OpmlService, @IODispatcher private val ioDispatcher: CoroutineDispatcher, @DefaultDispatcher @@ -32,24 +32,24 @@ class AccountViewModel @Inject constructor( private val _accountUiState = MutableStateFlow(AccountUiState()) val accountUiState: StateFlow = _accountUiState.asStateFlow() - val accounts = accountRepository.getAccounts() + val accounts = accountService.getAccounts() fun initData(accountId: Int) { viewModelScope.launch(ioDispatcher) { - _accountUiState.update { it.copy(selectedAccount = accountRepository.getAccountById(accountId)) } + _accountUiState.update { it.copy(selectedAccount = accountService.getAccountById(accountId)) } } } fun update(accountId: Int, block: Account.() -> Unit) { viewModelScope.launch(ioDispatcher) { - accountRepository.update(accountId, block) + accountService.update(accountId, block) } } fun exportAsOPML(accountId: Int, callback: (String) -> Unit = {}) { viewModelScope.launch(defaultDispatcher) { try { - callback(opmlRepository.saveToString(accountId)) + callback(opmlService.saveToString(accountId)) } catch (e: Exception) { Log.e("FeedsViewModel", "exportAsOpml: ", e) } @@ -74,7 +74,7 @@ class AccountViewModel @Inject constructor( fun delete(accountId: Int, callback: () -> Unit = {}) { viewModelScope.launch(ioDispatcher) { - accountRepository.delete(accountId) + accountService.delete(accountId) withContext(mainDispatcher) { callback() } @@ -83,7 +83,7 @@ class AccountViewModel @Inject constructor( fun clear(account: Account, callback: () -> Unit = {}) { viewModelScope.launch(ioDispatcher) { - rssRepository.get(account.type.id).deleteAccountArticles(account.id!!) + rssService.get(account.type.id).deleteAccountArticles(account.id!!) withContext(mainDispatcher) { callback() } @@ -92,9 +92,9 @@ class AccountViewModel @Inject constructor( fun addAccount(account: Account, callback: (Account?) -> Unit = {}) { viewModelScope.launch(ioDispatcher) { - val addAccount = accountRepository.addAccount(account) + val addAccount = accountService.addAccount(account) try { - if (rssRepository.get(addAccount.type.id).validCredentials()) { + if (rssService.get(addAccount.type.id).validCredentials()) { withContext(mainDispatcher) { callback(addAccount) } @@ -102,7 +102,7 @@ class AccountViewModel @Inject constructor( throw Exception("Unauthorized") } } catch (e: Exception) { - accountRepository.delete(account.id!!) + accountService.delete(account.id!!) withContext(mainDispatcher) { callback(null) } @@ -112,7 +112,7 @@ class AccountViewModel @Inject constructor( fun switchAccount(targetAccount: Account, callback: () -> Unit = {}) { viewModelScope.launch(ioDispatcher) { - accountRepository.switch(targetAccount) + accountService.switch(targetAccount) withContext(mainDispatcher) { callback() } diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/accounts/addition/AdditionViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/settings/accounts/addition/AdditionViewModel.kt index 9c3291c12..2108196ef 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/accounts/addition/AdditionViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/accounts/addition/AdditionViewModel.kt @@ -6,18 +6,18 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update -import me.ash.reader.domain.service.OpmlRepository -import me.ash.reader.domain.service.RssHelper -import me.ash.reader.domain.service.RssRepository -import me.ash.reader.domain.service.StringsRepository +import me.ash.reader.domain.service.OpmlService +import me.ash.reader.infrastructure.rss.RssHelper +import me.ash.reader.domain.service.RssService +import me.ash.reader.infrastructure.android.AndroidStringsHelper import javax.inject.Inject @HiltViewModel class AdditionViewModel @Inject constructor( - private val opmlRepository: OpmlRepository, - private val rssRepository: RssRepository, + private val opmlService: OpmlService, + private val rssService: RssService, private val rssHelper: RssHelper, - private val stringsRepository: StringsRepository, + private val androidStringsHelper: AndroidStringsHelper, ) : ViewModel() { private val _additionUiState = MutableStateFlow(AdditionUiState()) diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/tips/UpdateDialog.kt b/app/src/main/java/me/ash/reader/ui/page/settings/tips/UpdateDialog.kt index d2cbec4b6..9caef9e02 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/tips/UpdateDialog.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/tips/UpdateDialog.kt @@ -32,7 +32,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import kotlinx.coroutines.Dispatchers import me.ash.reader.R import me.ash.reader.infrastructure.preference.* -import me.ash.reader.infrastructure.source.Download +import me.ash.reader.infrastructure.net.Download import me.ash.reader.ui.component.base.RYDialog import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.installLatestApk diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/tips/UpdateViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/settings/tips/UpdateViewModel.kt index fec147a2a..eac6addae 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/tips/UpdateViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/tips/UpdateViewModel.kt @@ -5,14 +5,14 @@ import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch -import me.ash.reader.domain.service.RYRepository -import me.ash.reader.infrastructure.source.Download +import me.ash.reader.domain.service.AppService +import me.ash.reader.infrastructure.net.Download import me.ash.reader.ui.ext.notFdroid import javax.inject.Inject @HiltViewModel class UpdateViewModel @Inject constructor( - private val ryRepository: RYRepository, + private val appService: AppService, ) : ViewModel() { private val _updateUiState = MutableStateFlow(UpdateUiState()) @@ -25,7 +25,7 @@ class UpdateViewModel @Inject constructor( if (notFdroid) { viewModelScope.launch { preProcessor() - ryRepository.checkUpdate().let { + appService.checkUpdate().let { it?.let { if (it) { showDialog() @@ -64,7 +64,7 @@ class UpdateViewModel @Inject constructor( } _updateUiState.update { it.copy( - downloadFlow = ryRepository.downloadFile(url) + downloadFlow = appService.downloadFile(url) ) } }