Skip to content

Instantly share code, notes, and snippets.

View scottroemeschke's full-sized avatar

Scott Roe-Meschke scottroemeschke

  • Snap
  • Denver, Colorado
View GitHub Profile
@scottroemeschke
scottroemeschke / LoginDetails.kt
Last active May 23, 2017 15:11
Kotlin implementation for login details
data class LoginDetails(val email: String? = null, val username: String? = null) {
companion object {
val empty = LoginDetails()
}
val isPresent get() = email != null && username != null
}
@scottroemeschke
scottroemeschke / PersistedLoginDetailsRepository.java
Last active May 21, 2017 20:34
java implementation for login details repository
public final class PersistedLoginDetailsRepository implements LoginDetailsRepository {
private static final String PREVIOUS_EMAIL_KEY = "prev_email";
private static final String LOGIN_METHOD = "login_method";
private final RxPaperBook persistence;
private final BehaviorRelay<LoginDetails> detailsRelay = BehaviorRelay.create();
private final BehaviorRelay<LoginMethod> methodRelay = BehaviorRelay.create();
public PersistedLoginDetailsRepository(final @NonNull RxPaperBook persistence) {
@scottroemeschke
scottroemeschke / LoginDetails.java
Last active May 21, 2017 19:55
java implementation of login details
public final class LoginDetails {
private final String email;
private final String username;
public LoginDetails(@Nullable final String email, @Nullable final String username) {
this.email = email;
this.username = username;
}
@scottroemeschke
scottroemeschke / OperatorOverloadsKotlinPoet.kt
Created May 17, 2017 02:30
Example of operator overloads for Kotlin Poet
package com.squareup.kotlinpoet
import java.util.*
import javax.lang.model.element.Modifier
/** Operator overloads for concise building. */
/** ParameterSpec operators */
@JvmName("plusAssignAnnotationSpecs")
@scottroemeschke
scottroemeschke / LifecycleEmittingActivity.java
Last active December 26, 2016 20:16
An activity which has a subject which can be subscribed to which emits the lifecycle events when they occur.
public class SomeActivity extends AppCompatActivity implements LifecycleEmittingActivity {
Subject<ActivityLifecycleEvent> lifecycleEvents = BehaviorSubject.create();
@Override
public Observable<ActivityLifecycleEvent> getLifecycleEvents() {
return lifecycleEvents.hide();
}
@Override
@scottroemeschke
scottroemeschke / ActivityLifecycleEventEnum.java
Created December 26, 2016 19:45
Stupid-Simple Enum for Activity Lifecycle Events
public enum ActivityLifecyleEvent {
CREATED,
STARTED,
RESUMED,
PAUSED,
STOPED,
DESTROYED
}
@scottroemeschke
scottroemeschke / AndroidLifecycleHooksAsObservable.java
Last active December 26, 2016 19:24
Android Lifecycle Events as an Observable
public interface LifecycleEmittingActivity {
Observable<ActivityLifecycleEvent> getLifecycleEvents();
}
@scottroemeschke
scottroemeschke / ActivityLifecycleMethods.java
Created December 26, 2016 19:07
A list of android activity lifecycle hooks.
public void onCreate(Bundle savedInstanceState);
public void onStart();
public void onResume();
public void onPause();
public void onStop();
public void onDestroy();
@scottroemeschke
scottroemeschke / NaiveGetFileAsString.java
Created November 25, 2016 19:59
Naive RxWrapping that is synchronous for long-blocking operation
public Single<Optional<String>> getFileAsJsonString(String fileName) {
return Single.just(fileToString(fileName));
}
private Optional<String> fileToString(String fileName) {
try {
InputStream inputStream = assetManager.open(fileName);
return Optional.of(CharStreams.toString(new InputStreamReader(
inputStream, Charsets.UTF_8)));
} catch (IOException exception) {
@scottroemeschke
scottroemeschke / AssetManagerCloseMethod.java
Last active November 26, 2016 17:52
A reactive wrapper for closing Android's assetManager.
Completable close() {
return Completable.fromAction(() -> assetManager.close());
}