今どきの Retrofit と LiveData で Coroutine

ありがとうございます。


👉 Retrofit 

ご存知の通り Retrofit2 では、サスペンドな関数も利用できるようになっております。

👉 SpaceX REST API で試す Retrofit の coroutine 対応 


// NewModel.kt
@GET("/feed/here/")
suspend fun getData(@Query("token") token : String) : Status


// NewRepository.kt
class Repository {
  var client = RetrofitService.createService(JsonApi::class.java)
  suspend fun getData(token : String) = client.getData(token)
}

ので、以下のようなこれまでのコードは、


// OldViewModel.kt
val data = MutableLiveData<Status>()

private fun loadData(token: String){
  viewModelScope.launch {
    val retrievedData = withContext(Dispatchers.IO) {
      repository.getData(token)
    }
    data.value = retrievedData
  }
}

シンプルに以下のように書けます。


// NewViewModel.kt
val data : LiveData<Status> = liveData(Dispatchers.IO) {
      val retrievedData = repository.getData(token)
      emit(retrievedData)
    }

ありがとうございます。

👉 Exploring new Coroutines and Lifecycle Architectural Components integration on Android 
👉 Using Retrofit 2 with Kotlin coroutines - ProAndroidDev 


Android A/B パーテーション と Lineage OS インストール

大まかでもイメージしておくと得をすると思います。

👉 Here's a list of Android devices that support Seamless Updates 


👉 Download TWRP for sailfish 
👉 サポートが切れた Pixel に Android 10 相当の Lineage OS 17 を 

分かりやすく簡単に言いますが。

昔のパーテーション。

- recovery
- boot
- cache
- system
- vendor
- data

これが、Pixel時代以降の、A/B スタイルでは以下のようになります。

- boot_a
- boot_b
- system_a
- system_b
- vendor_a
- vendor_b
- data

キャッシュディレクトリは data/cache、リカバリパーテーションは boot_a と boot_b 以下に統合されました。

TWRP の flash 時には考慮が必須となります。

そして、TWRPのバージョンは、OpenGapps の 「Signature Verification」にも関係してきます。

👉 Help understanding A/B partitions | Google Pixel XL 
👉 TWRP lead explains why it'll take time for the custom recovery to support Android 10 

さらに、Android10では「ダイナミックパーテーション」などになるようです。

👉 Implementing Dynamic Partitions  |  Android Open Source Project 

よって、

Android10で初回のTWRP適用は、いきなり fastboot で flash するのはむずい。

なので、まず fastboot boot /path/to/twrp.img でメモリブートする。

そして、TWRPの端末への適用はインストーラ入りのzipで行う。

のが良いようです。

Pixelで以下の順でハマり続けた結果です。

Android10

非公式LineageOS17(Android10相当)

公式LineageOS16(Android9相当)


Gradle Build Scan は設定不要!!


👉 Getting started with build scans | Gradle Inc. 

無料です。

A build scan is a shareable and centralized record of a build that provides insights into what happened and why. By applying the build scan plugin to your project, you can publish build scans to https://scans.gradle.com for free.

👉 Creating Build Scans 

ターミナルから実行です。設定記述の追加は不要になりました。


./gradlew assembleDebug --scan

出力されるURLクリックから結果を見ることができます。

実行時間の一覧を見せてくれたり、

Gradle は 6.0、org.gradle.parallel=true をサジェストしてくれたりします。

有料版では、さらに高機能に使うことができるようです。