Remove direct api access from the home activity
This commit is contained in:
parent
442e4bf876
commit
554b8df9d0
@ -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.toEntity
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.persistence.toView
|
import bou.amine.apps.readerforselfossv2.android.utils.persistence.toView
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
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.rest.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
|
||||||
import bou.amine.apps.readerforselfossv2.service.SearchService
|
import bou.amine.apps.readerforselfossv2.service.SearchService
|
||||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||||
import bou.amine.apps.readerforselfossv2.utils.longHash
|
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 tabNewBadge: TextBadgeItem
|
||||||
private lateinit var tabArchiveBadge: TextBadgeItem
|
private lateinit var tabArchiveBadge: TextBadgeItem
|
||||||
private lateinit var tabStarredBadge: TextBadgeItem
|
private lateinit var tabStarredBadge: TextBadgeItem
|
||||||
private lateinit var api: SelfossApiImpl
|
|
||||||
private lateinit var customTabActivityHelper: CustomTabActivityHelper
|
private lateinit var customTabActivityHelper: CustomTabActivityHelper
|
||||||
private lateinit var appColors: AppColors
|
private lateinit var appColors: AppColors
|
||||||
private var offset: Int = 0
|
private var offset: Int = 0
|
||||||
@ -145,7 +142,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
private lateinit var config: Config
|
private lateinit var config: Config
|
||||||
|
|
||||||
override val di by closestDI()
|
override val di by closestDI()
|
||||||
private val apiDetailsService : ApiDetailsService by instance()
|
|
||||||
private val repository : Repository by instance()
|
private val repository : Repository by instance()
|
||||||
|
|
||||||
data class DrawerData(val tags: List<SelfossModel.Tag>?, val sources: List<SelfossModel.Source>?)
|
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()
|
customTabActivityHelper = CustomTabActivityHelper()
|
||||||
|
|
||||||
api = SelfossApiImpl(
|
|
||||||
// this,
|
|
||||||
// this@HomeActivity,
|
|
||||||
// settings.getBoolean("isSelfSignedCert", false),
|
|
||||||
// sharedPref.getString("api_timeout", "-1")!!.toLong()
|
|
||||||
apiDetailsService
|
|
||||||
)
|
|
||||||
|
|
||||||
dataBase = AndroidDeviceDatabase(applicationContext)
|
dataBase = AndroidDeviceDatabase(applicationContext)
|
||||||
searchService = SearchService(DateUtils(repository.apiMajorVersion))
|
searchService = SearchService(DateUtils(repository.apiMajorVersion))
|
||||||
dbService = AndroidDeviceDatabaseService(dataBase, searchService)
|
dbService = AndroidDeviceDatabaseService(dataBase, searchService)
|
||||||
@ -615,7 +603,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
val item = PrimaryDrawerItem().apply {
|
val item = PrimaryDrawerItem().apply {
|
||||||
nameText = source.getTitleDecoded()
|
nameText = source.getTitleDecoded()
|
||||||
identifier = source.id.toLong()
|
identifier = source.id.toLong()
|
||||||
iconUrl = source.getIcon(apiDetailsService.getBaseUrl())
|
iconUrl = source.getIcon(repository.baseUrl)
|
||||||
onDrawerItemClickListener = { _,_,_ ->
|
onDrawerItemClickListener = { _,_,_ ->
|
||||||
searchService.sourceIDFilter = source.id.toLong()
|
searchService.sourceIDFilter = source.id.toLong()
|
||||||
searchService.sourceFilter = source.title
|
searchService.sourceFilter = source.title
|
||||||
@ -989,7 +977,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
ItemCardAdapter(
|
ItemCardAdapter(
|
||||||
this,
|
this,
|
||||||
items,
|
items,
|
||||||
apiDetailsService,
|
|
||||||
db,
|
db,
|
||||||
customTabActivityHelper,
|
customTabActivityHelper,
|
||||||
internalBrowser,
|
internalBrowser,
|
||||||
@ -1007,7 +994,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
ItemListAdapter(
|
ItemListAdapter(
|
||||||
this,
|
this,
|
||||||
items,
|
items,
|
||||||
apiDetailsService,
|
|
||||||
db,
|
db,
|
||||||
customTabActivityHelper,
|
customTabActivityHelper,
|
||||||
internalBrowser,
|
internalBrowser,
|
||||||
|
@ -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.android.utils.network.isNetworkAvailable
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
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.service.SearchService
|
||||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||||
import com.amulyakhare.textdrawable.TextDrawable
|
import com.amulyakhare.textdrawable.TextDrawable
|
||||||
@ -35,7 +34,6 @@ import org.kodein.di.instance
|
|||||||
class ItemCardAdapter(
|
class ItemCardAdapter(
|
||||||
override val app: Activity,
|
override val app: Activity,
|
||||||
override var items: ArrayList<SelfossModel.Item>,
|
override var items: ArrayList<SelfossModel.Item>,
|
||||||
override val apiDetailsService: ApiDetailsService,
|
|
||||||
override val db: AppDatabase,
|
override val db: AppDatabase,
|
||||||
private val helper: CustomTabActivityHelper,
|
private val helper: CustomTabActivityHelper,
|
||||||
private val internalBrowser: Boolean,
|
private val internalBrowser: Boolean,
|
||||||
@ -78,16 +76,16 @@ class ItemCardAdapter(
|
|||||||
binding.itemImage.scaleType = ScaleType.CENTER_CROP
|
binding.itemImage.scaleType = ScaleType.CENTER_CROP
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itm.getThumbnail(apiDetailsService.getBaseUrl()).isEmpty()) {
|
if (itm.getThumbnail(repository.baseUrl).isEmpty()) {
|
||||||
binding.itemImage.visibility = View.GONE
|
binding.itemImage.visibility = View.GONE
|
||||||
Glide.with(c).clear(binding.itemImage)
|
Glide.with(c).clear(binding.itemImage)
|
||||||
binding.itemImage.setImageDrawable(null)
|
binding.itemImage.setImageDrawable(null)
|
||||||
} else {
|
} else {
|
||||||
binding.itemImage.visibility = View.VISIBLE
|
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 color = generator.getColor(itm.getSourceTitle())
|
||||||
|
|
||||||
val drawable =
|
val drawable =
|
||||||
@ -97,7 +95,7 @@ class ItemCardAdapter(
|
|||||||
.build(itm.getSourceTitle().toTextDrawableString(c), color)
|
.build(itm.getSourceTitle().toTextDrawableString(c), color)
|
||||||
binding.sourceImage.setImageDrawable(drawable)
|
binding.sourceImage.setImageDrawable(drawable)
|
||||||
} else {
|
} else {
|
||||||
c.circularBitmapDrawable(config, itm.getIcon(apiDetailsService.getBaseUrl()), binding.sourceImage)
|
c.circularBitmapDrawable(config, itm.getIcon(repository.baseUrl), binding.sourceImage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.android.utils.glide.circularBitmapDrawable
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
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.service.SearchService
|
||||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||||
import com.amulyakhare.textdrawable.TextDrawable
|
import com.amulyakhare.textdrawable.TextDrawable
|
||||||
@ -27,7 +26,6 @@ import org.kodein.di.instance
|
|||||||
class ItemListAdapter(
|
class ItemListAdapter(
|
||||||
override val app: Activity,
|
override val app: Activity,
|
||||||
override var items: ArrayList<SelfossModel.Item>,
|
override var items: ArrayList<SelfossModel.Item>,
|
||||||
override val apiDetailsService: ApiDetailsService,
|
|
||||||
override val db: AppDatabase,
|
override val db: AppDatabase,
|
||||||
private val helper: CustomTabActivityHelper,
|
private val helper: CustomTabActivityHelper,
|
||||||
private val internalBrowser: Boolean,
|
private val internalBrowser: Boolean,
|
||||||
@ -61,9 +59,9 @@ class ItemListAdapter(
|
|||||||
|
|
||||||
binding.sourceTitleAndDate.text = itm.sourceAndDateText(DateUtils(repository.apiMajorVersion))
|
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 color = generator.getColor(itm.getSourceTitle())
|
||||||
|
|
||||||
val drawable =
|
val drawable =
|
||||||
@ -74,10 +72,10 @@ class ItemListAdapter(
|
|||||||
|
|
||||||
binding.itemImage.setImageDrawable(drawable)
|
binding.itemImage.setImageDrawable(drawable)
|
||||||
} else {
|
} else {
|
||||||
c.circularBitmapDrawable(config, itm.getIcon(apiDetailsService.getBaseUrl()), binding.itemImage)
|
c.circularBitmapDrawable(config, itm.getIcon(repository.baseUrl), binding.itemImage)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.bitmapCenterCrop(config, itm.getThumbnail(apiDetailsService.getBaseUrl()), binding.itemImage)
|
c.bitmapCenterCrop(config, itm.getThumbnail(repository.baseUrl), binding.itemImage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.android.utils.Config
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
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.service.SearchService
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -20,7 +19,6 @@ import org.kodein.di.DIAware
|
|||||||
|
|
||||||
abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapter<VH>(), DIAware {
|
abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapter<VH>(), DIAware {
|
||||||
abstract var items: ArrayList<SelfossModel.Item>
|
abstract var items: ArrayList<SelfossModel.Item>
|
||||||
abstract val apiDetailsService: ApiDetailsService
|
|
||||||
abstract val repository: Repository
|
abstract val repository: Repository
|
||||||
abstract val db: AppDatabase
|
abstract val db: AppDatabase
|
||||||
abstract val userIdentifier: String
|
abstract val userIdentifier: String
|
||||||
|
Loading…
Reference in New Issue
Block a user