Skip to content

Commit

Permalink
Update target sdk to 29 and bumped to 0.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrambhia committed Sep 17, 2020
1 parent 665ff90 commit 57a1db1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<img src="https://raw.githubusercontent.com/jayrambhia/MovieRatings/master/screenshots/cover.png" width="480px"/>
</p>

You can get the latest Playstore version here on [Playstore](https://play.google.com/store/apps/details?id=com.fenchtose.flutter&referrer=utm_source%3Dgithub) - or download directly - [0.4.4](https://github.com/jayrambhia/MovieRatings/releases/download/v0.4.4/flutter_v0.4.4.apk)
You can get the latest Playstore version here on [Playstore](https://play.google.com/store/apps/details?id=com.fenchtose.flutter&referrer=utm_source%3Dgithub) - or download directly - [0.4.5](https://github.com/jayrambhia/MovieRatings/releases/download/v0.4.5/flutter_v0.4.5.apk)

## Screenshots of master

Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ properties.load(project.rootProject.file('local.properties').newDataInputStream(

ext.versionMajor = 0
ext.versionMinor = 4
ext.versionPatch = 4
ext.versionPatch = 5

android {
compileSdkVersion 28
compileSdkVersion 29
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
applicationId "com.fenchtose.flutter"
versionCode generateVersionCode()
versionName generateVersionName()
Expand Down Expand Up @@ -105,7 +105,7 @@ dependencies {
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

playstoreImplementation 'com.android.billingclient:billing:1.0'
playstoreImplementation 'com.android.billingclient:billing:3.0.0'
playstoreImplementation 'com.google.firebase:firebase-analytics:17.2.0'

// Moshi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.appcompat.app.AlertDialog
import android.util.Log
import android.view.ViewGroup
import com.fenchtose.movieratings.analytics.events.toFaEvent
import com.fenchtose.movieratings.analytics.ga.AppEvents
import com.fenchtose.movieratings.analytics.ga.GaLabels
import com.fenchtose.movieratings.base.RouterBaseActivity
import com.fenchtose.movieratings.base.router.Router
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ class DataSectionFragment: BaseFragment() {

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
val uri = data?.data
when(requestCode) {
REQUEST_OPEN_FILE -> {
if (resultCode == Activity.RESULT_OK && data != null && data.data != null) {
importData(data.data)
if (resultCode == Activity.RESULT_OK && data != null && uri != null) {
importData(uri)
}
}
REQUEST_CREATE_FILE -> {
if (resultCode == Activity.RESULT_OK && data != null && data.data != null) {
exportData(data.data, historyCheckboxSelected == true)
if (resultCode == Activity.RESULT_OK && data != null && uri != null) {
exportData(uri, historyCheckboxSelected == true)
}
historyCheckboxSelected = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Speaker(context: Context): TextToSpeech.OnInitListener {

fun talk(rating: MovieRating) {
rating.takeIf { it.imdbId.isNotEmpty() && it.rating >= 0f && rating.imdbId != currentRating?.imdbId }?.run {
talk(context.getString(R.string.rating_tts, title, rating))
talk(context.getString(R.string.rating_tts, title, this.rating.toString()))
currentRating = this
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.fenchtose.movieratings.features.premium
import android.content.Context
import android.util.AttributeSet
import android.widget.LinearLayout
import com.android.billingclient.api.SkuDetails

class CardsContainer @JvmOverloads constructor(
context: Context,
Expand All @@ -19,6 +20,7 @@ class CardsContainer @JvmOverloads constructor(
update(
listOf(
PurchaseCardContent(
skuDetails = SkuDetails(""),
sku = "test",
title = "Basic",
description = "This is a basic card",
Expand All @@ -32,7 +34,7 @@ class CardsContainer @JvmOverloads constructor(
}
}

fun update(content: List<PurchaseCardContent>, onPurchase: (String) -> Unit, onBrag: (String) -> Unit) {
fun update(content: List<PurchaseCardContent>, onPurchase: (SkuDetails) -> Unit, onBrag: (String) -> Unit) {
resizeTo(content.size)
content.forEachIndexed { index, item ->
if (cards.size > index) {
Expand Down Expand Up @@ -63,5 +65,6 @@ data class PurchaseCardContent(
val title: String,
val description: String,
val price: String,
val purchased: Int
val purchased: Int,
val skuDetails: SkuDetails
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.fenchtose.movieratings.util.show
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class DonatePageFragment: BaseFragment(), PurchasesUpdatedListener {
class DonatePageFragment : BaseFragment(), PurchasesUpdatedListener {

private var progressContainer: View? = null
private lateinit var cardsContainer: CardsContainer
Expand Down Expand Up @@ -68,22 +68,23 @@ class DonatePageFragment: BaseFragment(), PurchasesUpdatedListener {
cardsContainer = view.findViewById(R.id.cards_container)
progressContainer = view.findViewById(R.id.progress_container)
historyKeeper = DbHistoryKeeper(
PreferenceUserHistory(requireContext()),
ratingStore,
SettingsPreferences(requireContext())
)
PreferenceUserHistory(requireContext()),
ratingStore,
SettingsPreferences(requireContext())
)

billingClient = BillingClient.newBuilder(requireContext()).setListener(this).build()
billingClient?.startConnection(object: BillingClientStateListener {
billingClient = BillingClient.newBuilder(requireContext())
.enablePendingPurchases()
.setListener(this).build()
billingClient?.startConnection(object : BillingClientStateListener {
override fun onBillingServiceDisconnected() {

}

override fun onBillingSetupFinished(@BillingClient.BillingResponse responseCode: Int) {
isBillingAvailable = responseCode == BillingClient.BillingResponse.OK
override fun onBillingSetupFinished(result: BillingResult) {
isBillingAvailable = result.responseCode == BillingClient.BillingResponseCode.OK
queryAvailablePurchases()
}

})
}

Expand All @@ -94,16 +95,24 @@ class DonatePageFragment: BaseFragment(), PurchasesUpdatedListener {
}
}

override fun onPurchasesUpdated(@BillingClient.BillingResponse responseCode: Int, purchases: MutableList<Purchase>?) {
if (responseCode == BillingClient.BillingResponse.OK && purchases != null && !purchases.isEmpty()) {
override fun onPurchasesUpdated(result: BillingResult, purchases: MutableList<Purchase>?) {
if (result.responseCode == BillingClient.BillingResponseCode.OK && purchases != null && !purchases.isEmpty()) {
historyKeeper?.paidInAppPurchase()
AppEvents.completePurchase(purchases.first().sku).track()

purchases.forEach { purchase ->
if (purchase.purchaseState == Purchase.PurchaseState.PURCHASED && !purchase.isAcknowledged) {
val params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.purchaseToken).build()
billingClient?.acknowledgePurchase(params) { response ->
}
}
}

AlertDialog.Builder(context)
.setTitle(R.string.donate_dialog_title)
.setMessage(R.string.donate_dialog_message)
.setPositiveButton(android.R.string.ok){ dialog, _ -> dialog.dismiss() }
.show()
.setTitle(R.string.donate_dialog_title)
.setMessage(R.string.donate_dialog_message)
.setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() }
.show()

queryAvailablePurchases()
}
Expand All @@ -119,8 +128,8 @@ class DonatePageFragment: BaseFragment(), PurchasesUpdatedListener {
return
}

billingClient?.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP) {
_, purchases -> showDetails(skus, purchases?.map { it.sku } ?: listOf())
billingClient?.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP) { _, purchases ->
showDetails(skus, purchases?.map { it.sku } ?: listOf())
}
}

Expand All @@ -142,11 +151,10 @@ class DonatePageFragment: BaseFragment(), PurchasesUpdatedListener {
val params = SkuDetailsParams.newBuilder()
params.setSkusList(arrayListOf("donate_small", "donate_medium", "donate_large"))
params.setType(BillingClient.SkuType.INAPP)
billingClient?.querySkuDetailsAsync(params.build()) {
responseCode, skuDetails ->
if (responseCode == BillingClient.BillingResponse.OK && skuDetails != null && skuDetails.isNotEmpty()) {
queryPurchaseHistory(skuDetails)
}
billingClient?.querySkuDetailsAsync(params.build()) { response, skuDetails ->
if (response.responseCode == BillingClient.BillingResponseCode.OK && skuDetails != null && skuDetails.isNotEmpty()) {
queryPurchaseHistory(skuDetails)
}
}
}

Expand All @@ -170,6 +178,7 @@ class DonatePageFragment: BaseFragment(), PurchasesUpdatedListener {
val content = skus.map { details ->
PurchaseCardContent(
sku = details.sku,
skuDetails = details,
title = details.title.replace(regex, ""),
description = details.description,
price = details.price,
Expand All @@ -187,18 +196,17 @@ class DonatePageFragment: BaseFragment(), PurchasesUpdatedListener {
)
}

private fun onPurchaseRequested(sku: String) {
AppEvents.startPurchase(sku).track()
private fun onPurchaseRequested(skuDetails: SkuDetails) {
AppEvents.startPurchase(skuDetails.sku).track()

val flowParams = BillingFlowParams.newBuilder()
.setSku(sku)
.setType(BillingClient.SkuType.INAPP)
.build()
.setSkuDetails(skuDetails)
.build()

billingClient?.launchBillingFlow(activity, flowParams)
billingClient?.launchBillingFlow(requireActivity(), flowParams)
}

class DonatePath: RouterPath<DonatePageFragment>() {
class DonatePath : RouterPath<DonatePageFragment>() {
override fun createFragmentInstance() = DonatePageFragment()
override fun category() = GaCategory.SUPPORT_APP

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.Button
import android.widget.TextView
import com.android.billingclient.api.SkuDetails
import com.fenchtose.movieratings.R
import com.fenchtose.movieratings.util.show

class InAppPurchaseCard : androidx.cardview.widget.CardView {
class InAppPurchaseCard : CardView {

private val title: TextView
private val subtitle: TextView
Expand All @@ -32,11 +33,11 @@ class InAppPurchaseCard : androidx.cardview.widget.CardView {
thanksView = findViewById(R.id.bought_view)
}

fun update(content: PurchaseCardContent, onPurchase: (String) -> Unit, onBrag: (String) -> Unit) {
fun update(content: PurchaseCardContent, onPurchase: (SkuDetails) -> Unit, onBrag: (String) -> Unit) {
title.text = content.title
subtitle.text = content.description
cta.text = context.getString(R.string.donate_card_cta, content.price)
cta.setOnClickListener { onPurchase(content.sku) }
cta.setOnClickListener { onPurchase(content.skuDetails) }
cta.show(content.purchased == 0)
thanksView.show(content.purchased > 0)
bragCta.show(content.purchased > 0)
Expand Down

0 comments on commit 57a1db1

Please sign in to comment.