Skip to content

Instantly share code, notes, and snippets.

View elihart's full-sized avatar

Eli Hart elihart

  • Airbnb
  • San Francisco
View GitHub Profile
@elihart
elihart / ForceClearingAndroidResourceCache.kt
Created November 20, 2019 20:58
ForceClearingAndroidResourceCache
AppCompatDrawableManager.get().onConfigurationChanged(view.context)
val resources = view.resources
val currentConfig = resources.configuration
val currentDisplayMetrics = resources.displayMetrics
resources.updateConfiguration(null, currentDisplayMetrics)
resources.updateConfiguration(currentConfig, currentDisplayMetrics)
@elihart
elihart / MvrxIntegrationTestsGeneratedClass.kt
Last active November 20, 2019 21:15
MvrxIntegrationTestsGeneratedClass
@LargeTest
class MvrxIntegrationTests : MvRxIntegrationTestBase() {
@Test
fun booking_fragments_BookingFragment_Screenshots() {
runScreenshots("com.airbnb.android.booking.fragments.BookingFragment")
}
@Test
fun booking_fragments_BookingFragment_Interactions() {
runInteractionTest("com.airbnb.android.booking.fragments.BookingFragment")
@elihart
elihart / MvRxCombinedMocksExample.kt
Created November 20, 2019 21:16
MvRxCombinedMocksExample
override fun provideMocks() = combineMocks(
"Marketplace" to marketplaceMocks(),
"Plus" to plusMocks(),
"Plus ProHost" to plusProHostMocks()
)
@elihart
elihart / ktest.kts
Created November 27, 2019 16:08
Kotlin script that runs `gradle clean test` on other scripts to easily build and test them (using kscript)
import java.io.BufferedReader
import java.io.File
import java.util.concurrent.TimeUnit
import kotlin.system.exitProcess
/**
* This script takes the name of another kts script as an argument, builds that script with gradle, and runs
* its tests via "gradle clean test".
*/
@elihart
elihart / gist:be43575bf7e7447f67f08467a5604740
Created December 5, 2019 04:31
Rough example code of a system for declaring accessible Fragments, and then easily loading them.
// The tools below can be used to easily start fragments and activities across module boundaries.
// Example usage - a "directory" is declared like this object.
// Then you can use it to:
// Create a new fragment: Search.results().newInstance(fragmentArguments)
// Create an intent for the Fragment: Search.results().newIntent(context, fragmentArguments)
// Start an intent for the Fragment: Search.results().startActivity(context, fragmentArguments)
object Search : Fragments("com.example.android.search") {
fun results() = create<SearchArguments>("SearchResultsFragment")
@elihart
elihart / FragmentDirectory.kt
Created December 5, 2019 04:32
Rough example code of a system for declaring routes for Fragments and their argument types. Allows for easily loading the Fragments individually or in a new activity.. Assumes usage with MvRx, but can be used with normal Fragments and Activities with basic modification.
// The tools below can be used to easily start fragments and activities across module boundaries.
// Example usage - a "directory" is declared like this object.
// Then you can use it to:
// Create a new fragment: Search.results().newInstance(fragmentArguments)
// Create an intent for the Fragment: Search.results().newIntent(context, fragmentArguments)
// Start an intent for the Fragment: Search.results().startActivity(context, fragmentArguments)
object Search : Fragments("com.example.android.search") {
fun results() = create<SearchArguments>("SearchResultsFragment")