network: make ApiRetrofitService compute the feed icon url
authorDa Risk <da_risk@geekorum.com>
Tue, 03 Sep 2019 21:05:48 -0700
changeset 443 9cb8d61238b2
parent 442 ac6f8122d89f
child 444 c3593eabbbd1
network: make ApiRetrofitService compute the feed icon url
app/src/main/java/com/geekorum/ttrss/network/ApiRetrofitService.kt
app/src/main/java/com/geekorum/ttrss/network/TinyrssApiModule.java
--- a/app/src/main/java/com/geekorum/ttrss/network/ApiRetrofitService.kt	Tue Sep 03 19:53:28 2019 -0700
+++ b/app/src/main/java/com/geekorum/ttrss/network/ApiRetrofitService.kt	Tue Sep 03 21:05:48 2019 -0700
@@ -20,6 +20,7 @@
  */
 package com.geekorum.ttrss.network
 
+import com.geekorum.ttrss.accounts.ServerInformation
 import com.geekorum.ttrss.data.Article
 import com.geekorum.ttrss.data.ArticleContentIndexed
 import com.geekorum.ttrss.data.Category
@@ -50,7 +51,8 @@
  */
 class ApiRetrofitService(
     tokenRetriever: TokenRetriever,
-    private val tinyrssApi: TinyRssApi
+    private val tinyrssApi: TinyRssApi,
+    private val serverInformation: ServerInformation
 ) : ApiService {
 
     private val helper = RetrofitServiceHelper(tokenRetriever)
@@ -100,11 +102,18 @@
     override suspend fun getFeeds(): List<Feed> {
         val payload = GetFeedsRequestPayload(true, false,
                     GetFeedsRequestPayload.CATEGORY_ID_ALL_EXCLUDE_VIRTUALS)
+        val getConfigResponsePayload = executeOrFail("Unable to get feeds icons url") {
+            tinyrssApi.getConfig(GetConfigRequestPayload())
+        }
+        val baseFeedsIconsUrl = "${serverInformation.apiUrl}${getConfigResponsePayload.iconsUrl}"
         val response = executeOrFail("Unable to get feeds") {
             tinyrssApi.getFeeds(payload)
         }
         val feedlist = response.result
         return feedlist.map { it.toDataType() }
+            .map {
+                it.copy(feedIconUrl = "$baseFeedsIconsUrl/${it.id}.ico")
+            }
     }
 
     @Throws(ApiCallException::class)
--- a/app/src/main/java/com/geekorum/ttrss/network/TinyrssApiModule.java	Tue Sep 03 19:53:28 2019 -0700
+++ b/app/src/main/java/com/geekorum/ttrss/network/TinyrssApiModule.java	Tue Sep 03 21:05:48 2019 -0700
@@ -49,8 +49,8 @@
     abstract LoggedRequestInterceptorFactory bindLoggedRequestInterceptorFactory();
 
     @Provides
-    static ApiService provideApiService(TokenRetriever tokenRetriever, TinyRssApi tinyRssApi) {
-        return new ApiRetrofitService(tokenRetriever, tinyRssApi);
+    static ApiService provideApiService(TokenRetriever tokenRetriever, TinyRssApi tinyRssApi, ServerInformation serverInformation) {
+        return new ApiRetrofitService(tokenRetriever, tinyRssApi, serverInformation);
     }
 
     @Provides