#74 refactor feed
This commit is contained in:
		
							parent
							
								
									366f236f98
								
							
						
					
					
						commit
						1293ea3113
					
				
					 1 changed files with 81 additions and 34 deletions
				
			
		|  | @ -9,21 +9,47 @@ import androidx.compose.material.Text | ||||||
| import androidx.compose.runtime.Composable | import androidx.compose.runtime.Composable | ||||||
| import androidx.compose.ui.Alignment | import androidx.compose.ui.Alignment | ||||||
| import androidx.compose.ui.Modifier | import androidx.compose.ui.Modifier | ||||||
|  | import androidx.compose.ui.res.stringResource | ||||||
| import androidx.compose.ui.text.font.FontWeight | import androidx.compose.ui.text.font.FontWeight | ||||||
| import androidx.compose.ui.tooling.preview.Preview | import androidx.compose.ui.tooling.preview.Preview | ||||||
| import androidx.compose.ui.unit.dp | import androidx.compose.ui.unit.dp | ||||||
| import androidx.compose.ui.unit.sp | import androidx.compose.ui.unit.sp | ||||||
|  | import be.ugent.sel.studeez.common.composable.BasicTextButton | ||||||
| import be.ugent.sel.studeez.common.composable.DateText | import be.ugent.sel.studeez.common.composable.DateText | ||||||
|  | import be.ugent.sel.studeez.common.composable.Headline | ||||||
|  | import be.ugent.sel.studeez.common.ext.textButton | ||||||
| import be.ugent.sel.studeez.data.local.models.FeedEntry | import be.ugent.sel.studeez.data.local.models.FeedEntry | ||||||
| import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds | import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds | ||||||
|  | import be.ugent.sel.studeez.R.string as AppText | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
| fun Feed( | fun Feed( | ||||||
|     uiState: FeedUiState, |     uiState: FeedUiState, | ||||||
|     continueTask: (String, String) -> Unit, |     continueTask: (String, String) -> Unit, | ||||||
|  |     onEmptyFeedHelp: () -> Unit | ||||||
| ) { | ) { | ||||||
|     when (uiState) { |     when (uiState) { | ||||||
|         FeedUiState.Loading -> { |         FeedUiState.Loading -> LoadingFeed() | ||||||
|  |         is FeedUiState.Succes -> LoadedFeed( | ||||||
|  |             uiState = uiState, | ||||||
|  |             continueTask = continueTask, | ||||||
|  |             onEmptyFeedHelp = onEmptyFeedHelp | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | @Composable | ||||||
|  | fun LoadedFeed( | ||||||
|  |     uiState: FeedUiState.Succes, | ||||||
|  |     continueTask: (String, String) -> Unit, | ||||||
|  |     onEmptyFeedHelp: () -> Unit, | ||||||
|  | ) { | ||||||
|  |     if (uiState.feedEntries.isEmpty()) EmptyFeed(onEmptyFeedHelp) | ||||||
|  |     else FeedWithElements(uiState = uiState, continueTask = continueTask) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | @Composable | ||||||
|  | fun LoadingFeed() { | ||||||
|     Column( |     Column( | ||||||
|         modifier = Modifier |         modifier = Modifier | ||||||
|             .fillMaxWidth() |             .fillMaxWidth() | ||||||
|  | @ -34,7 +60,12 @@ fun Feed( | ||||||
|         CircularProgressIndicator(color = MaterialTheme.colors.onBackground) |         CircularProgressIndicator(color = MaterialTheme.colors.onBackground) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|         is FeedUiState.Succes -> { | 
 | ||||||
|  | @Composable | ||||||
|  | fun FeedWithElements( | ||||||
|  |     uiState: FeedUiState.Succes, | ||||||
|  |     continueTask: (String, String) -> Unit, | ||||||
|  | ) { | ||||||
|     val feedEntries = uiState.feedEntries |     val feedEntries = uiState.feedEntries | ||||||
|     LazyColumn { |     LazyColumn { | ||||||
|         items(feedEntries.toList()) { (date, feedEntries) -> |         items(feedEntries.toList()) { (date, feedEntries) -> | ||||||
|  | @ -62,6 +93,22 @@ fun Feed( | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | @Composable | ||||||
|  | fun EmptyFeed(onEmptyFeedHelp: () -> Unit) { | ||||||
|  |     Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { | ||||||
|  |         Column( | ||||||
|  |             horizontalAlignment = Alignment.CenterHorizontally, | ||||||
|  |             modifier = Modifier.fillMaxWidth() | ||||||
|  |         ) { | ||||||
|  |             Headline(text = stringResource(id = AppText.your_feed)) | ||||||
|  | 
 | ||||||
|  |             BasicTextButton( | ||||||
|  |                 AppText.empty_feed_help_text, | ||||||
|  |                 Modifier.textButton(), | ||||||
|  |                 action = onEmptyFeedHelp, | ||||||
|  |             ) | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -70,7 +117,7 @@ fun Feed( | ||||||
| fun FeedLoadingPreview() { | fun FeedLoadingPreview() { | ||||||
|     Feed( |     Feed( | ||||||
|         uiState = FeedUiState.Loading, |         uiState = FeedUiState.Loading, | ||||||
|         continueTask = { _, _ -> run {} }, |         continueTask = { _, _ -> run {} }, {} | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -108,6 +155,6 @@ fun FeedPreview() { | ||||||
|                 ) |                 ) | ||||||
|             ) |             ) | ||||||
|         ), |         ), | ||||||
|         continueTask = { _, _ -> run {} }, |         continueTask = { _, _ -> run {} }, {} | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
		Reference in a new issue
	
	 Lukas Barragan Torres
						Lukas Barragan Torres