Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not null mBillingClient (#315) #359

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions android/src/main/java/com/dooboolab/RNIap/RNIapModule.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.dooboolab.RNIap;

import android.app.Activity;
Expand Down Expand Up @@ -66,8 +67,6 @@ public class RNIapModule extends ReactContextBaseJavaModule {
private IInAppBillingService mService;
private BillingClient mBillingClient;

private boolean clientReady = false;

private ServiceConnection mServiceConn = new ServiceConnection() {
@Override public void onServiceDisconnected(ComponentName name) {
mService = null;
Expand Down Expand Up @@ -109,7 +108,7 @@ public RNIapModule(ReactApplicationContext reactContext) {
}

private void ensureConnection (final Promise promise, final Runnable callback) {
if (clientReady) {
if (mBillingClient != null && mBillingClient.isReady()) {
callback.run();
return;
}
Expand All @@ -124,7 +123,6 @@ public void onBillingSetupFinished(@BillingClient.BillingResponse int responseCo
if (responseCode == BillingClient.BillingResponse.OK ) {
Log.d(TAG, "billing client ready");
callback.run();
clientReady = true;
} else {
rejectPromiseWithBillingError(promise, responseCode);
}
Expand All @@ -133,15 +131,13 @@ public void onBillingSetupFinished(@BillingClient.BillingResponse int responseCo
@Override
public void onBillingServiceDisconnected() {
Log.d(TAG, "billing client disconnected");
clientReady = false;
}
};

try {
reactContext.bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);
mBillingClient = BillingClient.newBuilder(reactContext).setListener(purchasesUpdatedListener).build();
mBillingClient.startConnection(billingClientStateListener);
clientReady = true;
} catch (Exception e) {
promise.reject(E_NOT_PREPARED, e.getMessage(), e);
}
Expand Down Expand Up @@ -172,8 +168,6 @@ public void endConnection(final Promise promise) {
return;
}
}

mBillingClient = null;
promise.resolve(true);
}

Expand Down Expand Up @@ -554,4 +548,4 @@ private void rejectPromisesWithBillingError(final String key, final int response
promises.remove(key);
}
}
}
}