Skip to content

Instantly share code, notes, and snippets.

Adam McNeilly AdamMc331

Block or report user

Report or block AdamMc331

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
AdamMc331 /
Created Aug 26, 2019
My notes from a talk at Droidcon NYC about the .idea folder.

git rm -r —cached .idea? - Harry Grillo

What is this folder?

Comes from the IDE Intellij, which AS is forked from and that’s why we have it.

Projects are directory based, which is what the .idea/ folder is for.

The gitignore file is often kind of spotty about what’s ignored and what isn’t. But now there’s a fixed set of lines (that are also what the presenter recommends).


Meta data around libraries in the project. We don’t want to include this because dependency management tools are what’s responsible for setting this up (like gradle).

AdamMc331 / DependencyExample.kt
Created Jul 19, 2019
Quick example that shows how to use Kotlin default params to help with DI.
View DependencyExample.kt
class HumanTimeHelper(private val clock: IClock = SystemClock()) {
// This allows me to update my helper class, _without_ changing the call site!
View TestBug.kt
class QuestionViewModel {
private val state = MutableLiveData<QuestionState>()
private val currentQuestion: LiveData<Question> = {
(it as? QuestionState.Loaded)?.data
val questionTitle: String
get() = currentQuestion.value?.title.orEmpty
// In Java, I can do this
public class MainClass {
interface MyInterface {
public void printName();
public class SubClass extends MainClass {
AdamMc331 / ErrorHandling.kt
Last active Jan 25, 2019
Shows a way to use function types to handle errors.
View ErrorHandling.kt
// Create a custom error class that holds both the error that occured,
// and a function to invoke if it retries.
data class MyCustomError(
val error: Throwable? = null,
val retry: (() -> Unit)? = null
// Create a state class that represents the current state of your screen.
// This is where you'd wanna put data you have to display, like a list of items
// or maybe an error, and a function to call if you want to retry something
AdamMc331 /
Created May 30, 2018
Shows an implementation of a Room database DAO
public class AccountDAO_Impl implements AccountDAO {
private final RoomDatabase __db;
private final EntityInsertionAdapter __insertionAdapterOfAccount;
private final EntityDeletionOrUpdateAdapter __deletionAdapterOfAccount;
private final SharedSQLiteStatement __preparedStmtOfDeleteAll;
public AccountDAO_Impl(RoomDatabase __db) {
View GradleBuildError.txt
// NoClassDef
Caused by: java.lang.NoClassDefFoundError: com/android/ide/common/res2/ResourceSet
at org.jetbrains.kotlin.gradle.plugin.Android25ProjectHandler.getResDirectories(Android25ProjectHandler.kt:185)
at org.jetbrains.kotlin.gradle.plugin.Android25ProjectHandler.getResDirectories(Android25ProjectHandler.kt:21)
// Full
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app-refresh'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(
View ReifiedTesting.kt
class TestAssertion<T>(private val actual: T) {
fun matches(expected: T) {
assertEquals(expected, actual)
inline fun <reified T> assert(actual: T): TestAssertion<T> {
return TestAssertion(actual)
View Test.kt
interface Test {
val item: Int
class TestClass(context: Context): Test {
override val item = 5
AdamMc331 / Testing.kt
Created Apr 5, 2018
Small gist used to answer a followup question from the NY Android Meetup.
View Testing.kt
// Any actions that occur on the Registration screen, successful or otherwise, should only deal with the RegistrationRobot.
// If you move to a new screen, the robot itself doesn't need to be aware of that. Your test can create the new robot.
// As seen in this example, where we move the flow over to a ProfileRobot after clicking register.
fun testSuccessfulRegistration() {
You can’t perform that action at this time.