Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 312c08a1 authored by Fs00's avatar Fs00
Browse files

Do not re-download file on screen rotation or theme change

parent 522bd382
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -329,15 +329,31 @@ public class MainActivity extends CyaneaAppCompatActivity {

        String scheme = uri.getScheme();
        if (scheme != null && scheme.contains("http")) {
            downloadOrShowDownloadedFile(uri);
        } else {
            configurePdfViewAndLoad(viewBinding.pdfView.fromUri(uri));
        }
    }

    private void downloadOrShowDownloadedFile(Uri uri) {
        if (downloadedPdfFileContent == null) {
            downloadedPdfFileContent = (byte[]) getLastCustomNonConfigurationInstance();
        }
        if (downloadedPdfFileContent != null) {
            configurePdfViewAndLoad(viewBinding.pdfView.fromBytes(downloadedPdfFileContent));
        } else {
            // we will get the pdf asynchronously with the DownloadPDFFile object
            viewBinding.progressBar.setVisibility(View.VISIBLE);
            DownloadPDFFile downloadPDFFile = new DownloadPDFFile(this);
            downloadPDFFile.execute(uri.toString());
        } else {
            configurePdfViewAndLoad(viewBinding.pdfView.fromUri(uri));
        }
    }

    @Override
    public Object onRetainCustomNonConfigurationInstance() {
        return downloadedPdfFileContent;
    }

    public void hideProgressBar() {
        viewBinding.progressBar.setVisibility(View.GONE);
    }