Skip to content

Commit

Permalink
Dashboard Integration Temporary Finished
Browse files Browse the repository at this point in the history
  • Loading branch information
LeleStacia committed Jun 8, 2023
1 parent c0ae033 commit 20ca13d
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 244 deletions.
68 changes: 53 additions & 15 deletions app/src/main/java/com/satyamthakur/silver/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,74 @@ package com.satyamthakur.silver
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import com.satyamthakur.silver.ui.screen.dashboard.DashboardScreen
import com.satyamthakur.silver.ui.screen.dashboard.viewmodel.DashboardViewModel
import com.satyamthakur.silver.ui.theme.SilverTheme
import com.satyamthakur.silver.utility.Screen
import org.koin.androidx.compose.koinViewModel

@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val navController = rememberAnimatedNavController()
SilverTheme {
Surface(
modifier = Modifier.fillMaxSize()
) {
val viewModel = koinViewModel<DashboardViewModel>()
val nowShowingMovies by viewModel.nowShowingMovies.collectAsStateWithLifecycle()
val popularMovies by viewModel.popularMovies.collectAsStateWithLifecycle()
DashboardScreen(
onMovieClicked = {},
nowShowingMovies = nowShowingMovies,
onNowShowingMoviesRetry = {},
onSeeMoreNowShowingMovies = {},
popularMovies = popularMovies,
onSeeMorePopularMoviesClicked = {},
onPopularMoviesRetry = {}
)
Surface {
Scaffold(
topBar = {
CenterAlignedTopAppBar(title = {
Text(
text = stringResource(id = R.string.app_name),
style = MaterialTheme.typography.titleMedium.copy(
fontWeight = FontWeight.Black,
fontSize = 16.sp
)
)
})
}
) { paddingValues ->
NavHost(
navController = navController,
startDestination = Screen.Dashboard.route
) {
composable(route = Screen.Dashboard.route) {
val viewModel = koinViewModel<DashboardViewModel>()
val nowShowingMovies by viewModel.nowShowingMovies.collectAsStateWithLifecycle()
val popularMovies by viewModel.popularMovies.collectAsStateWithLifecycle()
DashboardScreen(
onMovieClicked = {},
onSeeMoreNowShowingMovies = {},
nowShowingMovies = nowShowingMovies,
onNowShowingMoviesRetry = viewModel::getNowShowingMovies,
onSeeMorePopularMoviesClicked = {},
popularMovies = popularMovies,
onPopularMoviesRetry = viewModel::getPopularMovies,
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
)
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,32 @@
package com.satyamthakur.silver.ui.screen.dashboard

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredHeightIn
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Button
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.satyamthakur.silver.R
import com.satyamthakur.silver.domain.model.Movie
import com.satyamthakur.silver.domain.model.PopularMovies
import com.satyamthakur.silver.ui.component.VerticalMovieItem
import com.satyamthakur.silver.ui.screen.dashboard.component.HorizontalMovies
import com.satyamthakur.silver.ui.screen.dashboard.component.SectionSeparator
import com.satyamthakur.silver.ui.screen.dashboard.component.VerticalMovies
import com.satyamthakur.silver.ui.theme.SilverTheme
import com.satyamthakur.silver.utility.Resource

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DashboardScreen(
onMovieClicked: (Movie) -> Unit,
Expand All @@ -52,141 +35,122 @@ fun DashboardScreen(
onSeeMoreNowShowingMovies: () -> Unit,
popularMovies: Resource<List<Movie>>,
onSeeMorePopularMoviesClicked: () -> Unit,
onPopularMoviesRetry: () -> Unit
onPopularMoviesRetry: () -> Unit,
modifier: Modifier = Modifier
) {
Scaffold(
topBar = {
CenterAlignedTopAppBar(title = {
Text(
text = stringResource(id = R.string.app_name),
style = MaterialTheme.typography.titleMedium.copy(
fontWeight = FontWeight.Black,
fontSize = 16.sp
)
)
})
}
) { paddingValues ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
) {
Box(
contentAlignment = Alignment.Center,
Column(
modifier = modifier
) {
if (nowShowingMovies is Resource.Loading && popularMovies is Resource.Loading) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
12.dp,
Alignment.CenterVertically
),
modifier = Modifier
.requiredHeightIn()
.fillMaxSize()
) {
Column {
SectionSeparator(
sectionTitle = stringResource(R.string.now_showing),
onSeeMoreClick = onSeeMoreNowShowingMovies
)
HorizontalMovies(
moviesResult = nowShowingMovies,
onMovieClicked = onMovieClicked,
onRetry = onNowShowingMoviesRetry
)
}
Text(text = stringResource(R.string.getting_the_movies_for_you))
LinearProgressIndicator()
}
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(24.dp)
)
Box(
contentAlignment = Alignment.Center,
} else {
Column(
modifier = Modifier
.fillMaxSize()
.weight(1f)
.weight(2f)
) {
Column {
SectionSeparator(
sectionTitle = stringResource(R.string.popular),
onSeeMoreClick = onSeeMorePopularMoviesClicked
)
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(12.dp)
)
Box(modifier = Modifier.fillMaxSize()) {
LazyColumn(
contentPadding = PaddingValues(horizontal = 24.dp, vertical = 8.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
SectionSeparator(
sectionTitle = stringResource(id = R.string.now_showing),
onSeeMoreClick = onSeeMoreNowShowingMovies
)
when (nowShowingMovies) {
is Resource.Error -> {
Column(
verticalArrangement = Arrangement.spacedBy(
8.dp,
Alignment.CenterVertically
),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxSize()
) {
when (popularMovies) {
is Resource.Error ->
item {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
12.dp,
Alignment.CenterVertically
),
modifier = Modifier
.fillMaxSize()
) {
Text(
text = popularMovies.message
?: stringResource(id = R.string.unknown_error),
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp)
)
Button(onClick = onPopularMoviesRetry) {
Text(text = stringResource(id = R.string.retry))
}
}
}
Text(
text = nowShowingMovies.message
?: stringResource(id = R.string.unknown_error),
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp)
)
Button(onClick = onNowShowingMoviesRetry) {
Text(text = stringResource(id = R.string.retry))
}
}
}

Resource.Loading ->
item {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
12.dp,
Alignment.CenterVertically
),
modifier = Modifier
.fillMaxSize()
) {
Text(text = stringResource(R.string.getting_the_movies_for_you))
LinearProgressIndicator()
}
}
Resource.Loading -> {
LinearProgressIndicator(
modifier = Modifier.fillMaxWidth()
)
}

Resource.None -> Unit
is Resource.Success -> {
HorizontalMovies(
movies = nowShowingMovies.data ?: emptyList(),
onMovieClicked = onMovieClicked
)
}
}
}

Resource.None -> Unit
is Resource.Success ->
items(
items = popularMovies.data ?: emptyList(),
key = { movie ->
movie.id
}
) { movie: Movie ->
VerticalMovieItem(
movie = movie,
onMovieClicked = onMovieClicked
)
}
Column(
modifier = Modifier
.fillMaxSize()
.weight(3f)
) {
SectionSeparator(
sectionTitle = stringResource(id = R.string.now_showing),
onSeeMoreClick = onSeeMorePopularMoviesClicked
)
when (popularMovies) {
is Resource.Error -> {
Column(
verticalArrangement = Arrangement.spacedBy(
8.dp,
Alignment.CenterVertically
),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxSize()
) {
Text(
text = popularMovies.message
?: stringResource(id = R.string.unknown_error),
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp)
)
Button(onClick = onPopularMoviesRetry) {
Text(text = stringResource(id = R.string.retry))
}
}
Box(
modifier = Modifier
.fillMaxWidth()
.height(16.dp)
.background(
brush = Brush.verticalGradient(
listOf(
MaterialTheme.colorScheme.background,
Color.Transparent
)
)
)
}

Resource.Loading -> {
LinearProgressIndicator(
modifier = Modifier.fillMaxWidth()
)
}

Resource.None -> Unit
is Resource.Success -> {
VerticalMovies(
movies = popularMovies.data ?: emptyList(),
onMovieClicked = onMovieClicked,
modifier = Modifier.weight(1f)
)
}
}
Expand Down
Loading

0 comments on commit 20ca13d

Please sign in to comment.