diff --git a/app/src/main/java/com/binarybricks/coiny/CoinyApplication.kt b/app/src/main/java/com/binarybricks/coiny/CoinyApplication.kt index 18653ef..0edbabf 100644 --- a/app/src/main/java/com/binarybricks/coiny/CoinyApplication.kt +++ b/app/src/main/java/com/binarybricks/coiny/CoinyApplication.kt @@ -8,6 +8,7 @@ import com.binarybricks.coiny.data.database.CoinyDatabase import com.crashlytics.android.Crashlytics import com.facebook.stetho.Stetho import com.squareup.leakcanary.LeakCanary +import io.reactivex.plugins.RxJavaPlugins import timber.log.Timber import timber.log.Timber.DebugTree @@ -50,6 +51,9 @@ class CoinyApplication : Application() { } database = Room.databaseBuilder(this, CoinyDatabase::class.java, DATABASE_NAME).build() + + // Logs all uncaught exceptions from RxJava usage and prevents default thread handling + RxJavaPlugins.setErrorHandler { throwable -> Timber.e(throwable) } } /** A tree which logs important information for crash reporting. */ diff --git a/app/src/main/java/com/binarybricks/coiny/stories/CryptoCompareRepository.kt b/app/src/main/java/com/binarybricks/coiny/stories/CryptoCompareRepository.kt index aa4de0d..5f3d283 100644 --- a/app/src/main/java/com/binarybricks/coiny/stories/CryptoCompareRepository.kt +++ b/app/src/main/java/com/binarybricks/coiny/stories/CryptoCompareRepository.kt @@ -27,8 +27,8 @@ Repository that interact with crypto api to get any info on coins. */ class CryptoCompareRepository( - private val baseSchedulerProvider: BaseSchedulerProvider, - private val coinyDatabase: CoinyDatabase? = null + private val baseSchedulerProvider: BaseSchedulerProvider, + private val coinyDatabase: CoinyDatabase? ) { /** diff --git a/app/src/main/java/com/binarybricks/coiny/stories/coinsearch/CoinDiscoveryFragment.kt b/app/src/main/java/com/binarybricks/coiny/stories/coinsearch/CoinDiscoveryFragment.kt index 13a8cd9..a88efce 100644 --- a/app/src/main/java/com/binarybricks/coiny/stories/coinsearch/CoinDiscoveryFragment.kt +++ b/app/src/main/java/com/binarybricks/coiny/stories/coinsearch/CoinDiscoveryFragment.kt @@ -7,6 +7,7 @@ import android.support.v4.app.Fragment import android.support.v7.app.AppCompatActivity import android.support.v7.widget.LinearLayoutManager import android.view.* +import com.binarybricks.coiny.CoinyApplication import com.binarybricks.coiny.R import com.binarybricks.coiny.components.* import com.binarybricks.coiny.data.PreferenceHelper @@ -40,7 +41,7 @@ class CoinDiscoveryFragment : Fragment(), CoinDiscoveryContract.View { } private val coinRepo by lazy { - CryptoCompareRepository(schedulerProvider) + CryptoCompareRepository(schedulerProvider, CoinyApplication.database) } private val coinDiscoveryPresenter: CoinDiscoveryPresenter by lazy { diff --git a/app/src/main/java/com/binarybricks/coiny/stories/dashboard/CoinDashboardFragment.kt b/app/src/main/java/com/binarybricks/coiny/stories/dashboard/CoinDashboardFragment.kt index d46dc58..b559ec0 100644 --- a/app/src/main/java/com/binarybricks/coiny/stories/dashboard/CoinDashboardFragment.kt +++ b/app/src/main/java/com/binarybricks/coiny/stories/dashboard/CoinDashboardFragment.kt @@ -56,7 +56,7 @@ class CoinDashboardFragment : Fragment(), CoinDashboardContract.View { } private val coinRepo by lazy { - CryptoCompareRepository(schedulerProvider) + CryptoCompareRepository(schedulerProvider, CoinyApplication.database) } private val coinDashboardPresenter: CoinDashboardPresenter by lazy { diff --git a/app/src/main/java/com/binarybricks/coiny/stories/settings/SettingsFragment.kt b/app/src/main/java/com/binarybricks/coiny/stories/settings/SettingsFragment.kt index ab5b853..bac599a 100644 --- a/app/src/main/java/com/binarybricks/coiny/stories/settings/SettingsFragment.kt +++ b/app/src/main/java/com/binarybricks/coiny/stories/settings/SettingsFragment.kt @@ -9,6 +9,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.binarybricks.coiny.BuildConfig +import com.binarybricks.coiny.CoinyApplication import com.binarybricks.coiny.R import com.binarybricks.coiny.data.PreferenceHelper import com.binarybricks.coiny.network.schedulers.SchedulerProvider @@ -30,7 +31,7 @@ class SettingsFragment : Fragment(), SettingsContract.View { } private val coinRepo by lazy { - CryptoCompareRepository(schedulerProvider) + CryptoCompareRepository(schedulerProvider, CoinyApplication.database) } private val settingsPresenter: SettingsPresenter by lazy { diff --git a/app/src/main/java/com/binarybricks/coiny/stories/settings/SettingsPresenter.kt b/app/src/main/java/com/binarybricks/coiny/stories/settings/SettingsPresenter.kt index 8b44121..c85862b 100644 --- a/app/src/main/java/com/binarybricks/coiny/stories/settings/SettingsPresenter.kt +++ b/app/src/main/java/com/binarybricks/coiny/stories/settings/SettingsPresenter.kt @@ -42,9 +42,10 @@ class SettingsPresenter( override fun refreshExchangeList() { compositeDisposable.add(coinRepo.getExchangeInfo() - .map { - compositeDisposable.add(coinRepo.insertExchangeIntoList(it).subscribe()) + .flatMap { + coinRepo.insertExchangeIntoList(it) } + .observeOn(schedulerProvider.ui()) .subscribe({ Timber.d("all exchanges loaded and inserted into db") currentView?.onExchangeListRefreshed()