Reintroduce network checks where required

This commit is contained in:
davidoskky 2022-08-18 14:48:27 +02:00
parent d654b1b0bd
commit d1481a1db6
3 changed files with 74 additions and 69 deletions

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

@ -378,7 +378,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
}
}
private fun isNetworkAvailable() = isConnectionAvailable.value && !offlineOverride
fun isNetworkAvailable() = isConnectionAvailable.value && !offlineOverride
// TODO: Handle offline actions
}