Last active
March 2, 2022 06:15
-
-
Save rahul-gill/95aa7ab7175d159918ae2106a594c6b8 to your computer and use it in GitHub Desktop.
ContestItem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun ContestItem( | |
contestModel: ContestModel, | |
onAddToCalendar: (Event) -> Unit = {} | |
) { | |
if (contestModel.name != "ProjectEuler+") Box { | |
Card( | |
modifier = Modifier.padding(bottom = 8.dp).fillMaxWidth(), | |
elevation = 2.dp, | |
shape = RectangleShape | |
) { | |
Row( | |
modifier = Modifier.padding(8.dp), | |
verticalAlignment = Alignment.CenterVertically | |
) { | |
val image = Util.loadLocalPicture(imageRes = contestModel.platform.imageId) | |
image?.let { | |
Image( | |
bitmap = it, | |
// FOR PREVIEW | |
// painter = painterResource(id = contestModel.platform.imageId), | |
contentDescription = "", | |
modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp), | |
colorFilter = ColorFilter.tint(MaterialTheme.colors.onSurface) | |
) | |
} | |
Column( | |
verticalArrangement = Arrangement.SpaceBetween, | |
modifier = Modifier.fillMaxWidth() | |
) { | |
Text( | |
text = contestModel.name, | |
style = MaterialTheme.typography.body1.copy(fontSize = 14.sp), | |
maxLines = 1, | |
overflow = TextOverflow.Ellipsis, | |
modifier = Modifier.widthIn(max = 250.dp) | |
) | |
Row( | |
horizontalArrangement = Arrangement.SpaceBetween, | |
modifier = Modifier.fillMaxWidth().padding(top = 4.dp) | |
) { | |
Text( | |
text = contestModel.timeString(), | |
style = MaterialTheme.typography.caption.copy(color = Color.Gray), | |
) | |
Text( | |
text = contestModel.status.status_string, | |
modifier = Modifier.padding(end = 2.dp), | |
style = MaterialTheme.typography.caption.copy( | |
fontWeight = FontWeight.Bold, | |
color = if (contestModel.status.status_string == "running") MaterialTheme.colors.primary else Color.Unspecified | |
) | |
) | |
} | |
} | |
} | |
} | |
Icon( | |
imageVector = Icons.Default.CalendarToday, | |
contentDescription = "", | |
modifier = Modifier | |
.padding(8.dp) | |
.clickable { onAddToCalendar(Event.from(contestModel)) } | |
.align(Alignment.TopEnd) | |
) | |
} | |
} | |
@Composable | |
fun Util.loadLocalPicture( | |
@DrawableRes imageRes: Int | |
): ImageBitmap? { | |
var bitmapState by remember { mutableStateOf<Bitmap?>(null) } | |
GlideApp.with(LocalContext.current) | |
.asBitmap() | |
.load(imageRes) | |
.into(object : CustomTarget<Bitmap>() { | |
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) { | |
bitmapState = resource | |
} | |
override fun onLoadCleared(placeholder: Drawable?) {} | |
}) | |
return bitmapState?.asImageBitmap() | |
} | |
@Composable | |
ContestsList(){ | |
LazyColumn { | |
item { Spacer(modifier = Modifier.height(60.dp)) } | |
var noFilters = true | |
for (filter in filer.values) { | |
if (filter == true) noFilters = false | |
} | |
itemsIndexed(if (noFilters) contests else contests.filter { filer[it.platform] == true }) { _, contest -> | |
ContestItem(contest, onAddToCalendar = onAddToCalendar) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment