导航菜单

页面标题

页面副标题

BetterTogether v3.0.0 - l.java 源代码

正在查看: BetterTogether v3.0.0 应用的 l.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package zc;

import a0.g0;
import a9.h;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import com.bettertogether.cache.preferences.PreferenceData;
import com.bettertogether.fitbit.FitbitAuthActivity;
import com.bettertogether.fitbit.api.models.FitbitAuthToken;
import com.bettertogether.remote.model.request.RecordRequestItem;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.fitness.Fitness;
import com.google.android.gms.fitness.FitnessLocal;
import com.google.android.gms.fitness.FitnessOptions;
import com.google.android.gms.fitness.LocalRecordingClient;
import com.google.android.gms.fitness.data.Bucket;
import com.google.android.gms.fitness.data.DataPoint;
import com.google.android.gms.fitness.data.DataSet;
import com.google.android.gms.fitness.data.DataSource;
import com.google.android.gms.fitness.data.DataType;
import com.google.android.gms.fitness.data.Field;
import com.google.android.gms.fitness.data.LocalDataType;
import com.google.android.gms.fitness.request.DataReadRequest;
import com.google.android.gms.fitness.request.LocalDataReadRequest;
import com.google.android.gms.fitness.result.DataReadResponse;
import com.google.android.gms.tasks.Task;
import en.o;
import et.d;
import g0.b;
import id.f;
import id.i;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import kotlin.Pair;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.collections.b0;
import kotlin.collections.f0;
import kotlin.collections.i0;
import kotlin.collections.j0;
import kotlin.collections.w0;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;
import kotlin.ranges.IntRange;
import lq.m;
import lq.n;
import mp.a0;
import s6.s;
import s6.z;
import u7.e;
import v.l1;
import v1.k;
import w.a2;
import w1.s1;
import yb.q;
import zf.a;
import zi.SV.dhLZvn;

public abstract class l extends u {
    public static final e Companion = new e();
    public static final int GLASS_VOLUME = 250;
    public static final int REQUEST_OAUTH_REQUEST_CODE = 3;
    private final FitnessOptions googleFitFitnessOptions;
    private final m preferenceData$delegate = n.b(new h(this, 0));

    public l() {
        FitnessOptions build = FitnessOptions.builder().addDataType(DataType.TYPE_STEP_COUNT_DELTA, 0).addDataType(DataType.AGGREGATE_STEP_COUNT_DELTA, 0).addDataType(DataType.AGGREGATE_CALORIES_EXPENDED, 0).addDataType(DataType.TYPE_HYDRATION, 0).build();
        Intrinsics.checkNotNullExpressionValue(build, "builder()\n        .addDa…SS_READ)\n        .build()");
        this.googleFitFitnessOptions = build;
    }

    public static final List access$filterRecordWithPeriod(l lVar, int i, List list) {
        lVar.getClass();
        return t(i, list);
    }

    public static final PreferenceData access$getPreferenceData(l lVar) {
        return (PreferenceData) lVar.preferenceData$delegate.getValue();
    }

    public static final Pair access$processData(l lVar, DataReadResponse dataReadResponse, DataType dataType, int i) {
        DataType dataType2;
        int i2;
        String str;
        DataType dataType3 = dataType;
        lVar.getClass();
        ArrayList arrayList = new ArrayList();
        int i3 = 0;
        String str2 = " ";
        if (dataReadResponse != null) {
            d.d("healthConnect").a(g0.f("bucket size -> ", dataReadResponse.getBuckets().size()), new Object[0]);
            int size = dataReadResponse.getBuckets().size();
            int i4 = 0;
            while (i3 < size) {
                boolean c = Intrinsics.c(dataType3, DataType.TYPE_HYDRATION);
                String str3 = dhLZvn.uuzSwHYi;
                if (c) {
                    if (!((DataSet) ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets().get(i4)).getDataPoints().isEmpty()) {
                        i4 = (int) Math.floor((((DataPoint) ((DataSet) ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets().get(i4)).getDataPoints().get(i4)).getValue(Field.FIELD_VOLUME).asFloat() * 1000) / GLASS_VOLUME);
                    }
                    String lowerCase = "WATER".toLowerCase(Locale.ROOT);
                    Intrinsics.checkNotNullExpressionValue(lowerCase, "toLowerCase(...)");
                    String valueOf = String.valueOf(i4);
                    DateFormat dateFormat = a.a;
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(str3);
                    Bucket bucket = (Bucket) dataReadResponse.getBuckets().get(i3);
                    TimeUnit timeUnit = TimeUnit.MILLISECONDS;
                    String format = simpleDateFormat.format(new Date(bucket.getStartTime(timeUnit)));
                    Intrinsics.checkNotNullExpressionValue(format, "SimpleDateFormat(\"yyyy-M…                        )");
                    arrayList.add(new RecordRequestItem(lowerCase, valueOf, a.b(format), String.valueOf(10)));
                    d.d("Google Fit hydration case :").a(b.n(g0.o("start /end  time hydration is ", ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets().size(), str2, i4, str2), new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date(((Bucket) dataReadResponse.getBuckets().get(i3)).getStartTime(timeUnit))), new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date(((Bucket) dataReadResponse.getBuckets().get(i3)).getEndTime(timeUnit)))), new Object[0]);
                    dataType2 = dataType;
                    str = str2;
                    i2 = size;
                } else {
                    dataType2 = dataType;
                    if (Intrinsics.c(dataType2, DataType.TYPE_STEP_COUNT_DELTA)) {
                        if (!((DataSet) ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets().get(i4)).getDataPoints().isEmpty()) {
                            i4 = ((DataPoint) ((DataSet) ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets().get(i4)).getDataPoints().get(i4)).getValue(Field.FIELD_STEPS).asInt();
                        }
                        String lowerCase2 = "STEPS".toLowerCase(Locale.ROOT);
                        Intrinsics.checkNotNullExpressionValue(lowerCase2, "toLowerCase(...)");
                        String valueOf2 = String.valueOf(i4);
                        DateFormat dateFormat2 = a.a;
                        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat(str3);
                        Bucket bucket2 = (Bucket) dataReadResponse.getBuckets().get(i3);
                        TimeUnit timeUnit2 = TimeUnit.MILLISECONDS;
                        String str4 = str2;
                        i2 = size;
                        String format2 = simpleDateFormat2.format(new Date(bucket2.getStartTime(timeUnit2)));
                        Intrinsics.checkNotNullExpressionValue(format2, "SimpleDateFormat(\"yyyy-M…                        )");
                        arrayList.add(new RecordRequestItem(lowerCase2, valueOf2, a.b(format2), String.valueOf(10)));
                        d.d("Google Fit steps case :").a(b.n(g0.o("start /end  time steps is ", ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets().size(), str4, i4, str4), new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date(((Bucket) dataReadResponse.getBuckets().get(i3)).getStartTime(timeUnit2))), new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date(((Bucket) dataReadResponse.getBuckets().get(i3)).getEndTime(timeUnit2)))), new Object[0]);
                        str = str4;
                    } else {
                        String str5 = str2;
                        i2 = size;
                        if (Intrinsics.c(dataType2, DataType.AGGREGATE_CALORIES_EXPENDED)) {
                            if (!((DataSet) ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets().get(i4)).getDataPoints().isEmpty()) {
                                i4 = (int) ((DataPoint) ((DataSet) ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets().get(i4)).getDataPoints().get(i4)).getValue(Field.FIELD_CALORIES).asFloat();
                            }
                            String lowerCase3 = "CALORIES".toLowerCase(Locale.ROOT);
                            Intrinsics.checkNotNullExpressionValue(lowerCase3, "toLowerCase(...)");
                            String valueOf3 = String.valueOf(i4);
                            DateFormat dateFormat3 = a.a;
                            SimpleDateFormat simpleDateFormat3 = new SimpleDateFormat(str3);
                            Bucket bucket3 = (Bucket) dataReadResponse.getBuckets().get(i3);
                            TimeUnit timeUnit3 = TimeUnit.MILLISECONDS;
                            String format3 = simpleDateFormat3.format(new Date(bucket3.getStartTime(timeUnit3)));
                            Intrinsics.checkNotNullExpressionValue(format3, "SimpleDateFormat(\"yyyy-M…                        )");
                            arrayList.add(new RecordRequestItem(lowerCase3, valueOf3, a.b(format3), String.valueOf(10)));
                            et.a d2 = d.d("Google Fit calories case :");
                            List dataSets = ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets();
                            int size2 = ((Bucket) dataReadResponse.getBuckets().get(i3)).getDataSets().size();
                            String format4 = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date(((Bucket) dataReadResponse.getBuckets().get(i3)).getStartTime(timeUnit3)));
                            String format5 = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date(((Bucket) dataReadResponse.getBuckets().get(i3)).getEndTime(timeUnit3)));
                            StringBuilder sb2 = new StringBuilder("start /end  time calories is ");
                            sb2.append(dataSets);
                            str = str5;
                            sb2.append(str);
                            sb2.append(size2);
                            sb2.append(str);
                            sb2.append(i4);
                            sb2.append(str);
                            sb2.append(format4);
                            sb2.append(format5);
                            d2.a(sb2.toString(), new Object[0]);
                        } else {
                            str = str5;
                            d.d("Google Fit calories case :").a(g0.j("start time else is ", new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date(((Bucket) dataReadResponse.getBuckets().get(i3)).getStartTime(TimeUnit.MILLISECONDS)))), new Object[0]);
                        }
                    }
                }
                i3++;
                i4 = 0;
                dataType3 = dataType2;
                str2 = str;
                size = i2;
            }
        }
        String str6 = str2;
        if (arrayList.size() > 1) {
            i0.n(arrayList, new k(21));
        }
        String value = ((RecordRequestItem) CollectionsKt.I(arrayList)).getValue();
        j0.t(arrayList);
        ArrayList t = t(i, arrayList);
        d.d("Record Item GFit :").a("record is " + i + str6 + new o().i(t), new Object[0]);
        return new Pair(t, value);
    }

    public static void fetchStepsAndCalories$default(l lVar, int i, int i2, Function1 function1, int i3, Object obj) {
        if (obj != null) {
            throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: fetchStepsAndCalories");
        }
        if ((i3 & 1) != 0) {
            i = 0;
        }
        lVar.fetchStepsAndCalories(i, i2, function1);
    }

    public static void signOutFromGoogle$default(l lVar, Function0 function0, Function0 function02, int i, Object obj) {
        if (obj != null) {
            throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: signOutFromGoogle");
        }
        if ((i & 1) != 0) {
            function0 = s1.M;
        }
        if ((i & 2) != 0) {
            function02 = s1.N;
        }
        lVar.signOutFromGoogle(function0, function02);
    }

    public static ArrayList t(int i, List list) {
        try {
            ArrayList arrayList = new ArrayList();
            int size = list.size() - 1;
            int size2 = list.size() - i;
            if (size2 < 0) {
                size2 = 0;
            }
            if (size2 <= size) {
                while (true) {
                    arrayList.add(list.get(size));
                    if (size == size2) {
                        break;
                    }
                    size--;
                }
            }
            if (arrayList.size() > 1) {
                i0.n(arrayList, new k(19));
            }
            return arrayList;
        } catch (Exception e3) {
            e3.printStackTrace();
            ArrayList arrayList2 = new ArrayList();
            int size3 = list.size() - 1;
            int size4 = list.size() - (i - 1);
            int i2 = size4 >= 0 ? size4 : 0;
            if (i2 <= size3) {
                while (true) {
                    arrayList2.add(list.get(size3));
                    if (size3 == i2) {
                        break;
                    }
                    size3--;
                }
            }
            if (arrayList2.size() > 1) {
                i0.n(arrayList2, new k(20));
            }
            return arrayList2;
        }
    }

    public final boolean checkGooglePermissionsGrantedFor(DataType... dataTypeArr) {
        Intrinsics.checkNotNullParameter(dataTypeArr, "dataTypes");
        FitnessOptions.Builder builder = FitnessOptions.builder();
        Intrinsics.checkNotNullExpressionValue(builder, "builder()");
        for (DataType dataType : dataTypeArr) {
            builder.addDataType(dataType, 0);
        }
        FitnessOptions build = builder.build();
        Intrinsics.checkNotNullExpressionValue(build, "fitnessOptionsBuilder.build()");
        return GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this), build);
    }

    public final void connectFitbit() {
        id.d l = s.l();
        Enum[] enumArr = {id.n.d, id.n.e};
        f fVar = new f(this);
        Intrinsics.checkNotNullParameter(this, "activity");
        Intrinsics.checkNotNullParameter(enumArr, "scopes");
        Intrinsics.checkNotNullParameter(fVar, "callback");
        d.d("Fitbit").a(g0.j("login(), scopes: ", b0.r(enumArr, ", ", 62)), new Object[0]);
        i iVar = l.b;
        iVar.d = fVar;
        Intrinsics.checkNotNullParameter(enumArr, "scopes");
        Uri.Builder buildUpon = Uri.parse("https://www.fitbit.com/oauth2/authorize/").buildUpon();
        id.m mVar = iVar.a;
        Uri.Builder appendQueryParameter = buildUpon.appendQueryParameter("client_id", mVar.a);
        ArrayList arrayList = new ArrayList(2);
        for (int i = 0; i < 2; i++) {
            arrayList.add(enumArr[i].name());
        }
        Uri build = appendQueryParameter.appendQueryParameter("scope", CollectionsKt.H(arrayList, " ", null, null, z.R, 30)).appendQueryParameter("response_type", "code").appendQueryParameter("redirect_uri", mVar.c).build();
        Intrinsics.checkNotNullExpressionValue(build, "parse(AUTHORIZE_URL)\n   …Url)\n            .build()");
        String uri = build.toString();
        Intrinsics.checkNotNullExpressionValue(uri, "authUrl.toString()");
        String str = l.a.c;
        Intrinsics.checkNotNullParameter(this, "context");
        Intrinsics.checkNotNullParameter(uri, "authUrl");
        Intrinsics.checkNotNullParameter(str, "authCallbackUrl");
        Intent intent = new Intent((Context) this, (Class<?>) FitbitAuthActivity.class);
        intent.putExtra("param_url_auth", uri);
        intent.putExtra("param_url_auth_callback", str);
        startActivity(intent);
    }

    public final void connectGoogleFit() {
        d.d("GoogleFit").a("connectGoogleFit", new Object[0]);
        GoogleSignInOptions build = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).addExtension(this.googleFitFitnessOptions).build();
        Intrinsics.checkNotNullExpressionValue(build, "Builder(GoogleSignInOpti…ons)\n            .build()");
        startActivityForResult(GoogleSignIn.getClient(this, build).getSignInIntent(), 3);
    }

    public final List<RecordRequestItem> ensurePeriodSize(List<RecordRequestItem> list, int i) {
        Intrinsics.checkNotNullParameter(list, "sortedList");
        ArrayList arrayList = new ArrayList();
        Calendar calendar = Calendar.getInstance();
        calendar.add(5, -1);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        List<RecordRequestItem> list2 = list;
        int c = w0.c(f0.k(list2, 10));
        if (c < 16) {
            c = 16;
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap(c);
        for (Object obj : list2) {
            linkedHashMap.put(((RecordRequestItem) obj).getDate(), obj);
        }
        for (int i2 = 0; i2 < i; i2++) {
            String format = simpleDateFormat.format(calendar.getTime());
            DateFormat dateFormat = a.a;
            Intrinsics.checkNotNullExpressionValue(format, "dateStr");
            RecordRequestItem recordRequestItem = (RecordRequestItem) linkedHashMap.get(a.b(format));
            if (recordRequestItem != null) {
                arrayList.add(recordRequestItem);
            } else {
                String lowerCase = "STEPS".toLowerCase(Locale.ROOT);
                Intrinsics.checkNotNullExpressionValue(lowerCase, "toLowerCase(...)");
                arrayList.add(new RecordRequestItem(lowerCase, "0", a.b(format), String.valueOf(10)));
            }
            calendar.add(5, -1);
        }
        return CollectionsKt.R(arrayList, new k(18));
    }

    public final void fetchStepsAndCalories(int i, int i2, Function1<? super Pair<? extends List<RecordRequestItem>, String>, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        ArrayList arrayList = new ArrayList();
        kotlin.jvm.internal.b0 b0Var = new kotlin.jvm.internal.b0();
        kotlin.jvm.internal.b0 b0Var2 = new kotlin.jvm.internal.b0();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(5, 0);
        long timeInMillis = calendar.getTimeInMillis();
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTimeInMillis(timeInMillis);
        calendar2.add(5, -7);
        calendar2.set(11, 0);
        calendar2.set(12, 0);
        calendar2.set(13, 0);
        calendar2.set(14, 0);
        long timeInMillis2 = calendar2.getTimeInMillis();
        et.a d2 = d.d("DateLogger");
        StringBuilder g = e.g("date is one ", timeInMillis2, " - ");
        g.append(timeInMillis);
        d2.a(g.toString(), new Object[0]);
        LocalDataReadRequest.Builder aggregate = new LocalDataReadRequest.Builder().aggregate(LocalDataType.TYPE_STEP_COUNT_DELTA);
        TimeUnit timeUnit = TimeUnit.DAYS;
        LocalDataReadRequest.Builder bucketByTime = aggregate.bucketByTime(1, timeUnit);
        TimeUnit timeUnit2 = TimeUnit.MILLISECONDS;
        LocalDataReadRequest build = bucketByTime.setTimeRange(timeInMillis2, timeInMillis, timeUnit2).build();
        Intrinsics.checkNotNullExpressionValue(build, "Builder()\n            .a…NDS)\n            .build()");
        LocalDataReadRequest build2 = new LocalDataReadRequest.Builder().aggregate(LocalDataType.TYPE_CALORIES_EXPENDED).bucketByTime(1, timeUnit).setTimeRange(timeInMillis2, timeInMillis, timeUnit2).build();
        Intrinsics.checkNotNullExpressionValue(build2, "Builder()\n            .a…NDS)\n            .build()");
        LocalRecordingClient localRecordingClient = FitnessLocal.getLocalRecordingClient(this);
        Intrinsics.checkNotNullExpressionValue(localRecordingClient, "getLocalRecordingClient(this)");
        localRecordingClient.readData(build).addOnSuccessListener(new h(6, new g(i, i2, this, arrayList, function1, b0Var, b0Var2))).addOnFailureListener(new d(i2, 0, this, arrayList, function1, b0Var, b0Var2));
        localRecordingClient.readData(build2).addOnSuccessListener(new h(7, new q(b0Var2, this, arrayList, i2, b0Var, function1))).addOnFailureListener(new d(i2, 1, this, arrayList, function1, b0Var2, b0Var));
    }

    public final String formatDateFromMilliseconds(long j) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:00", Locale.getDefault()).format(Long.valueOf(j));
        Intrinsics.checkNotNullExpressionValue(format, "localFormatter.format(milliseconds)");
        return format;
    }

    public final Pair<Long, Long> getTimeInterval() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.add(6, 1);
        long timeInMillis = calendar.getTimeInMillis();
        calendar.add(4, -1);
        calendar.add(5, -2);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        long timeInMillis2 = calendar.getTimeInMillis();
        d.d("DateLogger").a("date is " + new Date(timeInMillis2) + " - " + new Date(timeInMillis), new Object[0]);
        return new Pair<>(Long.valueOf(timeInMillis2), Long.valueOf(timeInMillis));
    }

    public boolean hasFitbitConnected() {
        return s.l().b.b();
    }

    public final boolean isGoogleFitInstalled() {
        boolean z;
        try {
            z = getPackageManager().getApplicationInfo("com.google.android.apps.fitness", 0).enabled;
        } catch (PackageManager.NameNotFoundException unused) {
            z = false;
        }
        d.d("GoogleFit").a(og.m.i("isGoogleFitInstalled ", z), new Object[0]);
        return z;
    }

    public final boolean isSameDate(String str) {
        Intrinsics.checkNotNullParameter(str, "dateStr");
        Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse(str);
        Calendar calendar = Calendar.getInstance();
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return parse != null && parse.getTime() == calendar.getTime().getTime();
    }

    public final void linkToInstallGoogleFit() {
        fs.d.C(this, "com.google.android.apps.fitness");
    }

    public void onFitbitConnectError() {
    }

    public void onFitbitConnectSuccess() {
    }

    public final void readDailyCaloriesLogFromGoogleFit(Function1<? super Integer, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        DataType dataType = DataType.AGGREGATE_CALORIES_EXPENDED;
        Intrinsics.checkNotNullExpressionValue(dataType, "AGGREGATE_CALORIES_EXPENDED");
        u(dataType, new i(this, function1, 0));
    }

    public final void readDailyCaloriesLogFromGoogleFitForSevenDays(int i, Function1<? super Pair<? extends List<RecordRequestItem>, String>, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        DataSource build = new DataSource.Builder().setDataType(DataType.TYPE_CALORIES_EXPENDED).setType(1).setStreamName("hydrationSource").setAppPackageName("com.google.android.gms").build();
        Intrinsics.checkNotNullExpressionValue(build, "Builder()\n            .s…ms\")\n            .build()");
        DataReadRequest.Builder builder = new DataReadRequest.Builder();
        DataType dataType = DataType.AGGREGATE_CALORIES_EXPENDED;
        DataReadRequest build2 = builder.aggregate(build, dataType).bucketByTime(1, TimeUnit.DAYS).setTimeRange(((Number) getTimeInterval().d).longValue(), ((Number) getTimeInterval().e).longValue(), TimeUnit.MILLISECONDS).build();
        Intrinsics.checkNotNullExpressionValue(build2, "Builder()\n            .a…NDS)\n            .build()");
        Intrinsics.checkNotNullExpressionValue(dataType, "AGGREGATE_CALORIES_EXPENDED");
        v(build2, i, dataType, new i(this, function1, 1));
    }

    public final void readDailyCaloriesLogFromRecordingApi(Function1<? super Integer, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        long currentTimeMillis = System.currentTimeMillis();
        Calendar calendar = Calendar.getInstance();
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        LocalDataReadRequest build = new LocalDataReadRequest.Builder().aggregate(LocalDataType.TYPE_CALORIES_EXPENDED).bucketByTime(1, TimeUnit.DAYS).setTimeRange(calendar.getTimeInMillis(), currentTimeMillis, TimeUnit.MILLISECONDS).build();
        Intrinsics.checkNotNullExpressionValue(build, "Builder()\n            .a…NDS)\n            .build()");
        LocalRecordingClient localRecordingClient = FitnessLocal.getLocalRecordingClient(this);
        Intrinsics.checkNotNullExpressionValue(localRecordingClient, "getLocalRecordingClient(this)");
        d.d("RecordingApiEnabled").a("syncUserRecordedData: Steps has been Updated on the Caliories  ", new Object[0]);
        localRecordingClient.readData(build).addOnSuccessListener(new h(4, new l1(3, function1))).addOnFailureListener(new h(5, function1));
    }

    public final void readDailyFloorsLogFromFitbit(Function1<? super Integer, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        s.l().c(function1);
    }

    public final void readDailyLogForSevenDaysRecordingApi(int i, Function1<? super Pair<? extends List<RecordRequestItem>, String>, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.add(6, 1);
        long timeInMillis = calendar.getTimeInMillis();
        calendar.add(4, -1);
        calendar.add(5, -1);
        long timeInMillis2 = calendar.getTimeInMillis();
        d.d("DateLogger").a("date is " + new Date(timeInMillis2) + " - " + new Date(timeInMillis), new Object[0]);
        LocalDataReadRequest build = new LocalDataReadRequest.Builder().aggregate(LocalDataType.TYPE_STEP_COUNT_DELTA).bucketByTime(1, TimeUnit.DAYS).setTimeRange(timeInMillis2, timeInMillis, TimeUnit.MILLISECONDS).build();
        Intrinsics.checkNotNullExpressionValue(build, "Builder()\n            .a…NDS)\n            .build()");
        LocalRecordingClient localRecordingClient = FitnessLocal.getLocalRecordingClient(this);
        Intrinsics.checkNotNullExpressionValue(localRecordingClient, "getLocalRecordingClient(this)");
        localRecordingClient.readData(build).addOnSuccessListener(new h(8, new a2(this, i, function1, 4))).addOnFailureListener(new h(9, function1));
    }

    public final void readDailyStepsFromTheRecordingApi(Function1<? super Integer, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        long timeInMillis = calendar.getTimeInMillis();
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTimeInMillis(timeInMillis);
        calendar2.set(11, 0);
        calendar2.set(12, 0);
        calendar2.set(13, 0);
        calendar2.set(14, 0);
        long timeInMillis2 = calendar2.getTimeInMillis();
        et.a d2 = d.d("CodeChecking");
        StringBuilder g = e.g("the start time is ", timeInMillis2, "  and end time is ");
        g.append(timeInMillis);
        d2.c(g.toString(), new Object[0]);
        LocalDataReadRequest build = new LocalDataReadRequest.Builder().aggregate(LocalDataType.TYPE_STEP_COUNT_DELTA).bucketByTime(1, TimeUnit.DAYS).setTimeRange(timeInMillis2, timeInMillis, TimeUnit.MILLISECONDS).build();
        Intrinsics.checkNotNullExpressionValue(build, "Builder()\n            .a…NDS)\n            .build()");
        LocalRecordingClient localRecordingClient = FitnessLocal.getLocalRecordingClient(this);
        Intrinsics.checkNotNullExpressionValue(localRecordingClient, "getLocalRecordingClient(this)");
        localRecordingClient.readData(build).addOnSuccessListener(new h(2, new l1(4, function1))).addOnFailureListener(new h(3, function1));
    }

    public final void readDailyStepsLogFromFitbit(Function1<? super Integer, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        s.l().d(function1);
    }

    public final void readDailyStepsLogFromGoogleFit(Function1<? super Integer, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        DataType dataType = DataType.TYPE_STEP_COUNT_DELTA;
        Intrinsics.checkNotNullExpressionValue(dataType, "TYPE_STEP_COUNT_DELTA");
        u(dataType, new i(this, function1, 2));
    }

    public final void readDailyStepsLogFromGoogleFitForSevenDays(int i, Function1<? super Pair<? extends List<RecordRequestItem>, String>, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.add(6, 1);
        long timeInMillis = calendar.getTimeInMillis();
        calendar.add(4, -1);
        calendar.add(5, -1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        long timeInMillis2 = calendar.getTimeInMillis();
        d.d("DateLogger").a("date is " + new Date(timeInMillis2) + " - " + new Date(timeInMillis), new Object[0]);
        DataSource.Builder builder = new DataSource.Builder();
        DataType dataType = DataType.TYPE_STEP_COUNT_DELTA;
        DataSource build = builder.setDataType(dataType).setType(1).setStreamName("estimated_steps").setAppPackageName("com.google.android.gms").build();
        Intrinsics.checkNotNullExpressionValue(build, "Builder()\n            .s…ms\")\n            .build()");
        DataReadRequest build2 = new DataReadRequest.Builder().aggregate(build, DataType.AGGREGATE_STEP_COUNT_DELTA).bucketByTime(1, TimeUnit.DAYS).setTimeRange(timeInMillis2, timeInMillis, TimeUnit.MILLISECONDS).build();
        Intrinsics.checkNotNullExpressionValue(build2, "Builder()\n            .a…NDS)\n            .build()");
        Intrinsics.checkNotNullExpressionValue(dataType, "TYPE_STEP_COUNT_DELTA");
        v(build2, i, dataType, new l1(5, function1));
    }

    public final void readDailyWaterLogFromFitbit(Function1<? super Integer, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        s.l().e(GLASS_VOLUME, function1);
    }

    public final void readDailyWaterLogFromGoogleFit(Function1<? super Integer, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        DataType dataType = DataType.TYPE_HYDRATION;
        Intrinsics.checkNotNullExpressionValue(dataType, "TYPE_HYDRATION");
        u(dataType, new i(this, function1, 3));
    }

    public final void readDailyWaterLogFromGoogleFitForSevenDays(int i, Function1<? super Pair<? extends List<RecordRequestItem>, String>, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "callback");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.add(6, 1);
        long timeInMillis = calendar.getTimeInMillis();
        calendar.add(4, -1);
        calendar.add(5, -1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        long timeInMillis2 = calendar.getTimeInMillis();
        d.d("DateLogger").a("date is " + new Date(timeInMillis2) + " - " + new Date(timeInMillis), new Object[0]);
        DataSource.Builder builder = new DataSource.Builder();
        DataType dataType = DataType.TYPE_HYDRATION;
        DataSource build = builder.setDataType(dataType).setType(1).setStreamName("hydrationSource").setAppPackageName("com.google.android.gms").build();
        Intrinsics.checkNotNullExpressionValue(build, "Builder()\n            .s…ms\")\n            .build()");
        DataReadRequest build2 = new DataReadRequest.Builder().aggregate(build, DataType.AGGREGATE_HYDRATION).bucketByTime(1, TimeUnit.DAYS).setTimeRange(timeInMillis2, timeInMillis, TimeUnit.MILLISECONDS).build();
        Intrinsics.checkNotNullExpressionValue(build2, "Builder()\n            .a…NDS)\n            .build()");
        Intrinsics.checkNotNullExpressionValue(dataType, "TYPE_HYDRATION");
        v(build2, i, dataType, new l1(6, function1));
    }

    public final void s(List list, int i, boolean z, boolean z2, Function1 function1) {
        String str;
        if (z && z2) {
            List<RecordRequestItem> R = CollectionsKt.R(list, new k(17));
            RecordRequestItem recordRequestItem = (RecordRequestItem) CollectionsKt.J(R);
            if (recordRequestItem == null || (str = recordRequestItem.getValue()) == null) {
                str = "0";
            }
            d.d("Record Item Recording API:").a("record is upper " + i + " " + CollectionsKt.b0(R), new Object[0]);
            if (!r1.isEmpty()) {
                R = ensurePeriodSize(CollectionsKt.b0(CollectionsKt.P(R, new IntRange(0, R.size() - 2))), i);
            }
            List<RecordRequestItem> list2 = R;
            d.d("Record Item Recording API:").a("record is upper lower " + i + " " + CollectionsKt.b0(list2), new Object[0]);
            ArrayList t = t(i, CollectionsKt.b0(list2));
            d.d("Record Item Recording API:").a("record is " + i + " " + new o().i(t), new Object[0]);
            function1.invoke(new Pair(t, str));
        }
    }

    public final void signOutFromFitbit() {
        String token;
        i iVar = s.l().b;
        iVar.getClass();
        d.d("FitbitAuthManager").a("logout()", new Object[0]);
        m mVar = iVar.c;
        FitbitAuthToken b = ((ld.a) mVar.getValue()).b();
        if (b != null && (token = b.getToken()) != null) {
            iVar.e.b(new aq.b(1, new aq.e(kotlin.jvm.internal.o.D0(kotlin.jvm.internal.o.S0(((kd.b) iVar.b.getValue()).a(iVar.c(), token))), new xc.a(9, z.S), 0), new f(iVar, 1)).e());
        }
        ((ld.a) mVar.getValue()).a();
    }

    public final void signOutFromGoogle(Function0<Unit> function0, Function0<Unit> function02) {
        Intrinsics.checkNotNullParameter(function0, "onSuccess");
        Intrinsics.checkNotNullParameter(function02, "onFailure");
        d.d("GoogleFit").a("signOut", new Object[0]);
        fs.d.o(this, new h(this, 1));
    }

    public final void u(DataType dataType, i iVar) {
        GoogleSignInAccount accountForExtension = GoogleSignIn.getAccountForExtension(this, this.googleFitFitnessOptions);
        Intrinsics.checkNotNullExpressionValue(accountForExtension, "getAccountForExtension(t… googleFitFitnessOptions)");
        Task readDailyTotal = Fitness.getHistoryClient(this, accountForExtension).readDailyTotal(dataType);
        Intrinsics.checkNotNullExpressionValue(readDailyTotal, "getHistoryClient(this, a….readDailyTotal(dataType)");
        aq.a d2 = a0.d(readDailyTotal);
        Intrinsics.checkNotNullExpressionValue(d2, "just(request)");
        aq.i iVar2 = new aq.i(kotlin.jvm.internal.o.S0(d2), new pe.m(1, new j(readDailyTotal, 0)), 1);
        Intrinsics.checkNotNullExpressionValue(iVar2, "request = Fitness.getHis…, 30, TimeUnit.SECONDS) }");
        aq.e eVar = new aq.e(new aq.e(kotlin.jvm.internal.o.D0(iVar2), new xc.a(3, new k(dataType, iVar, 0)), 2), new xc.a(4, new k(dataType, iVar, 1)), 0);
        Intrinsics.checkNotNullExpressionValue(eVar, "dataType: DataType,\n    …lback(null)\n            }");
        kotlin.jvm.internal.o.Q(eVar);
    }

    public final void v(DataReadRequest dataReadRequest, int i, DataType dataType, Function1 function1) {
        GoogleSignInAccount accountForExtension = GoogleSignIn.getAccountForExtension(this, this.googleFitFitnessOptions);
        Intrinsics.checkNotNullExpressionValue(accountForExtension, "getAccountForExtension(t… googleFitFitnessOptions)");
        Task readData = Fitness.getHistoryClient(this, accountForExtension).readData(dataReadRequest);
        Intrinsics.checkNotNullExpressionValue(readData, "getHistoryClient(this, a…readRequest\n            )");
        aq.a d2 = a0.d(readData);
        Intrinsics.checkNotNullExpressionValue(d2, "just(request)");
        aq.i iVar = new aq.i(kotlin.jvm.internal.o.S0(d2), new pe.m(0, new j(readData, 1)), 1);
        Intrinsics.checkNotNullExpressionValue(iVar, "request = Fitness.getHis…, 30, TimeUnit.SECONDS) }");
        aq.e eVar = new aq.e(new aq.e(kotlin.jvm.internal.o.D0(iVar), new xc.a(1, new n0.j0(dataType, this, i, function1, 4)), 2), new xc.a(2, new k(dataType, function1, 2)), 0);
        Intrinsics.checkNotNullExpressionValue(eVar, "private fun readDataFrom…  .emptySubscribe()\n    }");
        kotlin.jvm.internal.o.Q(eVar);
    }
}