package com.tapjoy; import android.content.Context; import android.content.SharedPreferences; import android.util.Base64; import com.tapjoy.TapjoyErrorMessage; import com.tapjoy.internal.c3; import com.tapjoy.internal.k2; import java.io.EOFException; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import kotlin.Lazy; import kotlin.LazyKt__LazyJVMKt; import kotlin.TuplesKt; import kotlin.collections.CollectionsKt__CollectionsKt; import kotlin.collections.MapsKt__MapsKt; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.SourceDebugExtension; import kotlin.text.StringsKt__StringsJVMKt; import kotlin.text.StringsKt__StringsKt; import org.w3c.dom.Document; @SourceDebugExtension({"SMAP\nTJUser.kt\nKotlin\n*S Kotlin\n*F\n+ 1 TJUser.kt\ncom/tapjoy/TJUser\n+ 2 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n*L\n1#1,323:1\n1855#2,2:324\n*S KotlinDebug\n*F\n+ 1 TJUser.kt\ncom/tapjoy/TJUser\n*L\n97#1:324,2\n*E\n"}) /* loaded from: classes4.dex */ public final class TJUser { public static String a = null; public static int b = -1; public static int c = -1; public static int d = -1; public static TJSegment e; public static TJKeyValueStorage g; public static final Lazy h; public static final TJUser INSTANCE = new TJUser(); public static final HashSet f = new HashSet(); static { Lazy lazy; lazy = LazyKt__LazyJVMKt.lazy(k2.a); h = lazy; } public static void a() { HashSet hashSet = f; if (hashSet.isEmpty()) { TJKeyValueStorage tJKeyValueStorage = g; if (tJKeyValueStorage != null) { tJKeyValueStorage.remove("pref_user_tags"); } hashSet.clear(); return; } List arrayList = new ArrayList(hashSet); com.tapjoy.internal.m mVar = com.tapjoy.internal.m.e; if (mVar == null) { throw new NullPointerException("unknownFields == null"); } if (arrayList instanceof com.tapjoy.internal.l0) { arrayList = ((com.tapjoy.internal.l0) arrayList).b; } if (arrayList != Collections.emptyList() && !(arrayList instanceof com.tapjoy.internal.t)) { com.tapjoy.internal.t tVar = new com.tapjoy.internal.t(arrayList); if (tVar.contains(null)) { throw new IllegalArgumentException("elements.contains(null)"); } arrayList = tVar; } com.tapjoy.internal.l lVar = new com.tapjoy.internal.l(); try { com.tapjoy.internal.w0 w0Var = new com.tapjoy.internal.w0(lVar); com.tapjoy.internal.o0 o0Var = com.tapjoy.internal.u0.f; com.tapjoy.internal.q0 q0Var = o0Var.b; if (q0Var == null) { q0Var = new com.tapjoy.internal.q0(o0Var, 3); o0Var.b = q0Var; } q0Var.a(w0Var, 1, arrayList); mVar.a(w0Var.a); try { String encodeToString = Base64.encodeToString(lVar.a(lVar.b), 2); TJKeyValueStorage tJKeyValueStorage2 = g; if (tJKeyValueStorage2 != null) { tJKeyValueStorage2.setValue("pref_user_tags", encodeToString); } } catch (EOFException e2) { throw new AssertionError(e2); } } catch (IOException e3) { throw new AssertionError(e3); } } public static final void b(TJSetUserIDListener tJSetUserIDListener) { if (tJSetUserIDListener != null) { tJSetUserIDListener.onSetUserIDSuccess(); } } public static final void c(TJSetUserIDListener tJSetUserIDListener) { if (tJSetUserIDListener != null) { tJSetUserIDListener.onSetUserIDFailure("Failed to set userID"); } if (tJSetUserIDListener != null) { tJSetUserIDListener.onSetUserIDFailure(-1, "Failed to set userID"); } } public static final void d(TJSetUserIDListener tJSetUserIDListener) { if (tJSetUserIDListener != null) { tJSetUserIDListener.onSetUserIDSuccess(); } } public static final void e(TJSetUserIDListener tJSetUserIDListener) { if (tJSetUserIDListener != null) { tJSetUserIDListener.onSetUserIDFailure(TJUserKt.USER_ID_FAILED_ERROR); } if (tJSetUserIDListener != null) { tJSetUserIDListener.onSetUserIDFailure(-1, TJUserKt.USER_ID_FAILED_ERROR); } } public final void checkIfMaxLevelRequired() { String appVersion = TJAppInfo.INSTANCE.getAppVersion(); if (appVersion != null && c >= 0) { TJKeyValueStorage tJKeyValueStorage = g; String str = null; Integer valueOf = tJKeyValueStorage != null ? Integer.valueOf(tJKeyValueStorage.getInt("pref_max_level_cache", -1)) : null; TJKeyValueStorage tJKeyValueStorage2 = g; if (tJKeyValueStorage2 == null || !tJKeyValueStorage2.contains("pref_app_version")) { TJKeyValueStorage tJKeyValueStorage3 = g; if (tJKeyValueStorage3 != null) { tJKeyValueStorage3.setValue("pref_app_version", appVersion); } str = appVersion; } else { TJKeyValueStorage tJKeyValueStorage4 = g; if (tJKeyValueStorage4 != null) { str = tJKeyValueStorage4.getString("pref_app_version", null); } } if (Intrinsics.areEqual(appVersion, str)) { int i = c; if (valueOf != null && valueOf.intValue() == i) { return; } } if (c <= -1 || appVersion.length() <= 0) { return; } TJKeyValueStorage tJKeyValueStorage5 = g; if (tJKeyValueStorage5 != null) { tJKeyValueStorage5.setValue("pref_max_level_cache", Integer.valueOf(c)); } TJKeyValueStorage tJKeyValueStorage6 = g; if (tJKeyValueStorage6 != null) { tJKeyValueStorage6.setValue("pref_app_version", appVersion); } d = c; } } public final Integer getMaxLevelParam() { int i = d; if (i > 0) { return Integer.valueOf(i); } return null; } public final String getUserID() { return a; } public final String getUserIdIfNotEmpty() { CharSequence trim; String str = a; if (str == null) { return null; } trim = StringsKt__StringsKt.trim(str); String obj = trim.toString(); if (obj == null || obj.length() <= 0) { return null; } return a; } public final int getUserLevel() { return b; } public final int getUserMaxLevel() { return c; } public final Integer getUserSegmentInt() { TJSegment tJSegment = e; if (tJSegment == null || tJSegment == TJSegment.UNKNOWN) { return null; } return Integer.valueOf(tJSegment.getValue()); } public final String getUserSegmentString() { TJSegment tJSegment = e; if (tJSegment == null || tJSegment == TJSegment.UNKNOWN) { return null; } return String.valueOf(tJSegment); } public final Set getUserTags() { return f; } public final void setContext(Context context) { Map mapOf; TJKeyValueStorage tJKeyValueStorage; TJKeyValueStorage tJKeyValueStorage2; TJKeyValueStorage tJKeyValueStorage3; String string; if (context != null) { TJKeyValueStorage tJKeyValueStorage4 = new TJKeyValueStorage(context, TapjoyConstants.TJC_PREFERENCE); g = tJKeyValueStorage4; SharedPreferences sharedPreferences = context.getSharedPreferences("fiverocks", 0); Intrinsics.checkNotNullExpressionValue(sharedPreferences, "getSharedPreferences(...)"); mapOf = MapsKt__MapsKt.mapOf(TuplesKt.to("ui", "pref_user_id"), TuplesKt.to("ul", "pref_user_level"), TuplesKt.to("utags", "pref_user_tags")); new TJPreferencesMigration(tJKeyValueStorage4, sharedPreferences, mapOf, CollectionsKt__CollectionsKt.emptyList()).migrateAllKeysIfExists(); INSTANCE.getClass(); TJKeyValueStorage tJKeyValueStorage5 = g; if (tJKeyValueStorage5 != null) { if (c < 0 && tJKeyValueStorage5.contains("pref_max_level")) { c = tJKeyValueStorage5.getInt("pref_max_level", -1); } if (e == null && tJKeyValueStorage5.contains("pref_user_segment")) { e = TJSegment.valueOf(tJKeyValueStorage5.getInt("pref_user_segment", TJSegment.UNKNOWN.getValue())); } String str = a; if ((str == null || str.length() == 0) && tJKeyValueStorage5.contains("pref_user_id")) { a = tJKeyValueStorage5.getString("pref_user_id", null); } if (tJKeyValueStorage5.contains("pref_user_level")) { b = tJKeyValueStorage5.getInt("pref_user_level", -1); } HashSet hashSet = f; if (hashSet.isEmpty() && tJKeyValueStorage5.contains("pref_user_tags") && (string = tJKeyValueStorage5.getString("pref_user_tags", null)) != null && string.length() != 0) { try { com.tapjoy.internal.i1 i1Var = (com.tapjoy.internal.i1) com.tapjoy.internal.i1.d.a(Base64.decode(string, 2)); hashSet.clear(); hashSet.addAll(i1Var.c); } catch (IOException unused) { tJKeyValueStorage5.remove("pref_user_tags"); } catch (IllegalArgumentException unused2) { tJKeyValueStorage5.remove("pref_user_tags"); } } } INSTANCE.getClass(); int i = c; if (i >= -1 && (tJKeyValueStorage3 = g) != null) { tJKeyValueStorage3.setValue("pref_max_level", Integer.valueOf(i)); } TJSegment tJSegment = e; if (tJSegment != null) { if (tJSegment == TJSegment.UNKNOWN) { TJKeyValueStorage tJKeyValueStorage6 = g; if (tJKeyValueStorage6 != null) { tJKeyValueStorage6.remove("pref_user_segment"); } } else { TJKeyValueStorage tJKeyValueStorage7 = g; if (tJKeyValueStorage7 != null) { Intrinsics.checkNotNull(tJSegment); tJKeyValueStorage7.setValue("pref_user_segment", Integer.valueOf(tJSegment.getValue())); } } } int i2 = b; if (i2 >= -1 && (tJKeyValueStorage2 = g) != null) { tJKeyValueStorage2.setValue("pref_user_level", Integer.valueOf(i2)); } String str2 = a; if (str2 != null && str2.length() != 0 && (tJKeyValueStorage = g) != null) { tJKeyValueStorage.setValue("pref_user_id", a); } a(); } } public final void setUserIdRequest(String str, final TJSetUserIDListener tJSetUserIDListener) { boolean equals; Document buildDocument; String nodeTrimValue; if (str != null && str.length() > 200) { setUserId(null); TapjoyLog.e("TJUser", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.INTEGRATION_ERROR, TJUserKt.USER_ID_MAX_LENGTH_ERROR)); TapjoyUtil.runOnMainThread(new Runnable() { // from class: com.tapjoy.TJUser$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { TJUser.a(TJSetUserIDListener.this); } }); return; } if (str != null && str.length() != 0 && Intrinsics.areEqual(str, a)) { TapjoyUtil.runOnMainThread(new Runnable() { // from class: com.tapjoy.TJUser$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { TJUser.b(TJSetUserIDListener.this); } }); return; } if (str == null || str.length() == 0) { setUserId(null); TapjoyLog.e("TJUser", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.INTEGRATION_ERROR, "Failed to set userID")); TapjoyUtil.runOnMainThread(new Runnable() { // from class: com.tapjoy.TJUser$$ExternalSyntheticLambda4 @Override // java.lang.Runnable public final void run() { TJUser.c(TJSetUserIDListener.this); } }); return; } setUserId(str); TapjoyLog.d("TJUser", "URL parameters: " + TapjoyConnectCore.getInstance().getBaseURLParams()); TapjoyLog.i("TJUser", "Setting userID to " + str); String hostURL = TapjoyConnectCore.getInstance().getHostURL(); c3 c3Var = (c3) h.getValue(); String str2 = hostURL + TapjoyConstants.TJC_USER_ID_URL_PATH; Map baseURLParams = TapjoyConnectCore.getInstance().getBaseURLParams(); c3Var.getClass(); String str3 = c3.a(str2, baseURLParams).c; boolean z = false; if (str3 != null && (buildDocument = TapjoyUtil.buildDocument(str3)) != null && (nodeTrimValue = TapjoyUtil.getNodeTrimValue(buildDocument.getElementsByTagName("Success"))) != null && Intrinsics.areEqual(nodeTrimValue, "true")) { z = true; } if (!z) { equals = StringsKt__StringsJVMKt.equals(hostURL, TapjoyConnectCore.getInstance().getHostURL(), true); if (!equals) { setUserIdRequest(str, tJSetUserIDListener); return; } } if (z) { TapjoyLog.i("TJUser", "Set userID is successful"); TapjoyUtil.runOnMainThread(new Runnable() { // from class: com.tapjoy.TJUser$$ExternalSyntheticLambda2 @Override // java.lang.Runnable public final void run() { TJUser.d(TJSetUserIDListener.this); } }); } else { setUserId(null); TapjoyLog.e("TJUser", new TapjoyErrorMessage(TapjoyErrorMessage.ErrorType.SDK_ERROR, "Failed to set userID")); TapjoyUtil.runOnMainThread(new Runnable() { // from class: com.tapjoy.TJUser$$ExternalSyntheticLambda3 @Override // java.lang.Runnable public final void run() { TJUser.e(TJSetUserIDListener.this); } }); } } public final void setUserTags(Set set) { CharSequence trim; HashSet hashSet = new HashSet(); if (set != null) { Iterator it = set.iterator(); while (it.hasNext()) { trim = StringsKt__StringsKt.trim((String) it.next()); String obj = trim.toString(); if (obj.length() > 0 && obj.length() <= 200) { hashSet.add(obj); hashSet.size(); } } } HashSet hashSet2 = f; hashSet2.clear(); hashSet2.addAll(hashSet); a(); } public final Integer getUserLevelIfNeeded() { int i = b; if (i > -1) { return Integer.valueOf(i); } return null; } public final TJSegment getUserSegment() { TJSegment tJSegment = e; return tJSegment == null ? TJSegment.UNKNOWN : tJSegment; } public final void setUserId(String str) { CharSequence trim; TJKeyValueStorage tJKeyValueStorage; if (str == null) { a = null; TJKeyValueStorage tJKeyValueStorage2 = g; if (tJKeyValueStorage2 != null) { tJKeyValueStorage2.remove("pref_user_id"); return; } return; } trim = StringsKt__StringsKt.trim(str); String obj = trim.toString(); a = obj; if (obj == null || obj.length() == 0 || (tJKeyValueStorage = g) == null) { return; } tJKeyValueStorage.setValue("pref_user_id", a); } public final void setUserLevel(int i) { TJKeyValueStorage tJKeyValueStorage; b = i; if (i >= -1 && (tJKeyValueStorage = g) != null) { tJKeyValueStorage.setValue("pref_user_level", Integer.valueOf(i)); } } public final void setUserMaxLevel(int i) { TJKeyValueStorage tJKeyValueStorage; c = i; if (i >= -1 && (tJKeyValueStorage = g) != null) { tJKeyValueStorage.setValue("pref_max_level", Integer.valueOf(i)); } } public final void setUserSegment(TJSegment tJSegment) { e = tJSegment; if (tJSegment == null) { return; } if (tJSegment == TJSegment.UNKNOWN) { TJKeyValueStorage tJKeyValueStorage = g; if (tJKeyValueStorage != null) { tJKeyValueStorage.remove("pref_user_segment"); return; } return; } TJKeyValueStorage tJKeyValueStorage2 = g; if (tJKeyValueStorage2 != null) { Intrinsics.checkNotNull(tJSegment); tJKeyValueStorage2.setValue("pref_user_segment", Integer.valueOf(tJSegment.getValue())); } } public static final void a(TJSetUserIDListener tJSetUserIDListener) { if (tJSetUserIDListener != null) { tJSetUserIDListener.onSetUserIDFailure(TJUserKt.USER_ID_MAX_LENGTH_ERROR); } if (tJSetUserIDListener != null) { tJSetUserIDListener.onSetUserIDFailure(-1, TJUserKt.USER_ID_MAX_LENGTH_ERROR); } } }