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
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() {
AdamMc331 / RxRepetitiveFragment.kt
Created Mar 14, 2018
Notice how each function subscribes to an observable, sets the state based on the response, and otherwise logs an error? Is there a way to somehow combine these three methods into one?
View RxRepetitiveFragment.kt
private fun fetchAllFacebookAlbums() {
val subscription = socialPhotosViewModel.getAllFacebookAlbums()
state = it
View ClickableListEditText.kt
class ClickableListEditText<T> : AppCompatEditText {
var items: List<T> = ArrayList()
private val displayItems: Array<String>
get() = { it.toString() }.toTypedArray()
private var mHint: CharSequence
var onItemSelectedListener: OnItemSelectedListener<T>? = null
You can’t perform that action at this time.