1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 17:10:33 +00:00

Open download dialog if video download is clicked instead

This commit is contained in:
Aris Poloway 2018-04-07 13:32:02 -04:00
parent 5ca0a0adf2
commit 676d64a24a
5 changed files with 43 additions and 32 deletions

View File

@ -238,14 +238,21 @@ public class MainActivity 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) {
if (requestCode == PermissionHelper.PERMISSION_READ_STORAGE || for (int i: grantResults){
requestCode == PermissionHelper.PERMISSION_WRITE_STORAGE){ if (i == PackageManager.PERMISSION_DENIED){
for (int i: grantResults){ return;
if (i == PackageManager.PERMISSION_DENIED){
return;
}
} }
NavigationHelper.openDownloads(this); }
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;
} }
} }

View File

@ -79,7 +79,7 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + 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(); getDialog().dismiss();
return; return;
} }

View File

@ -356,22 +356,10 @@ public class VideoDetailFragment
} }
break; break;
case R.id.detail_controls_download: case R.id.detail_controls_download:
if (!PermissionHelper.checkStoragePermissions(activity)) { if (!PermissionHelper.checkStoragePermissions(activity, PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
return; return;
} }
this.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();
}
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())) {
@ -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 // Stream Results
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/

View File

@ -428,7 +428,7 @@ public class NavigationHelper {
} }
public static boolean openDownloads(Activity activity) { public static boolean openDownloads(Activity activity) {
if (!PermissionHelper.checkStoragePermissions(activity)) { if (!PermissionHelper.checkStoragePermissions(activity, PermissionHelper.DOWNLOADS_REQUEST_CODE)) {
return false; return false;
} }
Intent intent = new Intent(activity, DownloadActivity.class); Intent intent = new Intent(activity, DownloadActivity.class);

View File

@ -18,26 +18,26 @@ import android.widget.Toast;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
public class PermissionHelper { public class PermissionHelper {
public static final int PERMISSION_WRITE_STORAGE = 778; public static final int DOWNLOAD_DIALOG_REQUEST_CODE = 778;
public static final int PERMISSION_READ_STORAGE = 777; 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 (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) @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) if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, ActivityCompat.requestPermissions(activity,
new String[]{ new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE}, Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSION_READ_STORAGE); requestCode);
return false; 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 // Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(activity, if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
@ -63,7 +63,7 @@ public class PermissionHelper {
// No explanation needed, we can request the permission. // No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(activity, ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSION_WRITE_STORAGE); requestCode);
// PERMISSION_WRITE_STORAGE is an // PERMISSION_WRITE_STORAGE is an
// app-defined int constant. The callback method gets the // app-defined int constant. The callback method gets the