Skip to content

Instantly share code, notes, and snippets.

View Skyyo's full-sized avatar
🇺🇦

Denis Rudenko Skyyo

🇺🇦
View GitHub Profile
@Skyyo
Skyyo / ObservableSharedPreferences.kt
Last active August 16, 2020 11:21
lifecycle aware sp listener #lifecycle #flow #shared_preferences
fun <T> SharedPreferences.observeKey(key: String, default: T): Flow<T> {
return callbackFlow {
send(getItem(key, default))
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, k ->
if (key == k) {
offer(getItem(key, default))
}
}
@Skyyo
Skyyo / DebounceTextWatcher.kt
Last active August 16, 2020 11:21
text watcher combined with flow #lifecycle #flow #text_watcher
fun AppCompatEditText.afterTextChangedFlow(): Flow<Editable?> {
return callbackFlow {
val watcher = object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
offer(s)
}
override fun beforeTextChanged(
s: CharSequence?,
start: Int,
@Skyyo
Skyyo / CustomBadgeDrawable.kt
Last active August 16, 2020 11:22
Custom badge drawable that can be attached to views #view #badge
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.Resources
import android.graphics.*
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.text.TextPaint
import android.text.TextUtils
import android.util.AttributeSet
@Skyyo
Skyyo / SnowFlakeView.kt
Last active August 16, 2020 11:22
SnowFlake effect/view. SnowFlakesEffect.kt credits to https://github.com/DrKLO/Telegram #view #snow
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.view.View
class SnowFlakeView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
//check if jetifier can be turned off
plugins {
id "com.github.plnice.canidropjetifier" version "0.5"
}
//command
./gradlew -Pandroid.enableJetifier=false canIDropJetifier
//check the unused/transitively used/wrongly delcared deps
plugins {
id("com.autonomousapps.dependency-analysis") version "0.54.0"
@Skyyo
Skyyo / RightSheetBehaviour.kt
Created August 27, 2020 17:21
Custom side sheet, until https://material.io/components/sheets-side get's published. #slide #sheet
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Parcel;
import android.os.Parcelable;
@Skyyo
Skyyo / DoubleProgressCircleIndicator.kt
Last active October 10, 2020 12:59
Double progress indicators inside circle. #customView
class DoubleProgressCircleIndicator @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private val darkGreenPaint = Paint().apply {
style = Paint.Style.FILL
color = ContextCompat.getColor(context, R.color.colorGreenDuskGreen)
}
@Skyyo
Skyyo / broadcast FCM pushes
Created November 19, 2020 14:09
#fcm #push notifications
@POST https://fcm.googleapis.com/fcm/send
HEADERS:
Authorization key=AAAA... (Server key)
Content-Type application/json
BODY:
{
"to": "/topics/topicName",
"content_available": false,
@Skyyo
Skyyo / LightNavigationBarsExtenstion.kt
Last active November 20, 2020 16:33
#extension #status bar colour
fun View.setLightNavigationBars(light: Boolean) =
ViewCompat.getWindowInsetsController(this)?.let { controller ->
controller.isAppearanceLightNavigationBars = light
controller.isAppearanceLightStatusBars = light
}
@Skyyo
Skyyo / HostInterceptor.kt
Last active October 23, 2021 16:04
dynamically change the host url
@Singleton
class HostSelectionInterceptor : Interceptor {
var host: String? = null
set(value) {
field = value?.toHttpUrlOrNull()?.host
}
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): okhttp3.Response {