package com.pichillilorenzo.flutter_inappwebview_android;

import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl;
import ed.q;
import ed.t;
import ed.u;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import tv.danmaku.ijk.media.player.IjkMediaMeta;

/* JADX INFO: loaded from: classes.dex */
public class PlatformUtil extends ChannelDelegateImpl {
    protected static final String LOG_TAG = "PlatformUtil";
    public static final String METHOD_CHANNEL_NAME = "com.pichillilorenzo/flutter_inappwebview_platformutil";

    @Nullable
    public InAppWebViewFlutterPlugin plugin;

    public PlatformUtil(InAppWebViewFlutterPlugin inAppWebViewFlutterPlugin) {
        super(new u(inAppWebViewFlutterPlugin.messenger, METHOD_CHANNEL_NAME));
        this.plugin = inAppWebViewFlutterPlugin;
    }

    public static String formatDate(long j10, String str, Locale locale, TimeZone timeZone) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(str, locale);
        simpleDateFormat.setTimeZone(timeZone);
        return simpleDateFormat.format(new Date(j10));
    }

    public static Locale getLocaleFromString(@Nullable String str) {
        if (str == null) {
            return Locale.US;
        }
        String[] strArrSplit = str.split("_");
        return new Locale(strArrSplit[0], strArrSplit.length > 1 ? strArrSplit[1] : "", strArrSplit.length > 2 ? strArrSplit[2] : "");
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl, com.pichillilorenzo.flutter_inappwebview_android.types.Disposable
    public void dispose() {
        super.dispose();
        this.plugin = null;
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl, com.pichillilorenzo.flutter_inappwebview_android.types.IChannelDelegate, ed.s
    public void onMethodCall(@NonNull q qVar, @NonNull t tVar) {
        String str = qVar.f25842a;
        str.getClass();
        if (!str.equals("formatDate")) {
            if (str.equals("getSystemVersion")) {
                tVar.success(String.valueOf(Build.VERSION.SDK_INT));
                return;
            } else {
                tVar.notImplemented();
                return;
            }
        }
        long jLongValue = ((Long) qVar.argument("date")).longValue();
        String str2 = (String) qVar.argument(IjkMediaMeta.IJKM_KEY_FORMAT);
        Locale localeFromString = getLocaleFromString((String) qVar.argument("locale"));
        String str3 = (String) qVar.argument("timezone");
        if (str3 == null) {
            str3 = "UTC";
        }
        tVar.success(formatDate(jLongValue, str2, localeFromString, TimeZone.getTimeZone(str3)));
    }
}
