Skip to content

Instantly share code, notes, and snippets.

View tim4dev's full-sized avatar

Yuriy Tim tim4dev

View GitHub Profile
@tim4dev
tim4dev / KeyboardObserver.kt
Last active April 29, 2022 04:39
Android keyboard state observer.
/**
* Android keyboard state observer.
* For portrait orientation only.
* https://bit.ly/3flvZar
* 2020 intelligence.worker@gmail.com.
*
* Example of usage:
* viewLifecycleOwner.lifecycleScope.launch {
* this@MyFragment.view?.run {
* KeyboardObserver().observe(your_root_view_here).distinctUntilChanged().collect { ... }
@mayankmkh
mayankmkh / PrettyPrint.kt
Last active April 11, 2024 11:52
Pretty Print Kotlin Data Class
fun Any.prettyPrint(): String {
var indentLevel = 0
val indentWidth = 4
fun padding() = "".padStart(indentLevel * indentWidth)
val toString = toString()
val stringBuilder = StringBuilder(toString.length)
@medyo
medyo / YouTubePlayerSupportFragmentX.java
Last active June 7, 2023 13:48
Solution: YouTubePlayerSupportFragment that supports androidx
package com.google.android.youtube.player;
/**
* Please create this directories schema com.google.android.youtube.player and post the file there
*/
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
@radoyankov
radoyankov / Example.kt
Last active January 27, 2023 08:59
Easy Spannable on Kotlin
val spanned = spannable{ bold("some") + italic(" formatted") + color(Color.RED, " text") }
val nested = spannable{ bold(italic("nested ")) + url("www.google.com", "text") }
val noWrapping = bold("no ") + sub("wrapping ) + sup("also ") + "works"
text_view.text = spanned + nested + noWrapping