Skip to content

Commit

Permalink
v3.5:
Browse files Browse the repository at this point in the history
Changed permission loading yet again
Increased permission timeout again
Added donation option :)
  • Loading branch information
Jolanrensen committed Oct 21, 2019
1 parent bf9ef32 commit 4715e40
Show file tree
Hide file tree
Showing 11 changed files with 472 additions and 9 deletions.
6 changes: 4 additions & 2 deletions wear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "nl.jolanrensen.permanentproxy"
minSdkVersion 23
targetSdkVersion 29
versionCode 10
versionName "3.4"
versionCode 12
versionName "3.5"
}
buildTypes {
release {
Expand All @@ -39,7 +39,9 @@ dependencies {
implementation 'com.tananaev:adblib:1.2'
implementation 'com.google.android.gms:play-services-wearable:17.0.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.billingclient:billing:1.1'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation "androidx.core:core-ktx:1.2.0-beta01"
implementation 'com.android.support:wear:28.0.0'
Expand Down
Binary file added wear/release/mobile-release.apk
Binary file not shown.
Binary file modified wear/release/wear-release.aab
Binary file not shown.
Binary file added wear/release/wear-release.apk
Binary file not shown.
7 changes: 5 additions & 2 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />

<uses-permission android:name="com.android.vending.BILLING"/>

<application
android:allowBackup="true"
Expand All @@ -33,6 +33,10 @@
android:name="com.google.android.wearable.standalone"
android:value="true" />

<activity
android:name=".DonateActivity"
android:label="@string/title_activity_donate">
</activity>
<activity
android:name=".EnableADBBluetoothActivity"
android:label="@string/title_activity_enable_adbbluetooth">
Expand All @@ -48,7 +52,6 @@
</intent-filter>
</activity>
<activity android:name=".RequestPermissionActivity" />

</application>

</manifest>
143 changes: 143 additions & 0 deletions wear/src/main/java/nl/jolanrensen/permanentproxy/DonateActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package nl.jolanrensen.permanentproxy

import android.os.Bundle
import android.support.wearable.activity.WearableActivity
import android.view.View
import androidx.core.view.isVisible
import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.BillingClient.BillingResponse.*
import com.android.billingclient.api.BillingClientStateListener
import com.android.billingclient.api.BillingFlowParams
import com.android.billingclient.api.SkuDetailsParams
import kotlinx.android.synthetic.main.activity_donate.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import nl.jolanrensen.permanentproxy.Constants.logD
import nl.jolanrensen.permanentproxy.Constants.logE
import nl.jolanrensen.permanentproxy.Constants.toast
import nl.jolanrensen.permanentproxy.Constants.toastLong

class DonateActivity : WearableActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_donate)

// Enables Always-on
setAmbientEnabled()

var billingClient: BillingClient? = null
billingClient = BillingClient.newBuilder(this)
.setListener { responseCode, purchases ->
logD("on purchases updated response: $responseCode, purchases: $purchases")
when (responseCode) {
FEATURE_NOT_SUPPORTED -> Unit
SERVICE_DISCONNECTED -> Unit
OK -> {
if (purchases != null) {
finish()
toastLong(
getString(R.string.donation_successful)
)
for (purchase in purchases) { // should only be 1
billingClient!!.consumeAsync(purchase.purchaseToken) { responseCode, _ ->
if (responseCode == OK)
logD("purchase consumed")
}
}
}
}
USER_CANCELED -> Unit
SERVICE_UNAVAILABLE -> Unit
BILLING_UNAVAILABLE -> Unit
ITEM_UNAVAILABLE -> Unit
DEVELOPER_ERROR -> Unit
ERROR -> Unit
ITEM_ALREADY_OWNED -> Unit
ITEM_NOT_OWNED -> Unit
}
}
.build()

var tries = 0
val billingClientStateListener = object : BillingClientStateListener {
override fun onBillingServiceDisconnected() {
logE("Billing service disconnected")
if (tries == 10) {
runOnUiThread {
toast(getString(R.string.couldnt_connect_to_play))
}
}
val listener = this
GlobalScope.launch(Dispatchers.Default) {
delay(100)
billingClient.startConnection(listener)
tries++
}
}

override fun onBillingSetupFinished(@BillingClient.BillingResponse responseCode: Int) {
logD("Billing setup finished")
// get purchases
val skuList = arrayListOf(
"thank_you",
"big_thank_you",
"bigger_thank_you",
"biggest_thank_you"
)
billingClient.querySkuDetailsAsync(
SkuDetailsParams.newBuilder()
.setSkusList(skuList)
.setType(BillingClient.SkuType.INAPP)
.build()
) { responseCode, skuDetailsList ->
logD("Billing sku details received, $responseCode, $skuDetailsList")
if (responseCode == OK && skuDetailsList != null) {
for (skuDetails in skuDetailsList) {
val sku = skuDetails.sku
val price = skuDetails.price
runOnUiThread {
when (sku) {
"thank_you" -> thank_you_price.text = price
"big_thank_you" -> big_thank_you_price.text = price
"bigger_thank_you" -> bigger_thank_you_price.text = price
"biggest_thank_you" -> biggest_thank_you_price.text = price
}
}
}
} else {
billing_not_working.isVisible = true
billing_not_working2.isVisible = true
}
}

val doPurchase = View.OnClickListener {
logD("Billing onclick $it")
billingClient!!.launchBillingFlow(
this@DonateActivity,
BillingFlowParams.newBuilder()
.setSku(
when (it.id) {
thank_you_card.id -> "thank_you"
big_thank_you_card.id -> "big_thank_you"
bigger_thank_you_card.id -> "bigger_thank_you"
biggest_thank_you_card.id -> "biggest_thank_you"
else -> null
}
)
.setType(BillingClient.SkuType.INAPP)
.build()
)
}

thank_you_card.setOnClickListener(doPurchase)
big_thank_you_card.setOnClickListener(doPurchase)
bigger_thank_you_card.setOnClickListener(doPurchase)
biggest_thank_you_card.setOnClickListener(doPurchase)
}
}
billingClient.startConnection(billingClientStateListener)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ class MainActivity : WearableActivity() {
PERMISSION

)
}

donate.setOnClickListener {
startActivity(
Intent(this, DonateActivity::class.java)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class RequestPermissionActivity : WearableActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_request_permission)

setAmbientEnabled()

cancel.setOnClickListener {
finish()
}
Expand All @@ -33,7 +35,7 @@ class RequestPermissionActivity : WearableActivity() {
ip = "localhost",
port = Constants.PORT,
command = "pm grant \\\nnl.jolanrensen.permanentproxy \\\nandroid.permission.WRITE_SECURE_SETTINGS",
timeout = 2000,
timeout = 2500,
ctrlC = false
) {
currentADBProcess = null
Expand Down Expand Up @@ -63,8 +65,8 @@ class RequestPermissionActivity : WearableActivity() {
// useless loading bar to show google the app is doing something
thread(start = true) {
var s = 0
while (s <= 20 && !stop) {
loading_bar.progress = ((s / 20f) * 100f).toInt()
while (s <= 25 && !stop) {
loading_bar.progress = ((s / 25f) * 100f).toInt()
s++
Thread.sleep(1000)
}
Expand Down
Loading

0 comments on commit 4715e40

Please sign in to comment.