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
class PhoneNumberVisualTransformation(countryCode: String) : SeparatorVisualTransformation() { | |
private val phoneNumberFormatter = PhoneNumberFormatter(countryCode) | |
override fun transform(input: CharSequence): CharSequence = phoneNumberFormatter.format(input.toString()) | |
override fun isSeparator(char: Char): Boolean = !PhoneNumberUtils.isNonSeparator(char) | |
} | |
private class PhoneNumberFormatter(countryCode: String) { | |
private val formatter = PhoneNumberUtil.getInstance().getAsYouTypeFormatter(countryCode) | |
fun format(number: String): String = number |
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
/* | |
* Copyright (c) 2022. Héctor de Isidro - hrules6872 | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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
private val LocalStore: ProvidableCompositionLocal<Store<*>> = compositionLocalOf { error("Store not provided") } | |
@Composable | |
fun <STATE : State> StoreProvider(store: Store<STATE>, content: @Composable Store<STATE>.() -> Unit) { | |
CompositionLocalProvider(LocalStore provides store) { | |
store.content() | |
} | |
} | |
@Composable |
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
fun <TYPE> List<TYPE>.padEndOrCompact(size: Int, fallback: TYPE): List<TYPE> { | |
if (size < 0) throw IllegalArgumentException("Desired length $size is less than zero.") | |
return (0 until size).map { this.getOrNull(it) ?: fallback } | |
} | |
fun <TYPE> List<TYPE>.padEnd(size: Int, fallback: TYPE): List<TYPE> { | |
if (size < 0) throw IllegalArgumentException("Desired length $size is less than zero.") | |
return when { | |
size > this.size -> this.padEndOrCompact(size, fallback) | |
else -> this |
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
#!/usr/bin/env sh | |
# export PATH=$PATH:~/Library/Android/sdk/platform-tools/ | |
case $1 in | |
"enter") | |
adb shell settings put global sysui_demo_allowed 1 | |
# display time 12:00 | |
adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1200 | |
# display full mobile data without type | |
adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e level 4 -e datatype false |
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
class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr) { | |
private val paint by lazy { Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL } } | |
@ColorInt | |
var color: Int = Color.TRANSPARENT | |
set(value) { | |
field = value | |
invalidate() | |
} |
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
/** | |
* Map it please. Returns a list containing the results of applying the | |
* given transform function to each element in the original collection. | |
* | |
* OP: https://twitter.com/jeranfox/status/1575133458631999488 | |
*/ | |
inline fun <TYPE, RESULT> Iterable<TYPE>.mip(transform: TYPE.() -> RESULT): List<RESULT> = map { it.transform() } | |
/** before: | |
* users.map { it.firstName } |
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
fun <T : Any> KClass<T>.safeOf(default: T, predicate: (T) -> Boolean): T = this.values().find { predicate(it) } ?: default | |
fun <T : Any> KClass<T>.values(): List<T> { | |
if (!this.isSealed) throw IllegalCallerException("Receiver MUST be a Sealed class") | |
return this.sealedSubclasses.map { sealedSubclass -> | |
when { | |
sealedSubclass.objectInstance != null -> sealedSubclass.objectInstance!! | |
else -> try { | |
sealedSubclass.primaryConstructor?.callBy(mapOf()) ?: throw Exception() | |
} catch (ignored: Exception) { |
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
public class TextViewDrawableSize extends TextView { | |
private static final int DEFAULT_COMPOUND_DRAWABLE_SIZE = -1; | |
private int compoundDrawableWidth; | |
private int compoundDrawableHeight; | |
public TextViewDrawableSize(Context context) { | |
this(context, null); | |
} | |
public TextViewDrawableSize(Context context, AttributeSet attrs) { |
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
/* Adds horizontal scrolling to tables in Obsidian Notes. Tested in Obsidian v0.15.9 | |
See also: https://forum.obsidian.md/t/css-horizontal-scrolling-tables/26581/4 | |
*/ | |
/* in preview / read mode */ | |
.markdown-preview-view table , | |
.markdown-source-view table { | |
display: block; /* This is needed for scrollbar */ | |
width: 100%; | |
max-width: -moz-max-content; |