Skip to content

Instantly share code, notes, and snippets.

View kibotu's full-sized avatar
🎯
Focusing

Jan Rabe kibotu

🎯
Focusing
View GitHub Profile
@kibotu
kibotu / extract_app_version.sh
Last active January 29, 2024 13:15
extract_app_version.sh
#!/bin/bash
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Check if -man option is passed
if [ -f "version-properties.gradle" ]; then
APP_VERSION_RAW=$(grep "appVersion *=" version-properties.gradle)
else
import java.lang.ref.WeakReference
import kotlin.reflect.KProperty
inline fun <reified T> weak() = WeakReferenceDelegate<T>()
inline fun <reified T> weak(value: T) = WeakReferenceDelegate(value)
/**
* e.g. var x by weak<Context?>(activity)
@kibotu
kibotu / Context+Extensions.kt
Last active March 21, 2022 14:40
Jetpack Compose get activity in Composable from LocalContext.
// val activity = LocalContext.current.findActivity()
tailrec fun Context.findActivity(): AppCompatActivity? = when (this) {
is AppCompatActivity -> this
is ContextWrapper -> baseContext.findActivity()
else -> null
}
@kibotu
kibotu / build.gradle
Last active March 29, 2022 15:52
Deploy aab to Huawei AppGallery.
// based on https://github.com/ferPrieto/steps-app-gallery-deploy/blob/main/step.sh
import groovy.json.JsonSlurper
ext {
def properties = project.gradle.startParameter.projectProperties
println(properties)
// https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agcapi-getstarted-0000001111845114
// IMPORTANT: when creating api key: 'N/A' as Project
@kibotu
kibotu / generate_dependencies.gradle
Last active July 18, 2022 12:41
Generating Dependencies for different build variants.
/**
* Generates a text file containing dependencies for different build variants
* and saves them into the respective variant asset folder.
* Also deletes files on clean.
*
* Can be safely used with <code>org.gradle.unsafe.configuration-cache=true</code>
*/
android.applicationVariants.all { variant ->
def name = variant.name
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- google's material design colours from
http://www.google.com/design/spec/style/color.html#color-ui-color-palette -->
<!--reds-->
<color name="md_red_50">#FFEBEE</color>
<color name="md_red_100">#FFCDD2</color>
<color name="md_red_200">#EF9A9A</color>
@kibotu
kibotu / WoobleAll.kt
Created October 21, 2021 08:32
Wooble All
// implementation "com.github.kibotu:AndroidAnimationsActions:2.0.1"
// maven { url 'https://jitpack.io' }
fun ViewGroup.woobleEVERYTHING() = children.forEach { it.startWobbling() }
fun View.startWobbling() {
val minDuration = 1f
val maxDuration = 1.5f
val duration: Float = randomRange(minDuration, maxDuration)
play(
@kibotu
kibotu / Lifecycle+Extensions.kt
Created October 7, 2021 09:33
waitForLifecycleEvent
@OptIn(ExperimentalCoroutinesApi::class)
suspend fun Lifecycle.waitForLifecycleEvent(event: Lifecycle.Event) = suspendCancellableCoroutine<Unit> { continuation ->
val observer = object : DefaultLifecycleObserver {
override fun onCreate(owner: LifecycleOwner) {
super.onCreate(owner)
if (event != Lifecycle.Event.ON_CREATE) return
continuationResume()
}
@kibotu
kibotu / validating_jsons.sh
Created August 11, 2021 08:37
Validating all jsons in folder
#!/usr/bin/env bash
set -e
set -x
find . -type f -name "*.json" -print0 | xargs -0 -I {} sh -c "echo Validating \"{}\"; cat \"{}\" | jq ."
@kibotu
kibotu / ThrottleFirstClickListener.kt
Last active August 6, 2021 13:05
ThrottleFirstClickListener
import android.view.View
/**
* An OnClickListener that sends only the first click of a given Time Interval
*
* @param defaultInterval time frame to skip until next click is send
* @param onThrottleFirstClick callback
*/
class ThrottleFirstClickListener(
private var defaultInterval: Int = 100,