Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Coding

Radek Piekarz radzio

👨‍💻
Coding
View GitHub Profile
View LiveEvent.kt
class LiveEvent<T> : MediatorLiveData<T>() {
private val observers = ConcurrentHashMap<LifecycleOwner, MutableSet<ObserverWrapper<T>>>()
@MainThread
override fun observe(owner: LifecycleOwner, observer: Observer<T>) {
val wrapper = ObserverWrapper(observer)
val set = observers[owner]
set?.apply {
add(wrapper)
View clean-branches
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done
View Instructions.md

Instructions

  • copy the file commit-msg to .git/hooks/commit-msg
  • make sure your delete the sample file .git/hooks/commit-msg.sample
  • Make commit msg executable. chmod +x .git/hooks/commit-msg
  • Edit commit-msg to better fit your development branch, commit regex and error message
  • Profit $$

Shell example

View MainViewModelTests.java
public class MainViewModelTests {
@Test
public void mainViewModel_firstName_lastName_helloButtonEnabledSetToTrue() throws Exception {
MainViewModel mainViewModel = new MainViewModel();
assertFalse(mainViewModel.helloButtonEnabled.get());
mainViewModel.firstName.set("a");
mainViewModel.lastName.set("b");
View MainViewModel.java
public static class MainViewModel {
public ObservableField<String> firstName = new ObservableField<>();
public ObservableField<String> lastName = new ObservableField<>();
public ObservableField<String> helloText = new ObservableField<>();
public ObservableBoolean helloButtonEnabled = new ObservableBoolean(false);
public MainViewModel() {
Observable.combineLatest(toObservable(firstName), toObservable(lastName), (firstName, lastName) -> StringUtils.isNotNullOrEmpty(firstName) && StringUtils.isNotNullOrEmpty(lastName))
View activity_main_button_2.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="@{viewModel.helloButtonEnabled}"
android:onClick="@{() -> viewModel.buttonClicked()}"
android:text="@string/btn_hello_rx" />
View activity_main_button_1.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="@{StringUtils.isNotNullOrEmpty(viewModel.firstName) &amp;&amp; StringUtils.isNotNullOrEmpty(viewModel.lastName)}"
android:onClick="@{() -> viewModel.buttonClicked()}"
android:text="@string/btn_hello" />
View RxUtils.java
public static <T> Observable<T> toObservable(@NonNull final ObservableField<T> observableField) {
return Observable.create(new Observable.OnSubscribe<T>() {
@Override
public void call(final Subscriber<? super T> subscriber) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(observableField.get());
}
final OnPropertyChangedCallback callback = new OnPropertyChangedCallback() {
View keybase.md

Keybase proof

I hereby claim:

  • I am radzio on github.
  • I am radzio (https://keybase.io/radzio) on keybase.
  • I have a public key ASCXQuDHoZ_wR4XsxPROEOYtzn38vcHRPNb2Msutwc6d-wo

To claim this, I am signing this object:

View AppCompatMaterialAlertDialog.java
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;