package com.bytedance.ies.powerpage.interceptor;

import X.0HH;
import X.FNZ;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.RouteIntent;
import com.bytedance.router.interceptor.IInterceptor;
import java.util.HashMap;

public class PowerPageInterceptor implements IInterceptor {
    public HashMap<String, String> LIZ;

    static {
        Covode.recordClassIndex(30336);
    }

    public PowerPageInterceptor() {
        HashMap<String, String> hashMap = new HashMap<>();
        this.LIZ = hashMap;
        hashMap.put("//about_activity", "com.ss.android.ugc.aweme.setting.page.about.AboutPage");
        hashMap.put("//ads/preview", "com.ss.android.ugc.aweme.commercialize.preview.ui.AdsPreviewFragment");
        hashMap.put("//authmanagement", "com.ss.android.ugc.aweme.setting.page.authmanager.AuthManagementPage");
        hashMap.put("//chat/center", "com.ss.android.ugc.aweme.im.sdk.chatlist.ui.fragment.SessionListFragment");
        hashMap.put("//chat/center2", "com.ss.android.ugc.aweme.im.sdk.chatlist.ui.fragment.SessionListFragmentV2");
        hashMap.put("//chatcontrol/setting", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.chat.ChatPrivacySettingFragment");
        hashMap.put("//commentcontrol/setting", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.comment.CommentPrivacySettingFragment");
        hashMap.put("//compliance/privacy_highlights_for_teens_feed", "com.ss.android.ugc.aweme.compliance.business.phl.feed.PhlFeedFragment");
        hashMap.put("//display/caption/setting", "com.ss.android.ugc.trill.setting.DisplayAndCaptionSettingPage");
        hashMap.put("//display/setting", "com.ss.android.ugc.trill.setting.DisplaySettingPage");
        hashMap.put("//duetcontrol/setting", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.duet.DuetPrivacySettingFragment");
        hashMap.put("//favoritenotice/setting", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.favorites.FavoriteNoticeSettingFragment");
        hashMap.put("//filtercomments", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.comment.CommentPrivacySettingFragment");
        hashMap.put("//filtercomments/dislike", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.commentfilter.subadapters.dislike.CommentFilterDislikeFragment");
        hashMap.put("//friends/contact", "com.ss.android.ugc.aweme.relation.fp.ContactFriendsPage");
        hashMap.put("//friends/facebook", "com.ss.android.ugc.aweme.relation.fp.FacebookFriendsPage");
        hashMap.put("//friends/invite_new", "com.ss.android.ugc.aweme.relation.fp.InviteFriendsPage");
        hashMap.put("//helper_center", "com.ss.android.ugc.aweme.i18n.settings.agreements.AgreementPage");
        hashMap.put("//inner_push_setting_manager", "com.ss.android.ugc.aweme.setting.serverpush.ui.InnerPushSettingsFragment");
        hashMap.put("//mentioncontrol/setting", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.tagmention.TagMentionPrivacySettingFragment");
        hashMap.put("//mylikelistcontrol/setting", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.likedlist.LikedListPrivacySettingFragment");
        hashMap.put("//poi/map", "com.ss.android.ugc.aweme.poi_map.LocationDetailFragment");
        hashMap.put("//poi/search", "com.ss.android.ugc.aweme.poi.search.PoiSearchFragment");
        hashMap.put("//preferred/language/setting", "com.ss.android.ugc.trill.setting.PreferredLanguageSettingPage");
        hashMap.put("//privacy/following_visibility", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.following.FollowingVisibilityPrivacySettingFragment");
        hashMap.put("//privacy/setting", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.PrivacySettingFragmentMain");
        hashMap.put("//privacy/suggest_account", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.suggestaccount.SuggestAccountPrivacySettingFragment");
        hashMap.put("//profile/viewer", "com.ss.android.ugc.aweme.profile.viewer.ui.ProfileViewerFragment");
        hashMap.put("//profileviewhistory/settings", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.profileviewers.ProfileViewHistorySettingFragment");
        hashMap.put("//push-setting", "com.ss.android.ugc.aweme.setting.serverpush.ui.PushSettingManagerPage");
        hashMap.put("//qna/settings", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.qa.QASettingFragment");
        hashMap.put("//qrcodev2", "com.ss.android.ugc.aweme.qrcode.QRCodeFragment");
        hashMap.put("//setting/accessibility", "com.ss.android.ugc.aweme.setting.page.accessibility.AccessibilitySettingPage");
        hashMap.put("//setting/background_audio", "com.ss.android.ugc.aweme.setting.page.backgroundaudio.BackgroundAudioPage");
        hashMap.put("//setting/blocklist", "com.ss.android.ugc.aweme.setting.page.privacy.BlackListPage");
        hashMap.put("//setting/datasaver", "com.ss.android.ugc.aweme.setting.page.datasave.DataSaverSettingPage");
        hashMap.put("//setting/datasaver/freedata", "com.ss.android.ugc.aweme.setting.page.datasave.zerorating.FreeDataPage");
        hashMap.put("//setting/diskmanager", "com.ss.android.ugc.aweme.setting.page.diskmanager.DiskManagerPage");
        hashMap.put("//setting/download", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.downloads.DownloadsPrivacySettingFragment");
        hashMap.put("//setting/findcontact", "com.ss.android.ugc.aweme.setting.unit.privacy.FindCtxSettingPage");
        hashMap.put("//setting/security", "com.ss.android.ugc.aweme.setting.page.security.SecurityPage");
        hashMap.put("//social/taglist", "com.ss.android.ugc.aweme.tag.VideoTagPage");
        hashMap.put("//stitchcontrol/setting", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.stitch.StitchPrivacySettingFragment");
        hashMap.put("//story/archive", "com.ss.android.ugc.aweme.story.archive.StoryArchiveFragment");
        hashMap.put("//translation/language/setting", "com.ss.android.ugc.trill.setting.TranslationLanguageSettingPage");
        hashMap.put("//translation/voice/setting", "com.ss.android.ugc.trill.setting.TranslationVoiceSettingPage");
        hashMap.put("//user/ask", "com.ss.android.ugc.aweme.qna.fragment.QnaAskQuestionFragment");
        hashMap.put("//user/ask/", "com.ss.android.ugc.aweme.qna.fragment.QnaAskQuestionFragment");
        hashMap.put("//user/profile", "com.ss.android.ugc.aweme.profile.ui.UserProfileFragment");
        hashMap.put("//user/qna/profile", "com.ss.android.ugc.aweme.qna.QnaProfile");
        hashMap.put("//user/qna_unavailable", "com.ss.android.ugc.aweme.qna.fragment.QuestionUnavailableFragment");
        hashMap.put("//videoviewhistory/settings", "com.ss.android.ugc.aweme.compliance.privacy.settings.account.pages.videoviewers.VideoViewHistorySettingFragment");
        hashMap.put("aweme://favorite/videos/allfavorites/content", "com.ss.android.ugc.aweme.favorites.ui.VideoAllFavoriteContentFragment");
        hashMap.put("aweme://favorite/videos/collections/add/video", "com.ss.android.ugc.aweme.favorites.ui.VideoCollectionAddVideosFragment");
        hashMap.put("aweme://favorite/videos/collections/content", "com.ss.android.ugc.aweme.favorites.ui.VideoCollectionCollectionContentFragment");
        hashMap.put("aweme://poi/detail", "com.ss.android.ugc.aweme.poi.videolist.PoiVideoListVideoListFragment");
        hashMap.put("aweme://push_setting_manager", "com.ss.android.ugc.aweme.setting.serverpush.ui.PushSettingManagerPage");
        hashMap.put("aweme://user/ask", "com.ss.android.ugc.aweme.qna.fragment.QnaAskQuestionFragment");
        hashMap.put("aweme://user/ask/", "com.ss.android.ugc.aweme.qna.fragment.QnaAskQuestionFragment");
        hashMap.put("aweme://user/inbox/follower", "com.ss.android.ugc.aweme.inbox.InboxFollowerFragment");
        hashMap.put("aweme://user/notification", "com.ss.android.ugc.aweme.notification.NotificationFragment");
        hashMap.put("aweme://user/notification_old", "com.ss.android.ugc.aweme.notification.MusNewNotificationFragment");
    }

    public static Bundle LIZ(Intent intent) {
        try {
            return intent.getExtras();
        } catch (Exception unused) {
            return null;
        }
    }

    public boolean matchInterceptRules(RouteIntent routeIntent) {
        try {
            if (!TextUtils.isEmpty(LIZ(routeIntent))) {
                return true;
            }
            return false;
        } catch (Exception e) {
            0HH.LIZ(e);
            return false;
        }
    }

    public static String LIZ(String str) {
        Uri parse = Uri.parse(str);
        if (!parse.isHierarchical()) {
            return null;
        }
        if (TextUtils.isEmpty(parse.getScheme())) {
            return str;
        }
        return "//" + parse.getAuthority() + parse.getPath();
    }

    private String LIZ(RouteIntent routeIntent) {
        if (routeIntent == null) {
            return null;
        }
        String url = routeIntent.getUrl();
        if (TextUtils.isEmpty(url)) {
            return null;
        }
        String LIZ2 = LIZ(url);
        String str = this.LIZ.get(LIZ2);
        if (TextUtils.isEmpty(str) && LIZ2.endsWith("/") && LIZ2.length() > 1) {
            LIZ2 = LIZ2.substring(0, LIZ2.length() - 1);
            str = this.LIZ.get(LIZ2);
        }
        if (TextUtils.isEmpty(str)) {
            LIZ2 = LIZIZ(url);
            str = this.LIZ.get(LIZ2);
        }
        if (!TextUtils.isEmpty(str) || !LIZ2.endsWith("/") || LIZ2.length() <= 1) {
            return str;
        }
        return this.LIZ.get(LIZ2.substring(0, LIZ2.length() - 1));
    }

    public static String LIZIZ(String str) {
        Uri parse = Uri.parse(str);
        if (!parse.isHierarchical()) {
            return null;
        }
        if (!TextUtils.isEmpty(parse.getScheme())) {
            return parse.getScheme() + "://" + parse.getAuthority() + parse.getPath();
        }
        return "//" + parse.getAuthority() + parse.getPath();
    }

    public boolean onInterceptRoute(Context context, RouteIntent routeIntent) {
        Class<?> cls;
        Bundle bundle;
        Context context2 = context;
        if (context2 == null || routeIntent == null) {
            return false;
        }
        Intent intent = null;
        try {
            String LIZ2 = LIZ(routeIntent);
            if (!TextUtils.isEmpty(LIZ2) && (cls = Class.forName(LIZ2)) != null) {
                try {
                    if (Fragment.class.isAssignableFrom(cls)) {
                        if (routeIntent.getExtra() != null) {
                            intent = routeIntent.getExtra();
                            bundle = LIZ(intent);
                        } else {
                            bundle = null;
                        }
                        Intent LIZ3 = FNZ.LIZ.LIZ(context2, cls, bundle, routeIntent.getRequestCode(), routeIntent.getOnActivityResultCallback());
                        if (LIZ3 == null || intent == null) {
                            return true;
                        }
                        intent.setComponent(LIZ3.getComponent());
                        intent.putExtra("power_page_fragment_class_name", cls.getCanonicalName());
                        return true;
                    }
                } catch (Exception e) {
                    0HH.LIZ(e);
                }
            }
        } catch (ClassNotFoundException e2) {
            0HH.LIZ(e2);
        } catch (Throwable unused) {
        }
        return false;
    }
}
