Use an enum to represent item type
This commit is contained in:
parent
fe59177efb
commit
d47cca2f5a
@ -49,6 +49,7 @@ 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.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
||||
import bou.amine.apps.readerforselfossv2.utils.longHash
|
||||
import com.ashokvarma.bottomnavigation.BottomNavigationBar
|
||||
import com.ashokvarma.bottomnavigation.BottomNavigationItem
|
||||
@ -905,7 +906,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
private fun getUnRead(appendResults: Boolean = false) {
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
binding.swipeRefreshLayout.isRefreshing = true
|
||||
repository.displayedItems = "unread"
|
||||
repository.displayedItems = ItemType.UNREAD
|
||||
items = if (appendResults) {
|
||||
repository.getNewerItems()
|
||||
} else {
|
||||
@ -919,7 +920,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
private fun getRead(appendResults: Boolean = false) {
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
binding.swipeRefreshLayout.isRefreshing = true
|
||||
repository.displayedItems = "all"
|
||||
repository.displayedItems = ItemType.ALL
|
||||
items = if (appendResults) {
|
||||
repository.getNewerItems()
|
||||
} else {
|
||||
@ -933,7 +934,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
private fun getStarred(appendResults: Boolean = false) {
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
binding.swipeRefreshLayout.isRefreshing = true
|
||||
repository.displayedItems = "starred"
|
||||
repository.displayedItems = ItemType.STARRED
|
||||
items = if (appendResults) {
|
||||
repository.getNewerItems()
|
||||
} else {
|
||||
|
@ -10,6 +10,7 @@ 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.utils.ItemType
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -81,7 +82,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
repository.markAsRead(i.id)
|
||||
}
|
||||
if (repository.displayedItems == "unread") {
|
||||
if (repository.displayedItems == ItemType.UNREAD) {
|
||||
items.remove(i)
|
||||
notifyItemRemoved(position)
|
||||
updateItems(items)
|
||||
|
@ -2,6 +2,7 @@ package bou.amine.apps.readerforselfossv2.repository
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
||||
|
||||
interface Repository {
|
||||
|
||||
@ -10,7 +11,7 @@ interface Repository {
|
||||
var baseUrl: String
|
||||
var dateUtils: DateUtils
|
||||
|
||||
var displayedItems: String
|
||||
var displayedItems: ItemType
|
||||
|
||||
// Settings
|
||||
var itemsCaching: Boolean
|
||||
|
@ -4,6 +4,7 @@ import bou.amine.apps.readerforselfossv2.rest.SelfossApi
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
||||
import com.russhwolf.settings.Settings
|
||||
import io.github.aakira.napier.Napier
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -18,16 +19,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
||||
override var baseUrl = apiDetails.getBaseUrl()
|
||||
override lateinit var dateUtils: DateUtils
|
||||
|
||||
override var displayedItems = "unread"
|
||||
set(value) {
|
||||
field = when (value) {
|
||||
"all" -> "all"
|
||||
"unread" -> "unread"
|
||||
"read" -> "read"
|
||||
"starred" -> "starred"
|
||||
else -> "all"
|
||||
}
|
||||
}
|
||||
override var displayedItems = ItemType.UNREAD
|
||||
|
||||
override var tagFilter: SelfossModel.Tag? = null
|
||||
override var sourceFilter: SelfossModel.Source? = null
|
||||
@ -54,7 +46,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
||||
|
||||
override suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
|
||||
// TODO: Check connectivity
|
||||
val fetchedItems = api.getItems(displayedItems,
|
||||
val fetchedItems = api.getItems(displayedItems.type,
|
||||
settings.getString("prefer_api_items_number", "200").toInt(),
|
||||
offset = 0,
|
||||
tagFilter?.tag,
|
||||
@ -70,7 +62,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
||||
override suspend fun getOlderItems(): ArrayList<SelfossModel.Item> {
|
||||
// TODO: Check connectivity
|
||||
val offset = items.size
|
||||
val fetchedItems = api.getItems(displayedItems,
|
||||
val fetchedItems = api.getItems(displayedItems.type,
|
||||
settings.getString("prefer_api_items_number", "200").toInt(),
|
||||
offset,
|
||||
tagFilter?.tag,
|
||||
@ -99,9 +91,9 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
||||
|
||||
private fun filterSelectedItems(items: ArrayList<SelfossModel.Item>): ArrayList<SelfossModel.Item> {
|
||||
val tmpItems = items
|
||||
if (displayedItems == "unread") {
|
||||
if (displayedItems == ItemType.UNREAD) {
|
||||
tmpItems.removeAll { !it.unread }
|
||||
} else if (displayedItems == "starred") {
|
||||
} else if (displayedItems == ItemType.STARRED) {
|
||||
tmpItems.removeAll { !it.starred }
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
package bou.amine.apps.readerforselfossv2.utils
|
||||
|
||||
enum class ItemType(val type: String) {
|
||||
UNREAD("unread"),
|
||||
ALL("all"),
|
||||
STARRED("starred")
|
||||
}
|
Loading…
Reference in New Issue
Block a user