Skip to content

Commit

Permalink
fix(app): Show error message when loading charts
Browse files Browse the repository at this point in the history
Fixes #62
  • Loading branch information
Joseph Cooper authored and grodin committed Mar 23, 2022
1 parent bfbd103 commit 829f7fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.michaelbull.result.combine
import com.github.michaelbull.result.coroutines.runSuspendCatching
import com.github.michaelbull.result.map
import com.github.michaelbull.result.mapError
import com.github.michaelbull.result.onFailure
import com.google.firebase.firestore.DocumentSnapshot
import com.google.firebase.firestore.FirebaseFirestore
import com.omricat.maplibrarian.model.ChartId
Expand All @@ -18,6 +19,7 @@ import com.omricat.maplibrarian.utils.DispatcherProvider
import com.omricat.maplibrarian.utils.logErrorAndMap
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.withContext
import timber.log.Timber

class FirebaseChartsService(
private val db: FirebaseFirestore,
Expand All @@ -34,6 +36,7 @@ class FirebaseChartsService(
}
}
.mapError(ChartsServiceError::fromThrowable)
.onFailure { Timber.e(it.message) }
.andThen { snapshot ->
snapshot.map { m -> m.parseMapModel() }.combine()
.mapError { e -> ChartsServiceError(e.message) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.squareup.workflow1.ui.WorkflowLayout
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.renderWorkflowIn
import kotlinx.coroutines.flow.StateFlow
import timber.log.Timber

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -42,7 +43,13 @@ internal class MainViewModel(app: Application, private val savedState: SavedStat
),
scope = viewModelScope,
savedStateHandle = savedState,
interceptors = listOf(SimpleLoggingWorkflowInterceptor())
interceptors = listOf(TimberLoggingWorkflowInterceptor)
)
}
}

internal object TimberLoggingWorkflowInterceptor : SimpleLoggingWorkflowInterceptor() {
override fun log(text: String) {
Timber.d(text)
}
}
9 changes: 6 additions & 3 deletions app/src/main/res/layout/error.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
xmlns:tools="http://schemas.android.com/tools"
tools:text="Error!" />

0 comments on commit 829f7fc

Please sign in to comment.