misc changes
* restore permission request popup previously removed in #2486 * use legacy file picker in cases where saf file picker is not available * fix missing file check logic in prepareSelectedDownload method (DownloadDialog.java)
This commit is contained in:
parent
950cf714d9
commit
dee3a18ea8
@ -60,6 +60,7 @@ import org.schabi.newpipe.report.ErrorActivity;
|
|||||||
import org.schabi.newpipe.util.Constants;
|
import org.schabi.newpipe.util.Constants;
|
||||||
import org.schabi.newpipe.util.KioskTranslator;
|
import org.schabi.newpipe.util.KioskTranslator;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
|
import org.schabi.newpipe.util.PermissionHelper;
|
||||||
import org.schabi.newpipe.util.ServiceHelper;
|
import org.schabi.newpipe.util.ServiceHelper;
|
||||||
import org.schabi.newpipe.util.StateSaver;
|
import org.schabi.newpipe.util.StateSaver;
|
||||||
import org.schabi.newpipe.util.ThemeHelper;
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
@ -421,6 +422,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch (requestCode) {
|
||||||
|
case PermissionHelper.DOWNLOADS_REQUEST_CODE:
|
||||||
|
NavigationHelper.openDownloads(this);
|
||||||
|
break;
|
||||||
|
case PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE:
|
||||||
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
|
||||||
|
if (fragment instanceof VideoDetailFragment) {
|
||||||
|
((VideoDetailFragment) fragment).openDownloadDialog();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,10 +74,13 @@ import static org.schabi.newpipe.util.ThemeHelper.resolveResourceIdFromAttr;
|
|||||||
*/
|
*/
|
||||||
public class RouterActivity extends AppCompatActivity {
|
public class RouterActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@State protected int currentServiceId = -1;
|
@State
|
||||||
|
protected int currentServiceId = -1;
|
||||||
private StreamingService currentService;
|
private StreamingService currentService;
|
||||||
@State protected LinkType currentLinkType;
|
@State
|
||||||
@State protected int selectedRadioPosition = -1;
|
protected LinkType currentLinkType;
|
||||||
|
@State
|
||||||
|
protected int selectedRadioPosition = -1;
|
||||||
protected int selectedPreviously = -1;
|
protected int selectedPreviously = -1;
|
||||||
|
|
||||||
protected String currentUrl;
|
protected String currentUrl;
|
||||||
@ -257,7 +260,7 @@ public class RouterActivity extends AppCompatActivity {
|
|||||||
.setNegativeButton(R.string.just_once, dialogButtonsClickListener)
|
.setNegativeButton(R.string.just_once, dialogButtonsClickListener)
|
||||||
.setPositiveButton(R.string.always, dialogButtonsClickListener)
|
.setPositiveButton(R.string.always, dialogButtonsClickListener)
|
||||||
.setOnDismissListener((dialog) -> {
|
.setOnDismissListener((dialog) -> {
|
||||||
if(!selectionIsDownload) finish();
|
if (!selectionIsDownload) finish();
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
@ -358,13 +361,13 @@ public class RouterActivity extends AppCompatActivity {
|
|||||||
positiveButton.setEnabled(state);
|
positiveButton.setEnabled(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleText(){
|
private void handleText() {
|
||||||
String searchString = getIntent().getStringExtra(Intent.EXTRA_TEXT);
|
String searchString = getIntent().getStringExtra(Intent.EXTRA_TEXT);
|
||||||
int serviceId = getIntent().getIntExtra(Constants.KEY_SERVICE_ID, 0);
|
int serviceId = getIntent().getIntExtra(Constants.KEY_SERVICE_ID, 0);
|
||||||
Intent intent = new Intent(getThemeWrapperContext(), MainActivity.class);
|
Intent intent = new Intent(getThemeWrapperContext(), MainActivity.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
NavigationHelper.openSearch(getThemeWrapperContext(),serviceId,searchString);
|
NavigationHelper.openSearch(getThemeWrapperContext(), serviceId, searchString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleChoice(final String selectedChoiceKey) {
|
private void handleChoice(final String selectedChoiceKey) {
|
||||||
@ -382,8 +385,10 @@ public class RouterActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (selectedChoiceKey.equals(getString(R.string.download_key))) {
|
if (selectedChoiceKey.equals(getString(R.string.download_key))) {
|
||||||
selectionIsDownload = true;
|
if (PermissionHelper.checkStoragePermissions(this, PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
|
||||||
openDownloadDialog();
|
selectionIsDownload = true;
|
||||||
|
openDownloadDialog();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,7 +400,7 @@ public class RouterActivity extends AppCompatActivity {
|
|||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(intent -> {
|
.subscribe(intent -> {
|
||||||
if(!internalRoute){
|
if (!internalRoute) {
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
}
|
}
|
||||||
@ -445,17 +450,21 @@ public class RouterActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
for (int i: grantResults){
|
for (int i : grantResults) {
|
||||||
if (i == PackageManager.PERMISSION_DENIED){
|
if (i == PackageManager.PERMISSION_DENIED) {
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (requestCode == PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE) {
|
||||||
|
openDownloadDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AdapterChoiceItem {
|
private static class AdapterChoiceItem {
|
||||||
final String description, key;
|
final String description, key;
|
||||||
@DrawableRes final int icon;
|
@DrawableRes
|
||||||
|
final int icon;
|
||||||
|
|
||||||
AdapterChoiceItem(String key, String description, int icon) {
|
AdapterChoiceItem(String key, String description, int icon) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@ -553,7 +562,8 @@ public class RouterActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
boolean isExtVideoEnabled = preferences.getBoolean(getString(R.string.use_external_video_player_key), false);
|
boolean isExtVideoEnabled = preferences.getBoolean(getString(R.string.use_external_video_player_key), false);
|
||||||
boolean isExtAudioEnabled = preferences.getBoolean(getString(R.string.use_external_audio_player_key), false);;
|
boolean isExtAudioEnabled = preferences.getBoolean(getString(R.string.use_external_audio_player_key), false);
|
||||||
|
;
|
||||||
|
|
||||||
PlayQueue playQueue;
|
PlayQueue playQueue;
|
||||||
String playerChoice = choice.playerChoice;
|
String playerChoice = choice.playerChoice;
|
||||||
|
@ -2,13 +2,13 @@ package org.schabi.newpipe.download;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.IdRes;
|
import android.support.annotation.IdRes;
|
||||||
@ -34,6 +34,8 @@ import android.widget.Spinner;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.nononsenseapps.filepicker.Utils;
|
||||||
|
|
||||||
import org.schabi.newpipe.MainActivity;
|
import org.schabi.newpipe.MainActivity;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.extractor.MediaFormat;
|
import org.schabi.newpipe.extractor.MediaFormat;
|
||||||
@ -50,6 +52,7 @@ import org.schabi.newpipe.settings.NewPipeSettings;
|
|||||||
import org.schabi.newpipe.util.FilePickerActivityHelper;
|
import org.schabi.newpipe.util.FilePickerActivityHelper;
|
||||||
import org.schabi.newpipe.util.FilenameUtils;
|
import org.schabi.newpipe.util.FilenameUtils;
|
||||||
import org.schabi.newpipe.util.ListHelper;
|
import org.schabi.newpipe.util.ListHelper;
|
||||||
|
import org.schabi.newpipe.util.PermissionHelper;
|
||||||
import org.schabi.newpipe.util.SecondaryStreamHelper;
|
import org.schabi.newpipe.util.SecondaryStreamHelper;
|
||||||
import org.schabi.newpipe.util.StreamItemAdapter;
|
import org.schabi.newpipe.util.StreamItemAdapter;
|
||||||
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
|
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
|
||||||
@ -57,7 +60,6 @@ import org.schabi.newpipe.util.ThemeHelper;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -178,6 +180,11 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
||||||
|
|
||||||
|
if (!PermissionHelper.checkStoragePermissions(getActivity(), PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
|
||||||
|
getDialog().dismiss();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
context = getContext();
|
context = getContext();
|
||||||
|
|
||||||
setStyle(STYLE_NO_TITLE, ThemeHelper.getDialogTheme(context));
|
setStyle(STYLE_NO_TITLE, ThemeHelper.getDialogTheme(context));
|
||||||
@ -322,9 +329,9 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ContentResolver.SCHEME_FILE.equals(data.getData().getScheme())) {
|
if (data.getData().getAuthority() != null && data.getData().getAuthority().startsWith(context.getPackageName())) {
|
||||||
File file = new File(URI.create(data.getData().toString()));
|
File file = Utils.getFileForUri(data.getData());
|
||||||
checkSelectedDownload(null, data.getData(), file.getName(), StoredFileHelper.DEFAULT_MIME);
|
checkSelectedDownload(null, Uri.fromFile(file), file.getName(), StoredFileHelper.DEFAULT_MIME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,10 +592,21 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
|
|||||||
if (!askForSavePath)
|
if (!askForSavePath)
|
||||||
Toast.makeText(context, getString(R.string.no_available_dir), Toast.LENGTH_LONG).show();
|
Toast.makeText(context, getString(R.string.no_available_dir), Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
if (NewPipeSettings.hasCreateDocumentSupport)
|
if (NewPipeSettings.hasCreateDocumentSupport) {
|
||||||
StoredFileHelper.requestSafWithFileCreation(this, REQUEST_DOWNLOAD_SAVE_AS, filename, mime);
|
StoredFileHelper.requestSafWithFileCreation(this, REQUEST_DOWNLOAD_SAVE_AS, filename, mime);
|
||||||
else
|
} else {
|
||||||
startActivityForResult(FilePickerActivityHelper.chooseFileToSave(context, filename), REQUEST_DOWNLOAD_SAVE_AS);
|
File initialSavePath;
|
||||||
|
if (radioStreamsGroup.getCheckedRadioButtonId() == R.id.audio_button)
|
||||||
|
initialSavePath = NewPipeSettings.getDir(Environment.DIRECTORY_MUSIC);
|
||||||
|
else
|
||||||
|
initialSavePath = NewPipeSettings.getDir(Environment.DIRECTORY_MOVIES);
|
||||||
|
|
||||||
|
initialSavePath = new File(initialSavePath, filename);
|
||||||
|
startActivityForResult(
|
||||||
|
FilePickerActivityHelper.chooseFileToSave(context, initialSavePath.getAbsolutePath()),
|
||||||
|
REQUEST_DOWNLOAD_SAVE_AS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -639,6 +657,11 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
|
|||||||
// This part is called if:
|
// This part is called if:
|
||||||
// * using SAF on older android version
|
// * using SAF on older android version
|
||||||
// * save path not defined
|
// * save path not defined
|
||||||
|
// * if the file exists overwrite it, is not necessary ask
|
||||||
|
if (!storage.existsAsFile() && !storage.create()) {
|
||||||
|
showFailedDialog(R.string.error_file_creation);
|
||||||
|
return;
|
||||||
|
}
|
||||||
continueSelectedDownload(storage);
|
continueSelectedDownload(storage);
|
||||||
return;
|
return;
|
||||||
} else if (targetFile == null) {
|
} else if (targetFile == null) {
|
||||||
|
@ -384,7 +384,10 @@ public class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.detail_controls_download:
|
case R.id.detail_controls_download:
|
||||||
this.openDownloadDialog();
|
if (PermissionHelper.checkStoragePermissions(activity,
|
||||||
|
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
|
||||||
|
this.openDownloadDialog();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.detail_uploader_root_layout:
|
case R.id.detail_uploader_root_layout:
|
||||||
if (TextUtils.isEmpty(currentInfo.getUploaderUrl())) {
|
if (TextUtils.isEmpty(currentInfo.getUploaderUrl())) {
|
||||||
|
@ -86,10 +86,10 @@ public class NewPipeSettings {
|
|||||||
PreferenceManager.setDefaultValues(context, R.xml.debug_settings, true);
|
PreferenceManager.setDefaultValues(context, R.xml.debug_settings, true);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
hasOpenDocumentTreeSupport = testFor(context, Intent.ACTION_OPEN_DOCUMENT_TREE);
|
hasOpenDocumentTreeSupport = testFor(context, Intent.ACTION_OPEN_DOCUMENT_TREE, false);
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
hasCreateDocumentSupport = testFor(context, Intent.ACTION_CREATE_DOCUMENT);
|
hasCreateDocumentSupport = testFor(context, Intent.ACTION_CREATE_DOCUMENT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !hasOpenDocumentTreeSupport) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !hasOpenDocumentTreeSupport) {
|
||||||
@ -118,7 +118,7 @@ public class NewPipeSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static File getDir(String defaultDirectoryName) {
|
public static File getDir(String defaultDirectoryName) {
|
||||||
return new File(Environment.getExternalStorageDirectory(), defaultDirectoryName);
|
return new File(Environment.getExternalStorageDirectory(), defaultDirectoryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,9 +126,14 @@ public class NewPipeSettings {
|
|||||||
return new File(dir, "NewPipe").toURI().toString();
|
return new File(dir, "NewPipe").toURI().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean testFor(@NonNull Context ctx, @NonNull String intentAction) {
|
private static boolean testFor(@NonNull Context ctx, @NonNull String intentAction, boolean isFile) {
|
||||||
Intent queryIntent = new Intent(intentAction);
|
Intent queryIntent = new Intent(intentAction)
|
||||||
queryIntent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
||||||
|
|
||||||
|
if (isFile) {
|
||||||
|
queryIntent.setType("*/*");
|
||||||
|
queryIntent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
List<ResolveInfo> infoList = ctx.getPackageManager()
|
List<ResolveInfo> infoList = ctx.getPackageManager()
|
||||||
.queryIntentActivities(queryIntent, PackageManager.MATCH_DEFAULT_ONLY);
|
.queryIntentActivities(queryIntent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
|
@ -446,6 +446,9 @@ public class NavigationHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean openDownloads(Activity activity) {
|
public static boolean openDownloads(Activity activity) {
|
||||||
|
if (!PermissionHelper.checkStoragePermissions(activity, PermissionHelper.DOWNLOADS_REQUEST_CODE)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Intent intent = new Intent(activity, DownloadActivity.class);
|
Intent intent = new Intent(activity, DownloadActivity.class);
|
||||||
activity.startActivity(intent);
|
activity.startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
@ -18,10 +18,12 @@ import android.widget.Toast;
|
|||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
|
|
||||||
public class PermissionHelper {
|
public class PermissionHelper {
|
||||||
|
public static final int DOWNLOAD_DIALOG_REQUEST_CODE = 778;
|
||||||
|
public static final int DOWNLOADS_REQUEST_CODE = 777;
|
||||||
|
|
||||||
public static boolean checkStoragePermissions(Activity activity, int requestCode) {
|
public static boolean checkStoragePermissions(Activity activity, int requestCode) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
if(!checkReadStoragePermissions(activity, requestCode)) return false;
|
if (!checkReadStoragePermissions(activity, requestCode)) return false;
|
||||||
}
|
}
|
||||||
return checkWriteStoragePermissions(activity, requestCode);
|
return checkWriteStoragePermissions(activity, requestCode);
|
||||||
}
|
}
|
||||||
@ -89,7 +91,7 @@ public class PermissionHelper {
|
|||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
context.startActivity(i);
|
context.startActivity(i);
|
||||||
return false;
|
return false;
|
||||||
}else return true;
|
} else return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPopupEnabled(Context context) {
|
public static boolean isPopupEnabled(Context context) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user