Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 3c8c4f7

Browse files
committed
fix: simplify logic for determining forward/backward transition in main activity
1 parent acf6973 commit 3c8c4f7

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

app/src/main/java/com/itsaky/androidide/activities/MainActivity.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,7 @@ class MainActivity : LimitlessIDEActivity() {
184184
MaterialSharedAxis.Y
185185
}
186186

187-
val isForward = when {
188-
previous == SCREEN_MAIN && screen == SCREEN_TEMPLATE_LIST -> true
189-
previous == SCREEN_TEMPLATE_LIST && screen == SCREEN_TEMPLATE_DETAILS -> true
190-
previous == SCREEN_TEMPLATE_DETAILS && screen == SCREEN_TEMPLATE_LIST -> false
191-
previous == SCREEN_TEMPLATE_DETAILS && screen == SCREEN_MAIN -> false
192-
previous == SCREEN_TEMPLATE_LIST && screen == SCREEN_MAIN -> false
193-
else -> throw IllegalStateException(
194-
"Invalid screen states. Previous: $previous Current: $screen"
195-
)
196-
}
187+
val isForward = (screen ?: 0) - previous == 1
197188

198189
val transition = MaterialSharedAxis(axis, isForward)
199190
transition.doOnEnd {

app/src/main/java/com/itsaky/androidide/viewmodel/MainViewModel.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ class MainViewModel : ViewModel() {
3434

3535
companion object {
3636

37-
// main screens
37+
// The values assigned to these variables reflect the order in which the screens are presented
38+
// to the user. A screen with a lower value is displayed before a screen with a higher value.
39+
// For example, SCREEN_MAIN is the first screen visible to the user, followed by SCREEN_TEMPLATE_LIST,
40+
// and then SCREEN_TEMPLATE_DETAILS.
41+
//
42+
// These values are used as unique identifiers for the screens as well as for determining whether
43+
// the screen change transition should be forward or backward.
3844
const val SCREEN_MAIN = 0
3945
const val SCREEN_TEMPLATE_LIST = 1
4046
const val SCREEN_TEMPLATE_DETAILS = 2

0 commit comments

Comments
 (0)