package vu2; import android.annotation.SuppressLint; import android.app.Application; 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 android.text.TextUtils; import com.meizu.cloud.pushsdk.notification.model.AdvanceSetting; import com.tencent.open.SocialConstants; import com.tencent.qcloud.core.util.IOUtils; import com.xingin.utils.XYUtilsCenter; import i20.b; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.SimpleTimeZone; import java.util.TimeZone; import kotlin.Metadata; import kotlin.Unit; import kotlin.collections.CollectionsKt__CollectionsKt; import kotlin.io.CloseableKt; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.Lambda; import kotlin.text.StringsKt__StringsKt; import n02.d; import t50.c; import z60.h; @Metadata(bv = {}, d1 = {"\u0000P\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010$\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\t\n\u0002\b\u0004\bÆ\u0002\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b!\u0010\"J$\u0010\b\u001a\u00020\u00072\u0014\u0010\u0004\u001a\u0010\u0012\u0004\u0012\u00020\u0003\u0012\u0006\u0012\u0004\u0018\u00010\u00010\u00022\u0006\u0010\u0006\u001a\u00020\u0005J&\u0010\f\u001a\u00020\u000b2\b\u0010\n\u001a\u0004\u0018\u00010\t2\u0014\u0010\u0004\u001a\u0010\u0012\u0004\u0012\u00020\u0003\u0012\u0006\u0012\u0004\u0018\u00010\u00010\u0002J&\u0010\r\u001a\u00020\u000b2\b\u0010\n\u001a\u0004\u0018\u00010\t2\u0014\u0010\u0004\u001a\u0010\u0012\u0004\u0012\u00020\u0003\u0012\u0006\u0012\u0004\u0018\u00010\u00010\u0002J&\u0010\u000e\u001a\u00020\u000b2\b\u0010\n\u001a\u0004\u0018\u00010\t2\u0014\u0010\u0004\u001a\u0010\u0012\u0004\u0012\u00020\u0003\u0012\u0006\u0012\u0004\u0018\u00010\u00010\u0002JD\u0010\u0016\u001a\u00020\u000b2\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\u000f\u001a\u00020\u00032\u0006\u0010\u0010\u001a\u00020\u00032\u0006\u0010\u0011\u001a\u00020\u00032\u0006\u0010\u0012\u001a\u00020\u00032\u0006\u0010\u0013\u001a\u00020\u00032\n\u0010\u0015\u001a\u0006\u0012\u0002\b\u00030\u0014H\u0003J\u0018\u0010\u0019\u001a\u00020\u00182\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\u0017\u001a\u00020\u0003H\u0002J&\u0010\u001b\u001a\u0010\u0012\u0004\u0012\u00020\u0003\u0012\u0006\u0012\u0004\u0018\u00010\u00010\u001a2\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\u0017\u001a\u00020\u0003H\u0003J\u0010\u0010\u001d\u001a\u00020\u001c2\u0006\u0010\n\u001a\u00020\tH\u0002J\u0010\u0010\u001e\u001a\u00020\u001c2\u0006\u0010\n\u001a\u00020\tH\u0002J\u0010\u0010 \u001a\u00020\u001f2\u0006\u0010\n\u001a\u00020\tH\u0002¨\u0006#"}, d2 = {"Lvu2/f;", "", "Ljava/util/HashMap;", "", "args", "Lt50/a;", "callback", "", "d", "Landroid/content/Context;", "context", "Lt50/c;", "j", h.f160753a, "i", "title", "startData", "endData", "id", "notes", "Ljava/util/ArrayList;", "alarmData", "c", "eventId", "", "g", "", "k", "", "e", y7.f.f156778k, "", "b", "<init>", "()V", "xybridge_library_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: XhsCalendarBridgeUtils.kt */ public final class f { /* renamed from: a reason: collision with root package name */ public static final f f141679a = new f(); /* renamed from: b reason: collision with root package name */ public static final List<String> f141680b = new ArrayList(); @Metadata(bv = {}, d1 = {"\u0000\u000e\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0003\u0010\u0005\u001a\u00020\u00022\b\u0010\u0001\u001a\u0004\u0018\u00010\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lfj2/a;", AdvanceSetting.NETWORK_TYPE, "", "invoke", "(Lfj2/a;)V", "<anonymous>"}, k = 3, mv = {1, 6, 0}) /* compiled from: XhsCalendarBridgeUtils.kt */ public static final class a extends Lambda implements Function1<fj2.a, Unit> { /* renamed from: a reason: collision with root package name */ public final /* synthetic */ t50.a f141681a; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public a(t50.a aVar) { super(1); this.f141681a = aVar; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Unit invoke(fj2.a aVar) { invoke(aVar); return Unit.INSTANCE; } public final void invoke(fj2.a aVar) { if (aVar == null) { this.f141681a.a(c.f132459d.b("denied")); } else if (!aVar.e() && aVar.h()) { this.f141681a.a(c.f132459d.b("denied")); } else if (aVar.e() || aVar.h()) { if (aVar.e() && !f.f141680b.contains(aVar.g())) { f.f141680b.add(aVar.g()); } if (f.f141680b.size() == 2) { this.f141681a.a(c.f132459d.b("authorized")); } } else { this.f141681a.a(c.f132459d.b("restricted")); } } } public final long b(Context context) { TimeZone timeZone = TimeZone.getDefault(); ContentValues contentValues = new ContentValues(); contentValues.put("name", "boohee"); contentValues.put("account_name", "BOOHEE@boohee.com"); contentValues.put("account_type", "com.android.boohee"); contentValues.put("calendar_displayName", "BOOHEE账户"); 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("calendar_timezone", timeZone.getID()); contentValues.put("ownerAccount", "BOOHEE@boohee.com"); contentValues.put("canOrganizerRespond", (Integer) 0); Uri t14 = d.t(context.getContentResolver(), Uri.parse("content://com.android.calendar/calendars").buildUpon().appendQueryParameter("caller_is_syncadapter", "true").appendQueryParameter("account_name", "BOOHEE@boohee.com").appendQueryParameter("account_type", "com.android.boohee").build(), contentValues); if (t14 == null) { return -1; } return ContentUris.parseId(t14); } @SuppressLint({"SimpleDateFormat"}) public final c c(Context context, String str, String str2, String str3, String str4, String str5, ArrayList<?> arrayList) { Uri uri; int e14 = e(context); if (e14 < 0) { return c.f132459d.c(-1, "add event failed"); } Calendar instance = Calendar.getInstance(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); simpleDateFormat.setTimeZone(new SimpleTimeZone(0, "GMT")); instance.setTime(simpleDateFormat.parse(str2)); long time = instance.getTime().getTime(); instance.setTime(simpleDateFormat.parse(str3)); long time2 = instance.getTime().getTime(); ContentValues contentValues = new ContentValues(); contentValues.put("title", str); contentValues.put(SocialConstants.PARAM_COMMENT, str5); contentValues.put("calendar_id", Integer.valueOf(e14)); contentValues.put("dtstart", Long.valueOf(time)); contentValues.put("dtend", Long.valueOf(time2)); contentValues.put("hasAlarm", (Integer) 1); contentValues.put("eventTimezone", TimeZone.getDefault().getID()); if (TextUtils.isEmpty(str4)) { uri = d.t(context.getContentResolver(), Uri.parse("content://com.android.calendar/events"), contentValues); } else { Map<String, Object> k14 = k(context, str4); if (k14 == null || k14.isEmpty()) { return c.f132459d.c(-1, "eventId not found"); } uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, Long.parseLong(str4)); d.H(context.getContentResolver(), uri, contentValues, null, null); } if (uri != null) { for (T t14 : arrayList) { if (t14 instanceof Double) { ContentValues contentValues2 = new ContentValues(); Intrinsics.checkNotNull(uri); contentValues2.put("event_id", Long.valueOf(ContentUris.parseId(uri))); contentValues2.put("minutes", Integer.valueOf((int) t14.doubleValue())); contentValues2.put("method", (Integer) 1); d.t(context.getContentResolver(), Uri.parse("content://com.android.calendar/reminders"), contentValues2); } } } return new c(0, StringsKt__StringsKt.substringAfterLast$default(String.valueOf(uri), (char) IOUtils.DIR_SEPARATOR_UNIX, (String) null, 2, (Object) null), "save success"); } public final void d(HashMap<String, Object> hashMap, t50.a aVar) { Intrinsics.checkNotNullParameter(hashMap, "args"); Intrinsics.checkNotNullParameter(aVar, "callback"); Context h10 = XYUtilsCenter.h(); if (h10 == null) { aVar.a(c.f132459d.c(-1, "activity is null")); } if (h10 != null) { b.f88607a.c(h10, new String[]{"android.permission.WRITE_CALENDAR", "android.permission.READ_CALENDAR"}, new a(aVar)); } } public final int e(Context context) { int f14 = f(context); if (f14 >= 0) { return f14; } if (b(context) >= 0) { return f(context); } return -1; } /* JADX WARNING: Code restructure failed: missing block: B:13:0x0033, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:14:0x0034, code lost: kotlin.io.CloseableKt.closeFinally(r7, r0); */ /* JADX WARNING: Code restructure failed: missing block: B:15:0x0037, code lost: throw r1; */ public final int f(Context context) { Cursor z14 = d.z(context.getContentResolver(), Uri.parse("content://com.android.calendar/calendars"), null, null, null, null); int i10 = -1; if (z14 == null) { CloseableKt.closeFinally(z14, null); return -1; } if (z14.getCount() > 0) { z14.moveToFirst(); i10 = z14.getInt(z14.getColumnIndex("_id")); } CloseableKt.closeFinally(z14, null); return i10; } /* JADX WARNING: Code restructure failed: missing block: B:24:0x0065, code lost: r9 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:25:0x0066, code lost: kotlin.io.CloseableKt.closeFinally(r0, r8); */ /* JADX WARNING: Code restructure failed: missing block: B:26:0x0069, code lost: throw r9; */ public final boolean g(Context context, String str) { Cursor z14 = d.z(context.getContentResolver(), Uri.parse("content://com.android.calendar/events"), null, null, null, null); boolean z15 = false; if (z14 != null) { if (z14.getCount() > 0) { z14.moveToFirst(); boolean z16 = false; while (true) { if (z14.isAfterLast()) { z15 = z16; break; } int i10 = z14.getInt(z14.getColumnIndex("_id")); if (!TextUtils.isEmpty(str) && i10 == Integer.parseInt(str)) { Uri withAppendedId = ContentUris.withAppendedId(Uri.parse("content://com.android.calendar/events"), (long) i10); Intrinsics.checkNotNullExpressionValue(withAppendedId, "withAppendedId(Uri.parse…_EVENT_URL), id.toLong())"); if (d.c(context.getContentResolver(), withAppendedId, null, null) == -1) { break; } z16 = true; } z14.moveToNext(); } } } Unit unit = Unit.INSTANCE; CloseableKt.closeFinally(z14, null); return z15; } public final c h(Context context, HashMap<String, Object> hashMap) { Intrinsics.checkNotNullParameter(hashMap, "args"); fj2.b bVar = fj2.b.f77239f; Application e14 = XYUtilsCenter.e(); Intrinsics.checkNotNullExpressionValue(e14, "getApp()"); if (bVar.n(e14, "android.permission.WRITE_CALENDAR")) { Application e15 = XYUtilsCenter.e(); Intrinsics.checkNotNullExpressionValue(e15, "getApp()"); if (bVar.n(e15, "android.permission.WRITE_CALENDAR")) { try { Object obj = hashMap.get("id"); if (obj != null) { String str = (String) obj; HashMap hashMap2 = new HashMap(); if (context == null || TextUtils.isEmpty(str)) { hashMap2.put("id", str); return new c(-1, hashMap2, "not found"); } hashMap2.put("id", str); Map<String, Object> k14 = k(context, str); if (!(!k14.isEmpty())) { return new c(-1, hashMap2, "eventId not found"); } hashMap2.putAll(k14); return c.f132459d.b(hashMap2); } throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } catch (Exception unused) { return c.f132459d.c(-1, "id is null"); } } } return c.f132459d.c(-1, "permission denied, call authorizeCalendarStatus first please"); } public final c i(Context context, HashMap<String, Object> hashMap) { Intrinsics.checkNotNullParameter(hashMap, "args"); fj2.b bVar = fj2.b.f77239f; Application e14 = XYUtilsCenter.e(); Intrinsics.checkNotNullExpressionValue(e14, "getApp()"); if (bVar.n(e14, "android.permission.WRITE_CALENDAR")) { Application e15 = XYUtilsCenter.e(); Intrinsics.checkNotNullExpressionValue(e15, "getApp()"); if (bVar.n(e15, "android.permission.WRITE_CALENDAR")) { try { Object obj = hashMap.get("id"); if (obj != null) { String str = (String) obj; if (context == null || TextUtils.isEmpty(str)) { return c.f132459d.c(-1, "activity is null"); } if (g(context, str)) { return c.f132459d.b(null); } return c.f132459d.c(-1, "delete failed"); } throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } catch (Exception unused) { return c.f132459d.c(-1, "id is null"); } } } return c.f132459d.c(-1, "permission denied, call authorizeCalendarStatus first please"); } public final c j(Context context, HashMap<String, Object> hashMap) { String str; String str2; String str3; String str4; ArrayList<?> arrayList; Intrinsics.checkNotNullParameter(hashMap, "args"); fj2.b bVar = fj2.b.f77239f; Application e14 = XYUtilsCenter.e(); Intrinsics.checkNotNullExpressionValue(e14, "getApp()"); if (bVar.n(e14, "android.permission.WRITE_CALENDAR")) { Application e15 = XYUtilsCenter.e(); Intrinsics.checkNotNullExpressionValue(e15, "getApp()"); if (bVar.n(e15, "android.permission.WRITE_CALENDAR")) { try { Object obj = hashMap.get("title"); if (obj != null) { String str5 = (String) obj; try { Object obj2 = hashMap.get("startDate"); if (obj2 != null) { str = (String) obj2; try { Object obj3 = hashMap.get("endDate"); if (obj3 != null) { str2 = (String) obj3; try { Object obj4 = hashMap.get("id"); if (obj4 != null) { str3 = (String) obj4; try { Object obj5 = hashMap.get("notes"); if (obj5 != null) { str4 = (String) obj5; try { Object obj6 = hashMap.get("alarm"); if (obj6 != null) { arrayList = (ArrayList) obj6; if (context == null) { return c.f132459d.c(-1, "activity is null"); } return c(context, str5, str, str2, str3, str4, arrayList); } throw new NullPointerException("null cannot be cast to non-null type java.util.ArrayList<*>"); } catch (Exception unused) { arrayList = CollectionsKt__CollectionsKt.arrayListOf(15); } } else { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } } catch (Exception unused2) { str4 = ""; } } else { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } } catch (Exception unused3) { str3 = ""; } } else { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } } catch (Exception unused4) { str2 = ""; } } else { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } } catch (Exception unused5) { str = ""; } } else { throw new NullPointerException("null cannot be cast to non-null type kotlin.String"); } } catch (Exception unused6) { return c.f132459d.c(-1, "title is null"); } } } return c.f132459d.c(-1, "permission denied, call authorizeCalendarStatus first please"); } /* JADX WARNING: Code restructure failed: missing block: B:20:0x00bd, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:21:0x00be, code lost: kotlin.io.CloseableKt.closeFinally(r8, r9); */ /* JADX WARNING: Code restructure failed: missing block: B:22:0x00c1, code lost: throw r0; */ @SuppressLint({"SimpleDateFormat"}) public final Map<String, Object> k(Context context, String str) { Cursor z14 = d.z(context.getContentResolver(), Uri.parse("content://com.android.calendar/events"), null, null, null, null); HashMap hashMap = new HashMap(); if (z14 != null) { if (z14.getCount() > 0) { z14.moveToFirst(); while (true) { if (z14.isAfterLast()) { break; } int i10 = z14.getInt(z14.getColumnIndex("_id")); if (!TextUtils.isEmpty(str) && i10 == Integer.parseInt(str)) { hashMap.put("notes", z14.getString(z14.getColumnIndex(SocialConstants.PARAM_COMMENT))); hashMap.put("title", z14.getString(z14.getColumnIndex("title"))); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); simpleDateFormat.setTimeZone(new SimpleTimeZone(0, "GMT")); String string = z14.getString(z14.getColumnIndex("dtstart")); Intrinsics.checkNotNullExpressionValue(string, "it.getString(it.getColum…Contract.Events.DTSTART))"); hashMap.put("startDate", simpleDateFormat.format(Double.valueOf(Double.parseDouble(string)))); String string2 = z14.getString(z14.getColumnIndex("dtend")); Intrinsics.checkNotNullExpressionValue(string2, "it.getString(it.getColum…arContract.Events.DTEND))"); hashMap.put("endDate", simpleDateFormat.format(Double.valueOf(Double.parseDouble(string2)))); break; } z14.moveToNext(); } } } Unit unit = Unit.INSTANCE; CloseableKt.closeFinally(z14, null); return hashMap; } }