Skip to content

Instantly share code, notes, and snippets.

@Test
fun getSearchedResult_receivedResponse_wrongPageSize_shouldFail() {
runBlocking {
enqueueMockResponse("ImageResponse.json")
val responseBody = service.getSearchedImage("nature", 5).body()
val photoList = responseBody!!.photos
assertThat(photoList.size).isEqualTo(6)
}
}
@Farhandroid
Farhandroid / MovieListContent.kt
Created February 22, 2022 20:10
MovieListContent
@Composable
fun MovieListContent(allMovies: List<Movie>, navController: NavHostController) {
LazyColumn(
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp)
) {
items(
items = allMovies,
itemContent = {
MovieListItem(movie = it, navController = navController)
@Farhandroid
Farhandroid / Movie.kt
Created February 22, 2022 20:22
Movie
data class Movie(
val movieId: Int,
val overview: String,
val imageId: Int,
val title: String,
val rating: String,
val releaseDate: String,
):Serializable
@Farhandroid
Farhandroid / NavigationGraph.kt
Created March 1, 2022 11:55
NavigationGraph
@Composable
fun NavigationGraph(navController: NavHostController) {
NavHost(navController, startDestination = BottomNavigationItem.Home.screen_route) {
composable(BottomNavigationItem.Home.screen_route) {
HomeScreen()
}
composable(BottomNavigationItem.Mail.screen_route) {
Mail()
}
composable(BottomNavigationItem.Person.screen_route) {
@Farhandroid
Farhandroid / BottomNavigationItem.kt
Created March 1, 2022 11:59
BottomNavigationItem
sealed class BottomNavigationItem(var title:String, var icon:Int, var screen_route:String){
object Home : BottomNavigationItem("Home", R.drawable.ic_baseline_home,"home")
object Mail: BottomNavigationItem("Mail",R.drawable.ic_baseline_mail_24,"mail")
object Person: BottomNavigationItem("profile",R.drawable.ic_baseline_person_24,"profile")
}
@Farhandroid
Farhandroid / BottomItem.kt
Last active March 1, 2022 12:13
BottomItem
@Composable
fun RowScope.BottomItem(
screen: BottomNavigationItem,
currentDestination: NavDestination?,
navController: NavHostController,
) {
//RowScope.BottomNavigationItem
BottomNavigationItem(
icon = { Icon(painterResource(id = screen.icon), contentDescription = screen.title) },
selected = currentDestination?.hierarchy?.any {
@Farhandroid
Farhandroid / CustomBottomNavigation.kt
Created March 1, 2022 12:18
CustomBottomNavigation
@Composable
fun CustomBottomNavigation(navController: NavHostController) {
val items = listOf(
BottomNavigationItem.Home,
BottomNavigationItem.Mail,
BottomNavigationItem.Person
)
BottomNavigation(
contentColor = Color.White
) {
@Composable
fun MainScreen() {
val navController = rememberNavController()
Scaffold(
bottomBar = {
BottomAppBar {
CustomBottomNavigation(navController = navController)
}
}
) {
@Farhandroid
Farhandroid / AppViewModel.kt
Last active March 3, 2022 11:46
AppViewModel
class AppViewModel : ViewModel() {
private val _titleInputFlow = MutableStateFlow<String>("")
val titleInputFlow: StateFlow<String> get() = _titleInputFlow
fun setTitle(title: String) {
_titleInputFlow.value = title
}
fun resetTitle() {
_titleInputFlow.value = ""
@Farhandroid
Farhandroid / MainContent.kt
Last active March 3, 2022 10:11
MainContent
private val viewModel = AppViewModel()
@Composable
fun MainContent(viewModel: AppViewModel) {
val title by viewModel.titleInputFlow.collectAsState()
Content(title = title, onTitleChange = {
viewModel.setTitle(it)
}, onResetClicked = { viewModel.resetTitle() })
}