refactor FeedEntry
This commit is contained in:
		
							parent
							
								
									9df80f4f93
								
							
						
					
					
						commit
						08c779030e
					
				
					 3 changed files with 119 additions and 76 deletions
				
			
		|  | @ -3,10 +3,13 @@ package be.ugent.sel.studeez.common.composable | ||||||
| import androidx.compose.foundation.layout.Arrangement | import androidx.compose.foundation.layout.Arrangement | ||||||
| import androidx.compose.foundation.layout.Row | import androidx.compose.foundation.layout.Row | ||||||
| import androidx.compose.foundation.layout.fillMaxWidth | import androidx.compose.foundation.layout.fillMaxWidth | ||||||
|  | import androidx.compose.foundation.layout.padding | ||||||
| import androidx.compose.material.Text | 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.text.font.FontWeight | ||||||
|  | import androidx.compose.ui.unit.dp | ||||||
| import androidx.compose.ui.unit.sp | import androidx.compose.ui.unit.sp | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
|  | @ -24,3 +27,13 @@ fun Headline( | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | @Composable | ||||||
|  | fun DateText(date: String) { | ||||||
|  |     Text( | ||||||
|  |         text = date, | ||||||
|  |         fontWeight = FontWeight.Bold, | ||||||
|  |         fontSize = 20.sp, | ||||||
|  |         modifier = Modifier.padding(horizontal = 10.dp) | ||||||
|  |     ) | ||||||
|  | } | ||||||
|  | @ -1,26 +1,19 @@ | ||||||
| package be.ugent.sel.studeez.screens.home | package be.ugent.sel.studeez.screens.home | ||||||
| 
 | 
 | ||||||
| import androidx.compose.foundation.background |  | ||||||
| import androidx.compose.foundation.layout.* | import androidx.compose.foundation.layout.* | ||||||
| import androidx.compose.foundation.lazy.LazyColumn | import androidx.compose.foundation.lazy.LazyColumn | ||||||
| import androidx.compose.foundation.lazy.items | import androidx.compose.foundation.lazy.items | ||||||
| import androidx.compose.foundation.shape.CircleShape |  | ||||||
| import androidx.compose.material.Card |  | ||||||
| import androidx.compose.material.Text | import androidx.compose.material.Text | ||||||
| import androidx.compose.runtime.Composable | import androidx.compose.runtime.Composable | ||||||
| import androidx.compose.runtime.collectAsState | import androidx.compose.runtime.collectAsState | ||||||
| import androidx.compose.ui.Alignment | import androidx.compose.ui.Alignment | ||||||
| import androidx.compose.ui.Modifier | import androidx.compose.ui.Modifier | ||||||
| import androidx.compose.ui.draw.clip |  | ||||||
| import androidx.compose.ui.graphics.Color |  | ||||||
| import androidx.compose.ui.text.font.FontWeight | import androidx.compose.ui.text.font.FontWeight | ||||||
| import androidx.compose.ui.text.style.TextOverflow | 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 androidx.hilt.navigation.compose.hiltViewModel | import androidx.hilt.navigation.compose.hiltViewModel | ||||||
| import be.ugent.sel.studeez.R | import be.ugent.sel.studeez.common.composable.DateText | ||||||
| import be.ugent.sel.studeez.common.composable.StealthButton |  | ||||||
| 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 | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
|  | @ -32,7 +25,7 @@ fun Feed( | ||||||
| 
 | 
 | ||||||
|     LazyColumn { |     LazyColumn { | ||||||
| 
 | 
 | ||||||
|         items(feedEntries.value.toList()) {(date, feedEntries) -> |         items(feedEntries.value.toList()) { (date, feedEntries) -> | ||||||
|             Row( |             Row( | ||||||
|                 horizontalArrangement = Arrangement.SpaceBetween, |                 horizontalArrangement = Arrangement.SpaceBetween, | ||||||
|                 modifier = Modifier |                 modifier = Modifier | ||||||
|  | @ -49,7 +42,7 @@ fun Feed( | ||||||
|                 ) |                 ) | ||||||
|             } |             } | ||||||
|             feedEntries.forEach { feedEntry -> |             feedEntries.forEach { feedEntry -> | ||||||
|                 FeedEntryCard(feedEntry = feedEntry) { |                 FeedEntry(feedEntry = feedEntry) { | ||||||
|                     viewModel.continueWithTask(open, feedEntry.subjectId, feedEntry.taskId) |                     viewModel.continueWithTask(open, feedEntry.subjectId, feedEntry.taskId) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  | @ -58,70 +51,11 @@ fun Feed( | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @Preview | ||||||
| @Composable | @Composable | ||||||
| fun DateText(date: String) { | fun FeedPreview() { | ||||||
|     Text( |     Feed( | ||||||
|         text = date, |         open = {}, | ||||||
|         fontWeight = FontWeight.Bold, |         viewModel = hiltViewModel(), | ||||||
|         fontSize = 20.sp, |  | ||||||
|         modifier = Modifier.padding(horizontal = 10.dp) |  | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
| 
 |  | ||||||
| @Composable |  | ||||||
| fun FeedEntryCard( |  | ||||||
|     feedEntry: FeedEntry, |  | ||||||
|     continueWithTask: () -> Unit, |  | ||||||
| ) { |  | ||||||
|     Card( |  | ||||||
|         modifier = Modifier |  | ||||||
|             .fillMaxWidth() |  | ||||||
|             .padding(horizontal = 10.dp, vertical = 5.dp), |  | ||||||
|     ) { |  | ||||||
|         Row( |  | ||||||
|             horizontalArrangement = Arrangement.SpaceBetween, |  | ||||||
|             verticalAlignment = Alignment.CenterVertically, |  | ||||||
|         ) { |  | ||||||
|             Row( |  | ||||||
|                 horizontalArrangement = Arrangement.spacedBy(8.dp), |  | ||||||
|                 verticalAlignment = Alignment.CenterVertically, |  | ||||||
|                 modifier = Modifier |  | ||||||
|                     .padding(start = 10.dp) |  | ||||||
|                     .weight(3f) |  | ||||||
|             ) { |  | ||||||
|                 Box( |  | ||||||
|                     modifier = Modifier |  | ||||||
|                         .size(20.dp) |  | ||||||
|                         .clip(CircleShape) |  | ||||||
|                         .background(Color(feedEntry.argb_color)), |  | ||||||
|                 ) |  | ||||||
|                 Column( |  | ||||||
|                     verticalArrangement = Arrangement.spacedBy(0.dp) |  | ||||||
|                 ) { |  | ||||||
|                     Text( |  | ||||||
|                         text = feedEntry.subJectName, |  | ||||||
|                         fontWeight = FontWeight.Bold, |  | ||||||
|                         overflow = TextOverflow.Ellipsis, |  | ||||||
|                         maxLines = 1, |  | ||||||
|                     ) |  | ||||||
|                     Row( |  | ||||||
|                         modifier = Modifier.fillMaxWidth(), |  | ||||||
|                         horizontalArrangement = Arrangement.SpaceBetween, |  | ||||||
|                         verticalAlignment = Alignment.CenterVertically, |  | ||||||
|                     ) { |  | ||||||
|                         Text(text = feedEntry.taskName) |  | ||||||
|                         Text(text = HoursMinutesSeconds(feedEntry.totalStudyTime).toString()) |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             StealthButton( |  | ||||||
|                 text = R.string.start, |  | ||||||
|                 modifier = Modifier |  | ||||||
|                     .padding(start = 10.dp, end = 5.dp) |  | ||||||
|                     .weight(1f) |  | ||||||
|             ) { |  | ||||||
|                 continueWithTask() |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | @ -0,0 +1,96 @@ | ||||||
|  | package be.ugent.sel.studeez.screens.home | ||||||
|  | 
 | ||||||
|  | import androidx.compose.foundation.background | ||||||
|  | import androidx.compose.foundation.layout.* | ||||||
|  | import androidx.compose.foundation.shape.CircleShape | ||||||
|  | import androidx.compose.material.Card | ||||||
|  | import androidx.compose.material.Text | ||||||
|  | import androidx.compose.runtime.Composable | ||||||
|  | import androidx.compose.ui.Alignment | ||||||
|  | import androidx.compose.ui.Modifier | ||||||
|  | import androidx.compose.ui.draw.clip | ||||||
|  | import androidx.compose.ui.graphics.Color | ||||||
|  | import androidx.compose.ui.text.font.FontWeight | ||||||
|  | import androidx.compose.ui.text.style.TextOverflow | ||||||
|  | import androidx.compose.ui.tooling.preview.Preview | ||||||
|  | import androidx.compose.ui.unit.dp | ||||||
|  | import be.ugent.sel.studeez.R | ||||||
|  | import be.ugent.sel.studeez.common.composable.StealthButton | ||||||
|  | import be.ugent.sel.studeez.data.local.models.FeedEntry | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds | ||||||
|  | 
 | ||||||
|  | @Composable | ||||||
|  | fun FeedEntry( | ||||||
|  |     feedEntry: FeedEntry, | ||||||
|  |     continueWithTask: () -> Unit, | ||||||
|  | ) { | ||||||
|  |     Card( | ||||||
|  |         modifier = Modifier | ||||||
|  |             .fillMaxWidth() | ||||||
|  |             .padding(horizontal = 10.dp, vertical = 5.dp), | ||||||
|  |     ) { | ||||||
|  |         Row( | ||||||
|  |             horizontalArrangement = Arrangement.SpaceBetween, | ||||||
|  |             verticalAlignment = Alignment.CenterVertically, | ||||||
|  |         ) { | ||||||
|  |             Row( | ||||||
|  |                 horizontalArrangement = Arrangement.spacedBy(8.dp), | ||||||
|  |                 verticalAlignment = Alignment.CenterVertically, | ||||||
|  |                 modifier = Modifier | ||||||
|  |                     .padding(start = 10.dp) | ||||||
|  |                     .weight(11f) | ||||||
|  |             ) { | ||||||
|  |                 Box( | ||||||
|  |                     modifier = Modifier | ||||||
|  |                         .size(20.dp) | ||||||
|  |                         .clip(CircleShape) | ||||||
|  |                         .background(Color(feedEntry.argb_color)), | ||||||
|  |                 ) | ||||||
|  |                 Row( | ||||||
|  |                     modifier = Modifier.fillMaxWidth(), | ||||||
|  |                     horizontalArrangement = Arrangement.SpaceBetween, | ||||||
|  |                     verticalAlignment = Alignment.CenterVertically, | ||||||
|  |                 ) { | ||||||
|  |                     Column( | ||||||
|  |                         verticalArrangement = Arrangement.spacedBy(0.dp) | ||||||
|  |                     ) { | ||||||
|  |                         Text( | ||||||
|  |                             text = feedEntry.subJectName, | ||||||
|  |                             fontWeight = FontWeight.Bold, | ||||||
|  |                             overflow = TextOverflow.Ellipsis, | ||||||
|  |                             maxLines = 1, | ||||||
|  |                         ) | ||||||
|  |                         Text( | ||||||
|  |                             text = feedEntry.taskName, | ||||||
|  |                             overflow = TextOverflow.Ellipsis, | ||||||
|  |                             maxLines = 1, | ||||||
|  |                         ) | ||||||
|  |                     } | ||||||
|  |                     Text(text = HoursMinutesSeconds(feedEntry.totalStudyTime).toString()) | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             StealthButton( | ||||||
|  |                 text = R.string.continue_task, | ||||||
|  |                 modifier = Modifier | ||||||
|  |                     .padding(start = 10.dp, end = 5.dp) | ||||||
|  |                     .weight(6f) | ||||||
|  |             ) { | ||||||
|  |                 continueWithTask() | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | @Preview | ||||||
|  | @Composable | ||||||
|  | fun FeedEntryPreview() { | ||||||
|  |     FeedEntry( | ||||||
|  |         continueWithTask = {}, | ||||||
|  |         feedEntry = FeedEntry( | ||||||
|  |             argb_color = 0xFFFFD200, | ||||||
|  |             subJectName = "Test Subject", | ||||||
|  |             taskName = "Test Taskkkkkkkkkkkkkkkkkkkkkkkkk", | ||||||
|  |             totalStudyTime = 20, | ||||||
|  |         ) | ||||||
|  |     ) | ||||||
|  | } | ||||||
		Reference in a new issue
	
	 brreynie
						brreynie