fun googleSignInOptionsObservable() : Observable<GoogleSignInOptions> =
Observable.just(
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(activity.getString(R.string.default_web_client_id))
.requestEmail()
.build())
fun googleApiClientObservable(gso : GoogleSignInOptions) : Observable<GoogleApiClient> =
This file contains 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
/** | |
var image = images.memeloperCompilingImage; | |
for(var day = 0; day < days.length; day++) { | |
if(day === 5 && !isMemeloperTodayPublushed(image)) { | |
// Public this memeloper every friday. | |
memeloperTopics.push(image); | |
} | |
} | |
**/ |
This file contains 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
List<Class<?>> assignables = Arrays.asList(Request.class, Response.class, HttpServletRequest.class, HttpServletResponse.class); | |
void callMethod(final Method me, final HttpServletRequest request, final HttpServletResponse response) { | |
Optional.ofNullable(me).ifPresent(m -> { | |
Optional<Class<?>[]> typesStream = Optional.of(m.getParameterTypes()); | |
typesStream | |
.filter(ctypes -> ctypes.length == 1) | |
.map(types -> types[0]) |
This file contains 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
public String cookie(String name) { | |
Cookie[] cookies = raw.getCookies(); | |
if (cookies != null) { | |
for (Cookie cookie : cookies) { | |
if (cookie.getName().equals(name)) { | |
return cookie.getValue(); | |
} | |
} | |
} | |
return null; |
#Intro
Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3
Kotlin project website is at kotlin.jetbrains.org.
All the codes here can be copied and run on Kotlin online editor.
Let's get started.
This file contains 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
/* | |
* Copyright 2014 Julian Shen | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains 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
// SignUp flow. | |
Observable.CombineLatest( | |
firstName .RxTextChanged(50).StartWith(string.Empty), | |
lastName .RxTextChanged(50).StartWith(string.Empty), | |
email .RxTextChanged(50).StartWith(string.Empty), | |
pwd .RxTextChanged(50).StartWith(string.Empty), | |
confirmPwd.RxTextChanged(50).StartWith(string.Empty), | |
gender .RxSelectedItem() .StartWith(0), | |
, Tuple.Create) | |
.SampleLatest( |
This file contains 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
public static class UiExtensions | |
{ | |
public static IObservable<Keycode> RxKeyPressed(this EditText tv, bool ignoreBackKey = false) => | |
Observable.Create((IObserver<Keycode> obs) => { | |
tv.SetOnKeyListener(new KeyUpPressedListener(obs, ignoreBackKey)); | |
return () => tv.SetOnKeyListener(null); | |
}); | |
public static IObservable<string> RxTextChanged (this TextView tv, int dueTimeMilliseconds = 500) => | |
FromEventPattern<TextChangedEventArgs> ( |
This file contains 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
public static class NetworkHelpers | |
{ | |
public static IObservable<T> WithProgressDialog<T>(this IObservable<T> source, Activity act) | |
{ | |
var p = new AlertDialog.Builder(act).Create(); | |
p.Show(); | |
return source.Finally(p.Dismiss); | |
} | |
} |
OlderNewer