Skip to content

Instantly share code, notes, and snippets.

View Tgo1014's full-sized avatar
💻

Tiago Araujo Tgo1014

💻
  • Barcelona, Spain
  • 18:47 (UTC +02:00)
  • X @Tgo1014
View GitHub Profile
@Jeevuz
Jeevuz / Extensions.kt
Last active January 3, 2023 10:25
Here I collect some of my most useful Kotlin extensions
inline fun SharedPreferences.edit(changes: SharedPreferences.Editor.() -> SharedPreferences.Editor) {
edit().changes().apply()
}
fun ImageView.tintSrc(@ColorRes colorRes: Int) {
val drawable = DrawableCompat.wrap(drawable)
DrawableCompat.setTint(drawable, ContextCompat.getColor(context, colorRes))
setImageDrawable(drawable)
if (drawable is TintAwareDrawable) invalidate() // Because in this case setImageDrawable will not call invalidate()
}
@russell-shizhen
russell-shizhen / Memos for building an Android Library project.md
Created October 17, 2018 09:24
Memos for building an Android Library project

Library build variants

Consider what features/functionalities

  • Debug
  • Release

Public API

Only expose the ones necessary

This can leave more flexibility to future API changes without breaking the APIs exposed in earlier versions.

Initial verification using code snippets to illustrate the API flow.

@recoverrelax
recoverrelax / BaseSharedPreferences.kt
Last active January 4, 2021 10:19
Base SharedPreferences usage for Kotlin (with dagger2 bonus)
abstract class BaseSharedPreferences(
val preferences: SharedPreferences,
val moshi: Moshi
) {
protected fun get(key: String, default: String): String = preferences.getString(key, default)
protected fun get(key: String, default: Int): Int = preferences.getInt(key, default)
protected fun get(key: String, default: Float): Float = preferences.getFloat(key, default)
protected fun get(key: String, default: Long): Long = preferences.getLong(key, default)
protected fun get(key: String, default: Boolean): Boolean = preferences.getBoolean(key, default)
package com.cobocn.hdms.app.ui.widget;
/**
* Created by benny on 14-9-19.
*/
import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;