Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Sliceのアレコレ

 Sliceのアレコレ

Yuki Mima

May 29, 2018
Tweet

More Decks by Yuki Mima

Other Decks in Technology

Transcript

  1. (PPHMF*0ͷ஌ݟ w ։࠵ͷલલ೔ೖΓ͕ྑͦ͞͏ w ࣌ࠩϘέ·͡ਏ͍ w ૣΊͷ#BEHF1JDLVQͰΑΓྑ͍੮Ͱ,FZOPUFΛݟΕΔ w ௚௨ͷγϟτϧόε͕ग़Δϗςϧ͕Α͍ w

    IUUQTXXXDPVOUSZJOOTDPN w #BEHF1JDLVQͷ࣌ؒ͸ޕલ࣌෼͘Β͍͕ྑͦ͞͏ w ன൧͕ޱʹ߹Θͳ͍ w 6CFS࠷ߴ
  2. class CryptoSliceProvider : SliceProvider() { private val path = "/crypto"

    override fun onCreateSliceProvider(): Boolean = true override fun onBindSlice(sliceUri: Uri): Slice? = when (sliceUri.path) { path -> { context.startService(Intent(context, CryptoService::class.java)) createCryptoSlice(sliceUri) } else -> null } private fun createCryptoSlice(sliceUri: Uri): Slice? = ListBuilder(context, sliceUri, ListBuilder.INFINITY) .addGridRow { it.apply { addCell { it.apply { addImage(IconCompat.createWithResource(context, R.drawable.ic_bitcoin), SMALL_IMAGE) addTitleText("Bitcoin") addText(CryptoService.bitcoin, true) } } ... } } .build() }
  3. class CryptoSliceProvider : SliceProvider() { private val path = "/crypto"

    override fun onCreateSliceProvider(): Boolean = true override fun onBindSlice(sliceUri: Uri): Slice? = when (sliceUri.path) { path -> { context.startService(Intent(context, CryptoService::class.java)) createCryptoSlice(sliceUri) } else -> null } private fun createCryptoSlice(sliceUri: Uri): Slice? = ListBuilder(context, sliceUri, ListBuilder.INFINITY) .addGridRow { it.apply { addCell { it.apply { addImage(IconCompat.createWithResource(context, R.drawable.ic_bitcoin), SMALL_IMAGE) addTitleText("Bitcoin") addText(CryptoService.bitcoin, true) } } ... } } .build() }
  4. class CryptoSliceProvider : SliceProvider() { private val path = "/crypto"

    override fun onCreateSliceProvider(): Boolean = true override fun onBindSlice(sliceUri: Uri): Slice? = when (sliceUri.path) { path -> { context.startService(Intent(context, CryptoService::class.java)) createCryptoSlice(sliceUri) } else -> null } private fun createCryptoSlice(sliceUri: Uri): Slice? = ListBuilder(context, sliceUri, ListBuilder.INFINITY) .addGridRow { it.apply { addCell { it.apply { addImage(IconCompat.createWithResource(context, R.drawable.ic_bitcoin), SMALL_IMAGE) addTitleText("Bitcoin") addText(CryptoService.bitcoin, true) } } ... } } .build() }
  5. class CryptoSliceProvider : SliceProvider() { private val path = "/crypto"

    override fun onCreateSliceProvider(): Boolean = true override fun onBindSlice(sliceUri: Uri): Slice? = when (sliceUri.path) { path -> { context.startService(Intent(context, CryptoService::class.java)) createCryptoSlice(sliceUri) } else -> null } private fun createCryptoSlice(sliceUri: Uri): Slice? = ListBuilder(context, sliceUri, ListBuilder.INFINITY) .addGridRow { it.apply { addCell { it.apply { addImage(…) addTitleText("Bitcoin") addText(CryptoService.bitcoin, true) } } ... } } .build() }
  6. class CryptoSliceProvider : SliceProvider() { private val path = "/crypto"

    override fun onCreateSliceProvider(): Boolean = true override fun onBindSlice(sliceUri: Uri): Slice? = when (sliceUri.path) { path -> { context.startService(Intent(context, CryptoService::class.java)) createCryptoSlice(sliceUri) } else -> null } private fun createCryptoSlice(sliceUri: Uri): Slice? = ListBuilder(context, sliceUri, ListBuilder.INFINITY) .addGridRow { it.apply { addCell { it.apply { addImage(…) addTitleText("Bitcoin") addText(CryptoService.bitcoin, true) } } ... } } .build() }
  7. class CryptoService : Service() { companion object { var bitcoin:

    String? = null ... } override fun onBind(p0: Intent?): IBinder? = null override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int = START_NOT_STICKY.also { _ -> apiClient.getCryptoList() .doOnFinish { stopSelf() } .subscribe({ bitcoin = "ˇ${it.toNumberformat()}" ... applicationContext.contentResolver.notifyChange(uri, null) }, { }) } }
  8. class CryptoService : Service() { companion object { var bitcoin:

    String? = null ... } override fun onBind(p0: Intent?): IBinder? = null override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int = START_NOT_STICKY.also { _ -> apiClient.getCryptoList() .doOnFinish { stopSelf() } .subscribe({ bitcoin = "ˇ${it.toNumberformat()}" applicationContext.contentResolver.notifyChange(uri, null) }, { }) } }
  9. class CryptoService : Service() { companion object { var bitcoin:

    String? = null ... } override fun onBind(p0: Intent?): IBinder? = null override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int = START_NOT_STICKY.also { _ -> apiClient.getCryptoList() .doFinally { stopSelf() } .subscribe({ bitcoin = "ˇ${it.toNumberformat()}" ... applicationContext.contentResolver.notifyChange(uri, null) }, { }) } }