Skip to content

Instantly share code, notes, and snippets.

View caseykulm's full-sized avatar
🔲

Casey Kulm caseykulm

🔲
View GitHub Profile
@caseykulm
caseykulm / module1-build.gradle
Created August 14, 2017 20:25
Case 3 (Naiive Solution): Yet another one off dependency
dependencies {
implementation deps.retrofit
implementation deps.retrofitGson
implementation deps.dagger
implementation 'com.google.guava:guava:23.0-android'
}
@caseykulm
caseykulm / module1-build.gradle
Created August 14, 2017 20:27
Case 3 (Templating Solution): Yet another one off dependency
dependencies {
implementation deps.retrofit
implementation deps.retrofitGson
implementation deps.dagger
implementation deps.guava
}
@caseykulm
caseykulm / RetroDoggo.kt
Last active September 6, 2017 17:43
Abstract Retrofit from your API
interface RetroDogApi {
@GET("/dogs/{doggoName}")
Flowable<Dog> getDoggo(@Path("doggoName") String doggoName);
}
interface DogApi {
Flowable<Dog> getDoggo(String doggoName);
}
class DogClient(val urlA: String, val urlB: String): DogApi {
@caseykulm
caseykulm / RetroDoggo.kt
Last active September 6, 2017 18:20
Abstract Factory for Retro APIs
interface RetroDogApi {
@GET("/dogs/{doggoName}")
Flowable<Dog> getDoggo(@Path("doggoName") String doggoName);
}
interface DogApi {
Flowable<Dog> getDoggo(String doggoName);
}
interface UrlInfoApi {
@caseykulm
caseykulm / DoggoStash.kt
Last active September 7, 2017 14:12
Inject Functions: 1
data class DoggoStash(
val leash: Leash,
val waterBowl: WaterBowl,
val bed: Bed)
fun proceedOnRoadTrip(doggoStash: DoggoStash) {
getDoggoLeashedUp(doggoStash.leash)
packupWaterBowl(doggoStash.waterBowl)
setupBedInBackSeat(doggoStash.bed)
startDriving()
@caseykulm
caseykulm / DoggoStash.kt
Last active September 7, 2017 14:21
Inject Functions: 2
interface TreatFactory {
fun getTreats(): Treats
}
class Petco: TreatFactory {
fun getTreats(): Treats {
// Details of how to get to Petco,
// what aisle the treats are on,
// what treats they carry that doggo
// likes, etc.
@caseykulm
caseykulm / DoggoStash.kt
Created September 7, 2017 14:25
Inject Functions: 3
interface TreatFactory {
fun getTreats(): Treats
}
class PetsMart: TreatFactory {
fun getTreats(): Treats {
// Petsmart details
}
}
@caseykulm
caseykulm / SpacesItemDecoration.kt
Last active December 26, 2017 17:26
Adds even spacing to a RecyclerView accepting a custom span count
class SpacesItemDecoration(private val space: Int, private val span: Int) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view)
val lastPosition = parent.adapter.itemCount - 1
val bottomRow = (lastPosition - position) < span
val rightColumn = (position % span) == (span - 1)
/**
* |A----B----C|
@caseykulm
caseykulm / LinesView.java
Last active January 2, 2018 21:18
Draw Lines for different measurements around a TextView in Android
// Using https://medium.com/@orhanobut/android-and-typography-101-5f06722dd611 for reference
// Update with https://github.com/suragch/AndroidFontMetrics/blob/master/app/src/main/java/net/studymongolian/fontmetrics/FontMetricsView.java
// Need to take into account multiple lines
public class LinesView extends FrameLayout {
private static final Paint
RED_PAINT = new Paint(Color.RED),
BLUE_PAINT = new Paint(Color.BLUE),
GREEN_PAINT = new Paint(Color.GREEN),
PURPLE_PAINT = new Paint(Color.MAGENTA);
@caseykulm
caseykulm / network_security_config.xml
Created January 15, 2018 17:25
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides>
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>