Compare commits

..

3 Commits

4 changed files with 92 additions and 85 deletions

View File

@ -1044,6 +1044,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
Toast.makeText(this, R.string.refresh_in_progress, Toast.LENGTH_SHORT).show()
// TODO: Use Dispatchers.IO
CoroutineScope(Dispatchers.Main).launch {
repository.offlineOverride = false
val updatedRemote = repository.updateRemote()
if (updatedRemote) {
// TODO: Send toast messages from the repository

View File

@ -43,7 +43,7 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con
override fun doWork(): Result {
val settings = Settings()
val periodicRefresh = settings.getBoolean("periodic_refresh", false)
if (periodicRefresh) {
if (periodicRefresh && repository.isNetworkAvailable()) {
CoroutineScope(Dispatchers.IO).launch {
val notificationManager =

View File

@ -278,6 +278,7 @@ class ArticleFragment : Fragment(), DIAware {
binding.progressBar.visibility = View.VISIBLE
val parser = MercuryApi()
if (repository.isNetworkAvailable()) {
parser.parseUrl(url).enqueue(
object : Callback<ParsedContent> {
override fun onResponse(
@ -315,7 +316,10 @@ class ArticleFragment : Fragment(), DIAware {
Glide
.with(requireContext())
.asBitmap()
.loadMaybeBasicAuth(config, response.body()!!.lead_image_url.orEmpty())
.loadMaybeBasicAuth(
config,
response.body()!!.lead_image_url.orEmpty()
)
.apply(RequestOptions.fitCenterTransform())
.into(binding.imageView)
} catch (e: Exception) {
@ -357,6 +361,7 @@ class ArticleFragment : Fragment(), DIAware {
}
)
}
}
private fun htmlToWebview() {
val stringColor = String.format("#%06X", 0xFFFFFF and appColors.colorAccent)

View File

@ -63,7 +63,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 && !offlineOverride) {
if (isNetworkAvailable()) {
val fetchedItems = api.getItems(
displayedItems.type,
settings.getString("prefer_api_items_number", "200").toInt(),
@ -84,7 +84,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
}
suspend fun getOlderItems(): ArrayList<SelfossModel.Item> {
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
val offset = items.size
val fetchedItems = api.getItems(
displayedItems.type,
@ -106,7 +106,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
}
suspend fun allItems(itemType: ItemType): List<SelfossModel.Item>? {
return if (isConnectionAvailable.value && !offlineOverride) {
return if (isNetworkAvailable()) {
api.getItems(
itemType.type,
200,
@ -137,7 +137,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun reloadBadges(): Boolean {
var success = false
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
val response = api.stats()
if (response != null) {
badgeUnread = response.unread
@ -153,7 +153,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 && !offlineOverride) {
return if (isNetworkAvailable()) {
api.tags()
} else {
// TODO: Compute from database
@ -163,7 +163,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 && !offlineOverride) {
return if (isNetworkAvailable()) {
api.spouts()
} else {
// TODO: Compute from database
@ -173,7 +173,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 && !offlineOverride) {
return if (isNetworkAvailable()) {
api.sources()
} else {
// TODO: Compute from database
@ -192,7 +192,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun markAsReadById(id: Int): Boolean {
var success = false
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
success = api.markAsRead(id.toString())?.isSuccess == true
}
return success
@ -209,7 +209,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun unmarkAsReadById(id: Int): Boolean {
var success = false
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
success = api.unmarkAsRead(id.toString())?.isSuccess == true
}
return success
@ -226,7 +226,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun starrById(id: Int): Boolean {
var success = false
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
success = api.starr(id.toString())?.isSuccess == true
}
return success
@ -243,7 +243,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun unstarrById(id: Int): Boolean {
var success = false
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
success = api.unstarr(id.toString())?.isSuccess == true
}
return success
@ -252,7 +252,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun markAllAsRead(items: ArrayList<SelfossModel.Item>): Boolean {
var success = false
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
success = api.markAllAsRead(items.map { it.id.toString() })?.isSuccess == true
}
@ -304,7 +304,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
filter: String
): Boolean {
var response = false
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
response = api.createSourceForVersion(
title,
url,
@ -321,7 +321,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 && !offlineOverride) {
if (isNetworkAvailable()) {
val response = api.deleteSource(id)
if (response != null) {
success = response.isSuccess
@ -333,7 +333,6 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun updateRemote(): Boolean {
var response = false
offlineOverride = false
if (isConnectionAvailable.value) {
response = api.update()?.isSuccess == true
}
@ -342,7 +341,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun login(): Boolean {
var result = false
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
try {
val response = api.login()
result = response?.isSuccess == true
@ -369,7 +368,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
private suspend fun updateApiVersion() {
apiMajorVersion = settings.getInt("apiVersionMajor", 0)
if (isConnectionAvailable.value && !offlineOverride) {
if (isNetworkAvailable()) {
val fetchedVersion = api.version()
if (fetchedVersion != null) {
apiMajorVersion = fetchedVersion.getApiMajorVersion()
@ -378,5 +377,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
}
}
fun isNetworkAvailable() = isConnectionAvailable.value && !offlineOverride
// TODO: Handle offline actions
}