mirror of https://github.com/readrops/Readrops.git
Remove moshi codegen, use manual adapters instead
This commit is contained in:
parent
11011010bf
commit
3c752b777a
|
@ -59,18 +59,16 @@ dependencies {
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
||||||
|
|
||||||
implementation('com.squareup.retrofit2:retrofit:2.9.0') {
|
implementation('com.squareup.retrofit2:retrofit:2.9.0') {
|
||||||
exclude group: 'okhttp3', module: 'okhttp3'
|
exclude group: 'com.squareup.okhttp3', module: 'okhttp3'
|
||||||
}
|
}
|
||||||
implementation('com.squareup.retrofit2:converter-moshi:2.9.0') {
|
implementation('com.squareup.retrofit2:converter-moshi:2.9.0') {
|
||||||
exclude group: 'moshi', module: 'moshi' // moshi converter uses moshi 1.8.0 which breaks codegen 1.9.2
|
exclude group: 'com.squareup.moshi', module: 'moshi'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation ('com.squareup.retrofit2:converter-simplexml:2.9.0')
|
implementation 'com.squareup.retrofit2:converter-simplexml:2.9.0'
|
||||||
|
|
||||||
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
|
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
|
||||||
|
|
||||||
implementation 'com.squareup.moshi:moshi:1.12.0'
|
implementation 'com.squareup.moshi:moshi:1.12.0'
|
||||||
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.12.0'
|
|
||||||
|
|
||||||
api 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
api 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
||||||
api 'org.jsoup:jsoup:1.13.1'
|
api 'org.jsoup:jsoup:1.13.1'
|
||||||
|
|
|
@ -5,10 +5,7 @@ import com.readrops.api.localfeed.LocalRSSDataSource
|
||||||
import com.readrops.api.services.Credentials
|
import com.readrops.api.services.Credentials
|
||||||
import com.readrops.api.services.freshrss.FreshRSSDataSource
|
import com.readrops.api.services.freshrss.FreshRSSDataSource
|
||||||
import com.readrops.api.services.freshrss.FreshRSSService
|
import com.readrops.api.services.freshrss.FreshRSSService
|
||||||
import com.readrops.api.services.freshrss.adapters.FreshRSSFeedsAdapter
|
import com.readrops.api.services.freshrss.adapters.*
|
||||||
import com.readrops.api.services.freshrss.adapters.FreshRSSFoldersAdapter
|
|
||||||
import com.readrops.api.services.freshrss.adapters.FreshRSSItemsAdapter
|
|
||||||
import com.readrops.api.services.freshrss.adapters.FreshRSSItemsIdsAdapter
|
|
||||||
import com.readrops.api.services.nextcloudnews.NextNewsDataSource
|
import com.readrops.api.services.nextcloudnews.NextNewsDataSource
|
||||||
import com.readrops.api.services.nextcloudnews.NextNewsService
|
import com.readrops.api.services.nextcloudnews.NextNewsService
|
||||||
import com.readrops.api.services.nextcloudnews.adapters.NextNewsFeedsAdapter
|
import com.readrops.api.services.nextcloudnews.adapters.NextNewsFeedsAdapter
|
||||||
|
@ -65,6 +62,7 @@ val apiModule = module {
|
||||||
.add(Types.newParameterizedType(List::class.java, String::class.java), FreshRSSItemsIdsAdapter())
|
.add(Types.newParameterizedType(List::class.java, String::class.java), FreshRSSItemsIdsAdapter())
|
||||||
.add(FreshRSSFeedsAdapter())
|
.add(FreshRSSFeedsAdapter())
|
||||||
.add(FreshRSSFoldersAdapter())
|
.add(FreshRSSFoldersAdapter())
|
||||||
|
.add(FreshRSSUserInfoAdapter())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.readrops.api.services.SyncResult;
|
import com.readrops.api.services.SyncResult;
|
||||||
import com.readrops.api.services.SyncType;
|
import com.readrops.api.services.SyncType;
|
||||||
import com.readrops.api.services.freshrss.json.FreshRSSUserInfo;
|
import com.readrops.api.services.freshrss.adapters.FreshRSSUserInfo;
|
||||||
import com.readrops.db.entities.Feed;
|
import com.readrops.db.entities.Feed;
|
||||||
import com.readrops.db.entities.Folder;
|
import com.readrops.db.entities.Folder;
|
||||||
import com.readrops.db.entities.Item;
|
import com.readrops.db.entities.Item;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.readrops.api.services.freshrss;
|
package com.readrops.api.services.freshrss;
|
||||||
|
|
||||||
import com.readrops.api.services.freshrss.json.FreshRSSUserInfo;
|
import com.readrops.api.services.freshrss.adapters.FreshRSSUserInfo;
|
||||||
import com.readrops.db.entities.Feed;
|
import com.readrops.db.entities.Feed;
|
||||||
import com.readrops.db.entities.Folder;
|
import com.readrops.db.entities.Folder;
|
||||||
import com.readrops.db.entities.Item;
|
import com.readrops.db.entities.Item;
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.readrops.api.services.freshrss.adapters
|
||||||
|
|
||||||
|
import com.readrops.api.utils.exceptions.ParseException
|
||||||
|
import com.readrops.api.utils.extensions.nextNullableString
|
||||||
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.JsonReader
|
||||||
|
import com.squareup.moshi.ToJson
|
||||||
|
|
||||||
|
data class FreshRSSUserInfo(
|
||||||
|
val userName: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
class FreshRSSUserInfoAdapter {
|
||||||
|
|
||||||
|
@ToJson
|
||||||
|
fun toJson(userInfo: FreshRSSUserInfo) = ""
|
||||||
|
|
||||||
|
@FromJson
|
||||||
|
fun fromJson(reader: JsonReader): FreshRSSUserInfo = with(reader) {
|
||||||
|
var userName: String? = null
|
||||||
|
|
||||||
|
return try {
|
||||||
|
beginObject()
|
||||||
|
|
||||||
|
while (hasNext()) {
|
||||||
|
when (nextName()) {
|
||||||
|
"userName" -> userName = nextNullableString()
|
||||||
|
else -> skipValue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endObject()
|
||||||
|
FreshRSSUserInfo(userName)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
throw ParseException(e.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
package com.readrops.api.services.freshrss.json
|
|
||||||
|
|
||||||
import com.squareup.moshi.JsonClass
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
|
||||||
data class FreshRSSUserInfo(val userEmail: String,
|
|
||||||
val userId: String,
|
|
||||||
val userName: String,
|
|
||||||
val userProfileId: String)
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.readrops.api.services.freshrss.adapters
|
||||||
|
|
||||||
|
import com.readrops.api.TestUtils
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import junit.framework.TestCase.assertEquals
|
||||||
|
import okio.Buffer
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class FreshRSSUserInfoAdapterTest {
|
||||||
|
|
||||||
|
private val adapter = Moshi.Builder()
|
||||||
|
.add(FreshRSSUserInfoAdapter())
|
||||||
|
.build()
|
||||||
|
.adapter(FreshRSSUserInfo::class.java)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun userInfoTest() {
|
||||||
|
val stream = TestUtils.loadResource("services/freshrss/adapters/user_info.json")
|
||||||
|
|
||||||
|
val userInfo = adapter.fromJson(Buffer().readFrom(stream))!!
|
||||||
|
|
||||||
|
assertEquals(userInfo.userName, "test")
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"userId": "test",
|
||||||
|
"userName": "test",
|
||||||
|
"userProfileId": "test",
|
||||||
|
"userEmail": ""
|
||||||
|
}
|
Loading…
Reference in New Issue