IAB: guarantee UI thread

pull/207/head
M66B 3 years ago
parent f98ee1ad81
commit f1443332f6

@ -199,40 +199,68 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
addBillingListener(new ActivityBilling.IBillingListener() { addBillingListener(new ActivityBilling.IBillingListener() {
@Override @Override
public void onConnected() { public void onConnected() {
post(new Runnable() {
@Override
public void run() {
ivConnected.setImageResource(R.drawable.twotone_cloud_done_24); ivConnected.setImageResource(R.drawable.twotone_cloud_done_24);
ivConnected.setVisibility(View.VISIBLE); ivConnected.setVisibility(View.VISIBLE);
} }
});
}
@Override @Override
public void onDisconnected() { public void onDisconnected() {
post(new Runnable() {
@Override
public void run() {
ivConnected.setImageResource(R.drawable.twotone_cloud_off_24); ivConnected.setImageResource(R.drawable.twotone_cloud_off_24);
ivConnected.setVisibility(View.VISIBLE); ivConnected.setVisibility(View.VISIBLE);
} }
});
}
@Override @Override
public void onSkuDetails(String sku, String price) { public void onSkuDetails(String sku, String price) {
if (ActivityBilling.getSkuPro().equals(sku)) { if (!ActivityBilling.getSkuPro().equals(sku))
return;
post(new Runnable() {
@Override
public void run() {
tvPrice.setText(getString(R.string.title_pro_one_time, price)); tvPrice.setText(getString(R.string.title_pro_one_time, price));
tvPrice.setVisibility(View.VISIBLE); tvPrice.setVisibility(View.VISIBLE);
btnPurchase.setEnabled(true); btnPurchase.setEnabled(true);
} }
});
} }
@Override @Override
public void onPurchasePending(String sku) { public void onPurchasePending(String sku) {
if (ActivityBilling.getSkuPro().equals(sku)) { if (!ActivityBilling.getSkuPro().equals(sku))
return;
post(new Runnable() {
@Override
public void run() {
btnPurchase.setEnabled(false); btnPurchase.setEnabled(false);
tvPending.setVisibility(View.VISIBLE); tvPending.setVisibility(View.VISIBLE);
} }
});
} }
@Override @Override
public void onPurchased(String sku, boolean purchased) { public void onPurchased(String sku, boolean purchased) {
if (ActivityBilling.getSkuPro().equals(sku)) { if (!ActivityBilling.getSkuPro().equals(sku))
return;
post(new Runnable() {
@Override
public void run() {
btnPurchase.setEnabled(!purchased); btnPurchase.setEnabled(!purchased);
tvPending.setVisibility(View.GONE); tvPending.setVisibility(View.GONE);
btnConsume.setEnabled(purchased); btnConsume.setEnabled(purchased);
} }
});
} }
@Override @Override
@ -254,6 +282,23 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
}); });
snackbar.show(); snackbar.show();
} }
private void post(Runnable runnable) {
final View view = getView();
if (view == null)
return;
view.post(new Runnable() {
@Override
public void run() {
try {
runnable.run();
} catch (Throwable ex) {
Log.e(ex);
}
}
});
}
}); });
} }

Loading…
Cancel
Save