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

Commit 7cb74f9e authored by Fs00's avatar Fs00
Browse files

Reuse code for copying file to Download folder

parent 700d8340
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -336,9 +336,8 @@ public class MainActivity extends ProgressActivity implements OnPageChangeListen
        try {
        try {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                InputStream inputStream = new FileInputStream(tempFile);
                InputStream inputStream = new FileInputStream(tempFile);
                File newFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), pdfFileName);
                File downloadDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                OutputStream outputStream = new FileOutputStream(newFile);
                Utils.createFileFromInputStream(downloadDirectory, pdfFileName, inputStream);
                Utils.readFromInputStreamToOutputStream(inputStream, outputStream);
            } else {
            } else {
                ActivityCompat.requestPermissions(
                ActivityCompat.requestPermissions(
                        this,
                        this,
+1 −1
Original line number Original line Diff line number Diff line
@@ -97,7 +97,7 @@ public class Utils {
        return BuildConfig.VERSION_NAME;
        return BuildConfig.VERSION_NAME;
    }
    }


    static void readFromInputStreamToOutputStream (InputStream inputStream, OutputStream outputStream) throws IOException {
    private static void readFromInputStreamToOutputStream (InputStream inputStream, OutputStream outputStream) throws IOException {
        byte[] buffer = new byte[8 * 1024];
        byte[] buffer = new byte[8 * 1024];
        int bytesRead = inputStream.read(buffer);
        int bytesRead = inputStream.read(buffer);
        while (bytesRead > -1) {
        while (bytesRead > -1) {