package com.tapjoy; import com.tapjoy.TapjoyErrorMessage; import com.tapjoy.internal.b3; import com.tapjoy.internal.c3; import java.util.Map; import org.w3c.dom.Document; /* loaded from: classes4.dex */ public final class g0 implements Runnable { public final /* synthetic */ Map a; public final /* synthetic */ TJSpendCurrencyListener b; public final /* synthetic */ TJCurrency c; public g0(TJCurrency tJCurrency, Map map, TJSpendCurrencyListener tJSpendCurrencyListener) { this.c = tJCurrency; this.a = map; this.b = tJSpendCurrencyListener; } @Override // java.lang.Runnable public final void run() { b3 a = c3.a(TapjoyConnectCore.getInstance().getHostURL() + TapjoyConstants.TJC_SPEND_CURRENCY_URL_PATH, this.a); TJCurrency tJCurrency = this.c; TJSpendCurrencyListener tJSpendCurrencyListener = this.b; synchronized (tJCurrency) { String str = "Failed to spend currency"; String str2 = a.c; if (str2 != null) { Document buildDocument = TapjoyUtil.buildDocument(str2); if (buildDocument != null) { String nodeTrimValue = TapjoyUtil.getNodeTrimValue(buildDocument.getElementsByTagName("Success")); if (nodeTrimValue != null && nodeTrimValue.equals("true")) { String nodeTrimValue2 = TapjoyUtil.getNodeTrimValue(buildDocument.getElementsByTagName("TapPoints")); String nodeTrimValue3 = TapjoyUtil.getNodeTrimValue(buildDocument.getElementsByTagName("CurrencyName")); if (nodeTrimValue2 != null && nodeTrimValue3 != null) { int parseInt = Integer.parseInt(nodeTrimValue2); tJCurrency.saveCurrencyBalance(parseInt); if (tJSpendCurrencyListener != null) { tJSpendCurrencyListener.onSpendCurrencyResponse(nodeTrimValue3, parseInt); } return; } TapjoyLog.e("TJCurrency", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.SERVER_ERROR, "spendCurrency response is invalid -- missing tags.")); } else if (nodeTrimValue == null || !nodeTrimValue.endsWith("false")) { TapjoyLog.e("TJCurrency", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.SERVER_ERROR, "spendCurrency response is invalid -- missing tag.")); } else { str = TapjoyUtil.getNodeTrimValue(buildDocument.getElementsByTagName("Message")); TapjoyLog.i("TJCurrency", str); if ("BalanceTooLowError".equals(TapjoyUtil.getNodeTrimValue(buildDocument.getElementsByTagName("MessageCode")))) { com.tapjoy.internal.w.a.c(); } } } } else { TapjoyLog.e("TJCurrency", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.SERVER_ERROR, "spendCurrency response is NULL")); } if (tJSpendCurrencyListener != null) { tJSpendCurrencyListener.onSpendCurrencyResponseFailure(str); } } } }