Strip Selfoss API from Items Adapters
This commit is contained in:
parent
dc10cafb1b
commit
9373024147
@ -1012,7 +1012,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
ItemCardAdapter(
|
||||
this,
|
||||
items,
|
||||
api,
|
||||
apiDetailsService,
|
||||
db,
|
||||
customTabActivityHelper,
|
||||
@ -1031,7 +1030,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
ItemListAdapter(
|
||||
this,
|
||||
items,
|
||||
api,
|
||||
apiDetailsService,
|
||||
db,
|
||||
customTabActivityHelper,
|
||||
|
@ -17,7 +17,7 @@ import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActiv
|
||||
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.network.isNetworkAvailable
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossApiImpl
|
||||
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
|
||||
@ -28,11 +28,13 @@ import com.bumptech.glide.Glide
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.kodein.di.DI
|
||||
import org.kodein.di.android.closestDI
|
||||
import org.kodein.di.instance
|
||||
|
||||
class ItemCardAdapter(
|
||||
override val app: Activity,
|
||||
override var items: ArrayList<SelfossModel.Item>,
|
||||
override val api: SelfossApiImpl,
|
||||
override val apiDetailsService: ApiDetailsService,
|
||||
override val db: AppDatabase,
|
||||
private val helper: CustomTabActivityHelper,
|
||||
@ -50,6 +52,9 @@ class ItemCardAdapter(
|
||||
private val imageMaxHeight: Int =
|
||||
c.resources.getDimension(R.dimen.card_image_max_height).toInt()
|
||||
|
||||
override val di: DI by closestDI(app)
|
||||
override val repository : Repository by instance()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val binding = CardItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(binding)
|
||||
@ -114,15 +119,15 @@ class ItemCardAdapter(
|
||||
if (c.isNetworkAvailable()) {
|
||||
if (item.starred) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
api.unstarr(item.id.toString())
|
||||
// TODO: save to db
|
||||
repository.unstarr(item.id.toString())
|
||||
// TODO: Handle failure
|
||||
}
|
||||
item.starred = false
|
||||
binding.favButton.isSelected = false
|
||||
} else {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
api.starr(item.id.toString())
|
||||
// TODO: save to db
|
||||
repository.starr(item.id.toString())
|
||||
// TODO: Handle failure
|
||||
}
|
||||
item.starred = true
|
||||
binding.favButton.isSelected = true
|
||||
|
@ -13,18 +13,20 @@ import bou.amine.apps.readerforselfossv2.android.utils.*
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossApiImpl
|
||||
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
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import org.kodein.di.DI
|
||||
import org.kodein.di.android.closestDI
|
||||
import org.kodein.di.instance
|
||||
|
||||
class ItemListAdapter(
|
||||
override val app: Activity,
|
||||
override var items: ArrayList<SelfossModel.Item>,
|
||||
override val api: SelfossApiImpl,
|
||||
override val apiDetailsService: ApiDetailsService,
|
||||
override val db: AppDatabase,
|
||||
private val helper: CustomTabActivityHelper,
|
||||
@ -39,6 +41,9 @@ class ItemListAdapter(
|
||||
private val generator: ColorGenerator = ColorGenerator.MATERIAL
|
||||
private val c: Context = app.baseContext
|
||||
|
||||
override val di: DI by closestDI(app)
|
||||
override val repository : Repository by instance()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val binding = ListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(binding)
|
||||
|
@ -8,7 +8,7 @@ import bou.amine.apps.readerforselfossv2.android.R
|
||||
import bou.amine.apps.readerforselfossv2.android.persistence.database.AppDatabase
|
||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.Config
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossApiImpl
|
||||
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
|
||||
@ -16,11 +16,12 @@ import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.kodein.di.DIAware
|
||||
|
||||
abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapter<VH>() {
|
||||
abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapter<VH>(), DIAware {
|
||||
abstract var items: ArrayList<SelfossModel.Item>
|
||||
abstract val api: SelfossApiImpl
|
||||
abstract val apiDetailsService: ApiDetailsService
|
||||
abstract val repository: Repository
|
||||
abstract val db: AppDatabase
|
||||
abstract val userIdentifier: String
|
||||
abstract val app: Activity
|
||||
@ -82,7 +83,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
||||
private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) {
|
||||
val i = items[position]
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
api.markAsRead(i.id.toString())
|
||||
repository.markAsRead(i.id.toString())
|
||||
// TODO: update db
|
||||
|
||||
}
|
||||
@ -101,7 +102,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
||||
|
||||
private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
api.unmarkAsRead(items[position].id.toString())
|
||||
repository.unmarkAsRead(items[position].id.toString())
|
||||
// Todo: SharedItems.unreadItem(app, api, db, items[position])
|
||||
// TODO: update db
|
||||
|
||||
|
@ -14,10 +14,10 @@ interface Repository {
|
||||
fun getTags(): List<SelfossModel.Tag>
|
||||
fun getSpouts(): List<SelfossModel.Spout>
|
||||
fun getSources(): List<SelfossModel.Source>
|
||||
fun markAsRead(id: String): Boolean
|
||||
fun unmarkAsRead(id: String): Boolean
|
||||
fun starr(id: String): Boolean
|
||||
fun unstarr(id: String): Boolean
|
||||
suspend fun markAsRead(id: String): Boolean
|
||||
suspend fun unmarkAsRead(id: String): Boolean
|
||||
suspend fun starr(id: String): Boolean
|
||||
suspend fun unstarr(id: String): Boolean
|
||||
fun markAllAsRead(ids: List<String>): Boolean
|
||||
fun createSource(title: String,
|
||||
url: String,
|
||||
|
@ -31,20 +31,27 @@ class RepositoryImpl(private val api: SelfossApi) : Repository {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun markAsRead(id: String): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun markAsRead(id: String): Boolean {
|
||||
// TODO: Check success, store in DB
|
||||
api.markAsRead(id)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun unmarkAsRead(id: String): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun unmarkAsRead(id: String): Boolean {
|
||||
// TODO: Check success, store in DB
|
||||
api.unmarkAsRead(id)
|
||||
return true }
|
||||
|
||||
override suspend fun starr(id: String): Boolean {
|
||||
// TODO: Check success, store in DB
|
||||
api.starr(id)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun starr(id: String): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun unstarr(id: String): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun unstarr(id: String): Boolean {
|
||||
// TODO: Check success, store in DB
|
||||
api.unstarr(id)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun markAllAsRead(ids: List<String>): Boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user