package com.ss.android.ugc.aweme.poi.service;

import X.07U;
import X.0AA;
import X.0AP;
import X.0HH;
import X.2FV;
import X.2HN;
import X.2He;
import X.2Pr;
import X.2UX;
import X.2nK;
import X.4OS;
import X.7s1;
import X.8jA;
import X.9EH;
import X.B9Q;
import X.B9R;
import X.BBP;
import X.BBQ;
import X.BE8;
import X.BE9;
import X.BFA;
import X.BFF;
import X.BFG;
import X.BFH;
import X.BFI;
import X.BFM;
import X.BFN;
import X.BFO;
import X.BFP;
import X.BFW;
import X.BGC;
import X.BGG;
import X.C01139qj;
import X.C1683AgB;
import X.C2745AxJ;
import X.C3150B9e;
import X.C3151B9f;
import X.C3185BAn;
import X.C3797BYb;
import X.CwZ;
import X.D1G;
import X.ESC;
import X.KEM;
import X.LWw;
import X.LWx;
import X.LnI;
import X.LsC;
import X.LsF;
import X.M12;
import X.P6l;
import X.PoH;
import X.PoL;
import X.S0f;
import X.SDv;
import X.SDx;
import X.SEQ;
import android.app.Application;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.Resources;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.fragment.app.Fragment;
import com.bytedance.bdlocation.BDLocation;
import com.bytedance.bpea.basics.Cert;
import com.bytedance.bpea.basics.PrivacyCert;
import com.bytedance.bpea.store.policy.PrivacyPolicyStore;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.agilelogger.ALog;
import com.ss.android.ugc.aweme.compliance.api.a;
import com.ss.android.ugc.aweme.feed.model.AnchorCommonStruct;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.poi.GuitarBundle;
import com.ss.android.ugc.aweme.poi.PokerBundle;
import com.ss.android.ugc.aweme.poi.collect.PoiCollectListFragment;
import com.ss.android.ugc.aweme.poi.collect.detailfeed.PoiCollectBarFragment;
import com.ss.android.ugc.aweme.poi.videopublish.PoiPublishModel;
import com.ss.android.ugc.aweme.poi_api.service.IPoiService;
import com.ss.android.ugc.aweme.services.publish.IAVPublishExtension;
import com.ss.android.ugc.tiktok.location.serviceimpl.LocationServiceImpl;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import kotlin.h.b.n;

public final class PoiServiceImpl implements IPoiService {
    public static final BFM LIZ = new BFM((byte) 0);
    public boolean LIZIZ;

    static {
        Covode.recordClassIndex(97547);
    }

    public final void LIZ(Cert cert) {
        M12.LIZ(cert);
        List<String> LIZ2 = BGC.LIZIZ.LIZ("poi");
        if ((LIZ2.contains("fyp") || LIZ2.contains("add_location") || LIZ2.contains("anchor")) && BGG.LIZIZ.LIZIZ() && a.LJIIJ().LJFF()) {
            C2745AxJ.LIZ.LIZ(cert, (LsC<? super String, 2Pr>) null);
        }
    }

    public final void LIZ(String str, boolean z, LsF<? super Double, ? super Double, ? super String, ? super Boolean, 2Pr> lsF, LsC<? super Boolean, 2Pr> lsC) {
        M12.LIZ(str, lsF, lsC);
        PoL poL = PoL.LIZIZ;
        PoH poH = new PoH();
        poH.LJI = str;
        poH.LJIILIIL = 1;
        poH.LJIIL = 1;
        poH.LJIILLIIL = z;
        poL.LIZ(poH, new BFO(str, lsF, lsC));
    }

    public final void LIZ(String str, String str2, String str3, String str4, String str5, String str6, String str7, int i, String str8, String str9, String str10) {
        M12.LIZ(str);
        M12.LIZ(str);
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("enter_from", "poi_detail");
        linkedHashMap.put("poi_id", str);
        if (str2 != null) {
            linkedHashMap.put("group_id", str2);
        }
        if (str3 != null) {
            linkedHashMap.put("author_id", str3);
        }
        if (str4 != null) {
            linkedHashMap.put("enter_method", str4);
        }
        if (str5 != null) {
            linkedHashMap.put("entrance_enter_method", str5);
        }
        if (str6 != null) {
            linkedHashMap.put("entrance_enter_page", str6);
        }
        if (str7 != null) {
            linkedHashMap.put("poi_backend_type", str7);
        }
        linkedHashMap.put("poi_info_source", "google");
        linkedHashMap.put("poi_device_samecity", String.valueOf(i));
        if (str8 != null) {
            linkedHashMap.put("poi_city", str8);
        }
        if (str9 != null) {
            linkedHashMap.put("poi_region_code", str9);
        }
        linkedHashMap.put("poi_info_source", "google");
        String str11 = str10;
        if (str11 != null) {
            linkedHashMap.put("log_pb", str11);
        }
        2nK.LIZ("poi_map_operation", linkedHashMap);
    }

    public final void LIZ(String str) {
        M12.LIZ(str);
        if (BGG.LIZIZ.LIZIZ()) {
            BE9.LIZJ.LIZ(str);
        }
    }

    public final void LIZ(View view, 0AA r12, Bundle bundle) {
        MethodCollector.i(18360);
        if (view == null || r12 == null) {
            MethodCollector.o(18360);
            return;
        }
        View findViewById = view.findViewById(2131368609);
        Fragment LIZ2 = r12.LIZ("poi_collect_bar_fragment");
        if (LIZ2 != null) {
            if (findViewById != null) {
                MethodCollector.o(18360);
                return;
            }
            0AP LIZ3 = r12.LIZ();
            LIZ3.LIZ(LIZ2);
            LIZ3.LIZJ();
        }
        if (findViewById == null) {
            FrameLayout frameLayout = new FrameLayout(view.getContext());
            frameLayout.setId(2131368609);
            Resources system = Resources.getSystem();
            n.LIZIZ(system, "");
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, LnI.LIZ(TypedValue.applyDimension(1, 58.0f, system.getDisplayMetrics())));
            layoutParams.gravity = 80;
            ((ViewGroup) view).addView(frameLayout, layoutParams);
        }
        if (bundle != null) {
            String string = bundle.getString("page_poi_id");
            String string2 = bundle.getString("poi_name");
            if (string2 == null) {
                string2 = "";
            }
            n.LIZIZ(string2, "");
            boolean z = bundle.getBoolean("is_collected");
            String string3 = bundle.getString("poi_address");
            if (string3 == null) {
                string3 = "";
            }
            n.LIZIZ(string3, "");
            Serializable serializable = bundle.getSerializable("poi_collect_mob_data");
            if (serializable != null) {
                M12.LIZ(string2, string3);
                PoiCollectBarFragment poiCollectBarFragment = new PoiCollectBarFragment();
                poiCollectBarFragment.LJ = string;
                poiCollectBarFragment.LJFF = string2;
                poiCollectBarFragment.LJI = z;
                poiCollectBarFragment.LJII = string3;
                poiCollectBarFragment.LJIIIIZZ = (BE8) serializable;
                0AP LIZ4 = r12.LIZ();
                LIZ4.LIZ(2131368609, poiCollectBarFragment, "poi_collect_bar_fragment");
                LIZ4.LIZJ();
                MethodCollector.o(18360);
                return;
            }
            NullPointerException nullPointerException = new NullPointerException("null cannot be cast to non-null type com.ss.android.ugc.aweme.poi.collect.PoiCollectMobData");
            MethodCollector.o(18360);
            throw nullPointerException;
        }
        MethodCollector.o(18360);
    }

    public final boolean LIZ(Aweme aweme) {
        List anchors;
        Object obj = null;
        if (aweme != null && (anchors = aweme.getAnchors()) != null) {
            Iterator it = anchors.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                Object next = it.next();
                AnchorCommonStruct anchorCommonStruct = (AnchorCommonStruct) next;
                if (anchorCommonStruct.getType() == 45 && anchorCommonStruct.getExtra().length() > 0) {
                    obj = next;
                    break;
                }
            }
        }
        return BFG.LIZ.LIZ() && obj != null;
    }

    public final void LIZ(HashMap<String, String> hashMap, Aweme aweme) {
        M12.LIZ(hashMap);
        Map<String, String> LIZ2 = LIZ((String) null, aweme);
        if (!LIZ2.isEmpty()) {
            hashMap.putAll(LIZ2);
        }
    }

    public final void LIZ(String str, String str2, String str3, String str4, int i, String str5, String str6, String str7) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("enter_from", "poi_map");
        if (str != null) {
            linkedHashMap.put("poi_id", str);
        }
        if (str2 != null) {
            linkedHashMap.put("group_id", str2);
        }
        if (str3 != null) {
            linkedHashMap.put("author_id", str3);
        }
        if (str4 != null) {
            linkedHashMap.put("poi_backend_type", str4);
        }
        linkedHashMap.put("poi_info_source", "google");
        linkedHashMap.put("poi_device_samecity", String.valueOf(i));
        if (str5 != null) {
            linkedHashMap.put("poi_city", str5);
        }
        if (str6 != null) {
            linkedHashMap.put("poi_region_code", str6);
        }
        if (str7 != null) {
            linkedHashMap.put("log_pb", str7);
        }
        2nK.LIZ("open_navigation", linkedHashMap);
    }

    public final C3185BAn LIZ() {
        return new BBP();
    }

    public final String LIZLLL() {
        return C2745AxJ.LIZ.LIZ();
    }

    public final HashMap<String, BFN> LJIIIZ() {
        return BFF.LIZ.LIZ();
    }

    public final Fragment LJIILIIL() {
        return new PoiCollectListFragment();
    }

    public final String LJI() {
        return BGG.LIZIZ.LIZ().LJFF;
    }

    public final String LJII() {
        return BGG.LIZIZ.LIZ().LJ;
    }

    public final String LJIIIIZZ() {
        return BGG.LIZIZ.LIZ().LIZJ;
    }

    public final float LJIIJJI() {
        return BGG.LIZIZ.LIZ().LJI;
    }

    public final D1G<? extends C1683AgB> LJIIL() {
        return KEM.LIZ.LIZ(BFW.class);
    }

    public final void LIZJ() {
        PoL poL = PoL.LIZIZ;
        Context LIZ2 = 9EH.LJJIFFI.LIZ();
        Objects.requireNonNull(LIZ2, "null cannot be cast to non-null type android.app.Application");
        poL.LIZ((Application) LIZ2);
    }

    public final boolean LJ() {
        if (!BGG.LIZIZ.LIZIZ()) {
            ALog.i("poi", "poi_config is not enable");
            return false;
        } else if (!S0f.LJIIJ.LIZIZ()) {
            ALog.i("poi", "is not login");
            return false;
        } else if (ESC.LJ()) {
            ALog.i("poi", "isKidsMode");
            return false;
        } else if (BFH.LIZ.LIZ()) {
            return true;
        } else {
            ALog.i("poi", "enable_add_poi_compliance is false");
            return false;
        }
    }

    public final Map<String, Object> LJFF() {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("poi_master_switch", Boolean.valueOf(LJ()));
        Map<String, List<String>> LIZIZ2 = BGC.LIZIZ.LIZIZ();
        if (!LIZIZ2.isEmpty()) {
            linkedHashMap.put("poi_popup_scenes", LIZIZ2.toString());
        }
        return linkedHashMap;
    }

    public final void LJIIJ() {
        if (!this.LIZIZ) {
            this.LIZIZ = true;
            if (BGG.LIZIZ.LIZIZ()) {
                2nK.LIZ("poi_function_on", LWx.LIZ(CwZ.LIZ("hit_poi_publish_rule", String.valueOf(LJ() ? 1 : 0))));
            }
        }
    }

    public final 07U<Class<?>, IAVPublishExtension<?>> LIZIZ() {
        if (LJ()) {
            C3797BYb.LIZ("poi_publish_show_add_location", 0);
            return new 07U<>(PoiPublishModel.class, new P6l());
        } else if (!BGG.LIZIZ.LIZIZ()) {
            return null;
        } else {
            if (!S0f.LJIIJ.LIZIZ()) {
                C3797BYb.LIZ("poi_publish_show_add_location", 1);
                return null;
            } else if (ESC.LJ()) {
                C3797BYb.LIZ("poi_publish_show_add_location", 2);
                return null;
            } else if (BFH.LIZ.LIZ()) {
                return null;
            } else {
                C3797BYb.LIZ("poi_publish_show_add_location", 3);
                return null;
            }
        }
    }

    public final boolean LIZIZ(Context context) {
        M12.LIZ(context);
        return BFA.LIZ.LIZ(context);
    }

    public final void LIZIZ(Cert cert) {
        M12.LIZ(cert);
        if (LocationServiceImpl.LIZJ().LIZIZ()) {
            try {
                LocationServiceImpl.LIZJ().LIZ(cert);
            } catch (Exception e) {
                0HH.LIZ(e);
            }
        }
    }

    public final void LIZIZ(LsC<? super String, 2Pr> lsC) {
        C2745AxJ axJ = C2745AxJ.LIZ;
        PrivacyCert.Builder with = PrivacyCert.Builder.Companion.with("bpea-1708");
        with.usage(" We plan to improve the TikTok content by POI and allow user to add location when publishing contents ,thus we need to apply GPS permission from users to get coarse location information.");
        with.tag("poi");
        with.policies(new C01139qj[]{PrivacyPolicyStore.getLatitudeAndLongitudePrivacyPolicy()});
        axJ.LIZ((Cert) with.build(), lsC);
    }

    public final boolean LIZJ(Context context) {
        M12.LIZ(context);
        if (Build.VERSION.SDK_INT >= 28) {
            Object LIZ2 = LIZ(context, "location");
            if (!(LIZ2 instanceof LocationManager)) {
                LIZ2 = null;
            }
            LocationManager locationManager = (LocationManager) LIZ2;
            if (locationManager != null) {
                return locationManager.isLocationEnabled();
            }
            return false;
        }
        try {
            if (Settings.Secure.getInt(context.getContentResolver(), "location_mode") != 0) {
                return true;
            }
            return false;
        } catch (Exception e) {
            0HH.LIZ(e);
            return false;
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:2:0x000d, code lost:
        r2 = (com.ss.android.ugc.aweme.poi.videopublish.PoiPublishModel) r2;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final com.ss.android.ugc.aweme.poi.PoiData LIZ(X.LsC<? super java.lang.Class<? extends java.lang.Object>, ? extends java.lang.Object> r11) {
        /*
            r10 = this;
            X.M12.LIZ(r11)
            java.lang.Class<com.ss.android.ugc.aweme.poi.videopublish.PoiPublishModel> r0 = com.ss.android.ugc.aweme.poi.videopublish.PoiPublishModel.class
            java.lang.Object r2 = r11.invoke(r0)
            boolean r0 = r2 instanceof com.ss.android.ugc.aweme.poi.videopublish.PoiPublishModel
            if (r0 == 0) goto L_0x0034
            com.ss.android.ugc.aweme.poi.videopublish.PoiPublishModel r2 = (com.ss.android.ugc.aweme.poi.videopublish.PoiPublishModel) r2
            com.bytedance.ug.sdk.poi.model.PoiItem r1 = r2.getPoiItem()
            if (r1 == 0) goto L_0x0034
            X.P7C r0 = X.P7C.LIZ
            com.ss.android.ugc.aweme.poi.PoiData r1 = r0.LIZ(r1)
            com.ss.android.ugc.aweme.poi.PoiMobParam r3 = new com.ss.android.ugc.aweme.poi.PoiMobParam
            r4 = 0
            r5 = 0
            r6 = 0
            java.lang.String r7 = r2.getEnterMethod()
            r8 = 7
            r9 = 0
            r3.<init>(r4, r5, r6, r7, r8, r9)
            r1.setMobParam(r3)
            java.lang.String r0 = r2.getLogId()
            r1.setLogId(r0)
            return r1
        L_0x0034:
            r0 = 0
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.poi.service.PoiServiceImpl.LIZ(X.LsC):com.ss.android.ugc.aweme.poi.PoiData");
    }

    public final void LIZ(Context context) {
        M12.LIZ(context);
        if (LJ() && BFA.LIZ.LIZ(context)) {
            BFA.LIZ((SDv) new BFI());
        }
    }

    public static Object LIZ(Context context, String str) {
        Object obj;
        MethodCollector.i(17740);
        if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) {
            if (!2FV.LIZIZ && "connectivity".equals(str)) {
                try {
                    new 7s1().LIZ();
                    2FV.LIZIZ = true;
                    obj = context.getSystemService(str);
                } catch (Throwable unused) {
                }
            }
            obj = context.getSystemService(str);
        } else if (2FV.LIZ) {
            synchronized (ClipboardManager.class) {
                try {
                    obj = context.getSystemService(str);
                    if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
                        Field declaredField = ClipboardManager.class.getDeclaredField("mHandler");
                        declaredField.setAccessible(true);
                        declaredField.set(obj, new 2He((Handler) declaredField.get(obj)));
                    }
                } catch (Exception e) {
                    8jA.LIZ(e, "ClipboardManager Handler Reflect Fail");
                } catch (Throwable th) {
                    MethodCollector.o(17740);
                    throw th;
                }
                2FV.LIZ = false;
            }
        } else {
            obj = context.getSystemService(str);
        }
        MethodCollector.o(17740);
        return obj;
    }

    public final Map<String, String> LIZ(String str, Aweme aweme) {
        boolean z;
        String str2;
        if (aweme == null) {
            return LWw.LIZ();
        }
        C3151B9f LIZ2 = C3151B9f.Companion.LIZ(aweme);
        if (LIZ2 == null) {
            return LWw.LIZ();
        }
        B9R LIZ3 = B9R.Companion.LIZ(aweme);
        B9Q b9q = B9R.Companion;
        C3150B9e b9e = C3151B9f.Companion;
        2UX r0 = new 2UX();
        b9e.LIZ(r0, LIZ2);
        b9q.LIZ(r0, LIZ3);
        Map<String, String> map = r0.LIZ;
        if (str == null || str.length() == 0) {
            z = true;
        } else {
            z = false;
        }
        if (z) {
            n.LIZIZ(map, "");
            return map;
        }
        C3151B9f LIZ4 = C3151B9f.Companion.LIZ(str);
        if (LIZ4 == null) {
            n.LIZIZ(map, "");
            return map;
        }
        n.LIZIZ(map, "");
        map.put("page_poi_id", LIZ4.getPoiId());
        map.put("page_poi_backend_type", LIZ4.getPoiBackEndType());
        map.put("page_poi_info_source", LIZ4.getPoiInfoSource());
        map.put("page_poi_city", LIZ4.getPoiCityCode());
        map.put("page_poi_region_code", LIZ4.getPoiRegionCode());
        Integer poiDeviceSameCity = LIZ4.getPoiDeviceSameCity();
        if (poiDeviceSameCity != null) {
            str2 = String.valueOf(poiDeviceSameCity.intValue());
        } else {
            str2 = null;
        }
        map.put("page_poi_device_samecity", str2);
        String fromGroupId = LIZ4.getFromGroupId();
        if (fromGroupId != null) {
            map.put("from_group_id", fromGroupId);
        }
        return map;
    }

    /* JADX WARNING: type inference failed for: r1v1, types: [X.BBQ, android.view.View] */
    public final View LIZ(Context context, Aweme aweme, String str) {
        M12.LIZ(context, str);
        if (!BFG.LIZ.LIZ() || aweme == null || C3151B9f.Companion.LIZ(aweme) == null) {
            return null;
        }
        return new BBQ(context, aweme, str);
    }

    public final PokerBundle LIZ(String str, double d, double d2) {
        M12.LIZ(str);
        new SDx(str);
        BDLocation LIZ2 = SEQ.LIZ().LIZ(d, d2);
        String str2 = "";
        if (LIZ2 == null) {
            return null;
        }
        LIZ2.LJI = str2;
        LIZ2.LJII = str2;
        M12.LIZ(LIZ2);
        String str3 = LIZ2.LJJIJIIJIL;
        if (str3 == null) {
            str3 = str2;
        }
        String str4 = LIZ2.LJFF;
        if (str4 == null) {
            str4 = str2;
        }
        String str5 = LIZ2.LIZIZ;
        if (str5 == null) {
            str5 = str2;
        }
        String str6 = LIZ2.LIZJ;
        if (str6 == null) {
            str6 = str2;
        }
        String str7 = LIZ2.LJ;
        if (str7 != null) {
            str2 = str7;
        }
        return new PokerBundle(str3, str4, str5, str6, str2);
    }

    public final GuitarBundle LIZ(Context context, String str, long j, Cert cert) {
        BDLocation LIZ2;
        M12.LIZ(context, str, cert);
        if (!LIZIZ(context) || !LIZJ(context) || (LIZ2 = BFA.LIZ.LIZ(str, j, cert)) == null) {
            return null;
        }
        M12.LIZ(LIZ2);
        return new GuitarBundle(LIZ2.getLatitude(), LIZ2.getLongitude());
    }

    public final 4OS LIZ(String str, boolean z, String str2, String str3, Map<String, String> map) {
        Map<String, String> map2 = map;
        M12.LIZ(map2);
        return new BFP(str, z, 0, str2, str3, new BE8((String) null, (String) null, (String) null, (String) null, (String) null, (String) null, (String) null, (String) null, 0, (String) null, (String) null, (String) null, (String) null, (String) null, (String) null, (String) null, (String) null, (String) null, (String) null, map2, 524287, (2HN) null), 4);
    }
}
