Skip to content

Instantly share code, notes, and snippets.

View jameswald's full-sized avatar
💭
🍵

James Wald jameswald

💭
🍵
View GitHub Profile
class GuidedWorkoutFragment : TonalFragment(R.layout.guided_workout_fragment) {
override val daggerComponent: GuidedWorkoutMergeComponent by fragmentComponent { scope, app ->
app.bindings<GuidedWorkoutMergeComponent.Parent>().guidedWorkoutComponentBuilder()
.coroutineScope(WorkoutCoroutineScope(scope))
.args(arg)
.build()
}
}
@gpeal
gpeal / ContributesApiCodeGenerator.kt
Last active February 12, 2024 20:10
Anvil Code Generator
package com.tonal.trainer.anvilcompilers
import com.google.auto.service.AutoService
import com.squareup.anvil.annotations.ContributesTo
import com.squareup.anvil.compiler.api.AnvilContext
import com.squareup.anvil.compiler.api.CodeGenerator
import com.squareup.anvil.compiler.api.GeneratedFile
import com.squareup.anvil.compiler.api.createGeneratedFile
import com.squareup.anvil.compiler.internal.asClassName
import com.squareup.anvil.compiler.internal.buildFile
/*
* Adds a Java agent that sets a defaultUncaughtExceptionHandler for all jvm test modules,
* to ensure that exceptions thrown in Rx subscriptions (and coroutines?) aren't lost.
*
* Usually, one would do this with a JUnit RunListener, but Gradle doesn't support JUnit
* RunListeners, see https://github.com/gradle/gradle/issues/1330
*
* This workaround adds a test dependency for all modules to the module containing the uncaught
* exception handler. This module contains a Java agent, which is called before JUnit runs. To
* setup the agent we compile the jar and add the filepath as JVM argument.
@ncipollo
ncipollo / FlowCallAdapterFactory.kt
Created September 16, 2019 22:36
Retrofit call adapter factory for Flow
package org.mtg.api
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import retrofit2.*
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
class FlowCallAdapterFactory private constructor() : CallAdapter.Factory() {
companion object {
@siyamed
siyamed / MyTextInputEditText.kt
Created May 3, 2019 17:44
Show Error in TextInputEditText
import android.content.Context
import android.graphics.Point
import android.graphics.Rect
import android.util.AttributeSet
import android.view.View
import android.view.ViewParent
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
class MyTextInputEditText : TextInputEditText {
@dlew
dlew / script.sh
Created November 9, 2018 16:36
Simple AndroidX Migration Script
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
#
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
@lukaseder
lukaseder / CallDefaultMethodThroughReflection.java
Created March 28, 2018 09:56
Correct Reflective Access to Interface Default Methods in Java 8, 9, 10
// Compile on JDK 9 or 10 with javac -source 1.8 -target 1.8 CallDefaultMethodThroughReflection.java
// Blog post here: https://blog.jooq.org/2018/03/28/correct-reflective-access-to-interface-default-methods-in-java-8-9-10
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@JoseAlcerreca
JoseAlcerreca / ObservableViewModel.kt
Last active February 28, 2021 00:07
An Observable ViewModel for Data Binding and Architecture Components
/*
* Copyright (C) 2018 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
@aahlenst
aahlenst / RxIdlingResource.java
Last active July 27, 2021 15:56
IdlingResource that makes Espresso 2 wait until all RxJava 2 tasks have finished
/*
* The MIT License
*
* Copyright (c) 2016 Andreas Ahlenstorf
*
* 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
@rocboronat
rocboronat / PermissionGranter.java
Last active December 26, 2022 07:05
Tap the "allow" button while running an Android instrumental test using UIAutomator
package com.fewlaps.android.permissiongranter;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.support.v4.content.ContextCompat;