@startuml
start
if (Have an access token?) then (yes)
else (no)
if (Have an refresh token?) then (yes)
while (Request access token) is (error)
if (retry?) then (yes)
View Main.kt
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
// in Activity | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
lifecycleScope.launchWhenCreated { | |
editNickName.textChangeAsFlow() | |
.map { it?.isNotEmpty() ?: false } | |
.collect { | |
sendButton.isEnabled = it | |
} | |
} |
View intent.kt
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
// deprecatedだけど新しいのは API 23からなので仕方ない | |
val intent = AccountManager.newChooseAccountIntent( | |
null, | |
null, | |
arrayOf("com.google"), | |
true, | |
null, | |
null, | |
null, | |
null |
View coroutine_statemachine.kt
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
fun delay(delayTime: Long, stateMachine: StateMachine) { | |
Thread.sleep(delayTime) | |
stateMachine.resume() | |
} | |
class StateMachine { | |
var state = 0 | |
var start = 0L | |
fun resume() { | |
when (state) { |
View WorkerService.kt
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
import android.app.IntentService | |
import android.content.Context | |
import android.content.Intent | |
import android.os.Bundle | |
import androidx.work.Data | |
import androidx.work.OneTimeWorkRequest | |
import androidx.work.WorkManager | |
import androidx.work.Worker |
View EditTextChannel.kt
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
import android.text.Editable | |
import android.text.TextWatcher | |
import android.widget.EditText | |
import kotlinx.coroutines.experimental.channels.Channel | |
import kotlinx.coroutines.experimental.channels.ReceiveChannel | |
import kotlinx.coroutines.experimental.channels.sendBlocking | |
import kotlinx.coroutines.experimental.launch | |
object EditTextChannel { | |
fun empty(editText: EditText): ReceiveChannel<Boolean> = ConflatedChannel<Boolean>().apply { |
View StateLiveData.kt
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
class StateLiveData<T> : MutableLiveData<T>() { | |
override fun onInactive() { | |
super.onInactive() | |
value = null | |
} | |
} |
View actor_fizzbuzz.kt
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
class Value(val value: Int, var output: String = "") | |
fun rule(seed: Int, print: String, next: SendChannel<Value>) = actor<Value> { | |
for (value in channel) { | |
next.send(value.apply { | |
if (value.value % seed == 0) { | |
this.output += print | |
} | |
}) | |
} |
View ide.kt
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
fun shouldOpenShop(shopId: Long): Boolean { | |
if( shopId <= 0L ){ | |
return false | |
} | |
if( this.shop == null ) { | |
return false | |
} | |
if( this.shop.id == shopId ) { // これを return this.shop.id == shopId にしろって言われる | |
return false | |
} |
View coroutine_extensions.kt
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
fun <T> async(context: CoroutineContext = CommonPool, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T) | |
= kotlinx.coroutines.experimental.async(context, start, block) | |
fun ui(start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit) | |
= launch(UI, start, block) | |
suspend fun <T, U> parallel(c1: suspend CoroutineScope.() -> T, c2: suspend CoroutineScope.() -> U): Pair<T, U> { | |
val c1Job = async(block = c1) | |
val c2Job = async(block = c2) | |
return Pair(c1Job.await(), c2Job.await()) |
View request.md
NewerOlder