Skip to content

Commit

Permalink
refactor: splash cleanup (#2236)
Browse files Browse the repository at this point in the history
* splash cleanup

fix errors

* fixed conflicts
  • Loading branch information
itsPronay authored Nov 19, 2024
1 parent 0ba80e6 commit 4182aaf
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 77 deletions.
9 changes: 9 additions & 0 deletions feature/splash/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.splash

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import junit.framework.TestCase.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -21,4 +28,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.mifos.feature.splash.test", appContext.packageName)
}
}
}
9 changes: 9 additions & 0 deletions feature/splash/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.
See https://github.com/openMF/android-client/blob/master/LICENSE.md
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.splash.navigation

import androidx.navigation.NavGraphBuilder
Expand All @@ -7,29 +16,29 @@ import com.mifos.feature.splash.splash.SplashScreen

fun NavGraphBuilder.splashNavGraph(
navigatePasscode: () -> Unit,
navigateLogin: () -> Unit
navigateLogin: () -> Unit,
) {
navigation(
startDestination = SplashScreens.SplashScreen.route,
route = SplashScreens.SplashScreenRoute.route,
) {
splashScreenRoute(
navigateLogin = navigateLogin,
navigatePasscode = navigatePasscode
navigatePasscode = navigatePasscode,
)
}
}

fun NavGraphBuilder.splashScreenRoute(
navigatePasscode: () -> Unit,
navigateLogin: () -> Unit
navigateLogin: () -> Unit,
) {
composable(
route = SplashScreens.SplashScreen.route,
) {
SplashScreen(
navigatePasscode = navigatePasscode,
navigateLogin = navigateLogin
navigateLogin = navigateLogin,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.splash.navigation

sealed class SplashScreens(val route: String) {

data object SplashScreenRoute : SplashScreens("splash_screen_route")

data object SplashScreen : SplashScreens("splash_screen")

}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.splash.splash

import androidx.compose.foundation.Image
Expand All @@ -20,47 +29,48 @@ import com.mifos.core.designsystem.theme.SummerSky
import com.mifos.feature.splash.R

@Composable
fun SplashScreen(
viewmodel: SplashScreenViewmodel = hiltViewModel(),
internal fun SplashScreen(
navigatePasscode: () -> Unit,
navigateLogin: () -> Unit
viewmodel: SplashScreenViewmodel = hiltViewModel(),
navigateLogin: () -> Unit,
) {
val state by viewmodel.isAuthenticated.collectAsStateWithLifecycle()

SplashScreen(
state = state,
navigatePasscode = navigatePasscode,
navigateLogin = navigateLogin
navigateLogin = navigateLogin,
)
}

@Composable
fun SplashScreen(
internal fun SplashScreen(
state: Boolean?,
navigatePasscode: () -> Unit,
navigateLogin: () -> Unit
navigateLogin: () -> Unit,
modifier: Modifier = Modifier,
) {

when (state) {
false -> navigateLogin()
true -> navigatePasscode()
else -> {}
}

MifosScaffold(
containerColor = SummerSky
modifier = modifier,
containerColor = SummerSky,
) { paddingValues ->
Column(
modifier = Modifier
.padding(paddingValues)
.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
horizontalAlignment = Alignment.CenterHorizontally,
) {
Image(
modifier = Modifier.size(100.dp),
painter = painterResource(id = R.drawable.feature_splash_icon),
contentDescription = null
contentDescription = null,
)
}
}
Expand All @@ -72,6 +82,6 @@ private fun SplashScreenPreview() {
SplashScreen(
state = false,
navigatePasscode = {},
navigateLogin = {}
navigateLogin = {},
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.splash.splash

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.datastore.PrefManager
Expand All @@ -14,7 +22,7 @@ import javax.inject.Inject

@HiltViewModel
class SplashScreenViewmodel @Inject constructor(
private val prefManager: PrefManager
private val prefManager: PrefManager,
) : ViewModel() {

private val _isAuthenticated = MutableStateFlow<Boolean?>(null)
Expand All @@ -28,5 +36,4 @@ class SplashScreenViewmodel @Inject constructor(
delay(2000)
_isAuthenticated.value = prefManager.isAuthenticated()
}

}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.splash

import junit.framework.TestCase.assertEquals
import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
Expand All @@ -14,4 +22,4 @@ class ExampleUnitTest {
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
}
9 changes: 0 additions & 9 deletions mifosng-android/src/main/res/layout/activity_splash.xml

This file was deleted.

13 changes: 0 additions & 13 deletions mifosng-android/src/main/res/layout/fragment_splash.xml

This file was deleted.

15 changes: 0 additions & 15 deletions mifosng-android/src/main/res/menu/splash_screen.xml

This file was deleted.

9 changes: 0 additions & 9 deletions mifosng-android/src/main/res/navigation/home_nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@
</activity>

<!-- CenterActivity-->
<activity
android:id="@+id/centersActivity"
android:name="com.mifos.mifosxdroid.online.CentersActivity"
android:label="activity_centers"
tools:layout="@layout/activity_centers">
<argument
android:name="centerId"
app:argType="integer" />
</activity>

<!-- GroupsActivity-->

Expand Down

0 comments on commit 4182aaf

Please sign in to comment.