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 f0 implements Runnable { public final /* synthetic */ Map a; public final /* synthetic */ TJGetCurrencyBalanceListener b; public final /* synthetic */ TJCurrency c; public f0(TJCurrency tJCurrency, Map map, TJGetCurrencyBalanceListener tJGetCurrencyBalanceListener) { this.c = tJCurrency; this.a = map; this.b = tJGetCurrencyBalanceListener; } @Override // java.lang.Runnable public final void run() { b3 a = c3.a(TapjoyConnectCore.getInstance().getHostURL() + TapjoyConstants.TJC_GET_CURRENCY_BALANCE_URL_PATH, this.a); TJCurrency tJCurrency = this.c; TJGetCurrencyBalanceListener tJGetCurrencyBalanceListener = this.b; synchronized (tJCurrency) { try { String str = a.c; if (str != null) { Document buildDocument = TapjoyUtil.buildDocument(str); if (buildDocument != null) { String nodeTrimValue = TapjoyUtil.getNodeTrimValue(buildDocument.getElementsByTagName("Success")); if (nodeTrimValue == null || !nodeTrimValue.equals("true")) { TapjoyLog.e("TJCurrency", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.SERVER_ERROR, "getCurrencyBalance response is invalid -- missing tag.")); } else { String nodeTrimValue2 = TapjoyUtil.getNodeTrimValue(buildDocument.getElementsByTagName("TapPoints")); String nodeTrimValue3 = TapjoyUtil.getNodeTrimValue(buildDocument.getElementsByTagName("CurrencyName")); if (nodeTrimValue2 == null || nodeTrimValue3 == null) { TapjoyLog.e("TJCurrency", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.SERVER_ERROR, "getCurrencyBalance response is invalid -- missing tags.")); } else { try { int parseInt = Integer.parseInt(nodeTrimValue2); int localCurrencyBalance = tJCurrency.getLocalCurrencyBalance(); if (TJCurrency.c != null && localCurrencyBalance != -9999 && parseInt > localCurrencyBalance) { StringBuilder sb = new StringBuilder("earned: "); int i = parseInt - localCurrencyBalance; sb.append(i); TapjoyLog.i("TJCurrency", sb.toString()); TJCurrency.c.onEarnedCurrency(nodeTrimValue3, i); } tJCurrency.saveCurrencyBalance(parseInt); if (tJGetCurrencyBalanceListener != null) { tJGetCurrencyBalanceListener.onGetCurrencyBalanceResponse(nodeTrimValue3, parseInt); } return; } catch (Exception e) { TapjoyLog.e("TJCurrency", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.SERVER_ERROR, "Error parsing XML and calling listener: " + e.toString())); } } } } } else { TapjoyLog.e("TJCurrency", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.SERVER_ERROR, "getCurrencyBalance response is NULL")); } if (tJGetCurrencyBalanceListener != null) { tJGetCurrencyBalanceListener.onGetCurrencyBalanceResponseFailure("Failed to get currency balance"); } } catch (Throwable th) { throw th; } } } }