Reintroduce network checks where required
This commit is contained in:
parent
e7172853dc
commit
3a2fab8e68
@ -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 =
|
||||||
|
@ -278,84 +278,89 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
binding.progressBar.visibility = View.VISIBLE
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
val parser = MercuryApi()
|
val parser = MercuryApi()
|
||||||
|
|
||||||
parser.parseUrl(url).enqueue(
|
if (repository.isNetworkAvailable()) {
|
||||||
object : Callback<ParsedContent> {
|
parser.parseUrl(url).enqueue(
|
||||||
override fun onResponse(
|
object : Callback<ParsedContent> {
|
||||||
call: Call<ParsedContent>,
|
override fun onResponse(
|
||||||
response: Response<ParsedContent>
|
call: Call<ParsedContent>,
|
||||||
) {
|
response: Response<ParsedContent>
|
||||||
// TODO: clean all the following after finding the mercury content issue
|
) {
|
||||||
try {
|
// TODO: clean all the following after finding the mercury content issue
|
||||||
if (response.body() != null && response.body()!!.content != null && !response.body()!!.content.isNullOrEmpty()) {
|
try {
|
||||||
try {
|
if (response.body() != null && response.body()!!.content != null && !response.body()!!.content.isNullOrEmpty()) {
|
||||||
binding.titleView.text = response.body()!!.title
|
|
||||||
if (typeface != null) {
|
|
||||||
binding.titleView.typeface = typeface
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
// Note: Mercury may return relative urls... If it does the url val will not be changed.
|
binding.titleView.text = response.body()!!.title
|
||||||
URL(response.body()!!.url)
|
if (typeface != null) {
|
||||||
url = response.body()!!.url
|
binding.titleView.typeface = typeface
|
||||||
} catch (e: MalformedURLException) {
|
|
||||||
// Mercury returned a relative url. We do nothing.
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
contentText = response.body()!!.content.orEmpty()
|
|
||||||
htmlToWebview()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isNullOrEmpty() && context != null) {
|
|
||||||
binding.imageView.visibility = View.VISIBLE
|
|
||||||
try {
|
|
||||||
Glide
|
|
||||||
.with(requireContext())
|
|
||||||
.asBitmap()
|
|
||||||
.loadMaybeBasicAuth(config, response.body()!!.lead_image_url.orEmpty())
|
|
||||||
.apply(RequestOptions.fitCenterTransform())
|
|
||||||
.into(binding.imageView)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
}
|
||||||
} else {
|
try {
|
||||||
binding.imageView.visibility = View.GONE
|
// Note: Mercury may return relative urls... If it does the url val will not be changed.
|
||||||
|
URL(response.body()!!.url)
|
||||||
|
url = response.body()!!.url
|
||||||
|
} catch (e: MalformedURLException) {
|
||||||
|
// Mercury returned a relative url. We do nothing.
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
if (context != null) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
binding.nestedScrollView.scrollTo(0, 0)
|
contentText = response.body()!!.content.orEmpty()
|
||||||
|
htmlToWebview()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
|
||||||
binding.progressBar.visibility = View.GONE
|
try {
|
||||||
} catch (e: Exception) {
|
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isNullOrEmpty() && context != null) {
|
||||||
if (context != null) {
|
binding.imageView.visibility = View.VISIBLE
|
||||||
|
try {
|
||||||
|
Glide
|
||||||
|
.with(requireContext())
|
||||||
|
.asBitmap()
|
||||||
|
.loadMaybeBasicAuth(
|
||||||
|
config,
|
||||||
|
response.body()!!.lead_image_url.orEmpty()
|
||||||
|
)
|
||||||
|
.apply(RequestOptions.fitCenterTransform())
|
||||||
|
.into(binding.imageView)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
binding.imageView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (context != null) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
binding.nestedScrollView.scrollTo(0, 0)
|
||||||
|
|
||||||
|
binding.progressBar.visibility = View.GONE
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (context != null) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
openInBrowserAfterFailing(customTabsIntent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (context != null) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} catch (e: Exception) {
|
||||||
try {
|
if (context != null) {
|
||||||
openInBrowserAfterFailing(customTabsIntent)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
if (context != null) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
if (context != null) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(
|
override fun onFailure(
|
||||||
call: Call<ParsedContent>,
|
call: Call<ParsedContent>,
|
||||||
t: Throwable
|
t: Throwable
|
||||||
) = openInBrowserAfterFailing(customTabsIntent)
|
) = openInBrowserAfterFailing(customTabsIntent)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun htmlToWebview() {
|
private fun htmlToWebview() {
|
||||||
|
@ -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
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user