Skip to content

Commit

Permalink
refactor: move Supabase client, VM and M into PeriodPalsApp
Browse files Browse the repository at this point in the history
  • Loading branch information
charliemangano committed Nov 9, 2024
1 parent d4527f6 commit 2c75e56
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions app/src/main/java/com/android/periodpals/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,6 @@ class MainActivity : ComponentActivity() {

private val locationService = GPSServiceImpl(this)

private val supabaseClient =
createSupabaseClient(
supabaseUrl = BuildConfig.SUPABASE_URL,
supabaseKey = BuildConfig.SUPABASE_KEY,
) {
install(Auth)
install(Postgrest)
}

private val authModel = AuthenticationModelSupabase(supabaseClient)
private val authenticationViewModel = AuthenticationViewModel(authModel)

private val userModel = UserRepositorySupabase(supabaseClient)
private val userViewModel = UserViewModel(userModel)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -65,18 +50,30 @@ class MainActivity : ComponentActivity() {
PeriodPalsAppTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
PeriodPalsApp(locationService, authenticationViewModel, userViewModel)
PeriodPalsApp(locationService)
}
}
}
}

@Composable
fun PeriodPalsApp(
locationService: GPSServiceImpl,
authenticationViewModel: AuthenticationViewModel,
userViewModel: UserViewModel,
) {
fun PeriodPalsApp(locationService: GPSServiceImpl) {

val supabaseClient =
createSupabaseClient(
supabaseUrl = BuildConfig.SUPABASE_URL,
supabaseKey = BuildConfig.SUPABASE_KEY,
) {
install(Auth)
install(Postgrest)
}

val authModel = AuthenticationModelSupabase(supabaseClient)
val authenticationViewModel = AuthenticationViewModel(authModel)

val userModel = UserRepositorySupabase(supabaseClient)
val userViewModel = UserViewModel(userModel)

val navController = rememberNavController()
val navigationActions = NavigationActions(navController)

Expand Down

0 comments on commit 2c75e56

Please sign in to comment.