Skip to content

Instantly share code, notes, and snippets.

View adam-hurwitz's full-sized avatar

Adam Hurwitz adam-hurwitz

View GitHub Profile
@adam-hurwitz
adam-hurwitz / ApplicationComponent.kt
Last active October 1, 2022 17:38 — forked from Zhuinden/ApplicationComponent.kt
Dagger + ViewModel + SavedStateHandle
@Singleton
@Component(modules = [AssistedInjectionModule::class])
interface ApplicationComponent {
fun mySavedStateViewModelFactory(): MySavedStateViewModel.Factory
}
@adam-hurwitz
adam-hurwitz / FeedViewModel.kt
Last active September 22, 2022 22:14
Android Model-View-Intent with Kotlin Flow - FeedViewModel.kt
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ExperimentalCoroutinesApi
class FeedViewModel @AssistedInject constructor(
@adam-hurwitz
adam-hurwitz / Rocket-Pool-Dashboard-Query
Last active December 22, 2021 18:40
Rocket Pool Dashboard Query
query stakerCheckpointData {
stakerBalanceCheckpoints(where: {stakerId: "SOME_WALLET_ADDRESS"} orderBy: blockTime orderDirection: desc){
ethBalance
rETHBalance
totalETHRewards
block
blockTime
}
}
@adam-hurwitz
adam-hurwitz / AssistedInjectModule.kt
Last active October 22, 2021 13:05
Dagger 2 AssistedInject ViewModels
import com.squareup.inject.assisted.dagger2.AssistedModule
import dagger.Module
@AssistedModule
@Module(includes = [AssistedInject_AssistedInjectModule::class])
class AssistedInjectModule
@adam-hurwitz
adam-hurwitz / dimens.xml
Last active January 29, 2021 02:22
ODG - Android Resource Files
<!--File path: app > src > main > res > values-->
<resources xmlns:tools="http://schemas.android.com/tools">
<!--Default screen margins, per the Android Design guidelines-->
<dimen name="margin_tiniest">2dp</dimen>
<dimen name="margin_tiny">4dp</dimen>
<dimen name="margin_small">8dp</dimen>
<dimen name="margin_medium">16dp</dimen>
<dimen name="margin_large">24dp</dimen>
@adam-hurwitz
adam-hurwitz / EditTextUtils.java
Last active January 29, 2021 01:11
ODG - EditText Utils
// Handle input length
private void handleInputLength(){
editTextViewName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 6){animateMethod();}
@adam-hurwitz
adam-hurwitz / Resource.kt
Last active January 28, 2021 00:15
ODG - UDF: Resource
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@adam-hurwitz
adam-hurwitz / RxSchedulers.kt
Last active January 26, 2021 18:37
ODG - RxJava Schedulers Helper
fun <T> Observable<T>.IOAndMainSchedulers() =
this.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
fun <T> Observable<T>.IOAndIOSchedulers() =
this.subscribeOn(Schedulers.io()).observeOn(Schedulers.io())
@adam-hurwitz
adam-hurwitz / ObservableZipBiFunction.kt
Last active January 26, 2021 18:07
ODG - RxJava Zip with BiFunction
// See sample: https://www.codexpedia.com/android/rxjava-2-zip-operator-example-in-android/
Observable.zip(
Observable.just("A"),
Observable.just("B"),
// First observable output, Second observable output, Combined result
BiFunction<String, String, String> { a, b ->
println("Zip build: " + a + b)
a + b
}
).subscribe { it ->
@adam-hurwitz
adam-hurwitz / ObservableZipFunction3.kt
Last active January 26, 2021 17:52
ODG - RxJava Zip with Function3
// See sample: https://www.codexpedia.com/android/rxjava-2-zip-operator-example-in-android/
import io.reactivex.functions.Function3
fun someMethod(){
val function3: Function3<String, String, String, String> = Function3 {
strings, strings2, strings3 ->
strings + strings2 + strings3
}