mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-24 16:20:03 +00:00
android: get the Google Play account country in the google flavor
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
package chat.simplex.app
|
||||
|
||||
// Play Billing is only in the google flavor, so the Play country stays unknown here
|
||||
fun loadPlayStoreCountry() {}
|
||||
@@ -0,0 +1,31 @@
|
||||
package chat.simplex.app
|
||||
|
||||
import chat.simplex.common.platform.androidAppContext
|
||||
import chat.simplex.common.platform.androidPlayStoreCountry
|
||||
import com.android.billingclient.api.*
|
||||
|
||||
// Requests the country of the Google Play account into [androidPlayStoreCountry].
|
||||
// It stays null when Play is unavailable or the user is not signed in.
|
||||
fun loadPlayStoreCountry() {
|
||||
val client = BillingClient.newBuilder(androidAppContext)
|
||||
.setListener { _, _ -> }
|
||||
.enablePendingPurchases(PendingPurchasesParams.newBuilder().enableOneTimeProducts().build())
|
||||
.build()
|
||||
client.startConnection(object : BillingClientStateListener {
|
||||
override fun onBillingSetupFinished(result: BillingResult) {
|
||||
if (result.responseCode != BillingClient.BillingResponseCode.OK) {
|
||||
client.endConnection()
|
||||
return
|
||||
}
|
||||
client.getBillingConfigAsync(GetBillingConfigParams.newBuilder().build()) { configResult, config ->
|
||||
if (configResult.responseCode == BillingClient.BillingResponseCode.OK) {
|
||||
androidPlayStoreCountry.value = config?.countryCode
|
||||
}
|
||||
client.endConnection()
|
||||
}
|
||||
}
|
||||
|
||||
// The connection is only used for this one request, it is not retried
|
||||
override fun onBillingServiceDisconnected() = client.endConnection()
|
||||
})
|
||||
}
|
||||
@@ -341,6 +341,8 @@ class SimplexApp: Application(), LifecycleEventObserver {
|
||||
|
||||
override fun androidIsXiaomiDevice(): Boolean = setOf("xiaomi", "redmi", "poco").contains(Build.BRAND.lowercase())
|
||||
|
||||
override fun androidLoadPlayStoreCountry() = loadPlayStoreCountry()
|
||||
|
||||
@SuppressLint("SourceLockedOrientationActivity")
|
||||
@Composable
|
||||
override fun androidLockPortraitOrientation() {
|
||||
|
||||
+5
@@ -1,5 +1,7 @@
|
||||
package chat.simplex.common.platform
|
||||
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import chat.simplex.common.BuildConfigCommon
|
||||
import chat.simplex.common.model.*
|
||||
import chat.simplex.common.ui.theme.DefaultTheme
|
||||
@@ -30,6 +32,9 @@ else
|
||||
|
||||
val databaseBackend: String = if (appPlatform == AppPlatform.ANDROID) "sqlite" else BuildConfigCommon.DATABASE_BACKEND
|
||||
|
||||
// Country of the Google Play account, only set in the google flavor of the Android app
|
||||
val androidPlayStoreCountry: MutableState<String?> = mutableStateOf(null)
|
||||
|
||||
class FifoQueue<E>(private var capacity: Int) : LinkedList<E>() {
|
||||
override fun add(element: E): Boolean {
|
||||
if (size > capacity) removeFirstOrNull()
|
||||
|
||||
+2
@@ -29,6 +29,8 @@ interface PlatformInterface {
|
||||
fun androidRestartNetworkObserver() {}
|
||||
fun androidCreateActiveCallState(): Closeable = Closeable { }
|
||||
fun androidIsXiaomiDevice(): Boolean = false
|
||||
// Requests the Google Play account country into [androidPlayStoreCountry]
|
||||
fun androidLoadPlayStoreCountry() {}
|
||||
val androidApiLevel: Int? get() = null
|
||||
// The build distributed via Google Play, which has to follow its policies
|
||||
val androidIsPlayStoreBuild: Boolean get() = false
|
||||
|
||||
Reference in New Issue
Block a user