Commit 839ee016 authored by Christophe Henry's avatar Christophe Henry

Fix no network case

parent eed7bcd7
......@@ -6,6 +6,7 @@
package="fr.chenry.android.freshrss">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<dist:module dist:instant="true" />
<application
android:name=".FreshRSSApplication"
......
package fr.chenry.android.freshrss
import android.app.Application
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.content.SharedPreferences
import android.content.*
import android.os.Handler
import android.os.IBinder
import androidx.core.app.NotificationManagerCompat
......@@ -96,7 +92,7 @@ class FreshRSSApplication : Application() {
private fun postDelayedRefesh() {
handler.postDelayed(this@FreshRSSApplication.refreshDelay * 60 * 1000, token) {
this@FreshRSSApplication.refresherService.value.whenNotNull {
it.refresh()
it.refresh(false)
postDelayedRefesh()
}
}
......
......@@ -5,12 +5,12 @@ import android.app.Service
import android.content.Intent
import android.os.Binder
import android.os.Build
import android.widget.Toast
import androidx.core.app.NotificationCompat
import fr.chenry.android.freshrss.R.drawable
import fr.chenry.android.freshrss.R.string
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.utils.NotificationChannels
import fr.chenry.android.freshrss.utils.NotificationHelper
import fr.chenry.android.freshrss.utils.*
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.all
import nl.komponents.kovenant.functional.bind
......@@ -43,9 +43,21 @@ class RefresherService: Service() {
override fun onBind(intent: Intent) = RefresherBinder()
fun refresh(): Promise<Unit, Exception> {
fun refresh(manual: Boolean = true): Promise<Unit, Exception> {
if(Store.refreshingPromise.value != null) return Store.refreshingPromise.value!!
if(!FreshRSSApplication.context.isConnectedToNetwork()) {
if(manual) {
Toast.makeText(
FreshRSSApplication.context,
getString(string.no_internet_connection_avaible),
Toast.LENGTH_LONG
).show()
}
Store.refreshingPromise.postValue(null)
return Promise.ofSuccess(Unit)
}
FreshRSSApplication.notificationManager
.notify(NotificationHelper.ONGOING_REFRESH_NOTIFICATION, refreshNotification)
......
......@@ -7,14 +7,10 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.postDelayed
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.RefresherService
import fr.chenry.android.freshrss.*
import fr.chenry.android.freshrss.store.database.models.VoidAccount
import fr.chenry.android.freshrss.store.viewmodels.AccountVM
import fr.chenry.android.freshrss.utils.e
import fr.chenry.android.freshrss.utils.whenNotNull
import fr.chenry.android.freshrss.utils.whenNull
import fr.chenry.android.freshrss.utils.*
import kotlinx.android.synthetic.main.activity_start.*
import nl.komponents.kovenant.ui.alwaysUi
import nl.komponents.kovenant.ui.failUi
......
......@@ -2,32 +2,26 @@ package fr.chenry.android.freshrss.components.subscriptionarticles
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.View
import android.view.ViewGroup
import android.os.Handler
import android.view.*
import android.webkit.WebView
import android.widget.Toast
import android.widget.Toast.LENGTH_SHORT
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.postDelayed
import androidx.fragment.app.Fragment
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.*
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.FRSSWebViewClient
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.ShareIntent
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.store.database.models.Article
import fr.chenry.android.freshrss.store.database.models.ReadStatus
import fr.chenry.android.freshrss.store.database.models.ReadStatus.UNREAD
import fr.chenry.android.freshrss.store.database.models.Subscription
import fr.chenry.android.freshrss.store.database.models.*
import fr.chenry.android.freshrss.store.viewmodels.SubscriptionArticleVM
import fr.chenry.android.freshrss.store.viewmodels.SubscriptionArticleVMF
import fr.chenry.android.freshrss.utils.e
import fr.chenry.android.freshrss.utils.isConnectedToNetwork
import nl.komponents.kovenant.ui.alwaysUi
import nl.komponents.kovenant.ui.failUi
......@@ -82,6 +76,10 @@ class SubscriptionArticlesDetailFragment : Fragment() {
setupShareAction(view)
setupOpenInBrowser(view)
if (article.readStatus == ReadStatus.UNREAD) handler.postDelayed(1000, token) {
setReadStatus(ReadStatus.READ)
}
return view
}
......@@ -91,11 +89,6 @@ class SubscriptionArticlesDetailFragment : Fragment() {
super.onCreateOptionsMenu(menu, inflater)
}
override fun onResume() {
super.onResume()
if (article.readStatus == UNREAD) setReadStatus(ReadStatus.READ)
}
override fun onDestroyView() {
activity.let { it as AppCompatActivity }.supportActionBar?.subtitle = null
super.onDestroyView()
......@@ -142,6 +135,15 @@ class SubscriptionArticlesDetailFragment : Fragment() {
}
private fun setReadStatus(readStatus: ReadStatus): Boolean {
if(!FreshRSSApplication.context.isConnectedToNetwork()) {
Toast.makeText(
FreshRSSApplication.context,
getString(R.string.no_internet_connection_avaible),
Toast.LENGTH_LONG
).show()
return false
}
if (isFetching.value!!) {
Toast.makeText(context, R.string.request_already_ongoing, LENGTH_SHORT).show()
return false
......@@ -150,7 +152,7 @@ class SubscriptionArticlesDetailFragment : Fragment() {
isFetching.value = true
Store.postReadStatus(article, readStatus)
.failUi { e ->
.failUi { e: Exception ->
this.e(e)
val readText = when (readStatus) {
......@@ -172,4 +174,9 @@ class SubscriptionArticlesDetailFragment : Fragment() {
"content" to article.content,
"href" to article.href
)
companion object {
private val handler = Handler()
private val token = object {}
}
}
package fr.chenry.android.freshrss.components.subscriptions
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.*
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
......@@ -15,24 +13,13 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import eu.davidea.fastscroller.FastScroller
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.MainNavDirections
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.subscriptions.SubscriptionSection.ALL
import fr.chenry.android.freshrss.components.subscriptions.SubscriptionSection.FAVORITES
import fr.chenry.android.freshrss.components.subscriptions.SubscriptionSection.UNREAD
import fr.chenry.android.freshrss.*
import fr.chenry.android.freshrss.components.subscriptions.SubscriptionSection.*
import fr.chenry.android.freshrss.components.subscriptions.adapters.SubscriptionsFlexibleAdapter
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.store.database.models.ReadStatus
import fr.chenry.android.freshrss.store.database.models.*
import fr.chenry.android.freshrss.store.database.models.ReadStatus.READ
import fr.chenry.android.freshrss.store.database.models.Subscription
import fr.chenry.android.freshrss.store.database.models.SubscriptionCategory
import fr.chenry.android.freshrss.store.database.models.Subscriptions
import fr.chenry.android.freshrss.store.database.models.VoidCategory
import fr.chenry.android.freshrss.store.viewmodels.AllSubscriptionsVM
import fr.chenry.android.freshrss.store.viewmodels.FavoritesSubscriptionsVM
import fr.chenry.android.freshrss.store.viewmodels.SubscriptionsFragmentCategoryVMF
import fr.chenry.android.freshrss.store.viewmodels.UnreadSubscriptionsVM
import fr.chenry.android.freshrss.store.viewmodels.*
import fr.chenry.android.freshrss.utils.whenNotNull
import kotlinx.android.synthetic.main.fast_scroller.*
import kotlinx.android.synthetic.main.fragment_subscriptions.*
......
package fr.chenry.android.freshrss.utils
import android.content.Context
import android.net.ConnectivityManager
import android.util.Log
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.joda.JodaModule
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.core.FuelError
import com.github.kittinunf.fuel.core.Request
import com.github.kittinunf.fuel.core.Response
import com.github.kittinunf.fuel.core.ResponseDeserializable
import com.github.kittinunf.fuel.core.*
import com.github.kittinunf.fuel.jackson.responseObject
import com.github.kittinunf.result.Result
import fr.chenry.android.freshrss.store.Store
......@@ -108,3 +107,8 @@ fun <V, E> Promise<V, E>.getOrDefault(default: V) = try {
fun <T : Any> T?.whenNotNull(body: (T) -> Unit) = if (this !== null) body(this).let { this } else this
fun <T : Any> T?.whenNull(body: () -> Unit) = this ?: body().let { this }
fun Context.isConnectedToNetwork(): Boolean {
val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager?
return connectivityManager?.activeNetworkInfo?.isConnectedOrConnecting() ?: false
}
......@@ -56,4 +56,6 @@
<string name="notification_channel_errors_description">FreshRSS a rencontre une erreur dont vous devriez être
informé
</string>
<string name="no_internet_connection_avaible">There is no internet connection avaible for now, please retry later
</string>
</resources>
\ No newline at end of file
......@@ -63,4 +63,8 @@
<string name="share_article">Share article of %s</string>
<string name="this_feed">this feed</string>
<string name="instance_url_malformed">This URL is malformed</string>
<string name="no_internet_connection_avaible">There is no internet connection avaible for now, please retry later
</string>
<!-- Other messages -->
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment