Skip to content

Commit

Permalink
fixing the settings crash
Browse files Browse the repository at this point in the history
  • Loading branch information
pranayairan committed Jan 19, 2019
1 parent 8c37cc0 commit db78d8f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/binarybricks/coiny/CoinyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit db78d8f

Please sign in to comment.