Support SAF properly
This commit is contained in:
parent
84709eb620
commit
4e133a3599
23 changed files with 451 additions and 311 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
|
@ -28,25 +27,6 @@ import java.io.File;
|
|||
public class FilePickerActivityHelper extends com.nononsenseapps.filepicker.FilePickerActivity {
|
||||
private CustomFilePickerFragment currentFragment;
|
||||
|
||||
public static Intent chooseSingleFile(@NonNull final Context context) {
|
||||
return new Intent(context, FilePickerActivityHelper.class)
|
||||
.putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false)
|
||||
.putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, false)
|
||||
.putExtra(FilePickerActivityHelper.EXTRA_SINGLE_CLICK, true)
|
||||
.putExtra(FilePickerActivityHelper.EXTRA_MODE, FilePickerActivityHelper.MODE_FILE);
|
||||
}
|
||||
|
||||
public static Intent chooseFileToSave(@NonNull final Context context,
|
||||
@Nullable final String startPath) {
|
||||
return new Intent(context, FilePickerActivityHelper.class)
|
||||
.putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false)
|
||||
.putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, true)
|
||||
.putExtra(FilePickerActivityHelper.EXTRA_ALLOW_EXISTING_FILE, true)
|
||||
.putExtra(FilePickerActivityHelper.EXTRA_START_PATH, startPath)
|
||||
.putExtra(FilePickerActivityHelper.EXTRA_MODE,
|
||||
FilePickerActivityHelper.MODE_NEW_FILE);
|
||||
}
|
||||
|
||||
public static boolean isOwnFileUri(@NonNull final Context context, @NonNull final Uri uri) {
|
||||
if (uri.getAuthority() == null) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import org.schabi.newpipe.streams.io.SharpInputStream;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import us.shandian.giga.io.StoredFileHelper;
|
||||
|
||||
/**
|
||||
* Created by Christian Schabesberger on 28.01.18.
|
||||
* Copyright 2018 Christian Schabesberger <chris.schabesberger@mailbox.org>
|
||||
|
|
@ -59,24 +62,23 @@ public final class ZipHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* This will extract data from Zipfiles.
|
||||
* This will extract data from ZipInputStream.
|
||||
* Caution this will override the original file.
|
||||
*
|
||||
* @param filePath The path of the zip
|
||||
* @param zipFile The zip file
|
||||
* @param file The path of the file on the disk where the data should be extracted to.
|
||||
* @param name The path of the file inside the zip.
|
||||
* @return will return true if the file was found within the zip file
|
||||
* @throws Exception
|
||||
*/
|
||||
public static boolean extractFileFromZip(final String filePath, final String file,
|
||||
public static boolean extractFileFromZip(final StoredFileHelper zipFile, final String file,
|
||||
final String name) throws Exception {
|
||||
try (ZipInputStream inZip = new ZipInputStream(new BufferedInputStream(
|
||||
new FileInputStream(filePath)))) {
|
||||
new SharpInputStream(zipFile.getStream())))) {
|
||||
final byte[] data = new byte[BUFFER_SIZE];
|
||||
|
||||
boolean found = false;
|
||||
|
||||
ZipEntry ze;
|
||||
|
||||
while ((ze = inZip.getNextEntry()) != null) {
|
||||
if (ze.getName().equals(name)) {
|
||||
found = true;
|
||||
|
|
@ -102,8 +104,9 @@ public final class ZipHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isValidZipFile(final String filePath) {
|
||||
try (ZipFile ignored = new ZipFile(filePath)) {
|
||||
public static boolean isValidZipFile(final StoredFileHelper file) {
|
||||
try (ZipInputStream ignored = new ZipInputStream(new BufferedInputStream(
|
||||
new SharpInputStream(file.getStream())))) {
|
||||
return true;
|
||||
} catch (final IOException ioe) {
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue