得物.apk(点击下载) / NewReleaseCalendarReminderUtils.java


package com.shizhuang.duapp.modules.productv2.releasecalendar.util;

import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CalendarContract;
import androidx.core.content.ContextCompat;
import com.meituan.robust.ChangeQuickRedirect;
import com.meituan.robust.PatchProxy;
import com.meituan.robust.PatchProxyResult;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import fo.a;
import java.util.Calendar;
import java.util.TimeZone;
import kotlin.Lazy;
import kotlin.LazyKt__LazyJVMKt;
import kotlin.Pair;
import kotlin.Unit;
import kotlin.io.CloseableKt;
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/* compiled from: NewReleaseCalendarReminderUtils.kt */
public final class NewReleaseCalendarReminderUtils {
    private static final Uri CALENDER_EVENT_URL = CalendarContract.Events.CONTENT_URI;
    private static final Uri CALENDER_REMINDER_URL = CalendarContract.Reminders.CONTENT_URI;
    private static final Uri CALENDER_URL = CalendarContract.Calendars.CONTENT_URI;
    @NotNull

    /* renamed from: a  reason: collision with root package name */
    public static final NewReleaseCalendarReminderUtils f24127a = new NewReleaseCalendarReminderUtils();
    public static ChangeQuickRedirect changeQuickRedirect;
    private static final Lazy hourTime$delegate = LazyKt__LazyJVMKt.lazy(NewReleaseCalendarReminderUtils$hourTime$2.INSTANCE);
    private static final Lazy minuteTime$delegate = LazyKt__LazyJVMKt.lazy(NewReleaseCalendarReminderUtils$minuteTime$2.INSTANCE);

    public final void a(@Nullable Context context, @Nullable String str, int i, @Nullable Long l) {
        int i3;
        long j;
        Object[] objArr = {context, str, new Integer(i), l};
        ChangeQuickRedirect changeQuickRedirect2 = changeQuickRedirect;
        Class cls = Integer.TYPE;
        if (!PatchProxy.proxy(objArr, this, changeQuickRedirect2, false, 302952, new Class[]{Context.class, String.class, cls, Long.class}, Void.TYPE).isSupported && context != null) {
            PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context}, this, changeQuickRedirect, false, 302949, new Class[]{Context.class}, cls);
            if (proxy.isSupported) {
                i3 = ((Integer) proxy.result).intValue();
            } else {
                try {
                    if (ContextCompat.checkSelfPermission(context, "android.permission.READ_CALENDAR") == 0) {
                        int b = b(context);
                        if (b >= 0) {
                            i3 = b;
                        } else {
                            PatchProxyResult proxy2 = PatchProxy.proxy(new Object[]{context}, this, changeQuickRedirect, false, 302951, new Class[]{Context.class}, Long.TYPE);
                            if (proxy2.isSupported) {
                                j = ((Long) proxy2.result).longValue();
                            } else {
                                TimeZone timeZone = TimeZone.getDefault();
                                ContentValues contentValues = new ContentValues();
                                contentValues.put("name", "得物");
                                contentValues.put("account_name", "dewu@shizhuang-inc.com");
                                contentValues.put("account_type", "LOCAL");
                                contentValues.put("calendar_displayName", "得物App");
                                contentValues.put("visible", (Integer) 1);
                                contentValues.put("calendar_color", (Integer) -16776961);
                                contentValues.put("calendar_access_level", (Integer) 700);
                                contentValues.put("sync_events", (Integer) 1);
                                contentValues.put("ownerAccount", "dewu@shizhuang-inc.com");
                                contentValues.put("canOrganizerRespond", (Integer) 0);
                                contentValues.put("name", "得物");
                                contentValues.put("calendar_timezone", timeZone.getID());
                                Uri insert = context.getContentResolver().insert(CALENDER_URL.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").appendQueryParameter("account_name", "dewu@shizhuang-inc.com").appendQueryParameter("account_type", "dewu@shizhuang-inc.com").build(), contentValues);
                                if (insert == null) {
                                    j = -1;
                                } else {
                                    j = ContentUris.parseId(insert);
                                }
                            }
                            if (j >= 0) {
                                i3 = b(context);
                            }
                        }
                    }
                } catch (RuntimeException unused) {
                    a.i("read permission is null", new Object[0]);
                }
                i3 = -1;
            }
            if (i3 >= 0) {
                try {
                    if (ContextCompat.checkSelfPermission(context, "android.permission.WRITE_CALENDAR") == 0) {
                        Long valueOf = (l != null && l.longValue() == 0) ? Long.valueOf(Calendar.getInstance().getTimeInMillis()) : l;
                        ContentValues contentValues2 = new ContentValues();
                        contentValues2.put(PushConstants.TITLE, str);
                        contentValues2.put("description", "");
                        contentValues2.put("calendar_id", Integer.valueOf(i3));
                        contentValues2.put("dtstart", valueOf);
                        contentValues2.put("dtend", valueOf);
                        contentValues2.put("original_id", Integer.valueOf(i));
                        contentValues2.put("hasAlarm", (Integer) 1);
                        contentValues2.put("eventTimezone", TimeZone.getDefault().getID());
                        Uri insert2 = context.getContentResolver().insert(CalendarContract.Events.CONTENT_URI, contentValues2);
                        if (insert2 != null) {
                            long parseId = ContentUris.parseId(insert2);
                            ContentValues contentValues3 = new ContentValues();
                            contentValues3.put("event_id", Long.valueOf(parseId));
                            contentValues3.put("minutes", (Integer) 5);
                            contentValues3.put(PushConstants.MZ_PUSH_MESSAGE_METHOD, (Integer) 1);
                            Uri insert3 = context.getContentResolver().insert(CALENDER_REMINDER_URL, contentValues3);
                            if (insert3 != null) {
                                ContentUris.parseId(insert3);
                            }
                        }
                    }
                } catch (RuntimeException unused2) {
                    a.i("write permission is null", new Object[0]);
                }
            }
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:17:0x0059, code lost:
        r1 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:18:0x005a, code lost:
        kotlin.io.CloseableKt.closeFinally(r0, r9);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:19:0x005d, code lost:
        throw r1;
     */
    public final int b(Context context) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context}, this, changeQuickRedirect, false, 302950, new Class[]{Context.class}, Integer.TYPE);
        if (proxy.isSupported) {
            return ((Integer) proxy.result).intValue();
        }
        Cursor query = context.getContentResolver().query(CALENDER_URL, new String[]{"_id"}, null, null, null, null);
        int i = -1;
        if (query == null) {
            CloseableKt.closeFinally(query, null);
            return -1;
        }
        if (query.getCount() > 0) {
            query.moveToFirst();
            i = query.getInt(query.getColumnIndexOrThrow("_id"));
        }
        CloseableKt.closeFinally(query, null);
        return i;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:35:0x00ac, code lost:
        r12 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:36:0x00ad, code lost:
        kotlin.io.CloseableKt.closeFinally(r0, r11);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:37:0x00b0, code lost:
        throw r12;
     */
    public final void c(@Nullable Context context, @NotNull String str, int i) {
        if (!PatchProxy.proxy(new Object[]{context, str, new Integer(i)}, this, changeQuickRedirect, false, 302953, new Class[]{Context.class, String.class, Integer.TYPE}, Void.TYPE).isSupported && context != null) {
            Cursor query = context.getContentResolver().query(CALENDER_EVENT_URL, null, null, null, null);
            if (query == null) {
                CloseableKt.closeFinally(query, null);
                return;
            }
            if (query.getCount() > 0) {
                query.moveToFirst();
                while (!query.isAfterLast()) {
                    String string = query.getString(query.getColumnIndex(PushConstants.TITLE));
                    if (query.getInt(query.getColumnIndex("original_id")) == i) {
                        if ((str.length() > 0) && Intrinsics.areEqual(str, string)) {
                            if (context.getContentResolver().delete(ContentUris.withAppendedId(CALENDER_EVENT_URL, query.getLong(query.getColumnIndex("_id"))), null, null) == -1) {
                                CloseableKt.closeFinally(query, null);
                                return;
                            }
                        }
                    }
                    query.moveToNext();
                }
            }
            Unit unit = Unit.INSTANCE;
            CloseableKt.closeFinally(query, null);
        }
    }

    public final long d() {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 302947, new Class[0], Long.TYPE);
        return proxy.isSupported ? ((Long) proxy.result).longValue() : ((Number) hourTime$delegate.getValue()).longValue();
    }

    @NotNull
    public final Pair<Long, Boolean> e(long j, long j12) {
        long j13;
        Object[] objArr = {new Long(j), new Long(j12)};
        ChangeQuickRedirect changeQuickRedirect2 = changeQuickRedirect;
        Class cls = Long.TYPE;
        PatchProxyResult proxy = PatchProxy.proxy(objArr, this, changeQuickRedirect2, false, 302954, new Class[]{cls, cls}, Pair.class);
        if (proxy.isSupported) {
            return (Pair) proxy.result;
        }
        long abs = Math.abs(j);
        PatchProxyResult proxy2 = PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 302948, new Class[0], cls);
        if (abs <= (proxy2.isSupported ? ((Long) proxy2.result).longValue() : ((Number) minuteTime$delegate.getValue()).longValue())) {
            return new Pair<>(Long.valueOf(j12), Boolean.TRUE);
        }
        if (Math.abs(j) <= d()) {
            if (j < 0) {
                j13 = j12 - Math.abs(j);
            } else {
                j13 = Math.abs(j) + j12;
            }
            return new Pair<>(Long.valueOf(j13), Boolean.TRUE);
        } else if (Math.abs(j) > d()) {
            return new Pair<>(0L, Boolean.FALSE);
        } else {
            return new Pair<>(0L, Boolean.FALSE);
        }
    }
}