Skip to content

Instantly share code, notes, and snippets.

@oldergod
oldergod / DataBindingAdapters.java
Last active March 30, 2017 06:07
DataBinding with <include> tags
public class DataBindingAdapters {
@BindingAdapter("visible") public static void setVisibility(View view, boolean isVisible) {
view.setVisibility(isVisible ? VISIBLE : GONE);
}
}
@oldergod
oldergod / 01_Activity.java
Last active January 19, 2018 22:19
Managing RxState Starting point
/**
* Many things are omitted to focus on the relevant data.
*/
public class Activity extends AppCompatActivity {
Binder binder;
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
bind();
}
@oldergod
oldergod / AndroidViewEvent.kt
Created September 18, 2019 13:01
Android view events for tests
import com.jakewharton.rxrelay2.PublishRelay
import io.reactivex.Observable
import io.reactivex.Observer
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
/**
* [PublishRelay]-like [Observable] enforcing:
* 1. a unique observer at a time, and
@oldergod
oldergod / hyperlink.js
Created November 18, 2020 01:43
Hyperlink on slack
@oldergod
oldergod / XmlOrJsonConverterFactory.java
Last active July 6, 2023 23:48
Retrofit: Xml or Json converter
public class XmlOrJsonConverterFactory extends Converter.Factory {
final Converter.Factory xml = SimpleXmlConverterFactory.create();
final Converter.Factory gson = GsonConverterFactory.create();
@Override
public Converter<ResponseBody, ?> responseBodyConverter(
Type type, Annotation[] annotations, Retrofit retrofit) {
// Retrofit gives us all the annotations so we just need to check
for (Annotation annotation : annotations) {
@oldergod
oldergod / 01_Activity.java
Last active July 25, 2023 05:49
Managing RxState Ending point
/**
* Many things are omitted to focus on the relevant data.
*/
public class Activity extends AppCompatActivity {
Binder binder;
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
Object lastCustomNonConfigInstance = getLastCustomNonConfigurationInstance();
if (lastCustomNonConfigInstance != null) {
binder = (Binder) lastCustomNonConfigInstance;