package com.xlx.speech.voicereadsdk.entrance; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.provider.Settings; import android.text.TextUtils; import com.bytedance.sdk.openadsdk.api.plugin.PluginConstants; import com.google.gson.Gson; import com.kuaishou.weapon.p0.h; import com.xlx.speech.e.b; import com.xlx.speech.e.d; import com.xlx.speech.f.c; import com.xlx.speech.i.a; import com.xlx.speech.i.b; import com.xlx.speech.m0.c0; import com.xlx.speech.m0.f; import com.xlx.speech.m0.h0; import com.xlx.speech.m0.j; import com.xlx.speech.m0.k; import com.xlx.speech.m0.l; import com.xlx.speech.m0.p; import com.xlx.speech.m0.w; import com.xlx.speech.voicereadsdk.bean.AdReward; import com.xlx.speech.voicereadsdk.bean.AdSlot; import com.xlx.speech.voicereadsdk.bean.VoiceConfig; import com.xlx.speech.voicereadsdk.bean.req.AdDetailParams; import com.xlx.speech.voicereadsdk.bean.req.AdStatusParams; import com.xlx.speech.voicereadsdk.bean.req.UploadReward; import com.xlx.speech.voicereadsdk.bean.resp.AdCheck; import com.xlx.speech.voicereadsdk.bean.resp.AdRequest; import com.xlx.speech.voicereadsdk.bean.resp.AdStatus; import com.xlx.speech.voicereadsdk.bean.resp.AdvertVoiceIntroduce; import com.xlx.speech.voicereadsdk.bean.resp.LoginResult; import com.xlx.speech.voicereadsdk.bean.resp.MultipleRewardAdResult; import com.xlx.speech.voicereadsdk.bean.resp.RewardConfig; import com.xlx.speech.voicereadsdk.bean.resp.SingleAdDetailResult; import com.xlx.speech.voicereadsdk.constant.VoiceConstant; import com.xlx.speech.voicereadsdk.ui.activity.SpeechVoiceMallActivity; import com.xlx.speech.voicereadsdk.ui.activity.SpeechVoiceMultipleRewardReservedActivity; import com.xlx.speech.voicereadsdk.ui.activity.SpeechVoiceMultipleRewardSingleActivity; import com.xlx.speech.voicereadsdk.ui.activity.enter.SpeechVoiceEnterSloganActivity; import com.xlx.speech.voicereadsdk.utils.IVoiceImageLoad; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.json.JSONObject; public final class SpeechVoiceManager { private static final List<AdRequest> adInfos = new ArrayList(); private boolean isLogin; private b mAdModel; private AdSlot mAdSlot; private Context mContext; private int mMaxReadNum; private int mSurplusReadNum; private d mUserModel; private VoiceAdListener mVoiceAdListener; private VoiceConfig mVoiceConfig; public static class SingletonHolder { private static final SpeechVoiceManager INSTANCE = new SpeechVoiceManager(); private SingletonHolder() { } } private SpeechVoiceManager() { this.mMaxReadNum = 0; this.mSurplusReadNum = 0; this.isLogin = false; } private boolean checkRewArdInfo() { VoiceAdListener voiceAdListener = this.mVoiceAdListener; if (voiceAdListener == null) { return false; } AdReward rewardInfo = voiceAdListener.getRewardInfo(100.0f, new AdReward(100.0f), 1); AdReward rewardInfo2 = this.mVoiceAdListener.getRewardInfo(200.0f, new AdReward(200.0f), 2); if (!(rewardInfo == null || rewardInfo2 == null)) { float rewardCount = rewardInfo.getRewardCount(); if (!(rewardInfo2.getRewardCount() == 0.0f && rewardCount == 0.0f)) { return true; } } this.mVoiceAdListener.onAdError(VoiceConstant.REWARD_INFO_ERROR); return false; } public static SpeechVoiceManager getVoiceManager() { return SingletonHolder.INSTANCE; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void gotoVoicePage(Context context, SingleAdDetailResult singleAdDetailResult, MultipleRewardAdResult multipleRewardAdResult) { RewardConfig rewardConfig = singleAdDetailResult != null ? singleAdDetailResult.rewardConfig : multipleRewardAdResult.getRewardConfig(); if ((rewardConfig != null && rewardConfig.isValid()) || checkRewArdInfo()) { HashMap<Float, AdReward> uploadMediaRewardInfo = uploadMediaRewardInfo(singleAdDetailResult, multipleRewardAdResult, rewardConfig); if (singleAdDetailResult != null) { singleAdDetailResult.rewardMap = uploadMediaRewardInfo; com.xlx.speech.i.b bVar = b.c.a; b.C0410b bVar2 = new b.C0410b(); bVar.a = bVar2; bVar2.a = singleAdDetailResult.adId; bVar2.b = singleAdDetailResult.sloganId; AdvertVoiceIntroduce advertVoiceIntroduce = singleAdDetailResult.advertVoiceIntroduce; bVar2.c = advertVoiceIntroduce != null ? advertVoiceIntroduce.voiceId : ""; String str = singleAdDetailResult.logId; String str2 = singleAdDetailResult.tagId; a aVar = a.C0409a.a; aVar.getClass(); HashMap hashMap = new HashMap(); hashMap.put("logId", str); hashMap.put("tagId", str2); aVar.a.C(com.xlx.speech.f.d.a(hashMap)).enqueue(new c()); if (TextUtils.equals("2", singleAdDetailResult.advertType)) { int i = SpeechVoiceMallActivity.b0; Intent intent = new Intent(context, SpeechVoiceMallActivity.class); intent.putExtra("data", singleAdDetailResult); context.startActivity(intent); } else if (!singleAdDetailResult.readFirstSloganForce) { Intent intent2 = new Intent(context, com.xlx.speech.v.a.a(singleAdDetailResult)); intent2.putExtra("EXTRA_PAGE_COUNT", 2); intent2.putExtra("data", singleAdDetailResult); context.startActivity(intent2); } else { Intent intent3 = new Intent(context, SpeechVoiceEnterSloganActivity.class); intent3.putExtra("data", singleAdDetailResult); context.startActivity(intent3); } } else { com.xlx.speech.i.b bVar3 = b.c.a; b.C0410b bVar4 = new b.C0410b(); bVar3.a = bVar4; bVar4.a = multipleRewardAdResult.getAdId(); int taskType = multipleRewardAdResult.getTaskType(); multipleRewardAdResult.setRewardMap(uploadMediaRewardInfo); if (taskType == 2) { int i2 = SpeechVoiceMultipleRewardReservedActivity.D; Intent intent4 = new Intent(context, SpeechVoiceMultipleRewardReservedActivity.class); intent4.putExtra("EXTRA_MULTIPLE_REWARD", multipleRewardAdResult); context.startActivity(intent4); return; } int i3 = SpeechVoiceMultipleRewardSingleActivity.T; Intent intent5 = new Intent(context, SpeechVoiceMultipleRewardSingleActivity.class); intent5.putExtra("EXTRA_MULTIPLE_REWARD", multipleRewardAdResult); context.startActivity(intent5); } } } private void login(final Context context, final AdSlot adSlot, final VoiceAdLoadListener voiceAdLoadListener) { if (!this.isLogin) { this.isLogin = true; this.mUserModel.a(context, adSlot, new com.xlx.speech.f.b<LoginResult>() { /* class com.xlx.speech.voicereadsdk.entrance.SpeechVoiceManager.AnonymousClass1 */ @Override // com.xlx.speech.f.e, com.xlx.speech.f.b public void onError(com.xlx.speech.f.a aVar) { SpeechVoiceManager.this.isLogin = false; VoiceAdLoadListener voiceAdLoadListener = voiceAdLoadListener; if (voiceAdLoadListener != null) { voiceAdLoadListener.onAdLoadError(aVar.a, aVar.b); } } public void onSuccess(LoginResult loginResult) { SpeechVoiceManager.this.isLogin = false; SpeechVoiceManager.this.mMaxReadNum = loginResult.getSaySuccessMaxNum(); SpeechVoiceManager.this.mSurplusReadNum = loginResult.getSurplusSaySuccessNum(); if (SpeechVoiceManager.this.mVoiceConfig.isDebug()) { try { com.xlx.speech.y.a aVar = new com.xlx.speech.y.a(context); aVar.a = new DialogInterface.OnClickListener() { /* class com.xlx.speech.voicereadsdk.entrance.SpeechVoiceManager.AnonymousClass1.AnonymousClass1 */ public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); SpeechVoiceManager.this.mVoiceConfig.setDebugAdvertType(i + 1); AnonymousClass1 r3 = AnonymousClass1.this; SpeechVoiceManager.this.getSingleAdDetail(adSlot, "", voiceAdLoadListener); } }; aVar.show(); return; } catch (Exception unused) { } } SpeechVoiceManager.this.mVoiceConfig.setDebugAdvertType(0); SpeechVoiceManager.this.getSingleAdDetail(adSlot, "", voiceAdLoadListener); } }); } } private void notifyAdLoadSuccess(VoiceAdLoadListener voiceAdLoadListener, float f, SingleAdDetailResult singleAdDetailResult, MultipleRewardAdResult multipleRewardAdResult) { AdRequest adRequest = new AdRequest(); adRequest.setAdDetail(singleAdDetailResult); adRequest.setMultipleRewardAdResult(multipleRewardAdResult); String string = c0.a().getString("speech_token", ""); boolean z = c0.a().getBoolean("speech_is_new_user", false); String string2 = c0.a().getString("speech_track_id", ""); String string3 = c0.a().getString("channel_app_name", ""); String string4 = c0.a().getString("channel_app_logo", ""); LoginResult loginResult = new LoginResult(); loginResult.setToken(string); loginResult.setNewUser(z); loginResult.setTrackId(string2); loginResult.setResourceName(string3); loginResult.setResourceLogo(string4); adRequest.setLoginResult(loginResult); adInfos.add(adRequest); if (voiceAdLoadListener != null) { voiceAdLoadListener.onAdLoadSuccess(f, this.mMaxReadNum, this.mSurplusReadNum); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void parsAdData(String str, VoiceAdLoadListener voiceAdLoadListener) { try { JSONObject jSONObject = new JSONObject(str); int optInt = jSONObject.optInt(PluginConstants.KEY_ERROR_CODE); String optString = jSONObject.optString("msg"); if (optInt == 200) { String optString2 = jSONObject.optString("data"); JSONObject optJSONObject = jSONObject.optJSONObject("data"); int optInt2 = optJSONObject.optInt("advertType"); int optInt3 = optJSONObject.optInt("taskType"); if (optInt2 != 3 || optInt3 <= 0) { SingleAdDetailResult singleAdDetailResult = (SingleAdDetailResult) l.a(optString2, SingleAdDetailResult.class); if (optInt2 == 3 && singleAdDetailResult.checkHasInstall == 1 && k.a(this.mContext, singleAdDetailResult.packageName)) { getSingleAdDetail(getAdSlot(), singleAdDetailResult.logId, voiceAdLoadListener); } else { notifyAdLoadSuccess(voiceAdLoadListener, singleAdDetailResult.ecpm, singleAdDetailResult, null); } } else { MultipleRewardAdResult multipleRewardAdResult = (MultipleRewardAdResult) l.a(optString2, MultipleRewardAdResult.class); notifyAdLoadSuccess(voiceAdLoadListener, multipleRewardAdResult.getEcpm(), null, multipleRewardAdResult); } } else if (voiceAdLoadListener != null) { voiceAdLoadListener.onAdLoadError(optInt, optString); } } catch (Throwable th) { th.printStackTrace(); if (voiceAdLoadListener != null) { voiceAdLoadListener.onAdLoadError(VoiceConstant.NET_ERROR_CODE, "广告数据异常"); } } } private HashMap<Float, AdReward> uploadMediaRewardInfo(SingleAdDetailResult singleAdDetailResult, MultipleRewardAdResult multipleRewardAdResult, RewardConfig rewardConfig) { String str; float f; float f2; HashMap<Float, AdReward> hashMap = new HashMap<>(); String str2 = ""; if (multipleRewardAdResult != null) { try { f2 = multipleRewardAdResult.getIcpmOne(); f = multipleRewardAdResult.getIcpmTwo(); str = multipleRewardAdResult.getTagId(); } catch (Throwable unused) { } } else { str = str2; f2 = 0.0f; f = 0.0f; } if (singleAdDetailResult != null) { f2 = singleAdDetailResult.icpmOne; f = singleAdDetailResult.icpmTwo; str = singleAdDetailResult.tagId; str2 = singleAdDetailResult.logId; } ArrayList arrayList = new ArrayList(); AdReward adReward = null; if (f2 > 0.0f) { VoiceAdListener voiceAdListener = this.mVoiceAdListener; AdReward rewardInfo = voiceAdListener != null ? voiceAdListener.getRewardInfo(f2, new AdReward(f2), 1) : null; if (!com.xlx.speech.a.b.a(rewardInfo)) { rewardInfo = rewardConfig.getReward(f2); } hashMap.put(Float.valueOf(f2), rewardInfo); UploadReward uploadReward = new UploadReward(); uploadReward.setiCPM(f2); uploadReward.setRewardCount(rewardInfo.rewardCount); uploadReward.setRewardName(rewardInfo.getRewardName()); uploadReward.setReward(rewardInfo.rewardCount + rewardInfo.getRewardName()); arrayList.add(uploadReward); } if (f > 0.0f) { VoiceAdListener voiceAdListener2 = this.mVoiceAdListener; if (voiceAdListener2 != null) { adReward = voiceAdListener2.getRewardInfo(f, new AdReward(f), 2); } if (!com.xlx.speech.a.b.a(adReward)) { adReward = rewardConfig.getReward(f); } hashMap.put(Float.valueOf(f), adReward); UploadReward uploadReward2 = new UploadReward(); uploadReward2.setiCPM(f); uploadReward2.setRewardCount(adReward.rewardCount); uploadReward2.setRewardName(adReward.getRewardName()); uploadReward2.setReward(adReward.rewardCount + adReward.getRewardName()); arrayList.add(uploadReward2); } com.xlx.speech.e.c.a(str2, str, 0, new Gson().toJson(arrayList)); return hashMap; } public void checkAdStatus(Context context, AdSlot adSlot, final CheckAdStatusListener checkAdStatusListener) { com.xlx.speech.e.b bVar = this.mAdModel; AnonymousClass5 r2 = new com.xlx.speech.f.b<AdStatus>() { /* class com.xlx.speech.voicereadsdk.entrance.SpeechVoiceManager.AnonymousClass5 */ @Override // com.xlx.speech.f.e, com.xlx.speech.f.b public void onError(com.xlx.speech.f.a aVar) { checkAdStatusListener.onError(aVar.a); h0.a(aVar.b); } public void onSuccess(AdStatus adStatus) { if (adStatus == null || !adStatus.isAdIsExist()) { checkAdStatusListener.onError(VoiceConstant.AD_NO_EXIST); } else { checkAdStatusListener.onVerifySuccess(); } } }; bVar.getClass(); VoiceConfig voiceConfig = SpeechVoiceSdk.getAdManger().getVoiceConfig(); boolean a = w.a("android.permission.RECORD_AUDIO"); boolean a2 = w.a(h.c); boolean a3 = w.a(h.j); String str = ""; if (a2) { try { str = f.a(context); } catch (Throwable unused) { } } String string = Settings.System.getString(context.getContentResolver(), "android_id"); String a4 = f.a(context, true); String b = f.b(context); String appId = voiceConfig.getAppId(); String appSecret = voiceConfig.getAppSecret(); String mediaUserId = adSlot.getMediaUserId(); String resourceId = adSlot.getResourceId(); int i = a ? 1 : 0; AdStatusParams adStatusParams = new AdStatusParams(str, a4, appId, appSecret, mediaUserId, a3 ? 1 : 0, a2 ? 1 : 0, i, b, string, resourceId); p.a("checkAdStatus:" + adStatusParams.toString()); a.C0409a.a.a.n(com.xlx.speech.f.d.a(adStatusParams)).enqueue(r2); } public void ensureContext(Context context) { if (this.mContext == null) { this.mContext = context; } } public void ensureInit(Context context) { VoiceConfig voiceConfig = this.mVoiceConfig; if (voiceConfig == null || TextUtils.isEmpty(voiceConfig.getAppId()) || TextUtils.isEmpty(this.mVoiceConfig.getAppSecret())) { try { ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128); String valueOf = String.valueOf(applicationInfo.metaData.get("xlx_app_id")); VoiceConfig build = new VoiceConfig.Builder().appId(valueOf).appSecret(String.valueOf(applicationInfo.metaData.get("xlx_app_secret"))).build(); this.mVoiceConfig = build; init(context, build); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } } public void getAdById(final Context context, final AdSlot adSlot, final String str, final String str2, VoiceAdListener voiceAdListener) { this.mVoiceAdListener = voiceAdListener; this.mUserModel.a(context, adSlot, new com.xlx.speech.f.b<LoginResult>() { /* class com.xlx.speech.voicereadsdk.entrance.SpeechVoiceManager.AnonymousClass4 */ public void onSuccess(LoginResult loginResult) { a aVar = a.C0409a.a; String str = str; String str2 = str2; String resourceId = adSlot.getResourceId(); aVar.getClass(); HashMap hashMap = new HashMap(); hashMap.put("adId", str); hashMap.put("pageMode", str2); hashMap.put("resourceId", resourceId); aVar.a.w(com.xlx.speech.f.d.a(hashMap)).enqueue(new com.xlx.speech.f.b<SingleAdDetailResult>() { /* class com.xlx.speech.voicereadsdk.entrance.SpeechVoiceManager.AnonymousClass4.AnonymousClass1 */ @Override // com.xlx.speech.f.e, com.xlx.speech.f.b public void onError(com.xlx.speech.f.a aVar) { super.onError(aVar); h0.a(aVar.b); } public void onSuccess(SingleAdDetailResult singleAdDetailResult) { AnonymousClass4 r0 = AnonymousClass4.this; SpeechVoiceManager.this.gotoVoicePage(context, singleAdDetailResult, null); } }); } }); } public AdSlot getAdSlot() { if (this.mAdSlot == null) { this.mAdSlot = new AdSlot.Builder().build(); } return this.mAdSlot; } public Context getContext() { return this.mContext; } public void getSingleAdDetail(AdSlot adSlot, String str, final VoiceAdLoadListener voiceAdLoadListener) { com.xlx.speech.e.b bVar = this.mAdModel; AnonymousClass3 r1 = new com.xlx.speech.f.b<String>() { /* class com.xlx.speech.voicereadsdk.entrance.SpeechVoiceManager.AnonymousClass3 */ @Override // com.xlx.speech.f.e, com.xlx.speech.f.b public void onError(com.xlx.speech.f.a aVar) { VoiceAdLoadListener voiceAdLoadListener = voiceAdLoadListener; if (voiceAdLoadListener != null) { voiceAdLoadListener.onAdLoadError(aVar.a, aVar.b); } } public void onSuccess(String str) { SpeechVoiceManager.this.parsAdData(str, voiceAdLoadListener); } }; bVar.getClass(); String mediaUserId = adSlot.getMediaUserId(); String resourceId = adSlot.getResourceId(); String reward = adSlot.getReward(); int rewardAmount = adSlot.getRewardAmount(); String userId = adSlot.getUserId(); String extra = adSlot.getExtra(); if (TextUtils.isEmpty(str)) { str = "0"; } AdDetailParams adDetailParams = new AdDetailParams(mediaUserId, resourceId, reward, rewardAmount, userId, extra, str); a aVar = a.C0409a.a; aVar.getClass(); aVar.a.j(com.xlx.speech.f.d.a(adDetailParams)).enqueue(new com.xlx.speech.e.a(bVar, r1)); } public VoiceAdListener getVoiceAdListener() { return this.mVoiceAdListener; } public VoiceConfig getVoiceConfig() { return this.mVoiceConfig; } public void init(Context context, VoiceConfig voiceConfig) { this.mContext = context.getApplicationContext(); this.mVoiceConfig = voiceConfig; f.a(context, false); f.b(context); adInfos.clear(); this.mAdModel = new com.xlx.speech.e.b(); this.mUserModel = new d(); } public void loadVoiceAd(Context context, AdSlot adSlot, VoiceAdLoadListener voiceAdLoadListener) { this.mAdSlot = adSlot; login(context, adSlot, voiceAdLoadListener); } public void setImageLoad(IVoiceImageLoad iVoiceImageLoad) { synchronized (IVoiceImageLoad.class) { j.a = iVoiceImageLoad; } } public void showVoiceAd(final Context context, VoiceAdListener voiceAdListener) { AdRequest adRequest; if (voiceAdListener != null) { this.mVoiceAdListener = voiceAdListener; } final MultipleRewardAdResult multipleRewardAdResult = null; try { adRequest = adInfos.get(0); } catch (Throwable unused) { adRequest = null; } final SingleAdDetailResult adDetail = adRequest != null ? adRequest.getAdDetail() : null; if (adRequest != null) { multipleRewardAdResult = adRequest.getMultipleRewardAdResult(); } if (adDetail != null && adDetail.advertType.equals("3")) { boolean z = true; if (adDetail.checkHasInstall == 1) { if (context.getPackageManager().getLaunchIntentForPackage(adDetail.packageName) == null) { z = false; } if (z) { try { List<AdRequest> list = adInfos; if (list.size() > 0) { list.remove(0); } } catch (Throwable unused2) { } showVoiceAd(context, voiceAdListener); return; } } } if (adRequest != null) { c0.a(adRequest.getLoginResult()); } if (adDetail == null && multipleRewardAdResult == null) { VoiceAdListener voiceAdListener2 = this.mVoiceAdListener; if (voiceAdListener2 != null) { voiceAdListener2.onAdError(VoiceConstant.AD_OVERDUE); return; } return; } com.xlx.speech.e.b bVar = this.mAdModel; String str = ""; String str2 = adDetail == null ? str : adDetail.logId; if (multipleRewardAdResult != null) { str = multipleRewardAdResult.getTagId(); } AnonymousClass2 r4 = new com.xlx.speech.f.b<AdCheck>() { /* class com.xlx.speech.voicereadsdk.entrance.SpeechVoiceManager.AnonymousClass2 */ @Override // com.xlx.speech.f.e, com.xlx.speech.f.b public void onError(com.xlx.speech.f.a aVar) { if (SpeechVoiceManager.this.mVoiceAdListener != null) { SpeechVoiceManager.this.mVoiceAdListener.onAdError(aVar.a); } } public void onSuccess(AdCheck adCheck) { SpeechVoiceManager.this.gotoVoicePage(context, adDetail, multipleRewardAdResult); if (SpeechVoiceManager.adInfos.size() > 0) { SpeechVoiceManager.adInfos.remove(0); } } }; bVar.getClass(); p.a("adCheck:" + str2); a aVar = a.C0409a.a; aVar.getClass(); HashMap hashMap = new HashMap(); if (!TextUtils.isEmpty(str2)) { hashMap.put("logId", str2); } if (!TextUtils.isEmpty(str)) { hashMap.put("tagId", str); } aVar.a.k(com.xlx.speech.f.d.a(hashMap)).enqueue(r4); } public void uploadAdConfig(VoiceConfig voiceConfig) { this.mVoiceConfig = voiceConfig; } }