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 androidx.lifecycle.LiveData | |
import androidx.lifecycle.MediatorLiveData | |
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Job | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.launch | |
fun <T> LiveData<T>.debounce(duration: Long = 1000L, coroutineScope: CoroutineScope) = MediatorLiveData<T>().also { mld -> | |
val source = 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
class CardView(context: Context, attributeSet: AttributeSet) : View(context, attributeSet) { | |
private var outerWidth = 0f | |
private var outerHeight = 0f | |
private var xCenter = 0f | |
private var yCenter = 0f | |
private var cornerRadius = 10f | |
private var shadowSize = 50f | |
private val shadowStartColor = 0x20000000 | |
private val shadowEndColor = 0x00000000 |
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
override fun onDraw(canvas: Canvas) { | |
super.onDraw(canvas) | |
val path = Path() | |
path.apply { | |
moveTo(shadowSize + cornerRadius, shadowSize + cornerRadius) | |
arcTo(0f, 0f, shadowSize * 2 + 2 * cornerRadius, shadowSize * 2 + 2 * cornerRadius, 180f, 90f, false) | |
moveTo(shadowSize + cornerRadius, shadowSize + cornerRadius) | |
arcTo(shadowSize, shadowSize, shadowSize + 2 * cornerRadius, shadowSize + 2 * cornerRadius, 270f, -90f, false) | |
} | |
canvas.drawPath(path, radialGradientPaint) |
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 path = Path() | |
val paint = Paint() | |
paint.apply { | |
strokeWidth = 20f | |
style = Paint.Style.FILL | |
} | |
path.apply { | |
moveTo(xCenter, yCenter) |
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 path = Path() | |
val paint = Paint() | |
paint.apply { | |
strokeWidth = 20f | |
style = Paint.Style.STROKE | |
} | |
path.apply { | |
moveTo(xCenter, yCenter) |
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
// With the assumption, this code is written inside a view | |
// choose a reasonable range of colors, some ranges won't be drawn and I don't know why actually. | |
private val shadowStartColor = 0x99ffffff.toInt() | |
private val shadowEndColor = 0x03ffffff | |
private val shadowSize = 50f | |
val radialGradientPaint =RadialGradient(centerX | |
, centerY, | |
radius, | |
intArrayOf(shadowStartColor, shadowEndColor), | |
floatArrayOf(0f, 1f), |
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
// Those are two tasks. | |
// TASK 1 | |
open class SingletonHolder<out T, in A>(creator: (A) -> T) { | |
private var creator: ((A) -> T)? = creator | |
@Volatile | |
private var instance: T? = 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
interface Displayable { | |
fun getType(): Int | |
} | |
// ---------------------------------- | |
abstract class ViewRenderer<in D : Displayable, VH : RecyclerView.ViewHolder>(val type: Int) { | |
abstract fun bindView(model: D, holder: VH) | |
abstract fun createViewHolder(parent: ViewGroup): VH | |
} |
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 PlayerActivity : AppCompatActivity() { | |
private lateinit var mMediaBrowserCompat: MediaBrowserCompat | |
private val connectionCallback: MediaBrowserCompat.ConnectionCallback = object : MediaBrowserCompat.ConnectionCallback() { | |
override fun onConnected() { | |
// The browser connected to the session successfully, use the token to create the controller | |
super.onConnected() | |
mMediaBrowserCompat.sessionToken.also { token -> |
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 MusicService : MediaBrowserServiceCompat() { | |
private var mMediaSession: MediaSessionCompat? = null | |
private lateinit var mStateBuilder: PlaybackStateCompat.Builder | |
private var mExoPlayer: SimpleExoPlayer? = null | |
private var oldUri: Uri? = null | |
private val mMediaSessionCallback = object : MediaSessionCompat.Callback() { | |
override fun onPlayFromUri(uri: Uri?, extras: Bundle?) { | |
super.onPlayFromUri(uri, extras) | |
uri?.let { | |
val mediaSource = extractMediaSourceFromUri(uri) |
NewerOlder