package com.kwad.sdk.core.d; import android.content.Context; import com.kwad.sdk.core.e.b; import com.kwad.sdk.core.request.model.f; import com.kwad.sdk.core.response.a.d; import com.kwad.sdk.core.response.model.AdTemplate; import com.kwad.sdk.service.ServiceProvider; import com.kwad.sdk.service.kwai.e; import com.kwad.sdk.utils.s; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import org.json.JSONArray; import org.json.JSONObject; public class a { public static SimpleDateFormat Ho = new SimpleDateFormat("yyyy-MM-dd"); private static volatile a aWp; private static void I(String str, String str2) { Context context = ((e) ServiceProvider.get(e.class)).getContext(); if (context != null) { context.getSharedPreferences("ksadsdk_local_ad_task_info", 0).edit().putString(str, str2).apply(); } } public static a Mv() { if (aWp == null) { synchronized (a.class) { if (aWp == null) { aWp = new a(); } } } return aWp; } public static List<f> Mw() { if (((e) ServiceProvider.get(e.class)).getContext() == null) { return null; } String string = getString("ksadsdk_local_ad_task_info_adstyle_data"); ArrayList<f> arrayList = new ArrayList(); try { JSONArray jSONArray = new JSONArray(string); int length = jSONArray.length(); for (int i = 0; i < length; i++) { JSONObject jSONObject = jSONArray.getJSONObject(i); f fVar = new f(); fVar.parseJson(jSONObject); arrayList.add(fVar); } } catch (Exception unused) { } ArrayList arrayList2 = new ArrayList(); for (f fVar2 : arrayList) { if (a(fVar2)) { arrayList2.add(fVar2); } } return arrayList2; } public static int Mx() { Context context = ((e) ServiceProvider.get(e.class)).getContext(); if (context == null) { return 30; } return context.getSharedPreferences("ksadsdk_local_ad_task_info", 0).getInt("reward_aggregation_max_per_day", 30); } public static long My() { Context context = ((e) ServiceProvider.get(e.class)).getContext(); if (context == null) { return 1200; } return context.getSharedPreferences("ksadsdk_local_ad_task_info", 0).getLong("reward_aggregation_min_interval", 1200); } private static boolean a(f fVar) { long j = fVar.bbD; if (j <= 0) { return false; } return Ho.format(new Date(j)).equals(Ho.format(new Date())); } public static void aB(AdTemplate adTemplate) { if (adTemplate.watched) { b.d("AdCounter", "startWatchAd this ad has been watched."); } else { aC(adTemplate); } } private static void aC(AdTemplate adTemplate) { f fVar; int cv = d.cv(adTemplate); int cm = d.cm(adTemplate); List Mw = Mw(); if (Mw == null || Mw.size() == 0) { Mw = new ArrayList(); fVar = new f(cm, cv, 1, System.currentTimeMillis()); } else { boolean z = false; Iterator it = Mw.iterator(); while (true) { if (!it.hasNext()) { break; } f fVar2 = (f) it.next(); if (fVar2.adStyle == cm && fVar2.taskType == cv) { fVar2.count++; if (!a(fVar2)) { fVar2.count = 1; fVar2.ad(System.currentTimeMillis()); } z = true; } } if (!z) { fVar = new f(cm, cv, 1, System.currentTimeMillis()); } I("ksadsdk_local_ad_task_info_adstyle_data", s.an(Mw).toString()); adTemplate.watched = true; } Mw.add(fVar); I("ksadsdk_local_ad_task_info_adstyle_data", s.an(Mw).toString()); adTemplate.watched = true; } public static List<f> cb(int i) { ArrayList arrayList = new ArrayList(); List<f> Mw = Mw(); if (!(Mw == null || Mw.size() == 0)) { for (f fVar : Mw) { if (15 == fVar.adStyle) { arrayList.add(fVar); } } } return arrayList; } public static void e(int i, long j) { Context context = ((e) ServiceProvider.get(e.class)).getContext(); if (context != null) { context.getSharedPreferences("ksadsdk_local_ad_task_info", 0).edit().putInt("reward_aggregation_max_per_day", i).putLong("reward_aggregation_min_interval", j).apply(); } } private static String getString(String str) { Context context = ((e) ServiceProvider.get(e.class)).getContext(); if (context == null) { return null; } return context.getSharedPreferences("ksadsdk_local_ad_task_info", 0).getString(str, null); } }