From 554b8df9d0898501e942fa1b0277104763555681 Mon Sep 17 00:00:00 2001 From: davide Date: Sat, 13 Aug 2022 17:11:07 +0200 Subject: [PATCH] Remove direct api access from the home activity --- .../readerforselfossv2/android/HomeActivity.kt | 16 +--------------- .../android/adapters/ItemCardAdapter.kt | 10 ++++------ .../android/adapters/ItemListAdapter.kt | 10 ++++------ .../android/adapters/ItemsAdapter.kt | 2 -- 4 files changed, 9 insertions(+), 29 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt index 89f0558..7aa54df 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt @@ -48,9 +48,7 @@ import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailabl import bou.amine.apps.readerforselfossv2.android.utils.persistence.toEntity import bou.amine.apps.readerforselfossv2.android.utils.persistence.toView import bou.amine.apps.readerforselfossv2.repository.Repository -import bou.amine.apps.readerforselfossv2.rest.SelfossApiImpl import bou.amine.apps.readerforselfossv2.rest.SelfossModel -import bou.amine.apps.readerforselfossv2.service.ApiDetailsService import bou.amine.apps.readerforselfossv2.service.SearchService import bou.amine.apps.readerforselfossv2.utils.DateUtils import bou.amine.apps.readerforselfossv2.utils.longHash @@ -124,7 +122,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar private lateinit var tabNewBadge: TextBadgeItem private lateinit var tabArchiveBadge: TextBadgeItem private lateinit var tabStarredBadge: TextBadgeItem - private lateinit var api: SelfossApiImpl private lateinit var customTabActivityHelper: CustomTabActivityHelper private lateinit var appColors: AppColors private var offset: Int = 0 @@ -145,7 +142,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar private lateinit var config: Config override val di by closestDI() - private val apiDetailsService : ApiDetailsService by instance() private val repository : Repository by instance() data class DrawerData(val tags: List?, val sources: List?) @@ -189,14 +185,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar customTabActivityHelper = CustomTabActivityHelper() - api = SelfossApiImpl( -// this, -// this@HomeActivity, -// settings.getBoolean("isSelfSignedCert", false), -// sharedPref.getString("api_timeout", "-1")!!.toLong() - apiDetailsService - ) - dataBase = AndroidDeviceDatabase(applicationContext) searchService = SearchService(DateUtils(repository.apiMajorVersion)) dbService = AndroidDeviceDatabaseService(dataBase, searchService) @@ -615,7 +603,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar val item = PrimaryDrawerItem().apply { nameText = source.getTitleDecoded() identifier = source.id.toLong() - iconUrl = source.getIcon(apiDetailsService.getBaseUrl()) + iconUrl = source.getIcon(repository.baseUrl) onDrawerItemClickListener = { _,_,_ -> searchService.sourceIDFilter = source.id.toLong() searchService.sourceFilter = source.title @@ -989,7 +977,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar ItemCardAdapter( this, items, - apiDetailsService, db, customTabActivityHelper, internalBrowser, @@ -1007,7 +994,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar ItemListAdapter( this, items, - apiDetailsService, db, customTabActivityHelper, internalBrowser, diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt index 949acfc..146df82 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt @@ -19,7 +19,6 @@ import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawa import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailable import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.rest.SelfossModel -import bou.amine.apps.readerforselfossv2.service.ApiDetailsService import bou.amine.apps.readerforselfossv2.service.SearchService import bou.amine.apps.readerforselfossv2.utils.DateUtils import com.amulyakhare.textdrawable.TextDrawable @@ -35,7 +34,6 @@ import org.kodein.di.instance class ItemCardAdapter( override val app: Activity, override var items: ArrayList, - override val apiDetailsService: ApiDetailsService, override val db: AppDatabase, private val helper: CustomTabActivityHelper, private val internalBrowser: Boolean, @@ -78,16 +76,16 @@ class ItemCardAdapter( binding.itemImage.scaleType = ScaleType.CENTER_CROP } - if (itm.getThumbnail(apiDetailsService.getBaseUrl()).isEmpty()) { + if (itm.getThumbnail(repository.baseUrl).isEmpty()) { binding.itemImage.visibility = View.GONE Glide.with(c).clear(binding.itemImage) binding.itemImage.setImageDrawable(null) } else { binding.itemImage.visibility = View.VISIBLE - c.bitmapCenterCrop(config, itm.getThumbnail(apiDetailsService.getBaseUrl()), binding.itemImage) + c.bitmapCenterCrop(config, itm.getThumbnail(repository.baseUrl), binding.itemImage) } - if (itm.getIcon(apiDetailsService.getBaseUrl()).isEmpty()) { + if (itm.getIcon(repository.baseUrl).isEmpty()) { val color = generator.getColor(itm.getSourceTitle()) val drawable = @@ -97,7 +95,7 @@ class ItemCardAdapter( .build(itm.getSourceTitle().toTextDrawableString(c), color) binding.sourceImage.setImageDrawable(drawable) } else { - c.circularBitmapDrawable(config, itm.getIcon(apiDetailsService.getBaseUrl()), binding.sourceImage) + c.circularBitmapDrawable(config, itm.getIcon(repository.baseUrl), binding.sourceImage) } } } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt index c656d6a..f6358bd 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt @@ -15,7 +15,6 @@ import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.rest.SelfossModel -import bou.amine.apps.readerforselfossv2.service.ApiDetailsService import bou.amine.apps.readerforselfossv2.service.SearchService import bou.amine.apps.readerforselfossv2.utils.DateUtils import com.amulyakhare.textdrawable.TextDrawable @@ -27,7 +26,6 @@ import org.kodein.di.instance class ItemListAdapter( override val app: Activity, override var items: ArrayList, - override val apiDetailsService: ApiDetailsService, override val db: AppDatabase, private val helper: CustomTabActivityHelper, private val internalBrowser: Boolean, @@ -61,9 +59,9 @@ class ItemListAdapter( binding.sourceTitleAndDate.text = itm.sourceAndDateText(DateUtils(repository.apiMajorVersion)) - if (itm.getThumbnail(apiDetailsService.getBaseUrl()).isEmpty()) { + if (itm.getThumbnail(repository.baseUrl).isEmpty()) { - if (itm.getIcon(apiDetailsService.getBaseUrl()).isEmpty()) { + if (itm.getIcon(repository.baseUrl).isEmpty()) { val color = generator.getColor(itm.getSourceTitle()) val drawable = @@ -74,10 +72,10 @@ class ItemListAdapter( binding.itemImage.setImageDrawable(drawable) } else { - c.circularBitmapDrawable(config, itm.getIcon(apiDetailsService.getBaseUrl()), binding.itemImage) + c.circularBitmapDrawable(config, itm.getIcon(repository.baseUrl), binding.itemImage) } } else { - c.bitmapCenterCrop(config, itm.getThumbnail(apiDetailsService.getBaseUrl()), binding.itemImage) + c.bitmapCenterCrop(config, itm.getThumbnail(repository.baseUrl), binding.itemImage) } } } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt index 58cc99d..6ec5237 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt @@ -10,7 +10,6 @@ import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.utils.Config import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.rest.SelfossModel -import bou.amine.apps.readerforselfossv2.service.ApiDetailsService import bou.amine.apps.readerforselfossv2.service.SearchService import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.CoroutineScope @@ -20,7 +19,6 @@ import org.kodein.di.DIAware abstract class ItemsAdapter : RecyclerView.Adapter(), DIAware { abstract var items: ArrayList - abstract val apiDetailsService: ApiDetailsService abstract val repository: Repository abstract val db: AppDatabase abstract val userIdentifier: String