package com.seewo.factoryaging.u0;

import android.content.SharedPreferences;
import android.util.Log;
import com.cvte.vman.entity.ThermalModuleInfo;
import com.seewo.factoryaging.FactoryAgingApplication;
import com.seewo.factoryaging.b0;
import j.i;
import j.k;
import j.k0.o;
import j.k0.p;
import j.k0.w;
import j.p0.d.r;
import j.p0.d.s;
import j.u0.t;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/* JADX INFO: compiled from: CpuTemperatureHelper.kt */
/* JADX INFO: loaded from: classes.dex */
public final class a {
    public static final a a = new a();
    private static final SimpleDateFormat b = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static final i c = k.b(b.b);

    /* JADX INFO: renamed from: com.seewo.factoryaging.u0.a$a, reason: collision with other inner class name */
    /* JADX INFO: compiled from: Comparisons.kt */
    public static final class C0013a<T> implements Comparator {
        @Override // java.util.Comparator
        public final int compare(T t, T t2) {
            return j.l0.b.a((String) ((Map.Entry) t).getKey(), (String) ((Map.Entry) t2).getKey());
        }
    }

    /* JADX INFO: compiled from: CpuTemperatureHelper.kt */
    static final class b extends s implements j.p0.c.a<SharedPreferences> {
        public static final b b = new b();

        b() {
            super(0);
        }

        @Override // j.p0.c.a
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public final SharedPreferences invoke() {
            return FactoryAgingApplication.e.d().getApplicationContext().getSharedPreferences("cpu_temperature_data", 0);
        }
    }

    private a() {
    }

    private final SharedPreferences a() {
        Object value = c.getValue();
        r.e(value, "<get-mSp>(...)");
        return (SharedPreferences) value;
    }

    private final boolean c(long j2) {
        return j2 % 10 == 0;
    }

    public final List<b0> b() {
        try {
            Set<Map.Entry<String, ?>> setEntrySet = a().getAll().entrySet();
            ArrayList arrayList = new ArrayList();
            for (Object obj : setEntrySet) {
                if (((Map.Entry) obj).getValue() instanceof String) {
                    arrayList.add(obj);
                }
            }
            List<Map.Entry> listK = w.K(arrayList, new C0013a());
            ArrayList arrayList2 = new ArrayList(p.p(listK, 10));
            for (Map.Entry entry : listK) {
                String str = (String) entry.getKey();
                r.e(str, "key");
                String strI0 = t.I0(str, 19);
                String strF0 = t.F0(str, 20);
                Object value = entry.getValue();
                if (value == null) {
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }
                arrayList2.add(new b0(strF0, (String) value, strI0));
            }
            return arrayList2;
        } catch (Throwable th) {
            Log.e("CpuTemperatureHelper", "getModuleDataList error", th);
            return o.g();
        }
    }

    public final void d(String str, long j2) {
        r.f(str, "temp");
        if (c(j2)) {
            try {
                String strValueOf = String.valueOf((int) Float.parseFloat(j.u0.r.E0(str).toString()));
                String str2 = b.format(new Date());
                a().edit().putString(str2 + "_cpu_0_temperature", strValueOf).apply();
            } catch (Throwable th) {
                Log.e("CpuTemperatureHelper", "saveTemperature error", th);
            }
        }
    }

    public final void e(List<? extends ThermalModuleInfo> list, long j2) {
        r.f(list, "modules");
        if (c(j2)) {
            try {
                String str = b.format(new Date());
                SharedPreferences.Editor editorEdit = a().edit();
                int i2 = 0;
                for (ThermalModuleInfo thermalModuleInfo : list) {
                    if (thermalModuleInfo.isValid) {
                        editorEdit.putString(str + "_cpu_" + i2 + "_temperature", String.valueOf(thermalModuleInfo.currentTemp));
                        i2++;
                    }
                }
                editorEdit.apply();
            } catch (Throwable th) {
                Log.e("CpuTemperatureHelper", "saveTemperatures error", th);
            }
        }
    }
}
