This file contains hidden or 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
service.loadDataWithNewTypeConverter() | |
.flatMapObservable { | |
it.data | |
} | |
.count() | |
.subscribe({ result -> | |
println("Size is: $result") | |
}, { error -> error.printStackTrace() }) |
This file contains hidden or 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
data class NewDataHolder( | |
@JsonAdapter(ObservableTypeAdapterFactory::class) | |
@SerializedName("data") | |
val data: Observable<DataItem> | |
) | |
class ObservableTypeAdapterFactory : TypeAdapterFactory { |
This file contains hidden or 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 JsonReaderObservable<T>(elementType: Type, gson: Gson, private val reader: JsonReader) : Observable<T>() { | |
private val subject = ReplaySubject.create<T>() | |
init { | |
reader.beginArray() | |
while (reader.hasNext()) { | |
subject.onNext(gson.fromJson(reader, elementType)) | |
} | |
reader.endArray() |
This file contains hidden or 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
service.loadDataWithoutAnyParsingAtAll() | |
.flatMapObservable { responseBody -> | |
Observable.create<DataItem> { emitter -> | |
JsonReader(responseBody.charStream()) | |
.use { reader -> | |
while (reader.hasNext()) { | |
if (reader.peek() == JsonToken.BEGIN_OBJECT) { | |
reader.beginObject() | |
if (reader.nextName() == "data") { |
This file contains hidden or 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
// Acquire a reference to the system Location Manager | |
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); | |
// Define a listener that responds to location updates | |
LocationListener locationListener = new LocationListener() { | |
public void onLocationChanged(Location location) { | |
// Called when a new location is found by the network location provider. | |
makeUseOfNewLocation(location); | |
} |
This file contains hidden or 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 java.io.File | |
fun main(args: Array<String>) { | |
val result = DayOneTask.run() | |
println(result) | |
} | |
object DayOneTask { |
OlderNewer