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

Kotlin初心者がGoogle Play Billing Libraryを使ってみた

Kotlin初心者がGoogle Play Billing Libraryを使ってみた

Kotlin初心者がGoogle Play Billing Libraryを使ってみた

Yukio MURAKAMI

November 27, 2019
Tweet

More Decks by Yukio MURAKAMI

Other Decks in Technology

Transcript

  1. sealed class FindUserResult { data class Found(val user: User) :

    FindUserResult() data class NotFound(val name: String) : FindUserResult() } fun findUserByName(name: String): FindUserResult { .... if (ݟ͔ͭͬͨ) return FindUserResult.Found(user) else return FindUserResult.NotFound(name) } val result = findUserByName("bitz") when (result) { is FindUserResult.Found -> println("find ${result.user}") is FindUserResult.NotFound ->println("find ${result.name}") } ϓϥΠϚϦίϯετϥΫλ ͜ΕܧঝͳΜͰ͢Ͷʂ
  2. IUUQTHJUIVCDPNBOESPJEQMBZCJMMJOHTBNQMFT class MakePurchaseFragment : Fragment() { override fun onViewCreated(view: View,

    savedInstanceState: Bundle?) { billingViewModel = ViewModelProviders.of(this).get(BillingViewModel::class.java) billingViewModel.purchasesLiveData.observe(this, Observer { it?.let { purchasesAdapter.setPurchases(it) } }) } } 7JFX.PEFM -JWF%BUB
  3. class BillingViewModel(application: Application) : AndroidViewModel(application) { val gasTankLiveData: LiveData<GasTank> init

    { repository = BillingRepository.getInstance(application) repository.startDataSourceConnections() purchasesLiveData = repository.purchasesLiveData } override fun onCleared() { super.onCleared() repository.endDataSourceConnections() viewModelScope.coroutineContext.cancel() } } *O"QQ#JMMJOHػೳͷΫϥε ͷσʔλͱ7JFX.PEFMར༻ ଆΛ݁ͼ͚ͭΔ
  4. class BillingRepository private constructor(private val application: Application) : PurchasesUpdatedListener, BillingClientStateListener

    { lateinit private var playStoreBillingClient: BillingClient val purchasesLiveData = mutableListOf<MutableList<SkuDetails>>() fun demo() { purchasesLiveData.setValue(ߋ৽͢Δ஋) } } ࣮ࡍͷίʔυͰ͸ɺઌ΄Ͳͷ3FTVMUܕͰ੒ޭ ͳΒσʔλΛࣦഊͳΒΤϥʔ৘ใΛฦ͢Α͏ ʹͨ͠ɻ