Commit da77f03b authored by Christophe Henry's avatar Christophe Henry

Merge branch 'refacto' into 'develop'

Refacto

See merge request !72
parents bd9092f7 4e427552
Pipeline #3482 failed with stage
in 0 seconds
......@@ -10,7 +10,8 @@
## Bug fixes
* Fix a bug preventing to refresh when subscription lists are empty ([!62](https://git.feneas.org/christophehenry/freshrss-android/merge_requests/62/))
* Fix a bug preventing to refresh when subscription lists are empty ([!62](https://git.feneas.org/christophehenry/freshrss-android/merge_requests/62/))
* Fix [#82](https://git.feneas.org/christophehenry/freshrss-android/issues/82): home and back buttons are sometimes not displayed correctly or not displayed at all ([!71](https://git.feneas.org/christophehenry/freshrss-android/merge_requests/71))
## Refactoring
......
......@@ -13,7 +13,6 @@ import fr.chenry.android.freshrss.RefresherService.RefresherBinder
import fr.chenry.android.freshrss.store.FreshRSSPreferences
import fr.chenry.android.freshrss.store.database.FreshRSSDabatabase
import fr.chenry.android.freshrss.store.database.FreshRSSDabatabase_Migrations
import fr.chenry.android.freshrss.utils.whenNotNull
import nl.komponents.kovenant.android.startKovenant
import nl.komponents.kovenant.android.stopKovenant
import org.acra.ACRA
......@@ -82,7 +81,7 @@ class FreshRSSApplication: Application() {
inline get() = NotificationManagerCompat.from(app)
val preferences: FreshRSSPreferences inline get() = app.preferences
fun getStringR(id: Int, vararg formatArgs: Any = arrayOf()): String = if(formatArgs.isEmpty())
fun getString(id: Int, vararg formatArgs: Any = arrayOf()): String = if(formatArgs.isEmpty())
app.resources.getString(id) else
app.resources.getString(id, *formatArgs)
}
......@@ -125,7 +124,7 @@ class FreshRSSApplication: Application() {
if(this.refreshFrequency == 0L) return
handler.postDelayed(this.refreshFrequency * 60 * 1000, token) {
this@FreshRSSApplication.refresherService.value.whenNotNull {
this@FreshRSSApplication.refresherService.value?.let {
it.refresh(false)
postDelayedRefesh()
}
......@@ -133,3 +132,5 @@ class FreshRSSApplication: Application() {
}
}
}
val F = FreshRSSApplication.Companion
......@@ -46,10 +46,10 @@ class RefresherService: Service() {
fun refresh(manual: Boolean = true): Promise<Unit, Exception> {
if(Store.refreshingPromise.value != null) return Store.refreshingPromise.value!!
if(!FreshRSSApplication.context.isConnectedToNetwork()) {
if(!F.context.isConnectedToNetwork()) {
if(manual) {
Toast.makeText(
FreshRSSApplication.context,
F.context,
getString(string.no_internet_connection_avaible),
Toast.LENGTH_LONG
).show()
......@@ -58,16 +58,14 @@ class RefresherService: Service() {
return Promise.ofSuccess(Unit)
}
FreshRSSApplication.notificationManager
.notify(NotificationHelper.ONGOING_REFRESH_NOTIFICATION, refreshNotification)
F.notificationManager.notify(NotificationHelper.ONGOING_REFRESH_NOTIFICATION, refreshNotification)
Store.ensureToken()
val promise = Store.getSubscriptions()
.bind {Store.getUnreadCount()}
.bind {
FreshRSSApplication
.db
F.db
.getAllSubcriptionsIds()
.blockingFirst()
.map {Store.getStreamContents(it)}
......@@ -78,9 +76,7 @@ class RefresherService: Service() {
Store.refreshingPromise.postValue(promise)
promise.always {Store.refreshingPromise.postValue(null)}
.failUi {
FreshRSSApplication
.notificationManager
.notify(NotificationHelper.FAIL_REFRESH_NOTIFICATION, failNotification)
F.notificationManager.notify(NotificationHelper.FAIL_REFRESH_NOTIFICATION, failNotification)
}.alwaysUi {
cancelRefreshNotification()
}
......@@ -89,18 +85,18 @@ class RefresherService: Service() {
}
fun cancelRefreshNotification() =
FreshRSSApplication.notificationManager.cancel(NotificationHelper.ONGOING_REFRESH_NOTIFICATION)
F.notificationManager.cancel(NotificationHelper.ONGOING_REFRESH_NOTIFICATION)
private fun createNotification(chan: NotificationChannels, title: Int, text: Int, color: Int? = null) =
NotificationCompat
.Builder(FreshRSSApplication.app, chan.channelId)
.setContentTitle(FreshRSSApplication.getStringR(title))
.setContentText(FreshRSSApplication.getStringR(text))
.Builder(F.app, chan.channelId)
.setContentTitle(F.getString(title))
.setContentText(F.getString(text))
.setSmallIcon(drawable.ic_rss_feed_black_24dp)
.setShowWhen(false)
.apply {
if(color != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.M)
this.color = FreshRSSApplication.context.getColor(color)
this.color = F.context.getColor(color)
}
inner class RefresherBinder: Binder() {
......
......@@ -9,19 +9,13 @@ import android.os.ResultReceiver
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.AdapterView
import android.widget.*
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.addTextChangedListener
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.utils.InstanceUrl
import fr.chenry.android.freshrss.utils.Try
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_login.*
import nl.komponents.kovenant.deferred
import nl.komponents.kovenant.resolve
......@@ -141,7 +135,7 @@ class LoginActivity : AppCompatActivity() {
private fun hideKeyboard() {
val deferred = deferred<Unit, Exception>()
val view = this.currentFocus
view.whenNotNull {
view?.let {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(it.windowToken, 0, object : ResultReceiver(null) {
override fun onReceiveResult(resultCode: Int, resultData: Bundle?) = deferred.resolve()
......
......@@ -9,7 +9,7 @@ import androidx.lifecycle.Observer
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.*
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.navigationdrawer.AddSubscriptionDialog
import fr.chenry.android.freshrss.components.subscriptions.MainSubscriptionFragmentDirections
......@@ -38,7 +38,7 @@ class MainActivity: AppCompatActivity() {
super.onCreate(savedInstanceState)
restoreState()
setContentView(R.layout.activity_main)
FreshRSSApplication.app.refresherService.value?.apply {refresh()}
F.app.refresherService.value?.apply {refresh()}
NavigationUI.setupActionBarWithNavController(this, navigation, appBarConfiguration)
setupActionBarWithNavController(navigation, appBarConfiguration)
drawerLayout.addDrawerListener(BurgerMenuDrawerListener(this))
......@@ -102,10 +102,10 @@ class MainActivity: AppCompatActivity() {
navigation.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
private fun restoreState() {
Store.subscriptionsSection.value = FreshRSSApplication.preferences.subscriptionSection
Store.subscriptionsSection.value = F.preferences.subscriptionSection
}
private fun saveState() {
FreshRSSApplication.app.preferences.subscriptionSection = Store.subscriptionsSection.value!!
F.app.preferences.subscriptionSection = Store.subscriptionsSection.value!!
}
}
......@@ -10,20 +10,21 @@ import androidx.lifecycle.ViewModelProvider
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.*
import fr.chenry.android.freshrss.utils.e
import fr.chenry.android.freshrss.utils.whenNull
import kotlinx.android.synthetic.main.activity_start.*
import nl.komponents.kovenant.ui.alwaysUi
import nl.komponents.kovenant.ui.failUi
import org.joda.time.LocalDateTime
class StartActivity : AppCompatActivity() {
private val model by lazy { ViewModelProvider(this).get(AccountVM::class.java) }
private val observer = object : Observer<RefresherService> {
class StartActivity: AppCompatActivity() {
private val model by lazy {ViewModelProvider(this).get(AccountVM::class.java)}
private val observer = object: Observer<RefresherService> {
override fun onChanged(t: RefresherService?) {
t.whenNotNull {
t?.let {
it.refresh()
.failUi { err -> this.e(err) }
.alwaysUi { FreshRSSApplication.app.refresherService.removeObserver(this) }
.failUi {err -> this.e(err)}
.alwaysUi {F.app.refresherService.removeObserver(this)}
}
}
}
......@@ -34,11 +35,9 @@ class StartActivity : AppCompatActivity() {
val now = LocalDateTime.now()
val userName = model.liveData.value.let {
it.whenNotNull {
FreshRSSApplication.app.refresherService.observeForever(observer)
}
it?.let {F.app.refresherService.observeForever(observer)}
when (it) {
when(it) {
null -> ""
VoidAccount -> ""
else -> " ${it.login}"
......@@ -46,17 +45,15 @@ class StartActivity : AppCompatActivity() {
}
activity_start_welcome_text.text = when {
now.isBefore(now.withTime(11, 0, 0, 0)) ->
FreshRSSApplication.getStringR(R.string.good_morning_user, userName)
now.isBefore(now.withTime(18, 0, 0, 0)) ->
FreshRSSApplication.getStringR(R.string.hello_user, userName)
else -> FreshRSSApplication.getStringR(R.string.good_evening_user, userName)
now.isBefore(now.withTime(11, 0, 0, 0)) -> F.getString(R.string.good_morning_user, userName)
now.isBefore(now.withTime(18, 0, 0, 0)) -> F.getString(R.string.hello_user, userName)
else -> F.getString(R.string.good_evening_user, userName)
}
}
override fun onResume() {
super.onResume()
model.liveData.value.whenNotNull {
model.liveData.value?.let {
startNextActivity(MainActivity::class.java)
}.whenNull {
startNextActivity(LoginActivity::class.java)
......
......@@ -8,14 +8,14 @@ import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.utils.*
import java.net.URL
class AddSubscriptionDialog(private val callback: (String) -> Unit): DialogFragment() {
private val clipboard by lazy {
FreshRSSApplication.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
F.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
}
private val dialogView by lazy {
......
......@@ -2,18 +2,18 @@ package fr.chenry.android.freshrss.components.navigationdrawer
import android.os.Bundle
import androidx.preference.*
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.R
class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
private val refreshFrequencyPreference: ListPreference by lazy {
findPreference(FreshRSSApplication.preferences.refreshFrequencyKey) as ListPreference
findPreference(F.preferences.refreshFrequencyKey) as ListPreference
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preference_screen)
refreshFrequencyPreference.apply {
this@SettingsFragment.onPreferenceChange(this, FreshRSSApplication.preferences.refreshFrequency)
this@SettingsFragment.onPreferenceChange(this, F.preferences.refreshFrequency)
onPreferenceChangeListener = this@SettingsFragment
}
}
......@@ -21,10 +21,10 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
if(preference.key == refreshFrequencyPreference.key) {
refreshFrequencyPreference.findIndexOfValue(newValue.toString()).let {
val newValueStr = if(it < 0) FreshRSSApplication.getStringR(R.string.refresh_frequency_30m) else
val newValueStr = if(it < 0) F.getString(R.string.refresh_frequency_30m) else
refreshFrequencyPreference.entries[it]
refreshFrequencyPreference.title =
FreshRSSApplication.getStringR(R.string.refresh_frequency_title, newValueStr)
F.getString(R.string.refresh_frequency_title, newValueStr)
}
return true
}
......
......@@ -11,7 +11,7 @@ import androidx.core.os.postDelayed
import androidx.fragment.app.Fragment
import androidx.lifecycle.*
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.FRSSWebView
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.ShareIntent
......@@ -76,7 +76,7 @@ class SubscriptionArticlesDetailFragment : Fragment() {
private fun setupShareAction(view: View) {
view.findViewById<ExtendedFloatingActionButton>(R.id.fab_share)
.setOnClickListener {
val chooserTitle = FreshRSSApplication.getStringR(R.string.share_article, subscription.title)
val chooserTitle = F.getString(R.string.share_article, subscription.title)
startActivity(Intent.createChooser(ShareIntent.create(getTemplateAttributes()), chooserTitle))
}
}
......@@ -114,12 +114,8 @@ 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()
if(!F.context.isConnectedToNetwork()) {
Toast.makeText(context, R.string.no_internet_connection_avaible, Toast.LENGTH_LONG).show()
return false
}
......
......@@ -6,7 +6,7 @@ import android.util.AttributeSet
import android.webkit.WebSettings.MENU_ITEM_NONE
import android.webkit.WebView
import androidx.fragment.app.Fragment
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.store.database.models.Article
import org.jsoup.Jsoup
......@@ -66,7 +66,7 @@ class FRSSWebView @JvmOverloads constructor(
link.after(newImage).remove()
newImage.after("""
|<a href="$linkToOriginalImage" class="link-to-original-image">
| ${FreshRSSApplication.getStringR(R.string.link_to_original_image)}
| ${F.getString(R.string.link_to_original_image)}
|</a>""".trimMargin())
}
......
......@@ -3,9 +3,8 @@ package fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils
import android.content.Intent
import android.content.Intent.*
import com.x5.template.Theme
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.R.string
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.SentenceCapFilter
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.StripFragmentFilter
import fr.chenry.android.freshrss.utils.nullIfBlank
......@@ -30,7 +29,7 @@ object ShareIntent {
fun create(attributes: Map<String, String>) = Intent(ACTION_SEND).apply {
type = "text/plain"
putExtra(EXTRA_TEXT, format(attributes))
val feedName = attributes["subscription"]?.nullIfBlank() ?: FreshRSSApplication.getStringR(R.string.this_feed)
putExtra(EXTRA_SUBJECT, FreshRSSApplication.getStringR(string.share_article, feedName))
val feedName = attributes["subscription"]?.nullIfBlank() ?: F.getString(R.string.this_feed)
putExtra(EXTRA_SUBJECT, F.getString(R.string.share_article, feedName))
}
}
......@@ -11,7 +11,7 @@ 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.F
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.subscriptions.SubscriptionSection.*
import fr.chenry.android.freshrss.components.subscriptions.adapters.SubscriptionsFlexibleAdapter
......@@ -20,7 +20,6 @@ import fr.chenry.android.freshrss.store.database.models.*
import fr.chenry.android.freshrss.store.database.models.ReadStatus.READ
import fr.chenry.android.freshrss.store.viewmodels.*
import fr.chenry.android.freshrss.utils.EmotionnalImageSubtext
import fr.chenry.android.freshrss.utils.whenNotNull
import kotlinx.android.synthetic.main.fragment_subscriptions.*
import nl.komponents.kovenant.Promise
......@@ -62,7 +61,7 @@ class SubscriptionsFragment: Fragment(), Observer<Subscriptions> {
UNREAD -> R.string.empty_subscriptions_section_unread
FAVORITES -> R.string.empty_subscriptions_section_favorites
}
}.let {FreshRSSApplication.getStringR(it, category.label)}
}.let {F.getString(it, category.label)}
view.findViewById<EmotionnalImageSubtext>(R.id.fragment_subscriptions_empty_list).text = contentDescription
......@@ -80,7 +79,7 @@ class SubscriptionsFragment: Fragment(), Observer<Subscriptions> {
it.isRefreshing = v != null
})
it.setOnRefreshListener {
FreshRSSApplication.app.refresherService.value.whenNotNull {rs -> rs.refresh()}
F.app.refresherService.value?.let {rs -> rs.refresh()}
}
}
......
......@@ -7,7 +7,7 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractHeaderItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.R
import java.util.concurrent.ConcurrentHashMap
......@@ -53,5 +53,4 @@ open class SubscriptionViewHeaderItem protected constructor(val title: String) :
}
}
object SubscriptionCategoryViewHeaderItem :
SubscriptionViewHeaderItem(FreshRSSApplication.getStringR(R.string.subscription_categories))
object SubscriptionCategoryViewHeaderItem : SubscriptionViewHeaderItem(F.getString(R.string.subscription_categories))
package fr.chenry.android.freshrss.store
import androidx.lifecycle.*
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.components.subscriptions.SubscriptionSection
import fr.chenry.android.freshrss.store.api.Api
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.ReadStatus.UNREAD
import fr.chenry.android.freshrss.store.database.models.SubscriptionCategory.Companion.fromApiItem
import fr.chenry.android.freshrss.utils.whenNotNull
import fr.chenry.android.freshrss.utils.whenNull
import nl.komponents.kovenant.*
import nl.komponents.kovenant.functional.bind
......@@ -25,11 +24,8 @@ object Store {
val refreshingPromise = MutableLiveData<Promise<Unit, Exception>>()
val account by lazy {
MutableLiveData<Account>().apply {
accountLiveData.value?.firstOrNull().whenNull {value = VoidAccount}
.whenNotNull {value = it}
accountLiveData.observeForever {self ->
self.firstOrNull().whenNull {value = VoidAccount}.whenNotNull {value = it}
}
accountLiveData.value?.firstOrNull()?.let {value = it}.whenNull {value = VoidAccount}
accountLiveData.observeForever {self -> self.firstOrNull()?.let {value = it}.whenNull {value = VoidAccount}}
}
}
......@@ -39,16 +35,16 @@ object Store {
private val onGoingPostRequests = ConcurrentHashMap<String, Promise<Unit, Exception>>()
init {
val flowable = FreshRSSApplication.db.getAccount()
val flowable = F.db.getAccount()
val account = flowable.blockingFirst().firstOrNull() ?: VoidAccount
api = Api(account)
accountLiveData = FreshRSSApplication.db.getAccount().toLiveData().apply {
accountLiveData = F.db.getAccount().toLiveData().apply {
observeForever {if(it.isNotEmpty()) api = Api(it.first())}
}
}
fun login(instance: String, user: String, password: String): Promise<Unit, Exception> =
Api.login(instance, user, password) then {FreshRSSApplication.db.insertAccount(it)}
Api.login(instance, user, password) then {F.db.insertAccount(it)}
fun ensureToken(): Promise<Unit, Exception> {
if(!api.account.isWriteTokenExpired) return Promise.ofSuccess(Unit)
......@@ -60,18 +56,18 @@ object Store {
fun getSubscriptions(): Promise<Unit, Exception> = api.getSubscriptions() bind {
val subscriptions = it.map {self -> Subscription.fromSubscriptionApiItem(self)}
val syncPromise = FreshRSSApplication.db.syncSubscriptions(subscriptions).always {
val syncPromise = F.db.syncSubscriptions(subscriptions).always {
task {
FreshRSSApplication.db.let {db ->
db.getAllSubcriptionsWithImageToUpdate()
F.db.apply {
getAllSubcriptionsWithImageToUpdate()
.blockingFirst()
.forEach {sub -> db.insertSubscriptionImage(sub.id, sub.fetchImage())}
.forEach {sub -> insertSubscriptionImage(sub.id, sub.fetchImage())}
}
}
}
val categoriesPromise = task {
val subscriptionCategories = it.flatMap {self -> self.categories}.map(::fromApiItem)
FreshRSSApplication.db.insertAllSubscriptionCategories(subscriptionCategories)
F.db.insertAllSubscriptionCategories(subscriptionCategories)
}
all(syncPromise, categoriesPromise, cancelOthersOnError = false).toSuccessVoid()
}
......@@ -80,23 +76,15 @@ object Store {
api.getUnreadCount() then {
totalUnreadCount.postValue(it.max)
it.unreadcounts
.forEach {self ->
FreshRSSApplication.db.updateSubscriptionCount(
self.id,
self.count
)
}
.forEach {self -> F.db.updateSubscriptionCount(self.id, self.count)}
}
fun getStreamContents(id: String): Promise<Unit, Exception> =
api.getStreamContents(id) bind {
val insertPromises = it.items.map {item ->
task {
FreshRSSApplication.db.insertArticle(Article.fromContentItem(item))
FreshRSSApplication.db.updateSubscriptionNewestArticleDate(
id,
item.crawled
)
F.db.insertArticle(Article.fromContentItem(item))
F.db.updateSubscriptionNewestArticleDate(id, item.crawled)
}
}
all(insertPromises, cancelOthersOnError = false).toSuccessVoid()
......@@ -107,13 +95,7 @@ object Store {
fun getUnreadItems(): Promise<Unit, Exception> =
api.getUnreadItems(lastFetchTimestamp) bind {
val promises = it.items.map {item ->
task {
FreshRSSApplication.db.upsertArticle(
Article.fromContentItem(item).copy(
readStatus = UNREAD
)
)
}
task {F.db.upsertArticle(Article.fromContentItem(item).copy(readStatus = UNREAD))}
}
lastFetchTimestamp = System.currentTimeMillis() % 1000
all(promises, cancelOthersOnError = false).toSuccessVoid()
......@@ -128,15 +110,14 @@ object Store {
article.requestOnGoing = false
onGoingPostRequests.remove(article.id)
}.success {
val db = FreshRSSApplication.db
db.upsertArticle(article.copy(readStatus = readStatus))
F.db.upsertArticle(article.copy(readStatus = readStatus))
when(readStatus) {
READ -> {
db.decrementSubscriptionCount(article.streamId)
F.db.decrementSubscriptionCount(article.streamId)
totalUnreadCount.postValue(max((totalUnreadCount.value ?: 0) - 1, 0))
}
UNREAD -> {
db.incrementSubscriptionCount(article.streamId)
F.db.incrementSubscriptionCount(article.streamId)
totalUnreadCount.postValue((totalUnreadCount.value ?: 0) + 1)
}
}
......@@ -158,9 +139,9 @@ object Store {
getStreamContents(id)
} bind {
getUnreadItems()
} alwaysUi { refreshingPromise.value = null }
} alwaysUi {refreshingPromise.value = null}
refreshingPromise.value.whenNotNull {
refreshingPromise.value?.let {
it.always {
addCallback().success(deferred::resolve).fail(deferred::reject)
}
......
package fr.chenry.android.freshrss.store.viewmodels
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.toLiveData
import fr.chenry.android.freshrss.FreshRSSApplication
import androidx.lifecycle.*
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.store.database.models.Account
class AccountVM : ViewModel() {
......@@ -13,7 +10,7 @@ class AccountVM : ViewModel() {
private val source: LiveData<List<Account>>
init {
val flowable = FreshRSSApplication.db.getAccount()
val flowable = F.db.getAccount()
source = flowable.toLiveData()
liveData = MutableLiveData<Account>().apply {
value = flowable.blockingFirst().firstOrNull()
......
package fr.chenry.android.freshrss.store.viewmodels
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.toLiveData
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.store.database.models.Article
import fr.chenry.android.freshrss.store.database.models.Articles