mirror of https://github.com/readrops/Readrops.git
Add basic Fever synchronisation with feeds and folders insertion
This commit is contained in:
parent
0885a9a3e4
commit
64b6fb0b4d
|
@ -5,6 +5,7 @@ import com.readrops.api.localfeed.LocalRSSDataSource
|
|||
import com.readrops.api.services.Credentials
|
||||
import com.readrops.api.services.fever.FeverDataSource
|
||||
import com.readrops.api.services.fever.FeverService
|
||||
import com.readrops.api.services.fever.adapters.*
|
||||
import com.readrops.api.services.freshrss.FreshRSSDataSource
|
||||
import com.readrops.api.services.freshrss.FreshRSSService
|
||||
import com.readrops.api.services.freshrss.adapters.*
|
||||
|
@ -98,9 +99,21 @@ val apiModule = module {
|
|||
Retrofit.Builder()
|
||||
.baseUrl(credentials.url)
|
||||
.client(get())
|
||||
.addConverterFactory(MoshiConverterFactory.create(get(named("feverMoshi"))))
|
||||
.build()
|
||||
.create(FeverService::class.java)
|
||||
}
|
||||
|
||||
single(named("feverMoshi")) {
|
||||
Moshi.Builder()
|
||||
.add(FeverFoldersAdapter())
|
||||
.add(FeverFeedsAdapter())
|
||||
.add(FeverItemsAdapter())
|
||||
.add(FeverFaviconsAdapter())
|
||||
.add(Boolean::class.java, FeverAPIAdapter())
|
||||
.add(FeverItemsIdsAdapter())
|
||||
.build()
|
||||
}
|
||||
|
||||
//endregion Fever
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package com.readrops.api.services.fever
|
||||
|
||||
import com.readrops.api.services.SyncResult
|
||||
import com.readrops.api.services.fever.adapters.FeverAPIAdapter
|
||||
import com.readrops.api.utils.ApiUtils
|
||||
import com.readrops.db.entities.Feed
|
||||
import com.squareup.moshi.Moshi
|
||||
import okhttp3.MultipartBody
|
||||
|
||||
|
@ -26,5 +26,13 @@ class FeverDataSource(private val service: FeverService) {
|
|||
adapter.fromJson(response.source())!!
|
||||
}
|
||||
|
||||
suspend fun getFeeds(): List<Feed> = service.getFeeds()
|
||||
suspend fun sync(body: MultipartBody): SyncResult {
|
||||
return SyncResult(
|
||||
feeds = service.getFeeds(body),
|
||||
folders = service.getFolders(body),
|
||||
items = service.getItems(body),
|
||||
unreadIds = service.getUnreadItemsIds(body),
|
||||
starredIds = service.getStarredItemsIds(body),
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.readrops.api.services.fever
|
||||
|
||||
import com.readrops.api.services.fever.adapters.Favicon
|
||||
import com.readrops.db.entities.Feed
|
||||
import com.readrops.db.entities.Folder
|
||||
import com.readrops.db.entities.Item
|
||||
|
@ -15,27 +16,20 @@ interface FeverService {
|
|||
suspend fun login(@Body body: MultipartBody): ResponseBody
|
||||
|
||||
@POST("?feeds")
|
||||
suspend fun getFeeds(): List<Feed>
|
||||
suspend fun getFeeds(@Body body: MultipartBody): List<Feed>
|
||||
|
||||
@get:POST("?groups")
|
||||
val folders: List<Folder>
|
||||
@POST("?groups")
|
||||
suspend fun getFolders(@Body body: MultipartBody): List<Folder>
|
||||
|
||||
@get:GET("?favicons")
|
||||
val favicons: Unit
|
||||
@POST("?favicons")
|
||||
suspend fun getFavicons(@Body body: MultipartBody): List<Favicon>
|
||||
|
||||
@POST("?items")
|
||||
suspend fun items(): List<Item>
|
||||
suspend fun getItems(@Body body: MultipartBody): List<Item>
|
||||
|
||||
@POST("?unread_item_ids")
|
||||
suspend fun unreadItemsIds(): List<String>
|
||||
suspend fun getUnreadItemsIds(@Body body: MultipartBody): List<String>
|
||||
|
||||
@POST("?saved_item_ids")
|
||||
suspend fun starredItemsIds()
|
||||
|
||||
@get:GET("?api")
|
||||
val api: Unit
|
||||
|
||||
companion object {
|
||||
const val END_POINT = ""
|
||||
}
|
||||
suspend fun getStarredItemsIds(@Body body: MultipartBody): List<String>
|
||||
}
|
|
@ -1,17 +1,22 @@
|
|||
package com.readrops.app.repositories
|
||||
|
||||
import android.content.Context
|
||||
import com.readrops.api.services.SyncType
|
||||
import com.readrops.api.services.fever.FeverDataSource
|
||||
import com.readrops.api.utils.ApiUtils
|
||||
import com.readrops.app.addfeed.FeedInsertionResult
|
||||
import com.readrops.app.addfeed.ParsingResult
|
||||
import com.readrops.db.Database
|
||||
import com.readrops.db.entities.Feed
|
||||
import com.readrops.db.entities.Folder
|
||||
import com.readrops.db.entities.Item
|
||||
import com.readrops.db.entities.account.Account
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Single
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.rx2.await
|
||||
import kotlinx.coroutines.rx2.rxCompletable
|
||||
import okhttp3.MultipartBody
|
||||
|
||||
class FeverRepository(
|
||||
private val feverDataSource: FeverDataSource,
|
||||
|
@ -38,11 +43,49 @@ class FeverRepository(
|
|||
|
||||
override fun sync(feeds: List<Feed>?, update: FeedUpdate?): Completable {
|
||||
return rxCompletable(context = dispatcher) {
|
||||
try {
|
||||
val syncType = if (account.lastModified != 0L) {
|
||||
SyncType.CLASSIC_SYNC
|
||||
} else {
|
||||
SyncType.INITIAL_SYNC
|
||||
}
|
||||
|
||||
val credentials = ApiUtils.md5hash("${account.login}:${account.password}")
|
||||
|
||||
val requestBody = MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.addFormDataPart("api_key", credentials)
|
||||
.build()
|
||||
|
||||
val syncResult = feverDataSource.sync(requestBody)
|
||||
|
||||
insertFolders(syncResult.folders)
|
||||
insertFeeds(syncResult.feeds)
|
||||
} catch (e: Exception) {
|
||||
error(e.message!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun addFeeds(results: List<ParsingResult>?): Single<List<FeedInsertionResult>> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
private fun insertFolders(folders: List<Folder>) {
|
||||
folders.forEach { it.accountId = account.id }
|
||||
database.folderDao().foldersUpsert(folders, account)
|
||||
}
|
||||
|
||||
private fun insertFeeds(feeds: List<Feed>) {
|
||||
feeds.forEach { it.accountId = account.id }
|
||||
database.feedDao().feedsUpsert(feeds, account)
|
||||
}
|
||||
|
||||
private fun insertItems(items: List<Item>) {
|
||||
|
||||
}
|
||||
|
||||
private fun insertItemsIds(unreadIds: List<String>, starredIds: List<String>) {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue