Skip to content

Instantly share code, notes, and snippets.

Ghedeon

Block or report user

Report or block Ghedeon

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
@Ghedeon
Ghedeon / NotNull.kt
Created Mar 4, 2019
NotNull delegate with lazy message
View NotNull.kt
fun <T: Any> notNull(lazyMessage: () -> Any): ReadWriteProperty<Any?, T> = NotNullVar(lazyMessage)
private class NotNullVar<T: Any>(val lazyMessage: () -> Any) : ReadWriteProperty<Any?, T> {
private var value: T? = null
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return value ?: throw IllegalStateException(lazyMessage.toString())
}
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
@Ghedeon
Ghedeon / Test.kt
Created Feb 1, 2019
Coroutine Test
View Test.kt
class AccountOwnerTypeViewModelTest {
@Rule
@JvmField
val rule = InstantTaskExecutorRule()
val mainThreadSurrogate = newSingleThreadContext("UI thread")
@Before
fun setUp() {
@Ghedeon
Ghedeon / NoSwipeabaleViewPager.kt
Last active Nov 3, 2018
A ViewPager with disabled swipe.
View NoSwipeabaleViewPager.kt
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager
class NoSwipeabaleViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) {
@SuppressLint("ClickableViewAccessibility")
@Ghedeon
Ghedeon / HideBottomViewOnScrollBehavior.kt
Last active Sep 27, 2018
HideBottomViewOnScrollBehavior that ensures BottomView visibility
View HideBottomViewOnScrollBehavior.kt
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.TimeInterpolator
import android.content.Context
import android.support.design.animation.AnimationUtils
import android.support.design.widget.CoordinatorLayout
import android.support.design.widget.Snackbar
import android.support.v4.view.ViewCompat
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
View NestedCoordinatorLayout.kt
import android.annotation.SuppressLint
import android.content.Context
import android.support.annotation.AttrRes
import android.support.design.widget.CoordinatorLayout
import android.support.v4.view.NestedScrollingChild2
import android.support.v4.view.NestedScrollingChildHelper
import android.util.AttributeSet
import android.view.View
import com.douglas.startpage.R
@Ghedeon
Ghedeon / filter_devices.groovy
Created Jul 22, 2015
Android Gradle (1.3.0-beta4). Filter multiple devices
View filter_devices.groovy
project.afterEvaluate {
project.("connectedDebugAndroidTest").doFirst {
def originalProvider = deviceProvider
deviceProvider = [
getName : { originalProvider.getName() },
init : { originalProvider.init() },
terminate : { originalProvider.terminate() },
getDevices : { filterDevices(originalProvider.getDevices()) },
getTimeoutInMs: { originalProvider.getTimeoutInMs() },
isConfigured : { originalProvider.isConfigured() },
View gradlew
#!/bin/sh
D=$(pwd)
G="gradlew"
while [ ! -x "$D/$G" -a "$D" != "/" ]; do
D=$(dirname $D)
done
if [ ! -x "$D/$G" ]; then
echo "No Gradle found in current or parent directories!"
exit 1
fi
View gist:affdc95aeafafe6684cd
import com.android.builder.testing.ConnectedDeviceProvider
def DEVICES_PROPERTY = "devices"
ConnectedDeviceProvider.metaClass.getProperty = { String name ->
def metaProperty = delegate.metaClass.getMetaProperty(name)
def property = metaProperty.getProperty(delegate)
if (name.equals(DEVICES_PROPERTY) && project.hasProperty(DEVICES_PROPERTY)) {
def devicesSerials = project.getProperties().get(DEVICES_PROPERTY).split(/,/)
def devices = property.findAll {devicesSerials.contains(it.serialNumber)}
property = devices
}
View gist:640b9fdaa4bc4460cc41
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "test.co.vv.myapplication"
minSdkVersion 15
targetSdkVersion 21
You can’t perform that action at this time.