Skip to content

Commit 988da4e

Browse files
Copilothoc081098
andcommitted
Code quality improvements: simplify navigator calls, fix operators, add release logging
Co-authored-by: hoc081098 <[email protected]>
1 parent 990923d commit 988da4e

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

app/src/main/java/com/hoc/flowmvi/initializer/TimberInitializer.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.hoc.flowmvi.initializer
44

55
import android.content.Context
6+
import android.util.Log
67
import androidx.startup.Initializer
78
import com.hoc.flowmvi.BuildConfig
89
import timber.log.Timber
@@ -12,10 +13,34 @@ class TimberInitializer : Initializer<Unit> {
1213
if (BuildConfig.DEBUG) {
1314
Timber.plant(Timber.DebugTree())
1415
} else {
15-
// TODO(Timber): plant release tree
16+
Timber.plant(ReleaseTree())
1617
}
1718
Timber.d("TimberInitializer...")
1819
}
1920

2021
override fun dependencies(): List<Class<out Initializer<*>>> = emptyList()
2122
}
23+
24+
/**
25+
* A Timber tree for release builds that only logs warnings and errors.
26+
* This prevents sensitive information from being logged in production.
27+
*/
28+
private class ReleaseTree : Timber.Tree() {
29+
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
30+
if (priority == Log.VERBOSE || priority == Log.DEBUG || priority == Log.INFO) {
31+
return
32+
}
33+
34+
// Log warnings and errors to system log
35+
// In a production app, you might want to send these to a crash reporting service
36+
// like Firebase Crashlytics, Sentry, etc.
37+
if (priority == Log.ERROR && t != null) {
38+
// You could send to crash reporting service here
39+
Log.e(tag, message, t)
40+
} else if (priority == Log.WARN) {
41+
Log.w(tag, message)
42+
} else if (priority == Log.ERROR) {
43+
Log.e(tag, message)
44+
}
45+
}
46+
}

core-ui/src/main/java/com/hoc/flowmvi/core_ui/parcelable.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import android.os.Parcelable
99
* https://stackoverflow.com/a/73311814/11191424
1010
*/
1111
inline fun <reified T : Parcelable> Intent.parcelable(key: String): T? =
12-
// TODO: Use `>`, because https://issuetracker.google.com/issues/240585930#comment6
13-
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
12+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
1413
getParcelableExtra(key, T::class.java)
1514
} else {
1615
@Suppress("DEPRECATION")
@@ -21,8 +20,7 @@ inline fun <reified T : Parcelable> Intent.parcelable(key: String): T? =
2120
* https://stackoverflow.com/a/73311814/11191424
2221
*/
2322
inline fun <reified T : Parcelable> Bundle.parcelable(key: String): T? =
24-
// TODO: Use `>`, because https://issuetracker.google.com/issues/240585930#comment6
25-
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
23+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
2624
getParcelable(key, T::class.java)
2725
} else {
2826
@Suppress("DEPRECATION")

feature-main/src/main/java/com/hoc/flowmvi/ui/main/MainActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class MainActivity : AbstractMviActivity<ViewIntent, ViewState, SingleEvent, Mai
4343
override fun onOptionsItemSelected(item: MenuItem): Boolean =
4444
when (item.itemId) {
4545
R.id.add_action -> {
46-
navigator.run { navigateToAdd() }
46+
navigator.navigateToAdd()
4747
true
4848
}
4949
R.id.search_action -> {
50-
navigator.run { navigateToSearch() }
50+
navigator.navigateToSearch()
5151
true
5252
}
5353
else -> super.onOptionsItemSelected(item)
@@ -106,7 +106,7 @@ class MainActivity : AbstractMviActivity<ViewIntent, ViewState, SingleEvent, Mai
106106
userAdapter.submitList(viewState.userItems)
107107

108108
mainBinding.run {
109-
errorGroup.isVisible = viewState.error !== null
109+
errorGroup.isVisible = viewState.error != null
110110
errorMessageTextView.text =
111111
viewState.error?.let {
112112
when (it) {

feature-search/src/main/java/com/hoc/flowmvi/ui/search/SearchActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SearchActivity : AbstractMviActivity<ViewIntent, ViewState, SingleEvent, S
6868
.setDuration(200),
6969
)
7070

71-
errorGroup.isVisible = viewState.error !== null
71+
errorGroup.isVisible = viewState.error != null
7272
if (errorGroup.isVisible) {
7373
errorMessageTextView.text =
7474
viewState.error?.let {

feature-search/src/main/java/com/hoc/flowmvi/ui/search/SearchVM.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class SearchVM(
9090
): Flow<PartialStateChange> =
9191
flatMapFirst {
9292
viewState.value.let { vs ->
93-
if (vs.error !== null) {
93+
if (vs.error != null) {
9494
executeSearch(vs.submittedQuery).takeUntil(searchableQueryFlow)
9595
} else {
9696
emptyFlow()

0 commit comments

Comments
 (0)