Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Building Coinverse's Android app

AdamHurwitz AdamSHurwitz

🚀
Building Coinverse's Android app
View GitHub Profile
@AdamSHurwitz
AdamSHurwitz / dimens.xml
Last active Jan 29, 2021
ODG - Android Resource Files
View dimens.xml
<!--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>
@AdamSHurwitz
AdamSHurwitz / EditTextUtils.java
Last active Jan 29, 2021
ODG - EditText Utils
View EditTextUtils.java
// 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();}
@AdamSHurwitz
AdamSHurwitz / Resource.kt
Last active Jan 28, 2021
ODG - UDF: Resource
View Resource.kt
/*
* 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
@AdamSHurwitz
AdamSHurwitz / RxSchedulers.kt
Last active Jan 26, 2021
ODG - RxJava Schedulers Helper
View RxSchedulers.kt
fun <T> Observable<T>.IOAndMainSchedulers() =
this.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
fun <T> Observable<T>.IOAndIOSchedulers() =
this.subscribeOn(Schedulers.io()).observeOn(Schedulers.io())
@AdamSHurwitz
AdamSHurwitz / ObservableZipBiFunction.kt
Last active Jan 26, 2021
ODG - RxJava Zip with BiFunction
View ObservableZipBiFunction.kt
// 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 ->
@AdamSHurwitz
AdamSHurwitz / ObservableZipFunction3.kt
Last active Jan 26, 2021
ODG - RxJava Zip with Function3
View ObservableZipFunction3.kt
// 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
}
@AdamSHurwitz
AdamSHurwitz / AvoidConcurrentModificationException.kt
Last active Jan 11, 2021
ODG - Kotlin: Avoiding ConcurrentModificationException
View AvoidConcurrentModificationException.kt
val integers = arrayListOf(1, 2, 3)
// Filter using streams.
val newIntegers = integers.filter { it != 2 }
// Use removeIf()
integers.removeIf { it == 2 }
// Use an iterator directly.
val iterator = integers.iterator()
@AdamSHurwitz
AdamSHurwitz / activity_main.xml
Created Jan 2, 2021
ODG - Android NavHost Fragment
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
@AdamSHurwitz
AdamSHurwitz / AssistedInjectModule.kt
Last active Dec 24, 2020
Dagger 2 AssistedInject ViewModels
View AssistedInjectModule.kt
import com.squareup.inject.assisted.dagger2.AssistedModule
import dagger.Module
@AssistedModule
@Module(includes = [AssistedInject_AssistedInjectModule::class])
class AssistedInjectModule
@AdamSHurwitz
AdamSHurwitz / someLayout.md
Last active Dec 18, 2020
ODG - Android Data Binding Samples
View someLayout.md

Strings

  • Static: android:text="@string/sell_recommend_views_label"

  • Concat resources: android:text="@{'Hello ' + user.firstName}"

  • Concat resource and var (Include %1s formatting in String resource): android:text='@{String.format(@string/string_name, uxContent.reduceByPrice)}'

  • Formatted: android:text='@{@string/some_string(uxContent.someVal, uxContent.someVal)}'