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