Skip to content

Commit

Permalink
Merge pull request #359 from mitchellmcm27/master
Browse files Browse the repository at this point in the history
Do not null mBillingClient (#315)
  • Loading branch information
hyochan committed Jan 7, 2019
2 parents ea22c5f + 3073090 commit 0dda7f4
Showing 1 changed file with 3 additions and 9 deletions.
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);
}
}
}
}

0 comments on commit 0dda7f4

Please sign in to comment.