This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@MainThread | |
fun <T> MutableLiveData<T>.mutate(mutator: T.() -> Unit) { | |
this.value = this.value?.apply(mutator) | |
} | |
@MainThread | |
fun <T> MutableLiveData<T>.modifyValue(transform: T.() -> T) { | |
this.value = this.value?.run(transform) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Disable during development. It speeds up compilation time. Keep enabled in production or CI tests. | |
Adagger.formatGeneratedSource=disabled | |
// https://stackoverflow.com/questions/39136042/dagger-reusable-scope-vs-singleton | |
@Reusable | |
// Modules to be object with static providers | |
object xModule | |
@JvmStatic | |
@Provide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2019 Coinbase, 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T> LiveData<T>.observe( | |
owner: LifecycleOwner, | |
crossinline observer: (T?) -> Unit | |
) { | |
observe(owner, Observer<T> { v -> observer(v) }) | |
} | |
inline fun <T> LiveData<T>.observeNonNull( | |
owner: LifecycleOwner, | |
crossinline observer: (T) -> Unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convenience factory to handle ViewModels with one parameter. | |
* | |
* Make a factory: | |
* ``` | |
* // Make a factory | |
* val FACTORY = viewModelFactory(::MyViewModel) | |
* ``` | |
* | |
* Use the generated factory: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class Event<out T>(private val content: T) { | |
var hasBeenHandled = false | |
private set // Allow external read but not write | |
/** | |
* Returns the content and prevents its use again. | |
*/ | |
fun getContentIfNotHandled(): T? { | |
return if (hasBeenHandled) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> { | |
override fun onChanged(event: Event<T>?) { | |
event?.getContentIfNotHandled()?.let { value -> | |
onEventUnhandledContent(value) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class DataBindingBaseAdapter | |
extends RecyclerView.Adapter<MyViewHolder> { | |
public MyViewHolder onCreateViewHolder(ViewGroup parent, | |
int viewType) { | |
LayoutInflater layoutInflater = | |
LayoutInflater.from(parent.getContext()); | |
ViewDataBinding binding = DataBindingUtil.inflate( | |
layoutInflater, viewType, parent, false); | |
return new MyViewHolder(binding); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataBindingViewHolder extends RecyclerView.ViewHolder { | |
private final ViewDataBinding binding; | |
public MyViewHolder(ViewDataBinding binding) { | |
super(binding.getRoot()); | |
this.binding = binding; | |
} | |
public void bind(Object obj) { | |
binding.setVariable(BR.obj, obj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log; | |
import com.squareup.okhttp.Interceptor; | |
import com.squareup.okhttp.Request; | |
import com.squareup.okhttp.Response; | |
import java.io.IOException; | |
public class LoggingInterceptor implements Interceptor { | |
@Override |
NewerOlder