Skip to content

Instantly share code, notes, and snippets.

Hannes Dorfmann sockeqwe

Block or report user

Report or block sockeqwe

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
@sockeqwe
sockeqwe / SwitchMap.kt
Created Apr 28, 2019
switchMap operator for Kotlin's Flow type.
View SwitchMap.kt
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
/**
View News.kt
data class News(
val title : String
val favorite : Boolean
)
View MyFormPresenter.java
class MyFormPresenter extends MviBasePresenter<MyFormView, FormViewState> {
@Override
public void bindIntents(){
Observable<FormViewState> state = intent( MyFormView::submitIntent)
.map(formInputData -> new FormViewState( isValidName(formInputData.name), isValidEmail(formInputData.email) ) );
subscribeViewState(state, MyFormView::render)
}
}
View FirstPageLoading.java
class FirstPageLoading implements PartialStateChanges {
@Override
public HomeViewState computeNewState(HomeViewState previousState)
return previousState.builder()
.firstPageLoading(true)
.firstPageError(null)
.build();
}
}
View FooActivity.java
class FooActivity extends MviActivity<...> {
@Inject FooPresenter
public void onCreate(Bundle bundle){
super.onCreate(bundle);
FooComponent component = DaggerFooComponent.builder()
.fooModule(new FooModule(bundle))
.build();
component.inject(this);
View PersonModel.java
class PersonsModel {
// In a real application fields would be private
// and we would have getters to access them
final boolean loading;
final List<Person> persons;
final Throwable error;
public(boolean loading, List<Person> persons, Throwable error){
this.loading = loading;
this.persons = persons;
@sockeqwe
sockeqwe / LastCall.java
Created Jan 5, 2017 — forked from passsy/LastCall.java
Mockito verification of the last call on a method
View LastCall.java
package com.pascalwelsch.mockito;
import org.mockito.exceptions.base.MockitoException;
import org.mockito.exceptions.verification.ArgumentsAreDifferent;
import org.mockito.internal.debugging.LocationImpl;
import org.mockito.internal.invocation.InvocationMatcher;
import org.mockito.internal.junit.JUnitTool;
import org.mockito.internal.reporting.SmartPrinter;
import org.mockito.internal.verification.api.VerificationData;
import org.mockito.internal.verification.argumentmatching.ArgumentMatchingTool;
@sockeqwe
sockeqwe / Query.java
Created May 22, 2016
RxJava wrapper for Firebase ValueEventListeners
View Query.java
package com.usehomeroom.vasuki.data;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fernandocejas.arrow.optional.Optional;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
View MyFragmentPagerAdapter.java
class MyFragmentPagerAdapter extends FragmentPagerAdapter {
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override public Fragment getItem(int position) {
return new OverviewFragmentBuilder(1).build();
}
@sockeqwe
sockeqwe / Pager.java
Created Nov 7, 2015 — forked from mttkay/Pager.java
A simple Rx based pager
View Pager.java
public class Pager<I, O> {
private static final Observable FINISH_SEQUENCE = Observable.never();
private PublishSubject<Observable<I>> pages;
private Observable<I> nextPage = finish();
private Subscription subscription = Subscriptions.empty();
private final PagingFunction<I> pagingFunction;
private final Func1<I, O> pageTransformer;
You can’t perform that action at this time.