diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/NewNextcloudNewsDataSource.kt b/api/src/main/java/com/readrops/api/services/nextcloudnews/NewNextcloudNewsDataSource.kt index e962abc6..d8607cda 100644 --- a/api/src/main/java/com/readrops/api/services/nextcloudnews/NewNextcloudNewsDataSource.kt +++ b/api/src/main/java/com/readrops/api/services/nextcloudnews/NewNextcloudNewsDataSource.kt @@ -80,12 +80,12 @@ class NewNextcloudNewsDataSource(private val service: NewNextcloudNewsService) { return service.createFeed(url, folderId) } - suspend fun changeFeedFolder(newFolderId: Int, feedId: Int) { + suspend fun changeFeedFolder(newFolderId: Int?, feedId: Int) { service.changeFeedFolder(feedId, mapOf("folderId" to newFolderId)) } - suspend fun renameFeed(name: String, folderId: Int) { - service.renameFeed(folderId, mapOf("feedTitle" to name)) + suspend fun renameFeed(name: String, feedId: Int) { + service.renameFeed(feedId, mapOf("feedTitle" to name)) } suspend fun deleteFeed(feedId: Int) { diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/NewNextcloudNewsService.kt b/api/src/main/java/com/readrops/api/services/nextcloudnews/NewNextcloudNewsService.kt index 9990f482..da99abb5 100644 --- a/api/src/main/java/com/readrops/api/services/nextcloudnews/NewNextcloudNewsService.kt +++ b/api/src/main/java/com/readrops/api/services/nextcloudnews/NewNextcloudNewsService.kt @@ -53,7 +53,7 @@ interface NewNextcloudNewsService { suspend fun deleteFeed(@Path("feedId") feedId: Int) @PUT("feeds/{feedId}/move") - suspend fun changeFeedFolder(@Path("feedId") feedId: Int, @Body folderIdMap: Map) + suspend fun changeFeedFolder(@Path("feedId") feedId: Int, @Body folderIdMap: Map) @PUT("feeds/{feedId}/rename") suspend fun renameFeed(@Path("feedId") feedId: Int, @Body feedTitleMap: Map) diff --git a/app/src/main/java/com/readrops/app/feedsfolders/feeds/EditFeedDialogFragment.java b/app/src/main/java/com/readrops/app/feedsfolders/feeds/EditFeedDialogFragment.java index 82e1bcfd..eb28c4f4 100644 --- a/app/src/main/java/com/readrops/app/feedsfolders/feeds/EditFeedDialogFragment.java +++ b/app/src/main/java/com/readrops/app/feedsfolders/feeds/EditFeedDialogFragment.java @@ -88,7 +88,7 @@ public class EditFeedDialogFragment extends DialogFragment implements AdapterVie viewModel.getFolders().observe(this, folders -> { values = new TreeMap<>(String::compareTo); - if (!account.getAccountType().getAccountConfig().isNoFolderCase()) + if (!account.getAccountType().getAccountConfig().getAddNoFolder()) values.put(getString(R.string.no_folder), 0); for (Folder folder : folders) { diff --git a/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedScreenModel.kt b/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedScreenModel.kt index bac67c21..8a563abb 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedScreenModel.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedScreenModel.kt @@ -54,7 +54,6 @@ class FeedScreenModel( _updateFeedDialogState.update { it.copy( isFeedUrlReadOnly = account.config.isFeedUrlReadOnly, - isNoFolderCase = account.config.isNoFolderCase ) } @@ -91,7 +90,6 @@ class FeedScreenModel( _updateFeedDialogState.update { it.copy( isFeedUrlReadOnly = account.config.isFeedUrlReadOnly, - isNoFolderCase = account.config.isNoFolderCase ) } @@ -101,7 +99,7 @@ class FeedScreenModel( .collect { folders -> _updateFeedDialogState.update { it.copy( - folders = if (!it.isNoFolderCase) { // TODO implement no folder case properly + folders = if (currentAccount!!.config.addNoFolder) { folders + listOf( Folder( id = 0, @@ -156,7 +154,8 @@ class FeedScreenModel( feedId = state.feed.id, feedName = state.feed.name!!, feedUrl = state.feed.url!!, - selectedFolder = state.folder + selectedFolder = state.folder ?: it.folders.find { folder -> folder.id == 0 }, + feedRemoteId = state.feed.remoteId ) } } @@ -336,8 +335,11 @@ class FeedScreenModel( id = feedId, name = feedName, url = feedUrl, - folderId = selectedFolder?.id, - remoteFolderId = selectedFolder?.remoteId + folderId = if (selectedFolder?.id != 0) + selectedFolder?.id + else null, + remoteFolderId = selectedFolder?.remoteId, + remoteId = feedRemoteId ) ) } catch (e: Exception) { diff --git a/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedState.kt b/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedState.kt index 23c87bcd..f0353310 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedState.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedState.kt @@ -41,6 +41,7 @@ data class AddFeedDialogState( data class UpdateFeedDialogState( val feedId: Int = 0, + val feedRemoteId: String? = null, val feedName: String = "", val feedNameError: TextFieldError? = null, val feedUrl: String = "", @@ -49,7 +50,6 @@ data class UpdateFeedDialogState( val folders: List = listOf(), val isAccountDropDownExpanded: Boolean = false, val isFeedUrlReadOnly: Boolean = true, - val isNoFolderCase: Boolean = false, val exception: Exception? = null ) { val isFeedNameError diff --git a/appcompose/src/main/java/com/readrops/app/compose/repositories/GetFoldersWithFeeds.kt b/appcompose/src/main/java/com/readrops/app/compose/repositories/GetFoldersWithFeeds.kt index 6a13a8e3..4689e67c 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/repositories/GetFoldersWithFeeds.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/repositories/GetFoldersWithFeeds.kt @@ -40,6 +40,7 @@ class GetFoldersWithFeeds( url = it.feedUrl, siteUrl = it.feedSiteUrl, description = it.feedDescription, + remoteId = it.feedRemoteId, unreadCount = itemCounts[it.feedId] ?: 0 ) } diff --git a/appcompose/src/main/java/com/readrops/app/compose/repositories/NextcloudNewsRepository.kt b/appcompose/src/main/java/com/readrops/app/compose/repositories/NextcloudNewsRepository.kt index 617f27e1..2d0930a0 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/repositories/NextcloudNewsRepository.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/repositories/NextcloudNewsRepository.kt @@ -80,7 +80,35 @@ class NextcloudNewsRepository( newFeeds: List, onUpdate: (Feed) -> Unit ): ErrorResult { - TODO("Not yet implemented") + val errors = mutableMapOf() + + for (newFeed in newFeeds) { + onUpdate(newFeed) + + try { + val feeds = dataSource.createFeed(newFeed.url!!, null) + insertFeeds(feeds) + } catch (e: Exception) { + errors[newFeed] = e + } + } + + return errors + } + + override suspend fun updateFeed(feed: Feed) { + val folder = + if (feed.folderId != null) database.newFolderDao().select(feed.folderId!!) else null + + dataSource.renameFeed(feed.name!!, feed.remoteId!!.toInt()) + dataSource.changeFeedFolder(folder?.remoteId?.toInt(), feed.remoteId!!.toInt()) + + super.updateFeed(feed) + } + + override suspend fun deleteFeed(feed: Feed) { + dataSource.deleteFeed(feed.remoteId!!.toInt()) + super.deleteFeed(feed) } private suspend fun insertFolders(folders: List) { diff --git a/appcompose/src/main/res/values-fr/strings.xml b/appcompose/src/main/res/values-fr/strings.xml index 0febef37..dec05c53 100644 --- a/appcompose/src/main/res/values-fr/strings.xml +++ b/appcompose/src/main/res/values-fr/strings.xml @@ -164,6 +164,6 @@ Erreur HTTP %1$d, veuillez vérifier vos champs Erreur HTTP %1$d, erreur serveur Erreur HTTP %1$d - L\'API de FreshRSS ne permet pas de modifier l\'URL + L\'API ne permet pas de modifier l\'URL Mise à jour du compte %1$s \ No newline at end of file diff --git a/appcompose/src/main/res/values/strings.xml b/appcompose/src/main/res/values/strings.xml index 2f422b9a..c9369076 100644 --- a/appcompose/src/main/res/values/strings.xml +++ b/appcompose/src/main/res/values/strings.xml @@ -170,6 +170,6 @@ HTTP error %1$d, please check your fields HTTP error %1$d, server error HTTP error %1$d - FreshRSS API doesn\'t support Feed URL modification + The API doesn\'t support Feed URL modification Updating %1$s account \ No newline at end of file diff --git a/db/src/main/java/com/readrops/db/dao/newdao/NewFolderDao.kt b/db/src/main/java/com/readrops/db/dao/newdao/NewFolderDao.kt index 06cc5aa3..276b5a1d 100644 --- a/db/src/main/java/com/readrops/db/dao/newdao/NewFolderDao.kt +++ b/db/src/main/java/com/readrops/db/dao/newdao/NewFolderDao.kt @@ -13,13 +13,13 @@ interface NewFolderDao : NewBaseDao { @Query(""" Select Feed.id As feedId, Feed.name As feedName, Feed.icon_url As feedIcon, Feed.url As feedUrl, - Feed.siteUrl As feedSiteUrl, Feed.description as feedDescription, Folder.id As folderId, + Feed.siteUrl As feedSiteUrl, Feed.description as feedDescription, Feed.remoteId as feedRemoteId, Folder.id As folderId, Folder.name As folderName, Feed.account_id as accountId, Folder.remoteId as folderRemoteId From Feed Left Join Folder On Folder.id = Feed.folder_id Where Feed.folder_id is NULL OR Feed.folder_id is NOT NULL And Feed.id is NULL Or Feed.id is NOT NULL And Feed.account_id = :accountId Group By Feed.id UNION ALL Select Feed.id As feedId, Feed.name As feedName, Feed.icon_url As feedIcon, Feed.url As feedUrl, - Feed.siteUrl As feedSiteUrl, Feed.description as feedDescription,Folder.id As folderId, + Feed.siteUrl As feedSiteUrl, Feed.description as feedDescription, Feed.remoteId as feedRemoteId, Folder.id As folderId, Folder.name As folderName, Folder.account_id as accountId, Folder.remoteId as folderRemoteId From Folder Left Join Feed On Folder.id = Feed.folder_id Where Feed.id is NULL And Folder.account_id = :accountId @@ -29,6 +29,9 @@ interface NewFolderDao : NewBaseDao { @Query("Select * From Folder Where account_id = :accountId") fun selectFolders(accountId: Int): Flow> + @Query("Select * from Folder Where id = :folderId") + fun select(folderId: Int): Folder + @Query("Select * From Folder Where name = :name And account_id = :accountId") suspend fun selectFolderByName(name: String, accountId: Int): Folder? diff --git a/db/src/main/java/com/readrops/db/entities/account/AccountConfig.kt b/db/src/main/java/com/readrops/db/entities/account/AccountConfig.kt index 3c58e078..c5451410 100644 --- a/db/src/main/java/com/readrops/db/entities/account/AccountConfig.kt +++ b/db/src/main/java/com/readrops/db/entities/account/AccountConfig.kt @@ -7,32 +7,29 @@ import kotlinx.parcelize.Parcelize data class AccountConfig( val isFeedUrlReadOnly: Boolean, // Enable or disable feed url modification in Feed Tab val canCreateFolder: Boolean, // Enable or disable folder creation in Feed Tab - val isNoFolderCase: Boolean, // Add a "No folder" option when modifying a feed's folder TODO add better name + val addNoFolder: Boolean, // Add a "No folder" option when modifying a feed's folder val useSeparateState: Boolean, // Let know if it uses ItemState table to synchronize read/star state ) : Parcelable { companion object { - @JvmField val LOCAL = AccountConfig( isFeedUrlReadOnly = false, canCreateFolder = true, - isNoFolderCase = false, + addNoFolder = true, useSeparateState = false, ) - @JvmField val NEXTCLOUD_NEWS = AccountConfig( - isFeedUrlReadOnly = false, + isFeedUrlReadOnly = true, canCreateFolder = true, - isNoFolderCase = false, + addNoFolder = true, useSeparateState = false, ) - @JvmField val FRESHRSS = AccountConfig( isFeedUrlReadOnly = true, canCreateFolder = false, - isNoFolderCase = true, + addNoFolder = false, useSeparateState = true, ) } diff --git a/db/src/main/java/com/readrops/db/pojo/FeedWithFolder.kt b/db/src/main/java/com/readrops/db/pojo/FeedWithFolder.kt index a6bb950d..9090d754 100644 --- a/db/src/main/java/com/readrops/db/pojo/FeedWithFolder.kt +++ b/db/src/main/java/com/readrops/db/pojo/FeedWithFolder.kt @@ -22,6 +22,7 @@ data class FolderWithFeed( val feedUrl: String? = null, val feedDescription: String? = null, val feedSiteUrl: String? = null, + val feedRemoteId: String? = null, val accountId: Int = 0 )