-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from mughalasim/feature/member-type
Version 12.0 - Added member type support with 3 types Admin, Supervisor and Member with different permissions determined in use cases
- Loading branch information
Showing
36 changed files
with
411 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/main/kotlin/com/ndemi/garden/gym/ui/screens/main/MainDetailsScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.ndemi.garden.gym.ui.screens.main | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.ImageShader | ||
import androidx.compose.ui.graphics.ShaderBrush | ||
import androidx.compose.ui.graphics.TileMode | ||
import androidx.compose.ui.res.imageResource | ||
import androidx.navigation.NavHostController | ||
import com.ndemi.garden.gym.R | ||
import com.ndemi.garden.gym.navigation.NavigationHost | ||
import com.ndemi.garden.gym.navigation.NavigationService | ||
import com.ndemi.garden.gym.ui.theme.AppTheme | ||
import com.ndemi.garden.gym.ui.theme.padding_screen | ||
import com.ndemi.garden.gym.ui.widgets.BottomNavItem | ||
import com.ndemi.garden.gym.ui.widgets.BottomNavigationWidget | ||
|
||
|
||
@Composable | ||
fun MainDetailsScreen( | ||
isAuthenticated: Boolean, | ||
isAdmin: Boolean, | ||
navController: NavHostController, | ||
navigationService: NavigationService, | ||
){ | ||
Scaffold( | ||
topBar = {}, | ||
bottomBar = { | ||
val bottomNavItems = if (isAuthenticated) { | ||
if (isAdmin) { | ||
BottomNavItem.getAdminBottomItems() | ||
} else { | ||
BottomNavItem.getMemberBottomItems() | ||
} | ||
} else { | ||
BottomNavItem.getLoginBottomItems() | ||
} | ||
BottomNavigationWidget( | ||
navController, | ||
bottomNavItems | ||
) | ||
}, | ||
) { innerPadding -> | ||
val image = ImageBitmap.imageResource(R.drawable.bg_pattern) | ||
val brush = remember(image) { ShaderBrush(ImageShader(image, TileMode.Repeated, TileMode.Repeated)) } | ||
Column( | ||
modifier = | ||
Modifier | ||
.padding(innerPadding) | ||
.fillMaxSize() | ||
.background(AppTheme.colors.backgroundScreen) | ||
.background(brush, alpha = 0.05f), | ||
verticalArrangement = Arrangement.spacedBy(padding_screen), | ||
) { | ||
NavigationHost( | ||
navController = navController, | ||
navigationService = navigationService, | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 49 additions & 2 deletions
51
app/src/main/kotlin/com/ndemi/garden/gym/ui/screens/main/MainScreenViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,67 @@ | ||
package com.ndemi.garden.gym.ui.screens.main | ||
|
||
import androidx.compose.runtime.Immutable | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.liveData | ||
import androidx.navigation.NavHostController | ||
import com.ndemi.garden.gym.navigation.NavigationService | ||
import com.ndemi.garden.gym.ui.utils.ErrorCodeConverter | ||
import cv.domain.DomainResult | ||
import cv.domain.entities.MemberEntity | ||
import cv.domain.usecase.AuthUseCase | ||
import kotlinx.coroutines.Dispatchers | ||
|
||
class MainScreenViewModel( | ||
private val navigationService: NavigationService, | ||
private val authUseCase: AuthUseCase, | ||
private val errorCodeConverter: ErrorCodeConverter, | ||
) : ViewModel() { | ||
fun setNavController(navController: NavHostController) = | ||
navigationService.setNavController(navController) | ||
|
||
fun getNavigationService(): NavigationService = navigationService | ||
|
||
fun isAuthenticated() = authUseCase.isAuthenticated() | ||
val authState = liveData(Dispatchers.IO) { | ||
emit(AuthState.UnAuthorised) | ||
authUseCase.getAuthState().collect{ | ||
when(it){ | ||
is DomainResult.Success -> | ||
emit(AuthState.Authorised) | ||
|
||
fun isAdmin() = authUseCase.isAdmin() | ||
is DomainResult.Error -> | ||
emit(AuthState.UnAuthorised) | ||
} | ||
} | ||
|
||
} | ||
|
||
val loggedInMember = liveData(Dispatchers.IO) { | ||
emit(UiState.Loading) | ||
authUseCase.getLoggedInUser().collect { | ||
|
||
when (it) { | ||
is DomainResult.Success -> | ||
emit(UiState.Success(it.data)) | ||
|
||
is DomainResult.Error -> | ||
emit(UiState.Error(errorCodeConverter.getMessage(it.error))) | ||
} | ||
} | ||
} | ||
|
||
@Immutable | ||
sealed interface AuthState { | ||
data object Authorised : AuthState | ||
|
||
data object UnAuthorised : AuthState | ||
} | ||
|
||
@Immutable | ||
sealed interface UiState { | ||
data object Loading : UiState | ||
|
||
data class Error(val message: String) : UiState | ||
|
||
data class Success(val member: MemberEntity) : UiState | ||
} | ||
} |
Oops, something went wrong.