Open download dialog if video download is clicked instead
This commit is contained in:
parent
5ca0a0adf2
commit
676d64a24a
|
@ -238,14 +238,21 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
if (requestCode == PermissionHelper.PERMISSION_READ_STORAGE ||
|
||||
requestCode == PermissionHelper.PERMISSION_WRITE_STORAGE){
|
||||
for (int i: grantResults){
|
||||
if (i == PackageManager.PERMISSION_DENIED){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
|
|||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
||||
if (!PermissionHelper.checkStoragePermissions(getActivity())) {
|
||||
if (!PermissionHelper.checkStoragePermissions(getActivity(), PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
|
||||
getDialog().dismiss();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -356,22 +356,10 @@ public class VideoDetailFragment
|
|||
}
|
||||
break;
|
||||
case R.id.detail_controls_download:
|
||||
if (!PermissionHelper.checkStoragePermissions(activity)) {
|
||||
if (!PermissionHelper.checkStoragePermissions(activity, PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
DownloadDialog downloadDialog =
|
||||
DownloadDialog.newInstance(currentInfo,
|
||||
sortedStreamVideosList,
|
||||
selectedVideoStream);
|
||||
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(activity,
|
||||
R.string.could_not_setup_download_menu,
|
||||
Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.openDownloadDialog();
|
||||
break;
|
||||
case R.id.detail_uploader_root_layout:
|
||||
if (TextUtils.isEmpty(currentInfo.getUploaderUrl())) {
|
||||
|
@ -1226,6 +1214,22 @@ public class VideoDetailFragment
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void openDownloadDialog() {
|
||||
try {
|
||||
DownloadDialog downloadDialog =
|
||||
DownloadDialog.newInstance(currentInfo,
|
||||
sortedStreamVideosList,
|
||||
selectedVideoStream);
|
||||
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(activity,
|
||||
R.string.could_not_setup_download_menu,
|
||||
Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Stream Results
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
|
|
@ -428,7 +428,7 @@ public class NavigationHelper {
|
|||
}
|
||||
|
||||
public static boolean openDownloads(Activity activity) {
|
||||
if (!PermissionHelper.checkStoragePermissions(activity)) {
|
||||
if (!PermissionHelper.checkStoragePermissions(activity, PermissionHelper.DOWNLOADS_REQUEST_CODE)) {
|
||||
return false;
|
||||
}
|
||||
Intent intent = new Intent(activity, DownloadActivity.class);
|
||||
|
|
|
@ -18,26 +18,26 @@ import android.widget.Toast;
|
|||
import org.schabi.newpipe.R;
|
||||
|
||||
public class PermissionHelper {
|
||||
public static final int PERMISSION_WRITE_STORAGE = 778;
|
||||
public static final int PERMISSION_READ_STORAGE = 777;
|
||||
public static final int DOWNLOAD_DIALOG_REQUEST_CODE = 778;
|
||||
public static final int DOWNLOADS_REQUEST_CODE = 777;
|
||||
|
||||
|
||||
public static boolean checkStoragePermissions(Activity activity) {
|
||||
public static boolean checkStoragePermissions(Activity activity, int requestCode) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
if(!checkReadStoragePermissions(activity)) return false;
|
||||
if(!checkReadStoragePermissions(activity, requestCode)) return false;
|
||||
}
|
||||
return checkWriteStoragePermissions(activity);
|
||||
return checkWriteStoragePermissions(activity, requestCode);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
|
||||
public static boolean checkReadStoragePermissions(Activity activity) {
|
||||
public static boolean checkReadStoragePermissions(Activity activity, int requestCode) {
|
||||
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(activity,
|
||||
new String[]{
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||
PERMISSION_READ_STORAGE);
|
||||
requestCode);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class PermissionHelper {
|
|||
}
|
||||
|
||||
|
||||
public static boolean checkWriteStoragePermissions(Activity activity) {
|
||||
public static boolean checkWriteStoragePermissions(Activity activity, int requestCode) {
|
||||
// Here, thisActivity is the current activity
|
||||
if (ContextCompat.checkSelfPermission(activity,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
|
@ -63,7 +63,7 @@ public class PermissionHelper {
|
|||
// No explanation needed, we can request the permission.
|
||||
ActivityCompat.requestPermissions(activity,
|
||||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||
PERMISSION_WRITE_STORAGE);
|
||||
requestCode);
|
||||
|
||||
// PERMISSION_WRITE_STORAGE is an
|
||||
// app-defined int constant. The callback method gets the
|
||||
|
|
Loading…
Reference in New Issue