Skip to content

Commit

Permalink
Merge pull request #72 from PetJournal/feature/refactor_screen_preview
Browse files Browse the repository at this point in the history
Feature/refactor screen preview
  • Loading branch information
JorgeTranin authored Sep 26, 2024
2 parents bb8b351 + 34021da commit 34449b2
Show file tree
Hide file tree
Showing 22 changed files with 404 additions and 60 deletions.
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,9 @@ Nossa abordagem de teste ajuda a manter a qualidade e estabilidade do software,
- **Perguntas, dúvidas ou problemas**: Sinta-se a vontade para abrir uma essue [Clicando aqui](https://github.com/PetJournal/petjournal.android/issues)

## Contribuições
<a href="https://www.linkedin.com/in/leozinhozd/" style="text-decoration: none;">
<img src="https://github.com/PetJournal/petjournal.android/assets/42920754/03f445fb-d46e-455c-96fd-9aea840228a1" width="100px" alt="gus" style="display: block;"/>
</a><a href="https://github.com/gusoliveira21" style="text-decoration: none;">
<img src="https://github.com/PetJournal/petjournal.android/assets/42920754/0066a0c4-f87f-4e9c-bd89-d60be8399d7a" width="100px" alt="gus" style="display: block;"/>
</a><a href="https://github.com/LucasOliveiraSimao" style="text-decoration: none;">
<img src="https://github.com/PetJournal/petjournal.android/assets/42920754/558455ec-e37d-4721-8313-8f6936879ab6" width="100px" alt="luc" style="display: block;"/>
</a><a href="https://github.com/N0stalgiaUltra" style="text-decoration: none;">
<img src="https://github.com/PetJournal/petjournal.android/assets/42920754/9defc5c5-103d-40e5-9cb3-ca3cf995543e" width="100px" alt="vin" style="display: block;"/>
</a><a href="https://github.com/ovitorhilario" style="text-decoration: none;">
<img src="https://github.com/PetJournal/petjournal.android/assets/42920754/59311cd1-c5de-4764-88f9-ad8b7b0b177b" width="100px" alt="vit" style="display: block;"/>
</a><a href="https://www.linkedin.com/in/gelsonsouza/" style="text-decoration: none;">
<img src="https://github.com/PetJournal/petjournal.android/assets/42920754/c5204a6d-1dbf-4ecc-9e6d-9111cd119cf2" width="100px" alt="gel" style="display: block;"/>
</a>


[![NotyKT Contributors](https://contrib.rocks/image?repo=PetJournal/petjournal.android)](https://github.com/PetJournal/petjournal.android/graphs/contributors)


## Licença
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
Expand All @@ -24,9 +25,8 @@ fun NavigationBar(navController: NavController) {
)

BottomNavigation(
modifier = Modifier
.fillMaxWidth(),
backgroundColor = if (darkTheme) Color(0xFFFF4081) else Color(0xFFB90063)
modifier = Modifier.fillMaxWidth(),
backgroundColor = if (darkTheme) Color(0xFFFF4081) else MaterialTheme.colorScheme.primary
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ fun LoginScreen(navController: NavController) {
}
}
}
Screen(navController, viewModel)
Screen(navController)
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
package com.soujunior.petjournal.ui.screens_app.account_manager.loginScreen

import androidx.lifecycle.ViewModel
import com.soujunior.petjournal.ui.states.TaskState
import com.soujunior.petjournal.ui.util.ValidationEvent
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.receiveAsFlow
import com.soujunior.petjournal.ui.util.ValidationEvent
import com.soujunior.petjournal.ui.states.TaskState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.receiveAsFlow

class FakeLoginViewModel : LoginViewModel() {
override val message = MutableStateFlow("Mensagem de Teste")
override var state: LoginFormState
get() = LoginFormState()
set(value) {}
override val validationEventChannel = Channel<ValidationEvent>()
override val validationEvents = emptyFlow<ValidationEvent>()
override val taskState = MutableStateFlow<TaskState>(TaskState.Idle)
override fun passwordRemember() {
}

override fun success(resultPostLogin: String) {
}

override fun failed(exception: Throwable?) { /* No-op */
}

override fun submitData() {
}

override fun enableButton(): Boolean {
return true
}

override fun onEvent(event: LoginFormEvent) {
}
}

abstract class LoginViewModel : ViewModel() {
abstract var state: LoginFormState
abstract val validationEventChannel: Channel<ValidationEvent>
open val validationEvents: Flow<ValidationEvent>
get() = validationEventChannel.receiveAsFlow()

abstract val message : StateFlow<String>
abstract val message: StateFlow<String>

abstract val taskState: StateFlow<TaskState>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,34 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.soujunior.petjournal.R
import com.soujunior.petjournal.ui.components.DashedInputText
import com.soujunior.petjournal.ui.screens_app.account_manager.loginScreen.FakeLoginViewModel
import com.soujunior.petjournal.ui.screens_app.account_manager.loginScreen.LoginFormEvent
import com.soujunior.petjournal.ui.screens_app.account_manager.loginScreen.LoginViewModel
import com.soujunior.petjournal.ui.theme.PetJournalTheme
import ir.kaaveh.sdpcompose.sdp
import org.koin.androidx.compose.getViewModel

@Composable
fun Screen(navController: NavController, viewModel: LoginViewModel) {

fun getLoginViewModelForPreview(): LoginViewModel {
return if (LocalInspectionMode.current) {
FakeLoginViewModel()
} else {
getViewModel()
}
}
@Composable
fun Screen(navController: NavController, /*viewModel: LoginViewModel*/) {
val viewModel = getLoginViewModelForPreview()
val systemUiController = rememberSystemUiController()

systemUiController.setSystemBarsColor(
Expand Down Expand Up @@ -99,7 +113,7 @@ fun Screen(navController: NavController, viewModel: LoginViewModel) {
}
item {

Spacer(modifier = Modifier.padding(top = 75.sdp))
Spacer(modifier = Modifier.padding(top = 45.sdp))

}
item {
Expand All @@ -111,3 +125,11 @@ fun Screen(navController: NavController, viewModel: LoginViewModel) {
}
}
}
@Preview(showBackground = true)
@Composable
fun LoginRegisterPreview(){
val nav = rememberNavController()
PetJournalTheme {
Screen(nav)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import org.koin.androidx.compose.getViewModel
@ExperimentalPagerApi
@Composable
fun HomeScreen(navController: NavController) {
Screen(navController, getViewModel())
Screen(navController)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,49 @@ package com.soujunior.petjournal.ui.screens_app.screen_home.homeScreen
import androidx.lifecycle.ViewModel
import com.soujunior.domain.model.response.GuardianNameResponse
import com.soujunior.petjournal.R
import com.soujunior.petjournal.ui.util.ValidationEvent
import com.soujunior.petjournal.ui.states.TaskState
import com.soujunior.petjournal.ui.util.ValidationEvent
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.receiveAsFlow

class FakeHomeViewModel : HomeScreenViewModel() {
override var state: HomeState
get() = HomeState()
set(value) {}
override val validationEventChannel = Channel<ValidationEvent>()
override val message = MutableStateFlow("Mensagem de Teste")
override fun success(name: GuardianNameResponse) {}

override fun getData() {}

override fun logout() {}

override val validationEvents = emptyFlow<ValidationEvent>()
override val name: StateFlow<GuardianNameResponse> =
MutableStateFlow(GuardianNameResponse("Jorge", ""))


override val taskState = MutableStateFlow<TaskState>(TaskState.Idle)

override fun failed(exception: Throwable?) { /* No-op */
}


}

abstract class HomeScreenViewModel : ViewModel() {
abstract val taskState: StateFlow<TaskState>
abstract var state: HomeState
abstract val validationEventChannel: Channel<ValidationEvent>
open val validationEvents: Flow<ValidationEvent>
get() = validationEventChannel.receiveAsFlow()

abstract val name : StateFlow<GuardianNameResponse>
abstract val message : StateFlow<String>
abstract val name: StateFlow<GuardianNameResponse>
abstract val message: StateFlow<String>
abstract fun success(name: GuardianNameResponse)
abstract fun getData()
abstract fun logout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,40 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.soujunior.petjournal.R
import com.soujunior.petjournal.ui.screens_app.screen_home.homeScreen.HomeScreenViewModel
import com.soujunior.petjournal.ui.components.NavigationBar
import com.soujunior.petjournal.ui.components.ScaffoldCustom
import com.soujunior.petjournal.ui.screens_app.screen_home.homeScreen.FakeHomeViewModel
import com.soujunior.petjournal.ui.screens_app.screen_home.homeScreen.HomeScreenViewModel
import com.soujunior.petjournal.ui.states.TaskState
import com.soujunior.petjournal.ui.theme.PetJournalTheme
import com.soujunior.petjournal.ui.util.ValidationEvent
import com.soujunior.petjournal.ui.util.capitalizeFirstLetter
import org.koin.androidx.compose.getViewModel

@Composable
fun getHomeViewModelForPreview(): HomeScreenViewModel {
return if (LocalInspectionMode.current) {
FakeHomeViewModel()
} else {
getViewModel()
}
}

@ExperimentalPagerApi
@Composable
fun Screen(navController: NavController, viewModel: HomeScreenViewModel) {
fun Screen(navController: NavController) {
val viewModel: HomeScreenViewModel = getHomeViewModelForPreview()
val showDropdownMenu = remember { mutableStateOf(false) }
val taskState by viewModel.taskState.collectAsState()
val name = remember { mutableStateOf(viewModel.name.value.firstName) }
Expand All @@ -64,7 +80,7 @@ fun Screen(navController: NavController, viewModel: HomeScreenViewModel) {
}

val systemUiController = rememberSystemUiController()
systemUiController.setSystemBarsColor( color = Color.Transparent, darkIcons = true )
systemUiController.setSystemBarsColor(color = Color.Transparent, darkIcons = true)
systemUiController.setNavigationBarColor(Color.Black)
Column(modifier = Modifier.navigationBarsPadding()) {
ScaffoldCustom(
Expand Down Expand Up @@ -155,4 +171,14 @@ fun Screen(navController: NavController, viewModel: HomeScreenViewModel) {
}
})
}
}

@OptIn(ExperimentalPagerApi::class)
@Preview(showBackground = true)
@Composable
fun HomeScreenPreview() {
val nav = rememberNavController()
PetJournalTheme {
Screen(nav)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.emptyFlow

class FakeIntroRegisterPetViewModel : IntroRegisterPetViewModel() {
override val name = MutableStateFlow<String?>("Nome de Teste")
override val visualizedScreen = MutableStateFlow(false)
override val message = MutableStateFlow("Mensagem de Teste")
override val validationEventChannel = Channel<ValidationEvent>()
override val validationEvents = emptyFlow<ValidationEvent>()
override val taskState = MutableStateFlow<TaskState>(TaskState.Idle)

override fun success() { /* No-op */ }
override fun failed(exception: Throwable?) { /* No-op */ }
override fun setWasViewed() { /* No-op */ }
override fun getName() { /* No-op */ }
override fun getWasViewed() { /* No-op */ }
}

abstract class IntroRegisterPetViewModel : ViewModel() {
abstract val name: StateFlow<String?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,52 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.soujunior.petjournal.R
import com.soujunior.petjournal.ui.components.Button2
import com.soujunior.petjournal.ui.components.IndeterminateCircularIndicator
import com.soujunior.petjournal.ui.components.NavigationBar
import com.soujunior.petjournal.ui.components.ScaffoldCustom
import com.soujunior.petjournal.ui.screens_app.screens_pets.introRegisterPetScreen.FakeIntroRegisterPetViewModel
import com.soujunior.petjournal.ui.screens_app.screens_pets.introRegisterPetScreen.IntroRegisterPetViewModel
import com.soujunior.petjournal.ui.states.TaskState
import com.soujunior.petjournal.ui.theme.PetJournalTheme
import com.soujunior.petjournal.ui.util.ValidationEvent
import ir.kaaveh.sdpcompose.sdp
import org.koin.androidx.compose.getViewModel

@Composable
fun getIntroRegisterPetViewModelForPreview(): IntroRegisterPetViewModel {
return if (LocalInspectionMode.current) {
FakeIntroRegisterPetViewModel()
} else {
getViewModel()
}
}

@Composable
fun Screen(navController: NavController) {
val viewModel: IntroRegisterPetViewModel = getViewModel()
val viewModel: IntroRegisterPetViewModel = getIntroRegisterPetViewModelForPreview()
val context = LocalContext.current
val name by viewModel.name.collectAsState()
val taskState by viewModel.taskState.collectAsState()

LaunchedEffect(key1 = context) {
viewModel.validationEvents.collect { event ->
when (event) {
is ValidationEvent.Success -> {
navController.popBackStack()
navController.navigate("pets/speciesChoice")
if(!LocalInspectionMode.current){
LaunchedEffect(key1 = context) {
viewModel.validationEvents.collect { event ->
when (event) {
is ValidationEvent.Success -> {
navController.popBackStack()
navController.navigate("pets/speciesChoice")
}

is ValidationEvent.Failed -> {}
}

is ValidationEvent.Failed -> {}
}
}
}
Expand Down Expand Up @@ -106,4 +123,13 @@ fun Screen(navController: NavController) {
}
})
}
}

@Preview(showBackground = true)
@Composable
fun IntroRegister(){
val nav = rememberNavController()
PetJournalTheme {
Screen(nav)
}
}
Loading

0 comments on commit 34449b2

Please sign in to comment.