导航菜单

页面标题

页面副标题

St.John's v1.0.9 - FolioPageFragment.java 源代码

正在查看: St.John's v1.0.9 应用的 FolioPageFragment.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.folioreader.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.ConsoleMessage;
import android.webkit.JavascriptInterface;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.bumptech.glide.load.Key;
import com.fasterxml.jackson.core.JsonPointer;
import com.folioreader.Config;
import com.folioreader.Constants;
import com.folioreader.FolioReader;
import com.folioreader.R;
import com.folioreader.mediaoverlay.MediaController;
import com.folioreader.mediaoverlay.MediaControllerCallbacks;
import com.folioreader.model.HighLight;
import com.folioreader.model.HighlightImpl;
import com.folioreader.model.event.MediaOverlayHighlightStyleEvent;
import com.folioreader.model.event.MediaOverlayPlayPauseEvent;
import com.folioreader.model.event.MediaOverlaySpeedEvent;
import com.folioreader.model.event.ReloadDataEvent;
import com.folioreader.model.event.RewindIndexEvent;
import com.folioreader.model.event.UpdateHighlightEvent;
import com.folioreader.model.locators.ReadLocator;
import com.folioreader.model.locators.SearchLocator;
import com.folioreader.model.sqlite.HighLightTable;
import com.folioreader.ui.activity.FolioActivityCallback;
import com.folioreader.ui.base.HtmlTask;
import com.folioreader.ui.base.HtmlTaskCallback;
import com.folioreader.ui.base.HtmlUtil;
import com.folioreader.ui.view.FolioWebView;
import com.folioreader.ui.view.LoadingView;
import com.folioreader.ui.view.VerticalSeekbar;
import com.folioreader.ui.view.WebViewPager;
import com.folioreader.util.AppUtil;
import com.folioreader.util.HighlightUtil;
import com.folioreader.util.UiUtil;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.regex.Pattern;
import kotlin.Metadata;
import kotlin.TypeCastException;
import kotlin.Unit;
import kotlin.jvm.JvmStatic;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Ref;
import kotlin.jvm.internal.StringCompanionObject;
import kotlin.text.StringsKt;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.readium.r2.shared.Link;
import org.readium.r2.shared.Locations;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000ò\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0000\n\u0002\b\u0003\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u000b\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005*\u0002GJ\u0018\u0000 \u008d\u00012\u00020\u00012\u00020\u00022\u00020\u00032\u00020\u0004:\u0002\u008d\u0001B\u0005¢\u0006\u0002\u0010\u0005J\u0006\u0010N\u001a\u00020OJ\b\u0010P\u001a\u00020OH\u0016J\u0006\u0010Q\u001a\u00020OJ\b\u0010R\u001a\u0004\u0018\u00010\u0010J\u001a\u0010S\u001a\u00020O2\b\u0010T\u001a\u0004\u0018\u00010\u000b2\u0006\u0010U\u001a\u00020\u000bH\u0007J\b\u0010V\u001a\u00020OH\u0016J\u0010\u0010W\u001a\u00020O2\u0006\u0010X\u001a\u00020\u000bH\u0016J\u0016\u0010Y\u001a\u00020O2\u0006\u0010U\u001a\u00020Z2\u0006\u0010[\u001a\u00020\tJ\u000e\u0010\\\u001a\u00020O2\u0006\u0010]\u001a\u000208J\b\u0010^\u001a\u00020OH\u0002J\b\u0010_\u001a\u00020OH\u0002J\b\u0010`\u001a\u00020OH\u0003J\u000e\u0010a\u001a\u00020O2\u0006\u00105\u001a\u00020\u000bJ&\u0010b\u001a\u0004\u0018\u00010#2\u0006\u0010c\u001a\u00020d2\b\u0010e\u001a\u0004\u0018\u00010f2\b\u00106\u001a\u0004\u0018\u000101H\u0016J\b\u0010g\u001a\u00020OH\u0016J\b\u0010h\u001a\u00020OH\u0016J\b\u0010i\u001a\u00020OH\u0016J\u0012\u0010j\u001a\u00020O2\b\u0010k\u001a\u0004\u0018\u00010\u000bH\u0007J\u0010\u0010l\u001a\u00020O2\u0006\u0010k\u001a\u00020\u000bH\u0016J\u0010\u0010m\u001a\u00020O2\u0006\u00100\u001a\u000201H\u0016J\b\u0010n\u001a\u00020OH\u0016J\u0010\u0010o\u001a\u00020O2\u0006\u0010p\u001a\u00020qH\u0007J\u0010\u0010r\u001a\u00020O2\u0006\u0010s\u001a\u00020tH\u0007J\b\u0010u\u001a\u00020OH\u0016J\u0010\u0010u\u001a\u00020O2\u0006\u0010v\u001a\u00020wH\u0007J\u000e\u0010x\u001a\u00020O2\u0006\u0010y\u001a\u00020\u000bJ\u0006\u0010z\u001a\u00020OJ\u000e\u0010{\u001a\u00020O2\u0006\u0010\n\u001a\u00020\u000bJ\u0006\u0010|\u001a\u00020OJ\u0010\u0010}\u001a\u00020O2\u0006\u0010~\u001a\u00020'H\u0007J\u0011\u0010\u007f\u001a\u00020O2\u0007\u0010\u0080\u0001\u001a\u00020\tH\u0002J\t\u0010\u0081\u0001\u001a\u00020OH\u0002J\u0012\u0010\u0082\u0001\u001a\u00020O2\u0007\u0010p\u001a\u00030\u0083\u0001H\u0007J\u0012\u0010\u0084\u0001\u001a\u00020O2\u0007\u0010\u0085\u0001\u001a\u00020\u000bH\u0007J\u0012\u0010\u0086\u0001\u001a\u00020O2\u0007\u0010p\u001a\u00030\u0087\u0001H\u0007J\u0012\u0010\u0088\u0001\u001a\u00020O2\u0007\u0010p\u001a\u00030\u0089\u0001H\u0007J\u0012\u0010\u008a\u0001\u001a\u00020O2\u0007\u0010\u008b\u0001\u001a\u00020'H\u0002J\t\u0010\u008c\u0001\u001a\u00020OH\u0002R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082.¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u0082D¢\u0006\u0002\n\u0000R\u0010\u0010\n\u001a\u0004\u0018\u00010\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\f\u001a\u0004\u0018\u00010\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\r\u001a\u00020\t8BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\r\u0010\u000eR\u0010\u0010\u000f\u001a\u0004\u0018\u00010\u0010X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0011\u001a\u0004\u0018\u00010\u0012X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0013\u001a\u0004\u0018\u00010\u0014X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0015\u001a\u0004\u0018\u00010\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0016\u001a\u0004\u0018\u00010\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0017\u001a\u0004\u0018\u00010\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0018\u001a\u0004\u0018\u00010\u0019X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u001a\u001a\u0004\u0018\u00010\u001bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u001c\u001a\u0004\u0018\u00010\u001bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u001d\u001a\u0004\u0018\u00010\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001e\u001a\u00020\tX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u001f\u001a\u0004\u0018\u00010 X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010!\u001a\u0004\u0018\u00010 X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\"\u001a\u0004\u0018\u00010#X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010$\u001a\u0004\u0018\u00010%X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010&\u001a\u00020'X\u0082\u000e¢\u0006\u0002\n\u0000R\u001c\u0010(\u001a\u0004\u0018\u00010)X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b*\u0010+\"\u0004\b,\u0010-R\u0010\u0010.\u001a\u0004\u0018\u00010/X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u00100\u001a\u0004\u0018\u000101X\u0082\u000e¢\u0006\u0002\n\u0000R\u0011\u00102\u001a\u00020\u000b8F¢\u0006\u0006\u001a\u0004\b3\u00104R\u000e\u00105\u001a\u00020\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u00106\u001a\u0004\u0018\u000101X\u0082\u000e¢\u0006\u0002\n\u0000R\u001c\u00107\u001a\u0004\u0018\u000108X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b9\u0010:\"\u0004\b;\u0010<R\u000e\u0010=\u001a\u00020'X\u0082\u000e¢\u0006\u0002\n\u0000R\u001a\u0010>\u001a\u00020?X\u0086.¢\u0006\u000e\n\u0000\u001a\u0004\b@\u0010A\"\u0004\bB\u0010CR\u000e\u0010D\u001a\u00020EX\u0082.¢\u0006\u0002\n\u0000R\u0010\u0010F\u001a\u00020GX\u0082\u0004¢\u0006\u0004\n\u0002\u0010HR\u0010\u0010I\u001a\u00020JX\u0082\u0004¢\u0006\u0004\n\u0002\u0010KR\u0010\u0010L\u001a\u0004\u0018\u00010MX\u0082\u000e¢\u0006\u0002\n\u0000¨\u0006\u008e\u0001"}, d2 = {"Lcom/folioreader/ui/fragment/FolioPageFragment;", "Landroidx/fragment/app/Fragment;", "Lcom/folioreader/ui/base/HtmlTaskCallback;", "Lcom/folioreader/mediaoverlay/MediaControllerCallbacks;", "Lcom/folioreader/ui/view/FolioWebView$SeekBarListener;", "()V", "chapterUrl", "Landroid/net/Uri;", "hasMediaOverlay", "", "highlightId", "", "highlightStyle", "isCurrentFragment", "()Z", "lastReadLocator", "Lcom/folioreader/model/locators/ReadLocator;", "loadingView", "Lcom/folioreader/ui/view/LoadingView;", "mActivityCallback", "Lcom/folioreader/ui/activity/FolioActivityCallback;", "mAnchorId", "mBookId", "mBookTitle", "mConfig", "Lcom/folioreader/Config;", "mFadeInAnimation", "Landroid/view/animation/Animation;", "mFadeOutAnimation", "mHtmlString", "mIsPageReloaded", "mMinutesLeftTextView", "Landroid/widget/TextView;", "mPagesLeftTextView", "mRootView", "Landroid/view/View;", "mScrollSeekbar", "Lcom/folioreader/ui/view/VerticalSeekbar;", "mTotalMinutes", "", "mWebview", "Lcom/folioreader/ui/view/FolioWebView;", "getMWebview", "()Lcom/folioreader/ui/view/FolioWebView;", "setMWebview", "(Lcom/folioreader/ui/view/FolioWebView;)V", "mediaController", "Lcom/folioreader/mediaoverlay/MediaController;", "outState", "Landroid/os/Bundle;", "pageName", "getPageName", "()Ljava/lang/String;", "rangy", "savedInstanceState", "searchLocatorVisible", "Lcom/folioreader/model/locators/SearchLocator;", "getSearchLocatorVisible", "()Lcom/folioreader/model/locators/SearchLocator;", "setSearchLocatorVisible", "(Lcom/folioreader/model/locators/SearchLocator;)V", "spineIndex", "spineItem", "Lorg/readium/r2/shared/Link;", "getSpineItem", "()Lorg/readium/r2/shared/Link;", "setSpineItem", "(Lorg/readium/r2/shared/Link;)V", "uiHandler", "Landroid/os/Handler;", "webChromeClient", "com/folioreader/ui/fragment/FolioPageFragment$webChromeClient$1", "Lcom/folioreader/ui/fragment/FolioPageFragment$webChromeClient$1;", "webViewClient", "com/folioreader/ui/fragment/FolioPageFragment$webViewClient$1", "Lcom/folioreader/ui/fragment/FolioPageFragment$webViewClient$1;", "webViewPager", "Lcom/folioreader/ui/view/WebViewPager;", "clearSearchLocator", "", "fadeInSeekBarIfInvisible", "fadeOutSeekBarIfVisible", "getLastReadLocator", "getUpdatedHighlightId", Constants.CHAPTER_ID, "style", "highLightTTS", "highLightText", "fragmentId", "highlight", "Lcom/folioreader/model/HighlightImpl$HighlightStyle;", "isAlreadyCreated", "highlightSearchLocator", "searchLocator", "initAnimations", "initSeekbar", "initWebView", "loadRangy", "onCreateView", "inflater", "Landroid/view/LayoutInflater;", "container", "Landroid/view/ViewGroup;", "onDestroy", "onDestroyView", "onError", "onReceiveHighlights", "html", "onReceiveHtml", "onSaveInstanceState", "onStop", "pauseButtonClicked", NotificationCompat.CATEGORY_EVENT, "Lcom/folioreader/model/event/MediaOverlayPlayPauseEvent;", "reload", "reloadDataEvent", "Lcom/folioreader/model/event/ReloadDataEvent;", "resetCurrentIndex", "resetIndex", "Lcom/folioreader/model/event/RewindIndexEvent;", "scrollToAnchorId", Constants.HREF, "scrollToFirst", "scrollToHighlightId", "scrollToLast", "setHorizontalPageCount", "horizontalPageCount", "setHtml", "reloaded", "setupScrollBar", "speedChanged", "Lcom/folioreader/model/event/MediaOverlaySpeedEvent;", "storeLastReadCfi", "cfi", "styleChanged", "Lcom/folioreader/model/event/MediaOverlayHighlightStyleEvent;", "updateHighlight", "Lcom/folioreader/model/event/UpdateHighlightEvent;", "updatePagesLeftText", "scrollY", "updatePagesLeftTextBg", "Companion", "folioreader_release"}, k = 1, mv = {1, 1, 13})
public final class FolioPageFragment extends Fragment implements HtmlTaskCallback, MediaControllerCallbacks, FolioWebView.SeekBarListener {
    private static final String BUNDLE_BOOK_TITLE = "BUNDLE_BOOK_TITLE";
    private static final String BUNDLE_READ_LOCATOR_CONFIG_CHANGE = "BUNDLE_READ_LOCATOR_CONFIG_CHANGE";
    public static final String BUNDLE_SEARCH_LOCATOR = "BUNDLE_SEARCH_LOCATOR";
    private static final String BUNDLE_SPINE_INDEX = "BUNDLE_SPINE_INDEX";
    private static final String BUNDLE_SPINE_ITEM = "BUNDLE_SPINE_ITEM";

    public static final Companion INSTANCE = new Companion(null);
    public static final String LOG_TAG;
    private HashMap _$_findViewCache;
    private Uri chapterUrl;
    private final boolean hasMediaOverlay;
    private String highlightId;
    private String highlightStyle;
    private ReadLocator lastReadLocator;
    private LoadingView loadingView;
    private FolioActivityCallback mActivityCallback;
    private String mAnchorId;
    private String mBookId;
    private String mBookTitle;
    private Config mConfig;
    private Animation mFadeInAnimation;
    private Animation mFadeOutAnimation;
    private String mHtmlString;
    private boolean mIsPageReloaded;
    private TextView mMinutesLeftTextView;
    private TextView mPagesLeftTextView;
    private View mRootView;
    private VerticalSeekbar mScrollSeekbar;
    private int mTotalMinutes;
    private FolioWebView mWebview;
    private MediaController mediaController;
    private Bundle outState;
    private Bundle savedInstanceState;
    private SearchLocator searchLocatorVisible;
    public Link spineItem;
    private Handler uiHandler;
    private WebViewPager webViewPager;
    private String rangy = "";
    private int spineIndex = -1;
    private final FolioPageFragment$webViewClient$1 webViewClient = new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            FolioActivityCallback folioActivityCallback;
            boolean z;
            String str;
            String str2;
            boolean isCurrentFragment;
            int i;
            FolioActivityCallback folioActivityCallback2;
            LoadingView loadingView;
            Bundle bundle;
            Bundle bundle2;
            ReadLocator readLocator;
            Bundle bundle3;
            LoadingView loadingView2;
            FolioActivityCallback folioActivityCallback3;
            Locations locations;
            String str3;
            String str4;
            boolean isCurrentFragment2;
            int i2;
            FolioActivityCallback folioActivityCallback4;
            LoadingView loadingView3;
            ReadLocator readLocator2;
            Locations locations2;
            Intrinsics.checkParameterIsNotNull(view, "view");
            Intrinsics.checkParameterIsNotNull(url, "url");
            FolioWebView mWebview = FolioPageFragment.this.getMWebview();
            if (mWebview == null) {
                Intrinsics.throwNpe();
            }
            mWebview.loadUrl("javascript:checkCompatMode()");
            FolioWebView mWebview2 = FolioPageFragment.this.getMWebview();
            if (mWebview2 == null) {
                Intrinsics.throwNpe();
            }
            mWebview2.loadUrl("javascript:alert(getReadingTime())");
            folioActivityCallback = FolioPageFragment.this.mActivityCallback;
            if (folioActivityCallback == null) {
                Intrinsics.throwNpe();
            }
            if (folioActivityCallback.getDirection() == Config.Direction.HORIZONTAL) {
                FolioWebView mWebview3 = FolioPageFragment.this.getMWebview();
                if (mWebview3 == null) {
                    Intrinsics.throwNpe();
                }
                mWebview3.loadUrl("javascript:initHorizontalDirection()");
            }
            StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
            String string = FolioPageFragment.this.getString(R.string.setmediaoverlaystyle);
            Intrinsics.checkExpressionValueIsNotNull(string, "getString(R.string.setmediaoverlaystyle)");
            String format = String.format(string, Arrays.copyOf(new Object[]{HighlightImpl.HighlightStyle.classForStyle(HighlightImpl.HighlightStyle.Normal)}, 1));
            Intrinsics.checkExpressionValueIsNotNull(format, "java.lang.String.format(format, *args)");
            view.loadUrl(format);
            String generateRangyString = HighlightUtil.generateRangyString(FolioPageFragment.this.getPageName());
            FolioPageFragment folioPageFragment = FolioPageFragment.this;
            Intrinsics.checkExpressionValueIsNotNull(generateRangyString, "rangy");
            folioPageFragment.rangy = generateRangyString;
            if (generateRangyString.length() != 0) {
                FolioPageFragment.this.loadRangy(generateRangyString);
            }
            z = FolioPageFragment.this.mIsPageReloaded;
            String str5 = null;
            if (!z) {
                str = FolioPageFragment.this.mAnchorId;
                if (TextUtils.isEmpty(str)) {
                    str2 = FolioPageFragment.this.highlightId;
                    if (!TextUtils.isEmpty(str2)) {
                        FolioWebView mWebview4 = FolioPageFragment.this.getMWebview();
                        if (mWebview4 == null) {
                            Intrinsics.throwNpe();
                        }
                        StringCompanionObject stringCompanionObject2 = StringCompanionObject.INSTANCE;
                        String string2 = FolioPageFragment.this.getString(R.string.go_to_highlight);
                        Intrinsics.checkExpressionValueIsNotNull(string2, "getString(R.string.go_to_highlight)");
                        str3 = FolioPageFragment.this.highlightId;
                        String format2 = String.format(string2, Arrays.copyOf(new Object[]{str3}, 1));
                        Intrinsics.checkExpressionValueIsNotNull(format2, "java.lang.String.format(format, *args)");
                        mWebview4.loadUrl(format2);
                        FolioPageFragment.this.highlightId = null;
                        return;
                    }
                    if (FolioPageFragment.this.getSearchLocatorVisible() == null) {
                        isCurrentFragment = FolioPageFragment.this.isCurrentFragment();
                        if (isCurrentFragment) {
                            bundle = FolioPageFragment.this.savedInstanceState;
                            if (bundle == null) {
                                Log.v(FolioPageFragment.LOG_TAG, "-> onPageFinished -> took from getEntryReadLocator");
                                folioActivityCallback3 = FolioPageFragment.this.mActivityCallback;
                                if (folioActivityCallback3 == null) {
                                    Intrinsics.throwNpe();
                                }
                                readLocator = folioActivityCallback3.getEntryReadLocator();
                            } else {
                                Log.v(FolioPageFragment.LOG_TAG, "-> onPageFinished -> took from bundle");
                                bundle2 = FolioPageFragment.this.savedInstanceState;
                                if (bundle2 == null) {
                                    Intrinsics.throwNpe();
                                }
                                readLocator = (ReadLocator) bundle2.getParcelable("BUNDLE_READ_LOCATOR_CONFIG_CHANGE");
                                bundle3 = FolioPageFragment.this.savedInstanceState;
                                if (bundle3 == null) {
                                    Intrinsics.throwNpe();
                                }
                                bundle3.remove("BUNDLE_READ_LOCATOR_CONFIG_CHANGE");
                            }
                            if (readLocator == null) {
                                loadingView2 = FolioPageFragment.this.loadingView;
                                if (loadingView2 == null) {
                                    Intrinsics.throwNpe();
                                }
                                loadingView2.hide();
                                return;
                            }
                            String cfi = readLocator.getLocations().getCfi();
                            String str6 = FolioPageFragment.LOG_TAG;
                            StringBuilder sb = new StringBuilder("-> onPageFinished -> readLocator -> ");
                            if (cfi == null) {
                                Intrinsics.throwNpe();
                            }
                            sb.append(cfi);
                            Log.v(str6, sb.toString());
                            FolioWebView mWebview5 = FolioPageFragment.this.getMWebview();
                            if (mWebview5 == null) {
                                Intrinsics.throwNpe();
                            }
                            StringCompanionObject stringCompanionObject3 = StringCompanionObject.INSTANCE;
                            String string3 = FolioPageFragment.this.getString(R.string.callScrollToCfi);
                            Intrinsics.checkExpressionValueIsNotNull(string3, "getString(R.string.callScrollToCfi)");
                            String format3 = String.format(string3, Arrays.copyOf(new Object[]{cfi}, 1));
                            Intrinsics.checkExpressionValueIsNotNull(format3, "java.lang.String.format(format, *args)");
                            mWebview5.loadUrl(format3);
                            return;
                        }
                        i = FolioPageFragment.this.spineIndex;
                        folioActivityCallback2 = FolioPageFragment.this.mActivityCallback;
                        if (folioActivityCallback2 == null) {
                            Intrinsics.throwNpe();
                        }
                        if (i != folioActivityCallback2.getCurrentChapterIndex() - 1) {
                            loadingView = FolioPageFragment.this.loadingView;
                            if (loadingView == null) {
                                Intrinsics.throwNpe();
                            }
                            loadingView.hide();
                            return;
                        }
                        FolioWebView mWebview6 = FolioPageFragment.this.getMWebview();
                        if (mWebview6 == null) {
                            Intrinsics.throwNpe();
                        }
                        mWebview6.loadUrl("javascript:scrollToLast()");
                        return;
                    }
                    StringCompanionObject stringCompanionObject4 = StringCompanionObject.INSTANCE;
                    String string4 = FolioPageFragment.this.getString(R.string.callHighlightSearchLocator);
                    Intrinsics.checkExpressionValueIsNotNull(string4, "getString(R.string.callHighlightSearchLocator)");
                    SearchLocator searchLocatorVisible = FolioPageFragment.this.getSearchLocatorVisible();
                    if (searchLocatorVisible != null && (locations = searchLocatorVisible.getLocations()) != null) {
                        str5 = locations.getCfi();
                    }
                    String format4 = String.format(string4, Arrays.copyOf(new Object[]{str5}, 1));
                    Intrinsics.checkExpressionValueIsNotNull(format4, "java.lang.String.format(format, *args)");
                    FolioWebView mWebview7 = FolioPageFragment.this.getMWebview();
                    if (mWebview7 == null) {
                        Intrinsics.throwNpe();
                    }
                    mWebview7.loadUrl(format4);
                    return;
                }
                FolioWebView mWebview8 = FolioPageFragment.this.getMWebview();
                if (mWebview8 == null) {
                    Intrinsics.throwNpe();
                }
                StringCompanionObject stringCompanionObject5 = StringCompanionObject.INSTANCE;
                String string5 = FolioPageFragment.this.getString(R.string.go_to_anchor);
                Intrinsics.checkExpressionValueIsNotNull(string5, "getString(R.string.go_to_anchor)");
                str4 = FolioPageFragment.this.mAnchorId;
                String format5 = String.format(string5, Arrays.copyOf(new Object[]{str4}, 1));
                Intrinsics.checkExpressionValueIsNotNull(format5, "java.lang.String.format(format, *args)");
                mWebview8.loadUrl(format5);
                FolioPageFragment.this.mAnchorId = null;
                return;
            }
            if (FolioPageFragment.this.getSearchLocatorVisible() == null) {
                isCurrentFragment2 = FolioPageFragment.this.isCurrentFragment();
                if (isCurrentFragment2) {
                    readLocator2 = FolioPageFragment.this.lastReadLocator;
                    if (readLocator2 == null) {
                        Intrinsics.throwNpe();
                    }
                    String cfi2 = readLocator2.getLocations().getCfi();
                    FolioWebView mWebview9 = FolioPageFragment.this.getMWebview();
                    if (mWebview9 == null) {
                        Intrinsics.throwNpe();
                    }
                    StringCompanionObject stringCompanionObject6 = StringCompanionObject.INSTANCE;
                    String string6 = FolioPageFragment.this.getString(R.string.callScrollToCfi);
                    Intrinsics.checkExpressionValueIsNotNull(string6, "getString(R.string.callScrollToCfi)");
                    String format6 = String.format(string6, Arrays.copyOf(new Object[]{cfi2}, 1));
                    Intrinsics.checkExpressionValueIsNotNull(format6, "java.lang.String.format(format, *args)");
                    mWebview9.loadUrl(format6);
                } else {
                    i2 = FolioPageFragment.this.spineIndex;
                    folioActivityCallback4 = FolioPageFragment.this.mActivityCallback;
                    if (folioActivityCallback4 == null) {
                        Intrinsics.throwNpe();
                    }
                    if (i2 != folioActivityCallback4.getCurrentChapterIndex() - 1) {
                        loadingView3 = FolioPageFragment.this.loadingView;
                        if (loadingView3 == null) {
                            Intrinsics.throwNpe();
                        }
                        loadingView3.hide();
                    } else {
                        FolioWebView mWebview10 = FolioPageFragment.this.getMWebview();
                        if (mWebview10 == null) {
                            Intrinsics.throwNpe();
                        }
                        mWebview10.loadUrl("javascript:scrollToLast()");
                    }
                }
            } else {
                StringCompanionObject stringCompanionObject7 = StringCompanionObject.INSTANCE;
                String string7 = FolioPageFragment.this.getString(R.string.callHighlightSearchLocator);
                Intrinsics.checkExpressionValueIsNotNull(string7, "getString(R.string.callHighlightSearchLocator)");
                SearchLocator searchLocatorVisible2 = FolioPageFragment.this.getSearchLocatorVisible();
                if (searchLocatorVisible2 != null && (locations2 = searchLocatorVisible2.getLocations()) != null) {
                    str5 = locations2.getCfi();
                }
                String format7 = String.format(string7, Arrays.copyOf(new Object[]{str5}, 1));
                Intrinsics.checkExpressionValueIsNotNull(format7, "java.lang.String.format(format, *args)");
                FolioWebView mWebview11 = FolioPageFragment.this.getMWebview();
                if (mWebview11 == null) {
                    Intrinsics.throwNpe();
                }
                mWebview11.loadUrl(format7);
            }
            FolioPageFragment.this.mIsPageReloaded = false;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            FolioActivityCallback folioActivityCallback;
            Intrinsics.checkParameterIsNotNull(view, "view");
            Intrinsics.checkParameterIsNotNull(url, "url");
            if (url.length() == 0) {
                return true;
            }
            folioActivityCallback = FolioPageFragment.this.mActivityCallback;
            if (folioActivityCallback == null) {
                Intrinsics.throwNpe();
            }
            if (!folioActivityCallback.goToChapter(url)) {
                FolioPageFragment.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));
            }
            return true;
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
            Intrinsics.checkParameterIsNotNull(view, "view");
            Intrinsics.checkParameterIsNotNull(url, "url");
            String lowerCase = url.toLowerCase();
            Intrinsics.checkExpressionValueIsNotNull(lowerCase, "(this as java.lang.String).toLowerCase()");
            if (StringsKt.contains$default(lowerCase, "/favicon.ico", false, 2, (Object) null)) {
                try {
                    return new WebResourceResponse("image/png", null, null);
                } catch (Exception e) {
                    Log.e(FolioPageFragment.LOG_TAG, "shouldInterceptRequest failed", e);
                }
            }
            return null;
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
            Intrinsics.checkParameterIsNotNull(view, "view");
            Intrinsics.checkParameterIsNotNull(request, "request");
            if (!request.isForMainFrame()) {
                Uri url = request.getUrl();
                Intrinsics.checkExpressionValueIsNotNull(url, "request.url");
                if (url.getPath() != null) {
                    Uri url2 = request.getUrl();
                    Intrinsics.checkExpressionValueIsNotNull(url2, "request.url");
                    String path = url2.getPath();
                    if (path == null) {
                        Intrinsics.throwNpe();
                    }
                    if (StringsKt.endsWith$default(path, "/favicon.ico", false, 2, (Object) null)) {
                        try {
                            return new WebResourceResponse("image/png", null, null);
                        } catch (Exception e) {
                            Log.e(FolioPageFragment.LOG_TAG, "shouldInterceptRequest failed", e);
                        }
                    }
                }
            }
            return null;
        }
    };
    private final FolioPageFragment$webChromeClient$1 webChromeClient = new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {
            Intrinsics.checkParameterIsNotNull(view, "view");
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Intrinsics.checkParameterIsNotNull(cm, "cm");
            super.onConsoleMessage(cm);
            return FolioWebView.INSTANCE.onWebViewConsoleMessage(cm, "WebViewConsole", cm.message() + " [" + cm.sourceId() + ":" + cm.lineNumber() + "]");
        }

        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            boolean isCurrentFragment;
            MediaController mediaController;
            Intrinsics.checkParameterIsNotNull(view, "view");
            Intrinsics.checkParameterIsNotNull(url, "url");
            Intrinsics.checkParameterIsNotNull(message, "message");
            Intrinsics.checkParameterIsNotNull(result, "result");
            if (!FolioPageFragment.this.isVisible()) {
                return true;
            }
            String str = message;
            if (TextUtils.isDigitsOnly(str)) {
                try {
                    FolioPageFragment.this.mTotalMinutes = Integer.parseInt(message);
                } catch (NumberFormatException unused) {
                    FolioPageFragment.this.mTotalMinutes = 0;
                }
            } else if (!Pattern.compile("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}").matcher(str).matches() && (!Intrinsics.areEqual(message, "undefined"))) {
                isCurrentFragment = FolioPageFragment.this.isCurrentFragment();
                if (isCurrentFragment) {
                    mediaController = FolioPageFragment.this.mediaController;
                    if (mediaController == null) {
                        Intrinsics.throwNpe();
                    }
                    mediaController.speakAudio(message);
                }
            }
            result.confirm();
            return true;
        }
    };

    @Metadata(bv = {1, 0, 3}, k = 3, mv = {1, 1, 13})
    public final class WhenMappings {
        public static final int[] $EnumSwitchMapping$0;

        static {
            int[] iArr = new int[MediaOverlayHighlightStyleEvent.Style.values().length];
            $EnumSwitchMapping$0 = iArr;
            iArr[MediaOverlayHighlightStyleEvent.Style.DEFAULT.ordinal()] = 1;
            iArr[MediaOverlayHighlightStyleEvent.Style.UNDERLINE.ordinal()] = 2;
            iArr[MediaOverlayHighlightStyleEvent.Style.BACKGROUND.ordinal()] = 3;
        }
    }

    @JvmStatic
    public static final FolioPageFragment newInstance(int i, String str, Link link, String str2) {
        return INSTANCE.newInstance(i, str, link, str2);
    }

    public void _$_clearFindViewByIdCache() {
        HashMap hashMap = this._$_findViewCache;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public View _$_findCachedViewById(int i) {
        if (this._$_findViewCache == null) {
            this._$_findViewCache = new HashMap();
        }
        View view = (View) this._$_findViewCache.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this._$_findViewCache.put(Integer.valueOf(i), findViewById);
        return findViewById;
    }

    @Override
    public void onError() {
    }

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J(\u0010\n\u001a\u00020\u000b2\u0006\u0010\f\u001a\u00020\r2\u0006\u0010\u000e\u001a\u00020\u00042\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0011\u001a\u00020\u0004H\u0007R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0004X\u0086T¢\u0006\u0002\n\u0000R\u000e\u0010\u0007\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u0010\u0010\t\u001a\u00020\u00048\u0006X\u0087\u0004¢\u0006\u0002\n\u0000¨\u0006\u0012"}, d2 = {"Lcom/folioreader/ui/fragment/FolioPageFragment$Companion;", "", "()V", FolioPageFragment.BUNDLE_BOOK_TITLE, "", FolioPageFragment.BUNDLE_READ_LOCATOR_CONFIG_CHANGE, FolioPageFragment.BUNDLE_SEARCH_LOCATOR, FolioPageFragment.BUNDLE_SPINE_INDEX, FolioPageFragment.BUNDLE_SPINE_ITEM, "LOG_TAG", "newInstance", "Lcom/folioreader/ui/fragment/FolioPageFragment;", "spineIndex", "", "bookTitle", "spineRef", "Lorg/readium/r2/shared/Link;", HighLightTable.COL_BOOK_ID, "folioreader_release"}, k = 1, mv = {1, 1, 13})
    public static final class Companion {
        private Companion() {
        }

        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        @JvmStatic
        public final FolioPageFragment newInstance(int spineIndex, String bookTitle, Link spineRef, String bookId) {
            Intrinsics.checkParameterIsNotNull(bookTitle, "bookTitle");
            Intrinsics.checkParameterIsNotNull(spineRef, "spineRef");
            Intrinsics.checkParameterIsNotNull(bookId, HighLightTable.COL_BOOK_ID);
            FolioPageFragment folioPageFragment = new FolioPageFragment();
            Bundle bundle = new Bundle();
            bundle.putInt(FolioPageFragment.BUNDLE_SPINE_INDEX, spineIndex);
            bundle.putString(FolioPageFragment.BUNDLE_BOOK_TITLE, bookTitle);
            bundle.putString(FolioReader.EXTRA_BOOK_ID, bookId);
            bundle.putSerializable(FolioPageFragment.BUNDLE_SPINE_ITEM, (Serializable) spineRef);
            folioPageFragment.setArguments(bundle);
            return folioPageFragment;
        }
    }

    static {
        Intrinsics.checkExpressionValueIsNotNull("FolioPageFragment", "FolioPageFragment::class.java.simpleName");
        LOG_TAG = "FolioPageFragment";
    }

    public final FolioWebView getMWebview() {
        return this.mWebview;
    }

    public final void setMWebview(FolioWebView folioWebView) {
        this.mWebview = folioWebView;
    }

    public final Link getSpineItem() {
        Link link = this.spineItem;
        if (link == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        return link;
    }

    public final void setSpineItem(Link link) {
        Intrinsics.checkParameterIsNotNull(link, "<set-?>");
        this.spineItem = link;
    }

    public final SearchLocator getSearchLocatorVisible() {
        return this.searchLocatorVisible;
    }

    public final void setSearchLocatorVisible(SearchLocator searchLocator) {
        this.searchLocatorVisible = searchLocator;
    }

    public final String getPageName() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.mBookTitle);
        sb.append("$");
        Link link = this.spineItem;
        if (link == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        sb.append(link.getHref());
        return sb.toString();
    }

    public final boolean isCurrentFragment() {
        if (isAdded()) {
            FolioActivityCallback folioActivityCallback = this.mActivityCallback;
            if (folioActivityCallback == null) {
                Intrinsics.throwNpe();
            }
            if (folioActivityCallback.getCurrentChapterIndex() == this.spineIndex) {
                return true;
            }
        }
        return false;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Intrinsics.checkParameterIsNotNull(inflater, "inflater");
        this.savedInstanceState = savedInstanceState;
        this.uiHandler = new Handler();
        if (getActivity() instanceof FolioActivityCallback) {
            this.mActivityCallback = (FolioActivityCallback) getActivity();
        }
        EventBus.getDefault().register(this);
        Bundle arguments = getArguments();
        if (arguments == null) {
            Intrinsics.throwNpe();
        }
        this.spineIndex = arguments.getInt(BUNDLE_SPINE_INDEX);
        Bundle arguments2 = getArguments();
        if (arguments2 == null) {
            Intrinsics.throwNpe();
        }
        this.mBookTitle = arguments2.getString(BUNDLE_BOOK_TITLE);
        Bundle arguments3 = getArguments();
        if (arguments3 == null) {
            Intrinsics.throwNpe();
        }
        Link serializable = arguments3.getSerializable(BUNDLE_SPINE_ITEM);
        if (serializable == null) {
            throw new TypeCastException("null cannot be cast to non-null type org.readium.r2.shared.Link");
        }
        this.spineItem = serializable;
        Bundle arguments4 = getArguments();
        if (arguments4 == null) {
            Intrinsics.throwNpe();
        }
        this.mBookId = arguments4.getString(FolioReader.EXTRA_BOOK_ID);
        FolioActivityCallback folioActivityCallback = this.mActivityCallback;
        String streamerUrl = folioActivityCallback != null ? folioActivityCallback.getStreamerUrl() : null;
        Link link = this.spineItem;
        if (link == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        String href = link.getHref();
        if (href == null) {
            Intrinsics.throwNpe();
        }
        if (href == null) {
            throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
        }
        String substring = href.substring(1);
        Intrinsics.checkExpressionValueIsNotNull(substring, "(this as java.lang.String).substring(startIndex)");
        Uri parse = Uri.parse(Intrinsics.stringPlus(streamerUrl, substring));
        Intrinsics.checkExpressionValueIsNotNull(parse, "Uri.parse(mActivityCallb…Item.href!!.substring(1))");
        this.chapterUrl = parse;
        this.searchLocatorVisible = savedInstanceState != null ? (SearchLocator) savedInstanceState.getParcelable(BUNDLE_SEARCH_LOCATOR) : null;
        Link link2 = this.spineItem;
        if (link2 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        if (link2 != null) {
            MediaController mediaController = new MediaController(getActivity(), MediaController.MediaType.TTS, this);
            this.mediaController = mediaController;
            mediaController.setTextToSpeech(getActivity());
        }
        this.highlightStyle = HighlightImpl.HighlightStyle.classForStyle(HighlightImpl.HighlightStyle.Normal);
        View inflate = inflater.inflate(R.layout.folio_page_fragment, container, false);
        this.mRootView = inflate;
        if (inflate == null) {
            Intrinsics.throwNpe();
        }
        View findViewById = inflate.findViewById(R.id.pagesLeft);
        if (findViewById == null) {
            throw new TypeCastException("null cannot be cast to non-null type android.widget.TextView");
        }
        this.mPagesLeftTextView = (TextView) findViewById;
        View view = this.mRootView;
        if (view == null) {
            Intrinsics.throwNpe();
        }
        View findViewById2 = view.findViewById(R.id.minutesLeft);
        if (findViewById2 == null) {
            throw new TypeCastException("null cannot be cast to non-null type android.widget.TextView");
        }
        this.mMinutesLeftTextView = (TextView) findViewById2;
        this.mConfig = AppUtil.INSTANCE.getSavedConfig(getContext());
        View view2 = this.mRootView;
        if (view2 == null) {
            Intrinsics.throwNpe();
        }
        this.loadingView = (LoadingView) view2.findViewById(R.id.loadingView);
        initSeekbar();
        initAnimations();
        initWebView();
        updatePagesLeftTextBg();
        return this.mRootView;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public final void pauseButtonClicked(MediaOverlayPlayPauseEvent event) {
        Intrinsics.checkParameterIsNotNull(event, NotificationCompat.CATEGORY_EVENT);
        if (isAdded()) {
            Link link = this.spineItem;
            if (link == null) {
                Intrinsics.throwUninitializedPropertyAccessException("spineItem");
            }
            if (link == null) {
                Intrinsics.throwNpe();
            }
            if (Intrinsics.areEqual(link.getHref(), event.getHref())) {
                MediaController mediaController = this.mediaController;
                if (mediaController == null) {
                    Intrinsics.throwNpe();
                }
                mediaController.stateChanged(event);
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public final void speedChanged(MediaOverlaySpeedEvent event) {
        Intrinsics.checkParameterIsNotNull(event, NotificationCompat.CATEGORY_EVENT);
        MediaController mediaController = this.mediaController;
        if (mediaController != null) {
            if (mediaController == null) {
                Intrinsics.throwNpe();
            }
            mediaController.setSpeed(event.getSpeed());
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public final void styleChanged(MediaOverlayHighlightStyleEvent event) {
        Intrinsics.checkParameterIsNotNull(event, NotificationCompat.CATEGORY_EVENT);
        if (isAdded()) {
            MediaOverlayHighlightStyleEvent.Style style = event.getStyle();
            if (style != null) {
                int i = WhenMappings.$EnumSwitchMapping$0[style.ordinal()];
                if (i == 1) {
                    this.highlightStyle = HighlightImpl.HighlightStyle.classForStyle(HighlightImpl.HighlightStyle.Normal);
                } else if (i == 2) {
                    this.highlightStyle = HighlightImpl.HighlightStyle.classForStyle(HighlightImpl.HighlightStyle.DottetUnderline);
                } else if (i == 3) {
                    this.highlightStyle = HighlightImpl.HighlightStyle.classForStyle(HighlightImpl.HighlightStyle.TextColor);
                }
            }
            FolioWebView folioWebView = this.mWebview;
            if (folioWebView == null) {
                Intrinsics.throwNpe();
            }
            StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
            String string = getString(R.string.setmediaoverlaystyle);
            Intrinsics.checkExpressionValueIsNotNull(string, "getString(R.string.setmediaoverlaystyle)");
            String format = String.format(string, Arrays.copyOf(new Object[]{this.highlightStyle}, 1));
            Intrinsics.checkExpressionValueIsNotNull(format, "java.lang.String.format(format, *args)");
            folioWebView.loadUrl(format);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public final void reload(ReloadDataEvent reloadDataEvent) {
        Intrinsics.checkParameterIsNotNull(reloadDataEvent, "reloadDataEvent");
        if (isCurrentFragment()) {
            getLastReadLocator();
        }
        if (isAdded()) {
            FolioWebView folioWebView = this.mWebview;
            if (folioWebView == null) {
                Intrinsics.throwNpe();
            }
            folioWebView.dismissPopupWindow();
            FolioWebView folioWebView2 = this.mWebview;
            if (folioWebView2 == null) {
                Intrinsics.throwNpe();
            }
            folioWebView2.initViewTextSelection();
            LoadingView loadingView = this.loadingView;
            if (loadingView == null) {
                Intrinsics.throwNpe();
            }
            loadingView.updateTheme();
            LoadingView loadingView2 = this.loadingView;
            if (loadingView2 == null) {
                Intrinsics.throwNpe();
            }
            loadingView2.show();
            this.mIsPageReloaded = true;
            setHtml(true);
            updatePagesLeftTextBg();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public final void updateHighlight(UpdateHighlightEvent event) {
        Intrinsics.checkParameterIsNotNull(event, NotificationCompat.CATEGORY_EVENT);
        if (isAdded()) {
            String generateRangyString = HighlightUtil.generateRangyString(getPageName());
            Intrinsics.checkExpressionValueIsNotNull(generateRangyString, "HighlightUtil.generateRangyString(pageName)");
            this.rangy = generateRangyString;
            loadRangy(generateRangyString);
        }
    }

    public final void scrollToAnchorId(String href) {
        Intrinsics.checkParameterIsNotNull(href, Constants.HREF);
        String str = href;
        if (TextUtils.isEmpty(str) || StringsKt.indexOf$default(str, '#', 0, false, 6, (Object) null) == -1) {
            return;
        }
        String substring = href.substring(StringsKt.lastIndexOf$default(str, '#', 0, false, 6, (Object) null) + 1);
        Intrinsics.checkExpressionValueIsNotNull(substring, "(this as java.lang.String).substring(startIndex)");
        this.mAnchorId = substring;
        LoadingView loadingView = this.loadingView;
        if (loadingView != null) {
            if (loadingView == null) {
                Intrinsics.throwNpe();
            }
            if (loadingView.getVisibility() != 0) {
                LoadingView loadingView2 = this.loadingView;
                if (loadingView2 == null) {
                    Intrinsics.throwNpe();
                }
                loadingView2.show();
                FolioWebView folioWebView = this.mWebview;
                if (folioWebView == null) {
                    Intrinsics.throwNpe();
                }
                StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
                String string = getString(R.string.go_to_anchor);
                Intrinsics.checkExpressionValueIsNotNull(string, "getString(R.string.go_to_anchor)");
                String format = String.format(string, Arrays.copyOf(new Object[]{this.mAnchorId}, 1));
                Intrinsics.checkExpressionValueIsNotNull(format, "java.lang.String.format(format, *args)");
                folioWebView.loadUrl(format);
                this.mAnchorId = null;
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public final void resetCurrentIndex(RewindIndexEvent resetIndex) {
        Intrinsics.checkParameterIsNotNull(resetIndex, "resetIndex");
        if (isCurrentFragment()) {
            FolioWebView folioWebView = this.mWebview;
            if (folioWebView == null) {
                Intrinsics.throwNpe();
            }
            folioWebView.loadUrl("javascript:rewindCurrentIndex()");
        }
    }

    @Override
    public void onReceiveHtml(String html) {
        Intrinsics.checkParameterIsNotNull(html, "html");
        if (isAdded()) {
            this.mHtmlString = html;
            setHtml(false);
        }
    }

    private final void setHtml(boolean reloaded) {
        final String string;
        Link link = this.spineItem;
        if (link == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        if (link != null) {
            this.mConfig = AppUtil.INSTANCE.getSavedConfig(getContext());
            Link link2 = this.spineItem;
            if (link2 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("spineItem");
            }
            String href = link2.getHref();
            final Ref.ObjectRef objectRef = new Ref.ObjectRef();
            objectRef.element = "";
            if (href == null) {
                Intrinsics.throwNpe();
            }
            int lastIndexOf$default = StringsKt.lastIndexOf$default(href, JsonPointer.SEPARATOR, 0, false, 6, (Object) null);
            if (lastIndexOf$default != -1) {
                String substring = href.substring(1, lastIndexOf$default + 1);
                Intrinsics.checkExpressionValueIsNotNull(substring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
                objectRef.element = substring;
            }
            Link link3 = this.spineItem;
            if (link3 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("spineItem");
            }
            String typeLink = link3.getTypeLink();
            if (typeLink == null) {
                Intrinsics.throwNpe();
            }
            if (StringsKt.equals(typeLink, getString(R.string.xhtml_mime_type), true)) {
                string = getString(R.string.xhtml_mime_type);
                Intrinsics.checkExpressionValueIsNotNull(string, "getString(R.string.xhtml_mime_type)");
            } else {
                string = getString(R.string.html_mime_type);
                Intrinsics.checkExpressionValueIsNotNull(string, "getString(R.string.html_mime_type)");
            }
            Handler handler = this.uiHandler;
            if (handler == null) {
                Intrinsics.throwUninitializedPropertyAccessException("uiHandler");
            }
            handler.post(new Runnable() {
                @Override
                public final void run() {
                    FolioActivityCallback folioActivityCallback;
                    String str;
                    Config config;
                    FolioWebView mWebview = FolioPageFragment.this.getMWebview();
                    if (mWebview == null) {
                        Intrinsics.throwNpe();
                    }
                    folioActivityCallback = FolioPageFragment.this.mActivityCallback;
                    String stringPlus = Intrinsics.stringPlus(folioActivityCallback != null ? folioActivityCallback.getStreamerUrl() : null, (String) objectRef.element);
                    Context context = FolioPageFragment.this.getContext();
                    if (context == null) {
                        Intrinsics.throwNpe();
                    }
                    str = FolioPageFragment.this.mHtmlString;
                    config = FolioPageFragment.this.mConfig;
                    if (config == null) {
                        Intrinsics.throwNpe();
                    }
                    mWebview.loadDataWithBaseURL(stringPlus, HtmlUtil.getHtmlContent(context, str, config), string, Key.STRING_CHARSET_NAME, null);
                }
            });
        }
    }

    public final void scrollToLast() {
        throw new UnsupportedOperationException("Method not decompiled: com.folioreader.ui.fragment.FolioPageFragment.scrollToLast():void");
    }

    public final void scrollToFirst() {
        throw new UnsupportedOperationException("Method not decompiled: com.folioreader.ui.fragment.FolioPageFragment.scrollToFirst():void");
    }

    private final void initWebView() {
        View view = this.mRootView;
        if (view == null) {
            Intrinsics.throwNpe();
        }
        FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.webViewLayout);
        FolioWebView folioWebView = (FolioWebView) frameLayout.findViewById(R.id.folioWebView);
        this.mWebview = folioWebView;
        if (folioWebView == null) {
            Intrinsics.throwNpe();
        }
        folioWebView.setParentFragment(this);
        this.webViewPager = (WebViewPager) frameLayout.findViewById(R.id.webViewPager);
        if (getActivity() instanceof FolioActivityCallback) {
            FolioWebView folioWebView2 = this.mWebview;
            if (folioWebView2 == null) {
                Intrinsics.throwNpe();
            }
            FolioActivityCallback folioActivityCallback = (FolioActivityCallback) getActivity();
            if (folioActivityCallback == null) {
                Intrinsics.throwNpe();
            }
            folioWebView2.setFolioActivityCallback(folioActivityCallback);
        }
        setupScrollBar();
        FolioWebView folioWebView3 = this.mWebview;
        if (folioWebView3 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView3.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public final void onLayoutChange(View view2, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) {
                VerticalSeekbar verticalSeekbar;
                FolioWebView mWebview = FolioPageFragment.this.getMWebview();
                if (mWebview == null) {
                    Intrinsics.throwNpe();
                }
                float contentHeight = mWebview.getContentHeight();
                if (FolioPageFragment.this.getMWebview() == null) {
                    Intrinsics.throwNpe();
                }
                int floor = (int) Math.floor(contentHeight * r2.getScale());
                FolioWebView mWebview2 = FolioPageFragment.this.getMWebview();
                if (mWebview2 == null) {
                    Intrinsics.throwNpe();
                }
                int measuredHeight = mWebview2.getMeasuredHeight();
                verticalSeekbar = FolioPageFragment.this.mScrollSeekbar;
                if (verticalSeekbar == null) {
                    Intrinsics.throwNpe();
                }
                verticalSeekbar.setMaximum(floor - measuredHeight);
            }
        });
        FolioWebView folioWebView4 = this.mWebview;
        if (folioWebView4 == null) {
            Intrinsics.throwNpe();
        }
        WebSettings settings = folioWebView4.getSettings();
        Intrinsics.checkExpressionValueIsNotNull(settings, "mWebview!!.settings");
        settings.setJavaScriptEnabled(true);
        FolioWebView folioWebView5 = this.mWebview;
        if (folioWebView5 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView5.setVerticalScrollBarEnabled(false);
        FolioWebView folioWebView6 = this.mWebview;
        if (folioWebView6 == null) {
            Intrinsics.throwNpe();
        }
        WebSettings settings2 = folioWebView6.getSettings();
        Intrinsics.checkExpressionValueIsNotNull(settings2, "mWebview!!.settings");
        settings2.setAllowFileAccess(true);
        FolioWebView folioWebView7 = this.mWebview;
        if (folioWebView7 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView7.setHorizontalScrollBarEnabled(false);
        FolioWebView folioWebView8 = this.mWebview;
        if (folioWebView8 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView8.addJavascriptInterface(this, "Highlight");
        FolioWebView folioWebView9 = this.mWebview;
        if (folioWebView9 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView9.addJavascriptInterface(this, "FolioPageFragment");
        FolioWebView folioWebView10 = this.mWebview;
        if (folioWebView10 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView10.addJavascriptInterface(this.webViewPager, "WebViewPager");
        FolioWebView folioWebView11 = this.mWebview;
        if (folioWebView11 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView11.addJavascriptInterface(this.loadingView, "LoadingView");
        FolioWebView folioWebView12 = this.mWebview;
        if (folioWebView12 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView12.addJavascriptInterface(this.mWebview, "FolioWebView");
        FolioWebView folioWebView13 = this.mWebview;
        if (folioWebView13 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView13.setScrollListener(new FolioWebView.ScrollListener() {
            @Override
            public void onScrollChange(int percent) {
                VerticalSeekbar verticalSeekbar;
                verticalSeekbar = FolioPageFragment.this.mScrollSeekbar;
                if (verticalSeekbar == null) {
                    Intrinsics.throwNpe();
                }
                verticalSeekbar.setProgressAndThumb(percent);
                FolioPageFragment.this.updatePagesLeftText(percent);
            }
        });
        FolioWebView folioWebView14 = this.mWebview;
        if (folioWebView14 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView14.setWebViewClient(this.webViewClient);
        FolioWebView folioWebView15 = this.mWebview;
        if (folioWebView15 == null) {
            Intrinsics.throwNpe();
        }
        folioWebView15.setWebChromeClient(this.webChromeClient);
        FolioWebView folioWebView16 = this.mWebview;
        if (folioWebView16 == null) {
            Intrinsics.throwNpe();
        }
        WebSettings settings3 = folioWebView16.getSettings();
        Intrinsics.checkExpressionValueIsNotNull(settings3, "mWebview!!.settings");
        settings3.setDefaultTextEncodingName("utf-8");
        HtmlTask htmlTask = new HtmlTask(this);
        Uri uri = this.chapterUrl;
        if (uri == null) {
            Intrinsics.throwUninitializedPropertyAccessException("chapterUrl");
        }
        htmlTask.execute(uri.toString());
    }

    @Override
    public void onStop() {
        super.onStop();
        String str = LOG_TAG;
        StringBuilder sb = new StringBuilder("-> onStop -> ");
        Link link = this.spineItem;
        if (link == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        sb.append(link.getHref());
        sb.append(" -> ");
        sb.append(isCurrentFragment());
        Log.v(str, sb.toString());
        MediaController mediaController = this.mediaController;
        if (mediaController == null) {
            Intrinsics.throwNpe();
        }
        mediaController.stop();
        if (isCurrentFragment()) {
            getLastReadLocator();
        }
    }

    public final ReadLocator getLastReadLocator() {
        String str = LOG_TAG;
        StringBuilder sb = new StringBuilder("-> getLastReadLocator -> ");
        Link link = this.spineItem;
        if (link == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        String href = link.getHref();
        if (href == null) {
            Intrinsics.throwNpe();
        }
        sb.append(href);
        Log.v(str, sb.toString());
        try {
            synchronized (this) {
                FolioWebView folioWebView = this.mWebview;
                if (folioWebView == null) {
                    Intrinsics.throwNpe();
                }
                folioWebView.loadUrl(getString(R.string.callComputeLastReadCfi));
                wait(5000L);
                Unit unit = Unit.INSTANCE;
            }
        } catch (InterruptedException e) {
            Log.e(LOG_TAG, "-> ", e);
        }
        return this.lastReadLocator;
    }

    @JavascriptInterface
    public final void storeLastReadCfi(String cfi) {
        Intrinsics.checkParameterIsNotNull(cfi, "cfi");
        synchronized (this) {
            Link link = this.spineItem;
            if (link == null) {
                Intrinsics.throwUninitializedPropertyAccessException("spineItem");
            }
            String href = link.getHref();
            if (href == null) {
                href = "";
            }
            String str = href;
            long time = new Date().getTime();
            Locations locations = new Locations((String) null, (String) null, (String) null, (String) null, (Double) null, (Long) null, 63, (DefaultConstructorMarker) null);
            locations.setCfi(cfi);
            String str2 = this.mBookId;
            if (str2 == null) {
                Intrinsics.throwNpe();
            }
            this.lastReadLocator = new ReadLocator(str2, str, time, locations);
            Intent intent = new Intent(FolioReader.ACTION_SAVE_READ_LOCATOR);
            intent.putExtra("com.folioreader.extra.READ_LOCATOR", this.lastReadLocator);
            Context context = getContext();
            if (context == null) {
                Intrinsics.throwNpe();
            }
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
            notify();
            Unit unit = Unit.INSTANCE;
        }
    }

    @JavascriptInterface
    public final void setHorizontalPageCount(int horizontalPageCount) {
        String str = LOG_TAG;
        StringBuilder sb = new StringBuilder("-> setHorizontalPageCount = ");
        sb.append(horizontalPageCount);
        sb.append(" -> ");
        Link link = this.spineItem;
        if (link == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        sb.append(link.getHref());
        Log.v(str, sb.toString());
        FolioWebView folioWebView = this.mWebview;
        if (folioWebView == null) {
            Intrinsics.throwNpe();
        }
        folioWebView.setHorizontalPageCount(horizontalPageCount);
    }

    public final void loadRangy(String rangy) {
        Intrinsics.checkParameterIsNotNull(rangy, "rangy");
        FolioWebView folioWebView = this.mWebview;
        if (folioWebView == null) {
            Intrinsics.throwNpe();
        }
        StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
        String format = String.format("javascript:if(typeof ssReader !== \"undefined\"){ssReader.setHighlights('%s');}", Arrays.copyOf(new Object[]{rangy}, 1));
        Intrinsics.checkExpressionValueIsNotNull(format, "java.lang.String.format(format, *args)");
        folioWebView.loadUrl(format);
    }

    private final void setupScrollBar() {
        Config config = this.mConfig;
        if (config == null) {
            Intrinsics.throwNpe();
        }
        int themeColor = config.getThemeColor();
        VerticalSeekbar verticalSeekbar = this.mScrollSeekbar;
        if (verticalSeekbar == null) {
            Intrinsics.throwNpe();
        }
        UiUtil.setColorIntToDrawable(themeColor, verticalSeekbar.getProgressDrawable());
        FragmentActivity activity = getActivity();
        if (activity == null) {
            Intrinsics.throwNpe();
        }
        Drawable drawable = ContextCompat.getDrawable(activity, R.drawable.icons_sroll);
        Config config2 = this.mConfig;
        if (config2 == null) {
            Intrinsics.throwNpe();
        }
        int themeColor2 = config2.getThemeColor();
        if (drawable == null) {
            Intrinsics.throwNpe();
        }
        UiUtil.setColorIntToDrawable(themeColor2, drawable);
        VerticalSeekbar verticalSeekbar2 = this.mScrollSeekbar;
        if (verticalSeekbar2 == null) {
            Intrinsics.throwNpe();
        }
        verticalSeekbar2.setThumb(drawable);
    }

    private final void initSeekbar() {
        View view = this.mRootView;
        if (view == null) {
            Intrinsics.throwNpe();
        }
        View findViewById = view.findViewById(R.id.scrollSeekbar);
        if (findViewById == null) {
            throw new TypeCastException("null cannot be cast to non-null type com.folioreader.ui.view.VerticalSeekbar");
        }
        VerticalSeekbar verticalSeekbar = (VerticalSeekbar) findViewById;
        this.mScrollSeekbar = verticalSeekbar;
        if (verticalSeekbar == null) {
            Intrinsics.throwNpe();
        }
        verticalSeekbar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.default_theme_accent_color), PorterDuff.Mode.SRC_IN);
    }

    private final void updatePagesLeftTextBg() {
        Config config = this.mConfig;
        if (config == null) {
            Intrinsics.throwNpe();
        }
        if (config.isNightMode()) {
            View view = this.mRootView;
            if (view == null) {
                Intrinsics.throwNpe();
            }
            view.findViewById(R.id.indicatorLayout).setBackgroundColor(Color.parseColor("#131313"));
            return;
        }
        View view2 = this.mRootView;
        if (view2 == null) {
            Intrinsics.throwNpe();
        }
        view2.findViewById(R.id.indicatorLayout).setBackgroundColor(-1);
    }

    public final void updatePagesLeftText(int scrollY) {
        String string;
        String string2;
        double d = scrollY;
        try {
            if (this.mWebview == null) {
                Intrinsics.throwNpe();
            }
            int ceil = (int) (Math.ceil(d / r11.getWebViewHeight()) + 1);
            FolioWebView folioWebView = this.mWebview;
            if (folioWebView == null) {
                Intrinsics.throwNpe();
            }
            double contentHeightVal = folioWebView.getContentHeightVal();
            if (this.mWebview == null) {
                Intrinsics.throwNpe();
            }
            int ceil2 = (int) Math.ceil(contentHeightVal / r6.getWebViewHeight());
            int i = ceil2 - ceil;
            if (i > 1) {
                string = getString(R.string.pages_left);
            } else {
                string = getString(R.string.page_left);
            }
            Intrinsics.checkExpressionValueIsNotNull(string, "if (pagesRemaining > 1)\n…tring(R.string.page_left)");
            StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
            Locale locale = Locale.US;
            Intrinsics.checkExpressionValueIsNotNull(locale, "Locale.US");
            String format = String.format(locale, string, Arrays.copyOf(new Object[]{Integer.valueOf(i)}, 1));
            Intrinsics.checkExpressionValueIsNotNull(format, "java.lang.String.format(locale, format, *args)");
            int ceil3 = (int) Math.ceil((i * this.mTotalMinutes) / ceil2);
            if (ceil3 > 1) {
                StringCompanionObject stringCompanionObject2 = StringCompanionObject.INSTANCE;
                Locale locale2 = Locale.US;
                Intrinsics.checkExpressionValueIsNotNull(locale2, "Locale.US");
                String string3 = getString(R.string.minutes_left);
                Intrinsics.checkExpressionValueIsNotNull(string3, "getString(R.string.minutes_left)");
                string2 = String.format(locale2, string3, Arrays.copyOf(new Object[]{Integer.valueOf(ceil3)}, 1));
                Intrinsics.checkExpressionValueIsNotNull(string2, "java.lang.String.format(locale, format, *args)");
            } else if (ceil3 == 1) {
                StringCompanionObject stringCompanionObject3 = StringCompanionObject.INSTANCE;
                Locale locale3 = Locale.US;
                Intrinsics.checkExpressionValueIsNotNull(locale3, "Locale.US");
                String string4 = getString(R.string.minute_left);
                Intrinsics.checkExpressionValueIsNotNull(string4, "getString(R.string.minute_left)");
                string2 = String.format(locale3, string4, Arrays.copyOf(new Object[]{Integer.valueOf(ceil3)}, 1));
                Intrinsics.checkExpressionValueIsNotNull(string2, "java.lang.String.format(locale, format, *args)");
            } else {
                string2 = getString(R.string.less_than_minute);
                Intrinsics.checkExpressionValueIsNotNull(string2, "getString(R.string.less_than_minute)");
            }
            TextView textView = this.mMinutesLeftTextView;
            if (textView == null) {
                Intrinsics.throwNpe();
            }
            textView.setText(string2);
            TextView textView2 = this.mPagesLeftTextView;
            if (textView2 == null) {
                Intrinsics.throwNpe();
            }
            textView2.setText(format);
        } catch (ArithmeticException e) {
            Log.e("divide error", e.toString());
        } catch (IllegalStateException e2) {
            Log.e("divide error", e2.toString());
        }
    }

    private final void initAnimations() {
        Animation loadAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.fadein);
        this.mFadeInAnimation = loadAnimation;
        if (loadAnimation == null) {
            Intrinsics.throwNpe();
        }
        loadAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationRepeat(Animation animation) {
                Intrinsics.checkParameterIsNotNull(animation, "animation");
            }

            @Override
            public void onAnimationStart(Animation animation) {
                VerticalSeekbar verticalSeekbar;
                Intrinsics.checkParameterIsNotNull(animation, "animation");
                verticalSeekbar = FolioPageFragment.this.mScrollSeekbar;
                if (verticalSeekbar == null) {
                    Intrinsics.throwNpe();
                }
                verticalSeekbar.setVisibility(0);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Intrinsics.checkParameterIsNotNull(animation, "animation");
                FolioPageFragment.this.fadeOutSeekBarIfVisible();
            }
        });
        Animation loadAnimation2 = AnimationUtils.loadAnimation(getActivity(), R.anim.fadeout);
        this.mFadeOutAnimation = loadAnimation2;
        if (loadAnimation2 == null) {
            Intrinsics.throwNpe();
        }
        loadAnimation2.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationRepeat(Animation animation) {
                Intrinsics.checkParameterIsNotNull(animation, "animation");
            }

            @Override
            public void onAnimationStart(Animation animation) {
                Intrinsics.checkParameterIsNotNull(animation, "animation");
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                VerticalSeekbar verticalSeekbar;
                Intrinsics.checkParameterIsNotNull(animation, "animation");
                verticalSeekbar = FolioPageFragment.this.mScrollSeekbar;
                if (verticalSeekbar == null) {
                    Intrinsics.throwNpe();
                }
                verticalSeekbar.setVisibility(4);
            }
        });
    }

    @Override
    public void fadeInSeekBarIfInvisible() {
        VerticalSeekbar verticalSeekbar = this.mScrollSeekbar;
        if (verticalSeekbar == null) {
            Intrinsics.throwNpe();
        }
        if (verticalSeekbar.getVisibility() != 4) {
            VerticalSeekbar verticalSeekbar2 = this.mScrollSeekbar;
            if (verticalSeekbar2 == null) {
                Intrinsics.throwNpe();
            }
            if (verticalSeekbar2.getVisibility() != 8) {
                return;
            }
        }
        VerticalSeekbar verticalSeekbar3 = this.mScrollSeekbar;
        if (verticalSeekbar3 == null) {
            Intrinsics.throwNpe();
        }
        verticalSeekbar3.startAnimation(this.mFadeInAnimation);
    }

    public final void fadeOutSeekBarIfVisible() {
        VerticalSeekbar verticalSeekbar = this.mScrollSeekbar;
        if (verticalSeekbar == null) {
            Intrinsics.throwNpe();
        }
        if (verticalSeekbar.getVisibility() == 0) {
            VerticalSeekbar verticalSeekbar2 = this.mScrollSeekbar;
            if (verticalSeekbar2 == null) {
                Intrinsics.throwNpe();
            }
            verticalSeekbar2.startAnimation(this.mFadeOutAnimation);
        }
    }

    @Override
    public void onDestroyView() {
        Animation animation = this.mFadeInAnimation;
        if (animation == null) {
            Intrinsics.throwNpe();
        }
        animation.setAnimationListener(null);
        Animation animation2 = this.mFadeOutAnimation;
        if (animation2 == null) {
            Intrinsics.throwNpe();
        }
        animation2.setAnimationListener(null);
        EventBus.getDefault().unregister(this);
        super.onDestroyView();
        _$_clearFindViewByIdCache();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        Intrinsics.checkParameterIsNotNull(outState, "outState");
        super.onSaveInstanceState(outState);
        String str = LOG_TAG;
        StringBuilder sb = new StringBuilder("-> onSaveInstanceState -> ");
        Link link = this.spineItem;
        if (link == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        sb.append(link.getHref());
        Log.v(str, sb.toString());
        this.outState = outState;
        outState.putParcelable(BUNDLE_SEARCH_LOCATOR, this.searchLocatorVisible);
    }

    public final void highlight(HighlightImpl.HighlightStyle style, boolean isAlreadyCreated) {
        Intrinsics.checkParameterIsNotNull(style, "style");
        if (!isAlreadyCreated) {
            FolioWebView folioWebView = this.mWebview;
            if (folioWebView == null) {
                Intrinsics.throwNpe();
            }
            StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
            String format = String.format("javascript:if(typeof ssReader !== \"undefined\"){ssReader.highlightSelection('%s');}", Arrays.copyOf(new Object[]{HighlightImpl.HighlightStyle.classForStyle(style)}, 1));
            Intrinsics.checkExpressionValueIsNotNull(format, "java.lang.String.format(format, *args)");
            folioWebView.loadUrl(format);
            return;
        }
        FolioWebView folioWebView2 = this.mWebview;
        if (folioWebView2 == null) {
            Intrinsics.throwNpe();
        }
        StringCompanionObject stringCompanionObject2 = StringCompanionObject.INSTANCE;
        String format2 = String.format("javascript:setHighlightStyle('%s')", Arrays.copyOf(new Object[]{HighlightImpl.HighlightStyle.classForStyle(style)}, 1));
        Intrinsics.checkExpressionValueIsNotNull(format2, "java.lang.String.format(format, *args)");
        folioWebView2.loadUrl(format2);
    }

    @Override
    public void resetCurrentIndex() {
        if (isCurrentFragment()) {
            FolioWebView folioWebView = this.mWebview;
            if (folioWebView == null) {
                Intrinsics.throwNpe();
            }
            folioWebView.loadUrl("javascript:rewindCurrentIndex()");
        }
    }

    @JavascriptInterface
    public final void onReceiveHighlights(String html) {
        if (html != null) {
            FragmentActivity activity = getActivity();
            if (activity == null) {
                Intrinsics.throwNpe();
            }
            Intrinsics.checkExpressionValueIsNotNull(activity, "activity!!");
            String createHighlightRangy = HighlightUtil.createHighlightRangy(activity.getApplicationContext(), html, this.mBookId, getPageName(), this.spineIndex, this.rangy);
            Intrinsics.checkExpressionValueIsNotNull(createHighlightRangy, "HighlightUtil.createHigh…      rangy\n            )");
            this.rangy = createHighlightRangy;
        }
    }

    @Override
    public void highLightText(String fragmentId) {
        Intrinsics.checkParameterIsNotNull(fragmentId, "fragmentId");
        FolioWebView folioWebView = this.mWebview;
        if (folioWebView == null) {
            Intrinsics.throwNpe();
        }
        StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
        String string = getString(R.string.audio_mark_id);
        Intrinsics.checkExpressionValueIsNotNull(string, "getString(R.string.audio_mark_id)");
        String format = String.format(string, Arrays.copyOf(new Object[]{fragmentId}, 1));
        Intrinsics.checkExpressionValueIsNotNull(format, "java.lang.String.format(format, *args)");
        folioWebView.loadUrl(format);
    }

    @Override
    public void highLightTTS() {
        FolioWebView folioWebView = this.mWebview;
        if (folioWebView == null) {
            Intrinsics.throwNpe();
        }
        folioWebView.loadUrl("javascript:alert(getSentenceWithIndex('epub-media-overlay-playing'))");
    }

    @JavascriptInterface
    public final void getUpdatedHighlightId(String id, String style) {
        Intrinsics.checkParameterIsNotNull(style, "style");
        if (id != null) {
            HighlightImpl updateHighlightStyle = HighLightTable.updateHighlightStyle(id, style);
            if (updateHighlightStyle != null) {
                FragmentActivity activity = getActivity();
                if (activity == null) {
                    Intrinsics.throwNpe();
                }
                Intrinsics.checkExpressionValueIsNotNull(activity, "activity!!");
                HighlightUtil.sendHighlightBroadcastEvent(activity.getApplicationContext(), updateHighlightStyle, HighLight.HighLightAction.MODIFY);
            }
            final String generateRangyString = HighlightUtil.generateRangyString(getPageName());
            FragmentActivity activity2 = getActivity();
            if (activity2 == null) {
                Intrinsics.throwNpe();
            }
            activity2.runOnUiThread(new Runnable() {
                @Override
                public final void run() {
                    FolioPageFragment folioPageFragment = FolioPageFragment.this;
                    String str = generateRangyString;
                    Intrinsics.checkExpressionValueIsNotNull(str, "rangyString");
                    folioPageFragment.loadRangy(str);
                }
            });
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (isCurrentFragment()) {
            Bundle bundle = this.outState;
            if (bundle != null) {
                if (bundle == null) {
                    Intrinsics.throwNpe();
                }
                bundle.putSerializable(BUNDLE_READ_LOCATOR_CONFIG_CHANGE, (Serializable) this.lastReadLocator);
            }
            if (getActivity() != null) {
                FragmentActivity activity = getActivity();
                if (activity == null) {
                    Intrinsics.throwNpe();
                }
                Intrinsics.checkExpressionValueIsNotNull(activity, "activity!!");
                if (!activity.isFinishing()) {
                    FolioActivityCallback folioActivityCallback = this.mActivityCallback;
                    if (folioActivityCallback == null) {
                        Intrinsics.throwNpe();
                    }
                    folioActivityCallback.storeLastReadLocator(this.lastReadLocator);
                }
            }
        }
        FolioWebView folioWebView = this.mWebview;
        if (folioWebView != null) {
            if (folioWebView == null) {
                Intrinsics.throwNpe();
            }
            folioWebView.destroy();
        }
    }

    public final void scrollToHighlightId(String highlightId) {
        Intrinsics.checkParameterIsNotNull(highlightId, "highlightId");
        this.highlightId = highlightId;
        LoadingView loadingView = this.loadingView;
        if (loadingView != null) {
            if (loadingView == null) {
                Intrinsics.throwNpe();
            }
            if (loadingView.getVisibility() != 0) {
                LoadingView loadingView2 = this.loadingView;
                if (loadingView2 == null) {
                    Intrinsics.throwNpe();
                }
                loadingView2.show();
                FolioWebView folioWebView = this.mWebview;
                if (folioWebView == null) {
                    Intrinsics.throwNpe();
                }
                StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
                String string = getString(R.string.go_to_highlight);
                Intrinsics.checkExpressionValueIsNotNull(string, "getString(R.string.go_to_highlight)");
                String format = String.format(string, Arrays.copyOf(new Object[]{highlightId}, 1));
                Intrinsics.checkExpressionValueIsNotNull(format, "java.lang.String.format(format, *args)");
                folioWebView.loadUrl(format);
                this.highlightId = null;
            }
        }
    }

    public final void highlightSearchLocator(SearchLocator searchLocator) {
        Locations locations;
        Intrinsics.checkParameterIsNotNull(searchLocator, "searchLocator");
        Log.v(LOG_TAG, "-> highlightSearchLocator");
        this.searchLocatorVisible = searchLocator;
        LoadingView loadingView = this.loadingView;
        if (loadingView != null) {
            if (loadingView == null) {
                Intrinsics.throwNpe();
            }
            if (loadingView.getVisibility() != 0) {
                LoadingView loadingView2 = this.loadingView;
                if (loadingView2 == null) {
                    Intrinsics.throwNpe();
                }
                loadingView2.show();
                StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
                String string = getString(R.string.callHighlightSearchLocator);
                Intrinsics.checkExpressionValueIsNotNull(string, "getString(R.string.callHighlightSearchLocator)");
                SearchLocator searchLocator2 = this.searchLocatorVisible;
                String format = String.format(string, Arrays.copyOf(new Object[]{(searchLocator2 == null || (locations = searchLocator2.getLocations()) == null) ? null : locations.getCfi()}, 1));
                Intrinsics.checkExpressionValueIsNotNull(format, "java.lang.String.format(format, *args)");
                FolioWebView folioWebView = this.mWebview;
                if (folioWebView == null) {
                    Intrinsics.throwNpe();
                }
                folioWebView.loadUrl(format);
            }
        }
    }

    public final void clearSearchLocator() {
        String str = LOG_TAG;
        StringBuilder sb = new StringBuilder("-> clearSearchLocator -> ");
        Link link = this.spineItem;
        if (link == null) {
            Intrinsics.throwUninitializedPropertyAccessException("spineItem");
        }
        String href = link.getHref();
        if (href == null) {
            Intrinsics.throwNpe();
        }
        sb.append(href);
        Log.v(str, sb.toString());
        FolioWebView folioWebView = this.mWebview;
        if (folioWebView == null) {
            Intrinsics.throwNpe();
        }
        folioWebView.loadUrl(getString(R.string.callClearSelection));
        this.searchLocatorVisible = null;
    }
}