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
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<font | |
app:font="@font/roboto_thin" | |
app:fontStyle="normal" | |
app:fontWeight="100" /> | |
<font | |
app:font="@font/roboto_thinitalic" | |
app:fontStyle="italic" | |
app:fontWeight="100" /> | |
<font |
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
import android.content.Context | |
import android.graphics.RectF | |
import android.util.AttributeSet | |
import android.view.View | |
import androidx.annotation.Nullable | |
import kotlin.math.min | |
abstract class SizedView @JvmOverloads constructor( | |
context: Context, | |
@Nullable attrs: AttributeSet? = null, |
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
val View.isLeftToRight: Boolean | |
@SuppressLint("SwitchIntDef") | |
get() = when (ViewCompat.getLayoutDirection(this)) { | |
View.LAYOUT_DIRECTION_LTR -> true | |
View.LAYOUT_DIRECTION_RTL -> false | |
View.LAYOUT_DIRECTION_INHERIT -> (parent as? View)?.isLeftToRight ?: true | |
View.LAYOUT_DIRECTION_LOCALE -> TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_LTR | |
else -> throw IllegalStateException() | |
} |
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
#!/bin/bash | |
# inspiration for this script comes from here: https://www.androiddesignpatterns.com/2018/11/android-studio-svg-to-vector-cli.html | |
DESIRED_PATH="$1" | |
if [ -z "$1" ] | |
then | |
echo "No path provided.Please specify a path to clone the source files into." | |
echo -e "\nUsage: $ ./build_vdtool.sh [my-desired-path]\n" | |
echo "It is suggested to place these files outside of your dbx source in order to not mess up the project files" |
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
inline fun <reified T> TypedArray.autoRecycle(block: TypedArray.() -> T): T { | |
val result = block() | |
recycle() | |
return result | |
} | |
fun resolveDrawable(context: Context, @AttrRes attr: Int): Drawable? = | |
context.theme.obtainStyledAttributes(intArrayOf(attr)).autoRecycle { getDrawable(0) } |
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
/** Try to fetch a viewModel in [store] */ | |
@Composable | |
inline fun <reified T : ViewModel, S : ViewModelStoreOwner> viewModelInStore(store: S): Result<T> = | |
runCatching { | |
var result: Result<T>? = null | |
CompositionLocalProvider(LocalViewModelStoreOwner provides store) { | |
result = runCatching { viewModel(T::class.java) } | |
} | |
result!!.getOrThrow() |
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 inline fun <R> ByteArray.reduce( | |
offset: Int, size: Int, default: R, | |
reducer: (acc: R, element: Byte, offsetIdx: Int) -> R | |
): R { | |
var acc = default | |
val upperBound = offset + size | |
if (0 > offset && upperBound >= size) throw RuntimeException("Selected range not in bound. ${offset until upperBound} !in $indices") | |
for (i in offset until upperBound) { | |
acc = reducer(acc, get(i), i - offset) |
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
sealed class Either<out L, out R> { | |
abstract val left: L | |
abstract val right: R | |
abstract fun invert(): Either<R, L> | |
} | |
class Left<out L>(override val left: L) : Either<L, Nothing>() { | |
companion object { | |
@JvmStatic |
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
inline fun <reified T : Enum<T>> enumGetBy(default: T, predicate: (T) -> Boolean): T = | |
enumGetByOrNull(predicate) ?: default | |
inline fun <reified T : Enum<T>> enumGetByOrNull(predicate: (T) -> Boolean): T? = | |
enumValues<T>().find(predicate) | |
inline fun <reified T : Enum<T>> enumGetByName(name: String, default: T): T = | |
enumGetBy(default) { it.name == name } | |
inline fun <reified T : Enum<T>> enumGetByNameOrNull(name: String): T? = |
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
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.channels.Channel | |
import kotlinx.coroutines.channels.ClosedReceiveChannelException | |
import kotlinx.coroutines.isActive | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking | |
import kotlinx.coroutines.sync.Mutex | |
import kotlinx.coroutines.sync.withLock | |
import java.lang.ref.WeakReference |
OlderNewer