Reintroduce network checks where required

This commit is contained in:
davidoskky 2022-08-18 14:48:27 +02:00
parent e7172853dc
commit 3a2fab8e68
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 { override fun doWork(): Result {
val settings = Settings() val settings = Settings()
val periodicRefresh = settings.getBoolean("periodic_refresh", false) val periodicRefresh = settings.getBoolean("periodic_refresh", false)
if (periodicRefresh) { if (periodicRefresh && repository.isNetworkAvailable()) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
val notificationManager = val notificationManager =

View File

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