Skip to content

Instantly share code, notes, and snippets.

🚀
Building Coinverse's Android app

AdamHurwitz AdamSHurwitz

🚀
Building Coinverse's Android app
Block or report user

Report or block AdamSHurwitz

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
View SQLite.java
// Each item in stream emitted
public Observable<List<RecentSearch>> loadRecentSearchTerms() {
return Observable.just(
SQLite.select(RecentSearch_Table.recentSearchTerm)
.from(RecentSearch.class)
.queryList());
}
private void someMethod() {
@AdamSHurwitz
AdamSHurwitz / Repository.kt
Created Feb 2, 2020
RxJava: Retrofit Repository
View Repository.kt
public class Repository {
public void makeNetworkCall() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Service.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
// Converts Retrofit response into Observable.
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
@AdamSHurwitz
AdamSHurwitz / Service.java
Created Feb 2, 2020
RxJava: Retrofit Service
View Service.java
public interface Service {
@GET("public-api/v0/courses")
Observable<Model> getItems(...append params...);
}
}
View RxHelpersSample.java
public List<ObjectType> getStream(String stringId){
getStream(stringId)
.compose(RxHelpers.IOAndMainThreadSchedulers())
.map(ObjectModel -> model.getList())
.subscribe(list -> {
this.list = list;
}).unsubscribe();;
return this.list;
}
@AdamSHurwitz
AdamSHurwitz / Disposable.java
Last active Feb 2, 2020
RxJava: Disposables
View Disposable.java
CompositeDisposable compositeDisposable = new CompositeDisposable();
compositeDisposable.add(getDataMethod(stringParam)
.subscribe(this::addListMethod, throwable -> {
// Handle error.
}));
compositeDisposable.add(getDataMethodTwo(stringParam)
.subscribe(this::addListMethod, throwable -> {
// Handle error.
@AdamSHurwitz
AdamSHurwitz / JustExample.java
Last active Feb 2, 2020
RxJava: .just() Example
View JustExample.java
// Create Observable
public Observable<List<ObjectName>> getDataMethod(String stringParam) {
return Observable.just(/**get ObjectNames in a List*/);
}
// Subscribe
Subscription fullSubscription = getDataMethod(stringParam)
.subscribe( new Action1<List<UserActivityItem>>() {
@Override
public void call(List<ObjectName> listName) {
@AdamSHurwitz
AdamSHurwitz / build.gradle
Last active Feb 2, 2020
RxJava: build.gradle (Project: projectName)
View build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// Lambdas
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
@AdamSHurwitz
AdamSHurwitz / build.gradle
Created Feb 2, 2020
RxJava: build.gradle (Module: app)
View build.gradle
// Lambdas
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
android {
...
// Lambdas
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@AdamSHurwitz
AdamSHurwitz / Repository.kt
Last active Jan 27, 2020
Retrofit: Repository
View Repository.kt
object Repository {
// Use Kotlin Flow.
val results: LiveData<ArrayList<Model.Item>> get() = _results
private val _results = MutableLiveData<ArrayList<Model.Item>>()
fun makeNetworkCall() {
val retrofit: Retrofit = Retrofit.Builder()
.baseUrl("Base_url")
.addConverterFactory(GsonConverterFactory.create())
@AdamSHurwitz
AdamSHurwitz / Model.kt
Last active Jan 27, 2020
Retrofit: Model
View Model.kt
data class Item(val itemId: String)
data class Model(val items: ArrayList<Item>) : Parcelable {
constructor(parcel: Parcel) : this(arrayListOf())
override fun writeToParcel(parcel: Parcel, flags: Int) { }
override fun describeContents() = 0
companion object CREATOR : Parcelable.Creator<Model> {
You can’t perform that action at this time.