by Grzegorz Dyrda (@grzegorzdyrda)
Poniższa konstrukcja jest zupełnie poprawna:
| import java.net.HttpURLConnection | |
| import java.net.URL | |
| /** | |
| * Sends an HTTP request to the given [url], using the given HTTP [method]. The request can also | |
| * include custom [headers] and [body]. | |
| * | |
| * Returns the [Response] object containing [statusCode][Response.statusCode], | |
| * [headers][Response.headers] and [body][Response.body]. | |
| */ |
| /** | |
| * Created by Grzegorz Dyrda on 2017-12-07 | |
| */ | |
| import android.os.Handler | |
| import android.os.Looper | |
| private val mainHandler = Handler(Looper.getMainLooper()) | |
| fun postOnUiThread(action: () -> Unit) { |
by Grzegorz Dyrda (@grzegorzdyrda)
Poniższa konstrukcja jest zupełnie poprawna:
by Grzegorz Dyrda
W RxJava wszystkie strumienie są domyślnie "zimne" - czyli każda nowa subskrypcja powoduje skutki uboczne w źródle. Niestety, takie podejście sprawdza się jedynie w prostych "książkowych" przypadkach. Na co dzień, kiedy tworzymy logikę biznesową za pomocą łączenia/kombinacji strumieni, właściwość ta jest strasznie upierdliwa.
| // | |
| // Poniżej masz wycinek z mojej apki Śpiewnik. | |
| // Zwróć uwagę, że strumień `dialogItemSelected` jest wykorzystany wielokrotnie przez kolejne strumienie. | |
| // Dlatego też jest użyty operator `share` - żeby kolejne subskrypcje nie triggerowały ponownie kodu z flatMapa. | |
| // share() = publish().refCount() | |
| // | |
| val dialogItemSelected: Observable<Int> = | |
| view.onLabelLongPress //Observable<LabelEntity> | |
| .flatMap { label -> |
| /** | |
| * To make it work, just specify the fully-qualified name of this class as the "android:name" | |
| * attribute in your AndroidManifest.xml's <application> tag. | |
| */ | |
| public class Application extends android.app.Application { | |
| private static Application ourInstance; | |
| /** | |
| * This gets called by the Android OS when the process for your application/package is created. |