Skip to content

Instantly share code, notes, and snippets.

View fmedlin's full-sized avatar

Fred Medlin fmedlin

View GitHub Profile
@fmedlin
fmedlin / doOnFirst.kt
Created September 9, 2021 20:56
Flowable.doOnFirst
fun <T> Flowable<T>.doOnFirst(onFirstAction: (T) -> Unit): Flowable<T> =
take(1)
.doOnNext { onFirstAction.invoke(it) }
.concatWith(skip(1))
@fmedlin
fmedlin / kotlin-gist.kt
Last active September 24, 2019 00:08
Kotlin tips and tricks
// Simple cache
// h/t Matthew Good: Android United slack channel
fun <T> MutableList<T>.addCache(new: T, max: Int) {
if (max == size) {
this.remove(this.last())
this.add(new)
}
}
@fmedlin
fmedlin / DialogTest.kt
Created April 27, 2018 18:42
Robolectric Examples
/**
* The dialog returned by ShadowDialog.getLatestDialog() does not expose much for testing.
* However, getting an AlertDialog shadow can help.
*/
@RunWith(RobolectricTestRunner::class)
class WebLoginActivityTest {
private lateinit var activity: SomeActivity
@Before
@fmedlin
fmedlin / layout.xml
Created February 16, 2018 02:39
Get the correct toolbar shadow for all Android OS versions
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
app:cardElevation="4dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
@fmedlin
fmedlin / Toolbar.kotlin
Created February 16, 2018 02:36
The many ways to navigate back with a Toolbar
// (1) Defer to the support actionbar
// Set the toolbar to be the support actionbar of an AppCompatActivity
// ...
setSupportActionBar(find(R.id.toolbar))
with(supportActionBar!!) {
setDisplayHomeAsUpEnabled(true)
setDisplayShowHomeEnabled(true)
}
// ...
@fmedlin
fmedlin / mingw-w64-3.10-osx10.9.sh
Last active February 15, 2017 22:13 — forked from Drakulix/mingw-w64-3.10-osx10.9.sh
Script to install a Mingw-w64 Cross-Compiler Suite on Mac OS X 10.9
#!/bin/sh
# dependencies
echo "Installing dependencies via Homebrew (http://brew.sh)"
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew update
brew install gcc48
package com.google.ara.app.manager.util;
import java.util.List;
public final class ModuleNameJoiner {
private ModuleNameJoiner() { }
private static final String DEFAULT_SEPARATOR = ", ";
public static String join(List<String> moduleNames, String conjoiner) {
@fmedlin
fmedlin / gist:f85c90abf82c7182344f
Created March 3, 2015 02:20
Layout helper for modifying touchable area of a view
/**
* Adjust the touchable area of a view.
*/
public static void LayoutHelper adjustTouchableArea(View view, View parent, TouchDelegateSizer sizer) {
parent.post(new Runnable() {
@Override
public void run() {
Rect r = new Rect();
view.getHitRect(r);
parent.setTouchDelegate(new TouchDelegate(sizer.adjustTouchableArea(r), view));
/*
* Copyright (C) 2013 Square, Inc.
*
* 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