diff --git a/android-app/app/src/main/java/arun/com/chromer/data/history/paging/PagedHistoryDataSource.kt b/android-app/app/src/main/java/arun/com/chromer/data/history/paging/PagedHistoryDataSource.kt index 84da46e1..6e38b5f2 100644 --- a/android-app/app/src/main/java/arun/com/chromer/data/history/paging/PagedHistoryDataSource.kt +++ b/android-app/app/src/main/java/arun/com/chromer/data/history/paging/PagedHistoryDataSource.kt @@ -23,9 +23,6 @@ import androidx.paging.DataSource import androidx.paging.PositionalDataSource import arun.com.chromer.data.history.HistoryStore import arun.com.chromer.data.website.model.Website -import dev.arunkumar.android.rxschedulers.SchedulerProvider -import io.reactivex.disposables.CompositeDisposable -import java.util.concurrent.TimeUnit import javax.inject.Inject import javax.inject.Provider import javax.inject.Singleton @@ -33,22 +30,7 @@ import javax.inject.Singleton @Singleton class PagedHistoryDataSource @Inject -constructor( - private val historyStore: HistoryStore, - private val schedulerProvider: SchedulerProvider -) : PositionalDataSource() { - - private val compositeDisposable = CompositeDisposable() - - init { - addInvalidatedCallback { compositeDisposable.clear() } - compositeDisposable.add( - historyStore.changes() - .debounce(200, TimeUnit.MILLISECONDS) - .subscribe { invalidate() } - ) - } - +constructor(private val historyStore: HistoryStore) : PositionalDataSource() { override fun loadRange( params: LoadRangeParams, diff --git a/android-app/app/src/main/java/arun/com/chromer/history/HistoryFragment.kt b/android-app/app/src/main/java/arun/com/chromer/history/HistoryFragment.kt index 19cb5eff..1ffc7fb1 100644 --- a/android-app/app/src/main/java/arun/com/chromer/history/HistoryFragment.kt +++ b/android-app/app/src/main/java/arun/com/chromer/history/HistoryFragment.kt @@ -127,6 +127,7 @@ class HistoryFragment : BaseFragment(), Snackable, FabHandler { loadingLiveData.observe(owner, Observer { loading(it!!) }) historyPagedListLiveData.observe(owner, Observer { historyAdapter.submitList(it) }) } + loadHistory() } private fun setupIncognitoSwitch() { @@ -196,10 +197,7 @@ class HistoryFragment : BaseFragment(), Snackable, FabHandler { swipeRefreshLayout.apply { setColorSchemeColors(ContextCompat.getColor(context!!, R.color.colorPrimary), ContextCompat.getColor(context!!, R.color.accent)) - setOnRefreshListener { - viewModel.invalidate() - isRefreshing = false - } + setOnRefreshListener { loadHistory() } } ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(0, LEFT or RIGHT) { @@ -216,10 +214,15 @@ class HistoryFragment : BaseFragment(), Snackable, FabHandler { }).attachToRecyclerView(historyList) } + private fun loadHistory() { + viewModel.loadHistory() + } + override fun inject(fragmentComponent: FragmentComponent) = fragmentComponent.inject(this) override fun onResume() { super.onResume() + loadHistory() historySwitch.isChecked = !preferences.historyDisabled() } diff --git a/android-app/app/src/main/java/arun/com/chromer/history/HistoryFragmentViewModel.kt b/android-app/app/src/main/java/arun/com/chromer/history/HistoryFragmentViewModel.kt index aba1b92e..2347a686 100644 --- a/android-app/app/src/main/java/arun/com/chromer/history/HistoryFragmentViewModel.kt +++ b/android-app/app/src/main/java/arun/com/chromer/history/HistoryFragmentViewModel.kt @@ -25,6 +25,7 @@ import arun.com.chromer.data.history.HistoryRepository import arun.com.chromer.data.website.model.Website import arun.com.chromer.util.SchedulerProvider import rx.Observable +import rx.subjects.PublishSubject import rx.subscriptions.CompositeSubscription import timber.log.Timber import javax.inject.Inject @@ -41,10 +42,23 @@ constructor( val loadingLiveData = MutableLiveData() var historyPagedListLiveData = historyRepository.pagedHistory() + private val loaderSubject: PublishSubject = PublishSubject.create() val subs = CompositeSubscription() - fun invalidate() { - historyPagedListLiveData.value?.dataSource?.invalidate() + init { + /* subs.add(loaderSubject + .doOnNext { loadingLiveData.postValue(true) } + .switchMap { + historyRepository + .allItemsCursor + .compose(SchedulerProvider.applyIoSchedulers()) + }.doOnNext { loadingLiveData.postValue(false) } + .doOnNext(historyCursorLiveData::postValue) + .subscribe())*/ + } + + fun loadHistory() { + loaderSubject.onNext(0) } fun deleteAll(onSuccess: (rows: Int) -> Unit) { @@ -52,7 +66,7 @@ constructor( .deleteAll() .compose(SchedulerProvider.applyIoSchedulers()) .doOnNext { rows -> - invalidate() + loadHistory() onSuccess(rows) }.subscribe()) } @@ -60,9 +74,10 @@ constructor( fun deleteHistory(website: Website?) { subs.add(Observable.just(website) .filter { webSite -> webSite?.url != null } - .flatMap { historyRepository.delete(it!!) } + .flatMap { historyRepository.delete(it!!) } .compose(SchedulerProvider.applyIoSchedulers()) .doOnError(Timber::e) + .doOnNext { loadHistory() } .subscribe()) }