Swiggy v4.51.1版本的 MD5 值为:5af7ec91512a0a8c1510e3f8bac20b8b

以下内容为反编译后的 WebviewViewModel.java 源代码,内容仅作参考


package in.swiggy.android.feature.web.viewmodel;

import android.content.SharedPreferences;
import android.webkit.CookieManager;
import android.webkit.WebView;
import androidx.databinding.ObservableBoolean;
import com.rudderstack.android.sdk.core.MessageType;
import com.xiaomi.mipush.sdk.Constants;
import in.juspay.hyper.constants.Labels;
import in.swiggy.android.R;
import in.swiggy.android.SwiggyApplication;
import in.swiggy.android.apputils.r;
import in.swiggy.android.apputils.web.CallerContext;
import in.swiggy.android.commons.utils.x;
import in.swiggy.android.mvvm.services.t;
import in.swiggy.android.mvvm.viewmodels.z0;
import in.swiggy.android.tejas.network.HttpRequest;
import in.swiggy.koordinates.core.f;
import java.net.URL;
import java.util.HashMap;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.o;
import kotlin.text.Regex;
import kotlin.text.StringsKt__StringsKt;
import kotlin.text.q;
public final class WebviewViewModel extends z0 {
    public static final a S0 = new a(null);
    public static final int T0 = 8;
    private final Boolean A0;
    public in.swiggy.android.repositories.nps.service.a B0;
    public in.swiggy.android.repositories.nps.repository.a C0;
    public in.swiggy.android.feature.web.a D0;
    public SharedPreferences E0;
    private final ObservableBoolean F0;
    private final ObservableBoolean G0;
    private final ObservableBoolean H0;
    private final ObservableBoolean I0;
    private String J0;
    private t K0;
    private boolean L0;
    private final in.swiggy.android.viewmodelfactoryutils.b M0;
    private final ObservableBoolean N0;
    private final HashMap<String, String> O0;
    private String P0;
    private final ObservableBoolean Q0;
    private final Function0<Unit> R0;
    private final in.swiggy.android.feature.web.service.b X;
    private final CallerContext Y;
    private String Z;
    private String c0;
    private final String p0;
    private final String y0;
    private final String z0;

    public static final class a {
        public a(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private a() {
        }
    }

    public class b {
        public static final int[] a;

        static {
            int[] iArr = new int[CallerContext.values().length];
            try {
                iArr[CallerContext.NPS.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[CallerContext.WEBLINK.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[CallerContext.DELIVERY_INSTRUCTIONS.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[CallerContext.SUPER_LANDING.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                iArr[CallerContext.SUPER_PLAN.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                iArr[CallerContext.MENU_HYGIENE.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                iArr[CallerContext.MENU_STORY.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                iArr[CallerContext.SWIGGY_PWA.ordinal()] = 8;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                iArr[CallerContext.SWIGGY_PAY.ordinal()] = 9;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                iArr[CallerContext.GAMIFICATION.ordinal()] = 10;
            } catch (NoSuchFieldError unused10) {
            }
            try {
                iArr[CallerContext.RESTAURANT_INFO.ordinal()] = 11;
            } catch (NoSuchFieldError unused11) {
            }
            try {
                iArr[CallerContext.OTHER.ordinal()] = 12;
            } catch (NoSuchFieldError unused12) {
            }
            try {
                iArr[CallerContext.LAZYPAY.ordinal()] = 13;
            } catch (NoSuchFieldError unused13) {
            }
            a = iArr;
        }
    }

    public WebviewViewModel(in.swiggy.android.feature.web.service.b mWebviewActivityService, CallerContext callerContext, String str, String str2, String str3, String str4, String str5, Boolean bool) {
        super(mWebviewActivityService);
        o.k(mWebviewActivityService, "mWebviewActivityService");
        o.k(callerContext, "callerContext");
        this.X = mWebviewActivityService;
        this.Y = callerContext;
        this.Z = str;
        this.c0 = str2;
        this.p0 = str3;
        this.y0 = str4;
        this.z0 = str5;
        this.A0 = bool;
        this.F0 = new ObservableBoolean(false);
        this.G0 = new ObservableBoolean(false);
        this.H0 = new ObservableBoolean(false);
        this.I0 = new ObservableBoolean(false);
        this.M0 = new in.swiggy.android.viewmodelfactoryutils.b(R.drawable.connection_error, null);
        this.N0 = new ObservableBoolean(false);
        this.O0 = new HashMap<>();
        this.Q0 = new ObservableBoolean(true);
        this.R0 = new Function0<Unit>() {
            {
                super(0);
            }

            @Override
            public Unit invoke() {
                invoke2();
                return Unit.a;
            }

            public final void invoke2() {
                WebviewViewModel.this.g8().h(false);
                WebviewViewModel.this.F8();
            }
        };
    }

    private final void A8() {
        String str = this.Z;
        String K = u7().K();
        String str2 = this.p0;
        String str3 = this.y0;
        String customerId = u7().getCustomerId();
        this.Z = str + "?email=" + K + "&source=" + str2 + "&order_id=" + str3 + "&user_id=" + customerId;
    }

    private final void B8() {
        f a2 = o7().getLocation().getValue().a();
        double a3 = a2.a();
        double b2 = a2.b();
        this.O0.put("lat", String.valueOf(a3));
        this.O0.put("lng", String.valueOf(b2));
        if (a3 == 0.0d || b2 == 0.0d) {
            HashMap hashMap = new HashMap();
            hashMap.put("lat", String.valueOf(a3));
            hashMap.put("lng", String.valueOf(b2));
            v7().c("empty_lat_long", hashMap);
        }
    }

    private final void D8() {
        this.O0.put("platform", "Swiggy-Android");
        this.O0.put("analytics_platform", "an");
        this.O0.put("version_code", "1202");
    }

    public final void F8() {
        Boolean bool;
        String str;
        boolean U;
        String str2;
        boolean U2;
        String str3;
        boolean U3;
        boolean U4;
        String str4;
        boolean U5;
        String str5;
        boolean U6;
        String str6;
        this.F0.h(true);
        switch (b.a[this.Y.ordinal()]) {
            case 1:
                this.L0 = true;
                s7().j(s7().r("nps", "impression-nps-webview-opened", this.z0, this.y0, "-"));
                this.c0 = p7().getString(R.string.nps_redirect_url);
                String str7 = this.p0;
                if (str7 != null) {
                    i8().c();
                    if (o.f(str7, "account")) {
                        str = this.Z + "email=" + u7().K() + "&source=android-account&user_id=" + u7().getCustomerId() + "&app_version=1202";
                        break;
                    } else if (o.f(str7, MessageType.TRACK)) {
                        str = this.Z + "email=" + u7().K() + "&source=android-track&order_id=" + this.y0 + "&user_id=" + u7().getCustomerId() + "&app_version=1202";
                        break;
                    } else {
                        str = this.Z + "&userAgent=Swiggy-Android&appVersion=4.51.1";
                        break;
                    }
                }
                str = this.Z + "&userAgent=Swiggy-Android&appVersion=4.51.1";
                this.Z = str;
                break;
            case 2:
                if (v8()) {
                    if (w8() && (str3 = this.Z) != null) {
                        U3 = StringsKt__StringsKt.U(str3, "?", false, 2, null);
                        if (!U3) {
                            A8();
                        }
                    }
                } else {
                    String str8 = this.Z;
                    if (str8 != null) {
                        U = StringsKt__StringsKt.U(str8, ".swiggy.com", false, 2, null);
                        if (U && (str2 = this.Z) != null) {
                            U2 = StringsKt__StringsKt.U(str2, "?", false, 2, null);
                            if (!U2) {
                                A8();
                            }
                        }
                    }
                }
                this.X.p6(this.Z);
                this.L0 = true;
                break;
            case 3:
                if (v8()) {
                    if (w8() && (str5 = this.Z) != null) {
                        U6 = StringsKt__StringsKt.U(str5, "?", false, 2, null);
                        if (!U6) {
                            A8();
                        }
                    }
                } else {
                    String str9 = this.Z;
                    if (str9 != null) {
                        U4 = StringsKt__StringsKt.U(str9, ".swiggy.com", false, 2, null);
                        if (U4 && (str4 = this.Z) != null) {
                            U5 = StringsKt__StringsKt.U(str4, "?", false, 2, null);
                            if (!U5) {
                                A8();
                            }
                        }
                    }
                }
                CookieManager.getInstance().removeAllCookie();
                this.O0.put(HttpRequest.SWIGGY_HEADER_UID, this.X.K6());
                HashMap<String, String> hashMap = this.O0;
                String deviceId = u7().getDeviceId();
                o.j(deviceId, "getDeviceId(...)");
                hashMap.put(HttpRequest.SWIGGY_HEADER_DEVICE_ID, deviceId);
                this.O0.put("analytics_launch_screen", "");
                G8();
                D8();
                B8();
                this.L0 = false;
                break;
            case 4:
                this.X.f0(r0().n(R.color.super_default_bg_color));
                CookieManager.getInstance().removeAllCookie();
                this.O0.put(HttpRequest.SWIGGY_HEADER_UID, this.X.K6());
                this.O0.put("analytics_launch_screen", "");
                G8();
                D8();
                B8();
                break;
            case 5:
                this.X.f0(r0().n(R.color.super_default_bg_color));
                this.O0.put("analytics_launch_screen", "");
                CookieManager.getInstance().removeAllCookie();
                G8();
                D8();
                B8();
                break;
            case 6:
                G8();
                D8();
                break;
            case 7:
                CookieManager.getInstance().removeAllCookie();
                this.O0.put(HttpRequest.SWIGGY_HEADER_UID, this.X.K6());
                this.O0.put("analytics_launch_screen", "");
                G8();
                D8();
                B8();
                this.L0 = true;
                break;
            case 8:
                G8();
                break;
            case 9:
                if (o.f(j8().getString("swiggy_pay_specific_cookie_clear_enable", "true"), "true")) {
                    in.swiggy.android.feature.web.a p8 = p8();
                    if (p8 != null && (str6 = p8.m) != null) {
                        b8(str6);
                    }
                } else {
                    CookieManager.getInstance().removeAllCookie();
                }
                G8();
                D8();
                B8();
                this.L0 = false;
                this.F0.h(false);
                break;
            case 10:
                G8();
                D8();
                B8();
                this.L0 = true;
                this.Q0.h(false);
                break;
            case 11:
                G8();
                D8();
                B8();
                HashMap<String, String> hashMap2 = this.O0;
                String deviceId2 = u7().getDeviceId();
                o.j(deviceId2, "getDeviceId(...)");
                hashMap2.put(HttpRequest.SWIGGY_HEADER_DEVICE_ID, deviceId2);
                this.L0 = false;
                break;
            case 12:
                this.L0 = false;
                if (w8()) {
                    this.O0.put(HttpRequest.SWIGGY_HEADER_UID, this.X.K6());
                    HashMap<String, String> hashMap3 = this.O0;
                    String deviceId3 = u7().getDeviceId();
                    o.j(deviceId3, "getDeviceId(...)");
                    hashMap3.put(HttpRequest.SWIGGY_HEADER_DEVICE_ID, deviceId3);
                    G8();
                    D8();
                    B8();
                    break;
                }
                break;
        }
        if (this.A0 != null) {
            this.L0 = !bool.booleanValue();
        }
        H8();
    }

    private final void G8() {
        HashMap<String, String> hashMap = this.O0;
        String tid = u7().getTid();
        o.j(tid, "getTid(...)");
        hashMap.put(HttpRequest.TID_KEY, tid);
        HashMap<String, String> hashMap2 = this.O0;
        String token = u7().getToken();
        o.j(token, "getToken(...)");
        hashMap2.put("token", token);
        HashMap<String, String> hashMap3 = this.O0;
        String sessionId = u7().getSessionId();
        o.j(sessionId, "getSessionId(...)");
        hashMap3.put(HttpRequest.SWIGGY_HEADER_SID, sessionId);
    }

    private final void H8() {
        this.X.e2();
        this.X.p4();
        WebView.setWebContentsDebuggingEnabled(false);
        String str = this.Z;
        HashMap<String, String> hashMap = this.O0;
        r.z(str + "   " + hashMap);
        switch (b.a[this.Y.ordinal()]) {
            case 3:
                this.X.W0(this.Z, this.O0);
                return;
            case 4:
                this.X.W0(p8().f, this.O0);
                return;
            case 5:
                this.X.W0(p8().g, this.O0);
                return;
            case 6:
                this.X.W0(this.Z, this.O0);
                return;
            case 7:
                this.X.W0(this.Z, this.O0);
                return;
            case 8:
                this.X.W0(this.Z, this.O0);
                return;
            case 9:
                x8();
                return;
            case 10:
                this.X.W0(this.Z, this.O0);
                return;
            case 11:
                this.X.W0(this.Z, this.O0);
                return;
            case 12:
                this.X.W0(this.Z, this.O0);
                return;
            default:
                this.X.p6(this.Z);
                return;
        }
    }

    public final void I8() {
        G8();
        H8();
        this.X.W0(p8().g, this.O0);
    }

    private final void b8(String str) {
        CookieManager cookieManager = CookieManager.getInstance();
        String cookie = cookieManager.getCookie(str);
        if (cookie != null) {
            for (String str2 : (String[]) new Regex(";").k(cookie, 0).toArray(new String[0])) {
                cookieManager.setCookie(str, ((String[]) new Regex("=").k(str2, 0).toArray(new String[0]))[0] + "=;");
            }
        }
    }

    public static final void r8(Function0 tmp0) {
        o.k(tmp0, "$tmp0");
        tmp0.invoke();
    }

    public static final void s8(Function0 tmp0) {
        o.k(tmp0, "$tmp0");
        tmp0.invoke();
    }

    public static final void t8(Function1 tmp0, Object obj) {
        o.k(tmp0, "$tmp0");
        tmp0.invoke(obj);
    }

    public static final void u8(Function1 tmp0, Object obj) {
        o.k(tmp0, "$tmp0");
        tmp0.invoke(obj);
    }

    private final boolean v8() {
        if (o.f(j8().getString("swiggy_domain_check_on_swiggy_pay_enabled", "true"), "true")) {
            return true;
        }
        return false;
    }

    private final boolean w8() {
        boolean y;
        String str = this.Z;
        if (str != null) {
            try {
                String host = new URL(str).getHost();
                o.h(host);
                y = q.y(host, ".swiggy.com", false, 2, null);
                if (y) {
                    return true;
                }
            } catch (Exception e) {
                x.i("WebviewViewModel", e);
            }
        }
        return false;
    }

    private final void x8() {
        if (v8()) {
            if (w8()) {
                this.X.W0(this.Z, this.O0);
                return;
            } else {
                this.X.p6(this.Z);
                return;
            }
        }
        this.X.W0(this.Z, this.O0);
    }

    public final void C8(t tVar) {
        this.K0 = tVar;
    }

    public final void E8(boolean z) {
        this.L0 = z;
    }

    @Override
    public void J6() {
        super.J6();
        this.X.onDestroy();
    }

    @Override
    public void O6() {
        super.O6();
        SwiggyApplication.a aVar = SwiggyApplication.J;
        this.P0 = aVar.a();
        aVar.d(null);
    }

    @Override
    public void Q6() {
        super.Q6();
        SwiggyApplication.J.d(this.P0);
    }

    @Override
    public void U6() {
        s7().m(getScreenName());
    }

    public final void a8(Object... params) {
        o.k(params, "params");
        StringBuilder sb = new StringBuilder();
        sb.append("javascript:try{");
        sb.append("showInfoPopup");
        sb.append("(");
        int length = params.length;
        for (int i = 0; i < length; i++) {
            Object obj = params[i];
            if (obj instanceof String) {
                sb.append("'");
                sb.append((String) obj);
                sb.append("'");
            }
            if (i < params.length - 1) {
                sb.append(Constants.ACCEPT_TIME_SEPARATOR_SP);
            }
        }
        sb.append(")}catch(error){Android.onError(error.message);}");
        this.X.p6(sb.toString());
    }

    public final String c8() {
        return this.J0;
    }

    public final String d8() {
        return this.c0;
    }

    public final ObservableBoolean e8() {
        return this.Q0;
    }

    public final in.swiggy.android.viewmodelfactoryutils.b f8() {
        return this.M0;
    }

    public final ObservableBoolean g8() {
        return this.N0;
    }

    @Override
    public String getScreenName() {
        switch (b.a[this.Y.ordinal()]) {
            case 1:
                return "nps";
            case 2:
            case 12:
                return Labels.Android.WEBVIEW;
            case 3:
                return "chat-webview";
            case 4:
                return "super-landing";
            case 5:
            case 8:
            case 9:
            default:
                return "";
            case 6:
                return "hygiene-rating-page";
            case 7:
                return "menu-story";
            case 10:
                return "gamification";
            case 11:
                return "restaurant-info-webview";
            case 13:
                return "lazy-pay-tnc";
        }
    }

    public final t h8() {
        return this.K0;
    }

    public final in.swiggy.android.repositories.nps.service.a i8() {
        in.swiggy.android.repositories.nps.service.a aVar = this.B0;
        if (aVar != null) {
            return aVar;
        }
        o.C("npsService");
        return null;
    }

    @Override
    public void init() {
        m7().P(this.M0);
        io.reactivex.disposables.a aVar = this.L;
        io.reactivex.d<Boolean> P = u7().T().P(io.reactivex.android.schedulers.a.a());
        final Function1<Boolean, Unit> function1 = new Function1<Boolean, Unit>() {
            {
                super(1);
            }

            public final void a(Boolean bool) {
                WebviewViewModel.this.I8();
            }

            @Override
            public Unit invoke(Boolean bool) {
                a(bool);
                return Unit.a;
            }
        };
        io.reactivex.functions.d<? super Boolean> dVar = new io.reactivex.functions.d() {
            @Override
            public final void accept(Object obj) {
                WebviewViewModel.t8(Function1.this, obj);
            }
        };
        final WebviewViewModel$init$2 webviewViewModel$init$2 = new Function1<Throwable, Unit>() {
            @Override
            public Unit invoke(Throwable th) {
                invoke2(th);
                return Unit.a;
            }

            public final void invoke2(Throwable th) {
                x.i("WebviewViewModel", th);
            }
        };
        aVar.c(P.g0(dVar, new io.reactivex.functions.d() {
            @Override
            public final void accept(Object obj) {
                WebviewViewModel.u8(Function1.this, obj);
            }
        }));
    }

    public final SharedPreferences j8() {
        SharedPreferences sharedPreferences = this.E0;
        if (sharedPreferences != null) {
            return sharedPreferences;
        }
        o.C("sharedPreferences");
        return null;
    }

    public final boolean k8() {
        return this.L0;
    }

    public final ObservableBoolean l8() {
        return this.F0;
    }

    public final ObservableBoolean m8() {
        return this.I0;
    }

    public final ObservableBoolean n8() {
        return this.H0;
    }

    public final ObservableBoolean o8() {
        return this.G0;
    }

    public final in.swiggy.android.feature.web.a p8() {
        in.swiggy.android.feature.web.a aVar = this.D0;
        if (aVar != null) {
            return aVar;
        }
        o.C("webConstants");
        return null;
    }

    public final void q8() {
        this.F0.h(false);
        if (!G().isNetworkAvailable()) {
            this.N0.h(true);
            in.swiggy.android.viewmodelfactoryutils.b bVar = this.M0;
            final Function0<Unit> function0 = this.R0;
            bVar.o7(0, new io.reactivex.functions.a() {
                @Override
                public final void run() {
                    WebviewViewModel.r8(Function0.this);
                }
            }, getScreenName());
            return;
        }
        this.N0.h(true);
        in.swiggy.android.viewmodelfactoryutils.b bVar2 = this.M0;
        final Function0<Unit> function02 = this.R0;
        bVar2.o7(2, new io.reactivex.functions.a() {
            @Override
            public final void run() {
                WebviewViewModel.s8(Function0.this);
            }
        }, getScreenName());
    }

    public final void y8() {
        F8();
    }

    public final void z8(String str) {
        this.J0 = str;
    }
}