Skip to content

Commit d0d732b

Browse files
Clean saveFocusWhenNavigatingBack() code
1 parent 50ce437 commit d0d732b

File tree

1 file changed

+5
-7
lines changed
  • app/src/main/java/com/infomaniak/mail/utils

1 file changed

+5
-7
lines changed

app/src/main/java/com/infomaniak/mail/utils/UiUtils.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -165,26 +165,24 @@ object UiUtils {
165165
fun dividerDrawable(context: Context) = AppCompatResources.getDrawable(context, R.drawable.divider)
166166

167167
fun saveFocusWhenNavigatingBack(getLayout: () -> ViewGroup, lifecycle: Lifecycle) {
168+
168169
val lifecycleObserver = object : DefaultLifecycleObserver {
170+
169171
@IdRes
170172
private var lastFocusViewId: Int? = null
171173

172174
override fun onStart(owner: LifecycleOwner) {
173175
super.onStart(owner)
174-
lastFocusViewId?.let { viewId ->
175-
getLayout().findViewById<View>(viewId).requestFocus()
176-
}
176+
lastFocusViewId?.let { viewId -> getLayout().findViewById<View>(viewId).requestFocus() }
177177
}
178178

179179
override fun onStop(owner: LifecycleOwner) {
180-
getLayout().focusedChild?.let {
181-
lastFocusViewId = it.id
182-
}
180+
getLayout().focusedChild?.let { lastFocusViewId = it.id }
183181
super.onStop(owner)
184182
}
185183

186184
override fun onDestroy(owner: LifecycleOwner) {
187-
lifecycle.removeObserver(this)
185+
lifecycle.removeObserver(observer = this)
188186
super.onDestroy(owner)
189187
}
190188
}

0 commit comments

Comments
 (0)