导航菜单

页面标题

页面副标题

FMG v6.0 - DocumentoActivity.java 源代码

正在查看: FMG v6.0 应用的 DocumentoActivity.java JAVA 源代码文件

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


package it.icontact.android.pdf2ipad.irisfmg.view.documento;

import android.animation.Animator;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import butterknife.BindBool;
import butterknife.BindDimen;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.shockwave.pdfium.util.SizeF;
import icepick.Icepick;
import it.icontact.android.pdf2ipad.irisfmg.App;
import it.icontact.android.pdf2ipad.irisfmg.R;
import it.icontact.android.pdf2ipad.irisfmg.R2;
import it.icontact.android.pdf2ipad.irisfmg.files.FileManagerPDFs;
import it.icontact.android.pdf2ipad.irisfmg.model.DB;
import it.icontact.android.pdf2ipad.irisfmg.model.Documento;
import it.icontact.android.pdf2ipad.irisfmg.model.StatisticaEntryUtils;
import it.icontact.android.pdf2ipad.irisfmg.utils.ui.AnimatorUtils;
import it.icontact.android.pdf2ipad.irisfmg.utils.ui.ViewUtils;
import it.icontact.android.pdf2ipad.irisfmg.view.documento.DocumentoActivityViewModel;
import java.io.File;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class DocumentoActivity extends AppCompatActivity implements OnLoadCompleteListener, OnPageChangeListener {
    private Documento documento;
    private int documentoID;

    @BindView(R2.id.documento_nome)
    TextView documentoNome;

    @BindView(R2.id.bookmarks_button)
    View panelBookmarksButton;

    @BindView(R2.id.panel_bookmarks_panel)
    View panelBookmarksPanel;
    private Drawable panelButtonsActiveBg;
    private Drawable panelButtonsDefaultBg;

    @BindView(R2.id.panel_pages_panel)
    View panelPagesPanel;

    @BindView(R2.id.search_button)
    View panelSearchButton;

    @BindView(R2.id.panel_search_panel)
    View panelSearchPanel;

    @BindView(R2.id.pdf_viewer)
    PDFView pdfViewer;

    @BindBool(R2.bool.documento_panels_both)
    boolean panelsBoth = false;

    @BindDimen(R2.dimen.documento_panel_pages_height)
    int panelPagesHeight = 0;
    int currentPage = 0;
    boolean panelBookmarksVisible = false;
    boolean panelSearchVisible = false;
    boolean panelPagesVisible = false;
    boolean statisticaRegistrata = false;

    public static void startActivity(final Context c, final Documento documento) {
        Intent intent = new Intent(c, (Class<?>) DocumentoActivity.class);
        intent.putExtra("documento_id", documento.id);
        c.startActivity(intent);
    }

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_documento);
        ButterKnife.bind(this);
        Icepick.restoreInstanceState(this, savedInstanceState);
        this.panelButtonsDefaultBg = this.panelBookmarksButton.getBackground();
        this.panelButtonsActiveBg = new ColorDrawable(ResourcesCompat.getColor(getResources(), R.color.accent, getTheme()));
        ViewUtils.setVisibility(this.panelPagesPanel, false);
        ViewUtils.setVisibility(this.panelSearchPanel, false);
        ViewUtils.setVisibility(this.panelBookmarksPanel, false);
        this.documentoID = getIntent().getIntExtra("documento_id", 0);
        this.documentoNome.setText("");
        ((DocumentoActivityViewModel) ViewModelProviders.of(this, new DocumentoActivityViewModel.Factory(getApplication(), this.documentoID)).get(DocumentoActivityViewModel.class)).getDocumento().observe(this, new Observer<Documento>() {
            @Override
            public void onChanged(final Documento documento) {
                DocumentoActivity.this.load(documento);
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    public void load(final Documento documento) {
        this.documento = documento;
        if (documento == null) {
            finish();
            return;
        }
        this.documentoNome.setText(documento.nome);
        if (FileManagerPDFs.get(this).getFileState(documento) != FileManagerPDFs.State.AVAILABLE) {
            finish();
            return;
        }
        File file = FileManagerPDFs.get(this).getFile(documento);
        this.pdfViewer.setMinZoom(1.0f);
        this.pdfViewer.setMidZoom(2.0f);
        this.pdfViewer.setMaxZoom(8.0f);
        this.pdfViewer.fromFile(file).defaultPage(this.currentPage).swipeHorizontal(true).pageFling(false).spacing(10).onLoad(this).onPageChange(this).load();
        showBookmarksPanel(this.panelBookmarksVisible);
        showSearchPanel(this.panelSearchVisible);
        showPagesPanel(this.panelPagesVisible, false);
        if (!this.statisticaRegistrata) {
            StatisticaEntryUtils.insert(this, 4, String.format("Apro catalogo %s (%s)", documento.nome, documento.rev_label), documento.id);
            this.statisticaRegistrata = true;
        }
        new Thread() {
            @Override
            public void run() {
                DB.get(DocumentoActivity.this).notifiche().deleteAllForDocumento(documento.id);
            }
        }.start();
        ((App) getApplication()).analyticsSendScreen("DOCUMENTO: " + documento.nome);
    }

    @Override
    public void loadComplete(final int pagesNumber) {
        goToPage(this.currentPage);
    }

    public void goToPage(final int pageIndex) {
        float height;
        float height2;
        SizeF pageSize = this.pdfViewer.getPageSize(pageIndex);
        float width = pageSize.getWidth() / pageSize.getHeight();
        SizeF sizeF = new SizeF(this.pdfViewer.getWidth(), this.pdfViewer.getHeight());
        if (width > sizeF.getWidth() / sizeF.getHeight()) {
            height = sizeF.getWidth();
            height2 = pageSize.getWidth();
        } else {
            height = sizeF.getHeight();
            height2 = pageSize.getHeight();
        }
        float f = height / height2;
        this.pdfViewer.setMinZoom(f);
        this.pdfViewer.setMidZoom(f * 2.0f);
        this.pdfViewer.setMaxZoom(8.0f * f);
        this.pdfViewer.zoomTo(f);
        this.pdfViewer.jumpTo(pageIndex);
        float width2 = pageSize.getWidth() * f;
        if (width2 < sizeF.getWidth()) {
            this.pdfViewer.moveRelativeTo((sizeF.getWidth() - width2) / 2.0f, 0.0f);
        }
    }

    @Override
    public void onPageChanged(final int page, final int pageCount) {
        this.currentPage = page;
    }

    public int getCurrentPageIndex() {
        return this.currentPage;
    }

    @OnClick({R2.id.home_button})
    void homeButton() {
        finish();
    }

    @butterknife.OnClick({it.icontact.android.pdf2ipad.irisfmg.R2.id.share_button})
    void shareButton() {
        throw new UnsupportedOperationException("Method not decompiled: it.icontact.android.pdf2ipad.irisfmg.view.documento.DocumentoActivity.shareButton():void");
    }

    @OnClick({R2.id.bookmarks_button})
    void bookmarksButton() {
        showBookmarksPanel(!this.panelBookmarksVisible);
    }

    @OnClick({R2.id.search_button})
    void searchButton() {
        showSearchPanel(!this.panelSearchVisible);
    }

    @OnClick({R2.id.pages_button})
    void pagesButton() {
        showPagesPanel(!this.panelPagesVisible, true);
    }

    private void showBookmarksPanel(final boolean show) {
        if (show) {
            showSearchPanel(false);
            if (!this.panelsBoth) {
                showPagesPanel(false, false);
            }
        }
        this.panelBookmarksVisible = show;
        this.panelBookmarksButton.setBackground(show ? this.panelButtonsActiveBg : this.panelButtonsDefaultBg);
        ViewUtils.setVisibility(this.panelBookmarksPanel, show);
        if (show) {
            getSupportFragmentManager().beginTransaction().replace(R.id.panel_bookmarks_container, DocumentoBookmarksFragment.newInstance(this.documentoID)).commit();
            return;
        }
        Fragment findFragmentById = getSupportFragmentManager().findFragmentById(R.id.panel_bookmarks_container);
        if (findFragmentById != null) {
            getSupportFragmentManager().beginTransaction().remove(findFragmentById).commit();
        }
    }

    private void showSearchPanel(final boolean show) {
        if (show) {
            showBookmarksPanel(false);
            if (!this.panelsBoth) {
                showPagesPanel(false, false);
            }
        }
        this.panelSearchVisible = show;
        this.panelSearchButton.setBackground(show ? this.panelButtonsActiveBg : this.panelButtonsDefaultBg);
        ViewUtils.setVisibility(this.panelSearchPanel, show);
        if (show) {
            getSupportFragmentManager().beginTransaction().replace(R.id.panel_search_container, DocumentoSearchFragment.newInstance(this.documentoID)).commit();
            return;
        }
        Fragment findFragmentById = getSupportFragmentManager().findFragmentById(R.id.panel_search_container);
        if (findFragmentById != null) {
            getSupportFragmentManager().beginTransaction().remove(findFragmentById).commit();
        }
    }

    private void showPagesPanel(final boolean show, final boolean animate) {
        if (show && !this.panelsBoth) {
            showBookmarksPanel(false);
            showSearchPanel(false);
        }
        this.panelPagesVisible = show;
        AnimatorUtils.Listener listener = new AnimatorUtils.Listener() {
            @Override
            public void onAnimationEnd(final Animator animation) {
                if (show) {
                    DocumentoActivity.this.getSupportFragmentManager().beginTransaction().replace(R.id.panel_pages_container, DocumentoPagesFragment.newInstance(DocumentoActivity.this.documentoID)).commit();
                    return;
                }
                ViewUtils.setVisibility(DocumentoActivity.this.panelPagesPanel, false);
                Fragment findFragmentById = DocumentoActivity.this.getSupportFragmentManager().findFragmentById(R.id.panel_pages_container);
                if (findFragmentById != null) {
                    DocumentoActivity.this.getSupportFragmentManager().beginTransaction().remove(findFragmentById).commitAllowingStateLoss();
                }
            }
        };
        this.panelPagesPanel.clearAnimation();
        if (animate) {
            if (show) {
                ViewUtils.setVisibility(this.panelPagesPanel, true);
            }
            this.panelPagesPanel.setTranslationY(show ? this.panelPagesHeight : 0.0f);
            this.panelPagesPanel.animate().translationY(show ? 0.0f : this.panelPagesHeight).setListener(listener).start();
            return;
        }
        ViewUtils.setVisibility(this.panelPagesPanel, show);
        listener.onAnimationEnd(null);
    }

    @OnClick({R2.id.website_button})
    void websiteButton() {
        startActivity(new Intent("android.intent.action.VIEW", Uri.parse(getString(R.string.D1_COMPANY_LINK))));
    }

    @OnClick({R2.id.mail_button})
    void mailButton() {
        Intent intent = new Intent("android.intent.action.SENDTO");
        intent.setData(Uri.parse("mailto:"));
        intent.putExtra("android.intent.extra.EMAIL", new String[]{getString(R.string.D1_COMPANY_MAIL)});
        startActivity(Intent.createChooser(intent, null));
    }

    @OnClick({R2.id.phone_button})
    void phoneButton() {
        Intent intent = new Intent("android.intent.action.DIAL");
        intent.setData(Uri.parse("tel:" + getString(R.string.D1_COMPANY_PHONE)));
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onPDFFileStateChanged(final FileManagerPDFs.FileStateChanged event) {
        if (event.documento.id != this.documentoID || FileManagerPDFs.get(this).getFileState(event.documento) == FileManagerPDFs.State.AVAILABLE) {
            return;
        }
        finish();
    }

    @Override
    protected void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected void onSaveInstanceState(final Bundle outState) {
        super.onSaveInstanceState(outState);
        Icepick.saveInstanceState(this, outState);
    }

    @Override
    public void onBackPressed() {
        if (this.panelBookmarksVisible || this.panelSearchVisible || this.panelPagesVisible) {
            showBookmarksPanel(false);
            showSearchPanel(false);
            showPagesPanel(false, true);
            return;
        }
        super.onBackPressed();
    }
}