Skip to content

Instantly share code, notes, and snippets.

View Tgo1014's full-sized avatar
💻

Tiago Araujo Tgo1014

💻
  • Barcelona, Spain
  • 01:07 (UTC +02:00)
  • X @Tgo1014
View GitHub Profile
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;
@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)
@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.

@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()
}
@passsy
passsy / KIntent.kt
Last active March 28, 2023 06:51
Kotlin extension functions to start a generic Activity
package com.pascalwelsch.extensions
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
/**
* Extensions for simpler launching of Activities
@alex-shpak
alex-shpak / Interceptor.java
Last active March 29, 2023 21:06
Refreshing OAuth token with okhttp interceptors. All requests will wait until token refresh finished, and then will continue with the new token.
private class HttpInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
//Build new request
Request.Builder builder = request.newBuilder();
builder.header("Accept", "application/json"); //if necessary, say to consume JSON
@gotev
gotev / NavigationBottomBarSectionsStateKeeperWorkaround.kt
Last active June 12, 2023 16:08
JetPack Bottom Bar Navigation with Sections State
package jetpack.navigation.workaround
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.navigation.NavController
import androidx.navigation.ui.setupActionBarWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import java.lang.ref.WeakReference
@kibotu
kibotu / ViewExtensions.kt
Last active September 13, 2023 05:45
Kotlin extension method to set margin.
fun View.setMargins(
left: Int? = null,
top: Int? = null,
right: Int? = null,
bottom: Int? = null
) {
val lp = layoutParams as? ViewGroup.MarginLayoutParams
?: return
lp.setMargins(
@simonewebdesign
simonewebdesign / install-quake3.sh
Last active November 14, 2023 19:25
Install Quake 3: Arena on a mac
#!/bin/bash
# Install Quake 3: Arena on a mac
# Copyright (c) 2016 simonewebdesign
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,