Inject the Repository in the Reader Activity
Removed ApiDetailsService and SelfossApi from the activity
This commit is contained in:
parent
12e174dacd
commit
b14a6427da
@ -20,9 +20,8 @@ import bou.amine.apps.readerforselfossv2.android.persistence.migrations.MIGRATIO
|
||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
||||
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.toggleStar
|
||||
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 com.ftinc.scoop.Scoop
|
||||
import com.russhwolf.settings.Settings
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -39,8 +38,6 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
||||
private lateinit var userIdentifier: String
|
||||
private lateinit var appColors: AppColors
|
||||
|
||||
private lateinit var api: SelfossApiImpl
|
||||
|
||||
private lateinit var toolbarMenu: Menu
|
||||
|
||||
private lateinit var db: AppDatabase
|
||||
@ -51,7 +48,7 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
||||
private val ALIGN_LEFT = 2
|
||||
|
||||
override val di by closestDI()
|
||||
private val apiDetailsService : ApiDetailsService by instance()
|
||||
private val repository : Repository by instance()
|
||||
|
||||
private fun showMenuItem(willAddToFavorite: Boolean) {
|
||||
if (willAddToFavorite) {
|
||||
@ -96,14 +93,6 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
||||
markOnScroll = settings.getBoolean("mark_on_scroll", false)
|
||||
activeAlignment = settings.getInt("text_align", JUSTIFY)
|
||||
|
||||
api = SelfossApiImpl(
|
||||
// this,
|
||||
// this@ReaderActivity,
|
||||
// settings.getBoolean("isSelfSignedCert", false),
|
||||
// prefs.getString("api_timeout", "-1")!!.toLong()
|
||||
apiDetailsService
|
||||
)
|
||||
|
||||
if (allItems.isEmpty()) {
|
||||
finish()
|
||||
}
|
||||
@ -125,8 +114,8 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
||||
private fun readItem(item: SelfossModel.Item) {
|
||||
if (markOnScroll) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
api.markAsRead(item.id.toString())
|
||||
// TODO: update item in DB
|
||||
repository.markAsRead(item.id.toString())
|
||||
// TODO: Handle failure
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -223,14 +212,14 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
||||
R.id.star -> {
|
||||
if (allItems[binding.pager.currentItem].starred) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
api.unstarr(allItems[binding.pager.currentItem].id.toString())
|
||||
// TODO: update in DB
|
||||
repository.unstarr(allItems[binding.pager.currentItem].id)
|
||||
// TODO: Handle failure
|
||||
}
|
||||
afterUnsave()
|
||||
} else {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
api.starr(allItems[binding.pager.currentItem].id.toString())
|
||||
// TODO: update in DB
|
||||
repository.starr(allItems[binding.pager.currentItem].id)
|
||||
// TODO: Handle failure
|
||||
}
|
||||
afterSave()
|
||||
}
|
||||
|
@ -119,14 +119,14 @@ class ItemCardAdapter(
|
||||
if (c.isNetworkAvailable()) {
|
||||
if (item.starred) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
repository.unstarr(item.id.toString())
|
||||
repository.unstarr(item.id)
|
||||
// TODO: Handle failure
|
||||
}
|
||||
item.starred = false
|
||||
binding.favButton.isSelected = false
|
||||
} else {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
repository.starr(item.id.toString())
|
||||
repository.starr(item.id)
|
||||
// TODO: Handle failure
|
||||
}
|
||||
item.starred = true
|
||||
|
@ -19,8 +19,8 @@ interface Repository {
|
||||
suspend fun getSources(): ArrayList<SelfossModel.Source>?
|
||||
suspend fun markAsRead(id: String): Boolean
|
||||
suspend fun unmarkAsRead(id: String): Boolean
|
||||
suspend fun starr(id: String): Boolean
|
||||
suspend fun unstarr(id: String): Boolean
|
||||
suspend fun starr(id: Int): Boolean
|
||||
suspend fun unstarr(id: Int): Boolean
|
||||
fun markAllAsRead(ids: List<String>): Boolean
|
||||
suspend fun createSource(title: String,
|
||||
url: String,
|
||||
|
@ -58,15 +58,15 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
||||
api.unmarkAsRead(id)
|
||||
return true }
|
||||
|
||||
override suspend fun starr(id: String): Boolean {
|
||||
override suspend fun starr(id: Int): Boolean {
|
||||
// TODO: Check success, store in DB
|
||||
api.starr(id)
|
||||
api.starr(id.toString())
|
||||
return true
|
||||
}
|
||||
|
||||
override suspend fun unstarr(id: String): Boolean {
|
||||
override suspend fun unstarr(id: Int): Boolean {
|
||||
// TODO: Check success, store in DB
|
||||
api.unstarr(id)
|
||||
api.unstarr(id.toString())
|
||||
return true
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user