This file contains hidden or 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 CategoriesHorizontalList(modifier: Modifier = Modifier, data: List<String>) { | |
val selectedHourState = remember { mutableStateOf(0) } | |
Card( | |
elevation = elevationDefault, shape = boxShapeDefault, modifier = Modifier.padding(8.dp) | |
) { | |
LazyRow( | |
modifier = modifier.background(MaterialTheme.colors.primary.copy(alpha = 0.9f)), | |
horizontalArrangement = Arrangement.spacedBy(8.dp), | |
contentPadding = PaddingValues(horizontal = 8.dp) |
This file contains hidden or 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 IconTab(daysEnergyHistoric: DaysEnergyHistoric) { | |
var tabIndex by remember { mutableStateOf(0) } | |
val tabData = daysEnergyHistoric.toList() | |
TabRow(selectedTabIndex = tabIndex) { | |
tabData.forEachIndexed { index, pair -> | |
Tab(selected = tabIndex == index, onClick = { | |
tabIndex = index | |
}, text = { |
This file contains hidden or 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
@Test | |
fun myTest() = coroutineDispatcher.runBlockingTest { | |
val uc = GetPicturesUseCase(MyFakeRepository()) | |
val item = uc.invoke().first() | |
assert(item is ResultData.Failure) | |
} | |
This file contains hidden or 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
// Test if number have not numFractionDigits ex: (40.12345).roundTo(7) cant get the last 7 because have 5 | |
private fun Double.maxDecimals(numFractionDigits: Int) = try { | |
val factor = 10.0.pow(numFractionDigits.toDouble()) | |
(this * factor).roundToInt() / factor | |
} catch (e: Exception) { | |
e.localizedMessage?.toString()?.let { Log.e("Double.maxDecimals", it) } | |
this | |
} |
This file contains hidden or 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
For those cases where you have to calculate the elements before adding them to the list, | |
you "save" the boilerplate of creating a mutable list and then returning an immutable list. | |
The example of the docs is... but it is understood where it goes. | |
val y = buildList () { | |
add ('a') | |
addAll (x) | |
add ('d') | |
} | |
This file contains hidden or 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
fun Modifier.gradientBackground(colors: List<Color>, angle: Float) = this.then( | |
Modifier.drawBehind { | |
val angleRad = angle / 180f * PI | |
val x = kotlin.math.cos(angleRad).toFloat() //Fractional x | |
val y = kotlin.math.sin(angleRad).toFloat() //Fractional y | |
val radius:Float = kotlin.math.sqrt( | |
((size.width.pow(2) + size.height.pow(2))) / 2f) | |
val offset = center + Offset(x * radius, y * radius) |
This file contains hidden or 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
@Query("SELECT count(*) FROM alarm") | |
fun countAlarms(): Flow<Int> |
This file contains hidden or 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
sealed class ResultData<out T> { | |
class Loading<out T>: ResultData<T>() | |
data class Success<out T>( | |
val data: T | |
): ResultData<T>() | |
data class Failure<out T>( | |
val errorMessage: String?=null, val exception: Exception?= null | |
): ResultData<T>() |
This file contains hidden or 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 GradientView(modifier: Modifier = Modifier) { | |
Box( | |
modifier = Modifier | |
.background( | |
brush = Brush.verticalGradient( | |
colors = listOf( | |
MaterialTheme.colorScheme.primary, | |
MaterialTheme.colorScheme.secondary |
This file contains hidden or 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 BackgroundAlphaAnimated() { | |
val animatedAlpha = remember { Animatable(0f) } | |
Box( | |
Modifier | |
.background(color = (Color.DarkGray.copy(alpha = animatedAlpha.value))) | |
.fillMaxSize() | |
) | |
LaunchedEffect(animatedAlpha) { |