Remove direct api access from the home activity

This commit is contained in:
davide 2022-08-13 17:11:07 +02:00
parent 442e4bf876
commit 554b8df9d0
4 changed files with 9 additions and 29 deletions

View File

@ -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<SelfossModel.Tag>?, val sources: List<SelfossModel.Source>?)
@ -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,

View File

@ -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<SelfossModel.Item>,
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)
}
}
}

View File

@ -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<SelfossModel.Item>,
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)
}
}
}

View File

@ -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<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapter<VH>(), DIAware {
abstract var items: ArrayList<SelfossModel.Item>
abstract val apiDetailsService: ApiDetailsService
abstract val repository: Repository
abstract val db: AppDatabase
abstract val userIdentifier: String