network #28
@ -153,7 +153,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
val view = binding.root
|
||||
|
||||
fromTabShortcut = intent.getIntExtra("shortcutTab", -1) != -1
|
||||
offlineShortcut = intent.getBooleanExtra("startOffline", false)
|
||||
repository.offlineOverride = intent.getBooleanExtra("startOffline", false)
|
||||
|
||||
if (fromTabShortcut) {
|
||||
elementsShown = ItemType.fromInt(intent.getIntExtra("shortcutTab", ItemType.UNREAD.position))
|
||||
@ -197,7 +197,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
R.color.refresh_progress_3
|
||||
)
|
||||
binding.swipeRefreshLayout.setOnRefreshListener {
|
||||
offlineShortcut = false
|
||||
repository.offlineOverride = false
|
||||
lastFetchDone = false
|
||||
handleDrawerItems()
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
|
@ -28,6 +28,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
var searchFilter: String? = null
|
||||
|
||||
var itemsCaching = settings.getBoolean("items_caching", false)
|
||||
var offlineOverride = false
|
||||
|
||||
var apiMajorVersion = 0
|
||||
var badgeUnread = 0
|
||||
@ -49,7 +50,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
|
||||
// TODO: Use the updatedSince parameter
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
AmineB marked this conversation as resolved
Outdated
|
||||
val fetchedItems = api.getItems(
|
||||
displayedItems.type,
|
||||
settings.getString("prefer_api_items_number", "200").toInt(),
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
There should be a message emited on network available too. There should be a message emited on network available too.
|
||||
@ -71,7 +72,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
}
|
||||
|
||||
suspend fun getOlderItems(): ArrayList<SelfossModel.Item> {
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
val offset = items.size
|
||||
val fetchedItems = api.getItems(
|
||||
displayedItems.type,
|
||||
@ -93,7 +94,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
}
|
||||
|
||||
suspend fun allItems(itemType: ItemType): List<SelfossModel.Item>? {
|
||||
return if (isConnectionAvailable.value) {
|
||||
return if (isConnectionAvailable.value && !offlineOverride) {
|
||||
api.getItems(
|
||||
itemType.type,
|
||||
200,
|
||||
@ -123,7 +124,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun reloadBadges(): Boolean {
|
||||
var success = false
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
val response = api.stats()
|
||||
if (response != null) {
|
||||
badgeUnread = response.unread
|
||||
@ -139,7 +140,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun getTags(): List<SelfossModel.Tag>? {
|
||||
// TODO: Store in DB
|
||||
return if (isConnectionAvailable.value) {
|
||||
return if (isConnectionAvailable.value && !offlineOverride) {
|
||||
api.tags()
|
||||
} else {
|
||||
// TODO: Compute from database
|
||||
@ -149,7 +150,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun getSpouts(): Map<String, SelfossModel.Spout>? {
|
||||
// TODO: Store in DB
|
||||
return if (isConnectionAvailable.value) {
|
||||
return if (isConnectionAvailable.value && !offlineOverride) {
|
||||
api.spouts()
|
||||
} else {
|
||||
// TODO: Compute from database
|
||||
@ -159,7 +160,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun getSources(): ArrayList<SelfossModel.Source>? {
|
||||
// TODO: Store in DB
|
||||
return if (isConnectionAvailable.value) {
|
||||
return if (isConnectionAvailable.value && !offlineOverride) {
|
||||
api.sources()
|
||||
} else {
|
||||
// TODO: Compute from database
|
||||
@ -178,7 +179,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun markAsReadById(id: Int): Boolean {
|
||||
var success = false
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
Every block that does something like
can be refactored to something like
Every block that does something like
```
var success = false
if (isNetworkAvailable()) {
success = DOSOMETHING()
}
return success
```
can be refactored to something like
```
return isNetworkAvailable() && DOSOMETHING()
```
|
||||
success = api.markAsRead(id.toString())?.isSuccess == true
|
||||
}
|
||||
return success
|
||||
@ -197,7 +198,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
suspend fun unmarkAsReadById(id: Int): Boolean {
|
||||
// TODO: Check internet connection
|
||||
var success = false
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
Please refactor this Please refactor this
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
success = api.unmarkAsRead(id.toString())?.isSuccess == true
|
||||
}
|
||||
return success
|
||||
@ -214,7 +215,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun starrById(id: Int): Boolean {
|
||||
var success = false
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
Please refactor this Please refactor this
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
success = api.starr(id.toString())?.isSuccess == true
|
||||
}
|
||||
return success
|
||||
@ -231,7 +232,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun unstarrById(id: Int): Boolean {
|
||||
var success = false
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
Please refactor this Please refactor this
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
success = api.unstarr(id.toString())?.isSuccess == true
|
||||
}
|
||||
return success
|
||||
@ -240,7 +241,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun markAllAsRead(items: ArrayList<SelfossModel.Item>): Boolean {
|
||||
var success = false
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
Please refactor this Please refactor this
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
success = api.markAllAsRead(items.map { it.id.toString() })?.isSuccess == true
|
||||
}
|
||||
|
||||
@ -292,7 +293,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
filter: String
|
||||
): Boolean {
|
||||
var response = false
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
response = api.createSourceForVersion(
|
||||
title,
|
||||
url,
|
||||
@ -309,7 +310,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
suspend fun deleteSource(id: Int): Boolean {
|
||||
// TODO: Store in DB
|
||||
var success = false
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
val response = api.deleteSource(id)
|
||||
if (response != null) {
|
||||
success = response.isSuccess
|
||||
@ -321,7 +322,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun updateRemote(): Boolean {
|
||||
var response = false
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
This should use the same This should use the same `isNetworkAvailable()` function as the others.
AmineB
commented
And it can be refactored as the ones before. And it can be refactored as the ones before.
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
It's weird to have this here. If There is no need for an exception for this method. It's weird to have this here. `offlineOverride` shouldn't be overridden from inside the repository.
If `offlineOverride` is `true` then return `false`.
There is no need for an exception for this method.
|
||||
response = api.update()?.isSuccess == true
|
||||
}
|
||||
return response
|
||||
@ -329,7 +330,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
suspend fun login(): Boolean {
|
||||
var result = false
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
try {
|
||||
val response = api.login()
|
||||
result = response?.isSuccess == true
|
||||
@ -356,7 +357,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
private suspend fun updateApiVersion() {
|
||||
apiMajorVersion = settings.getInt("apiVersionMajor", 0)
|
||||
|
||||
if (isConnectionAvailable.value) {
|
||||
if (isConnectionAvailable.value && !offlineOverride) {
|
||||
val fetchedVersion = api.version()
|
||||
if (fetchedVersion != null) {
|
||||
apiMajorVersion = fetchedVersion.getApiMajorVersion()
|
||||
|
Loading…
Reference in New Issue
Block a user
isConnectionAvailable.value && !offlineOverride
should be refactored inside a method namedisNetworkAvailable()