1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

Call DownloadDialog dismiss() in the correct way

This commit is contained in:
Stypox 2021-07-19 10:42:24 +02:00
parent 35e005caaa
commit 8f559965f6
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
2 changed files with 20 additions and 8 deletions

View File

@ -589,9 +589,9 @@ public class RouterActivity extends AppCompatActivity {
downloadDialog.setVideoStreams(sortedVideoStreams); downloadDialog.setVideoStreams(sortedVideoStreams);
downloadDialog.setAudioStreams(result.getAudioStreams()); downloadDialog.setAudioStreams(result.getAudioStreams());
downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex); downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex);
downloadDialog.setOnDismissListener(dialog -> finish());
downloadDialog.show(fm, "downloadDialog"); downloadDialog.show(fm, "downloadDialog");
fm.executePendingTransactions(); fm.executePendingTransactions();
downloadDialog.requireDialog().setOnDismissListener(dialog -> finish());
}, throwable -> }, throwable ->
showUnsupportedUrlDialog(currentUrl))); showUnsupportedUrlDialog(currentUrl)));
} }

View File

@ -3,6 +3,8 @@ package org.schabi.newpipe.download;
import android.app.Activity; import android.app.Activity;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -38,7 +40,6 @@ 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.RouterActivity;
import org.schabi.newpipe.databinding.DownloadDialogBinding; import org.schabi.newpipe.databinding.DownloadDialogBinding;
import org.schabi.newpipe.error.ErrorActivity; import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo; import org.schabi.newpipe.error.ErrorInfo;
@ -101,6 +102,9 @@ public class DownloadDialog extends DialogFragment
@State @State
int selectedSubtitleIndex = 0; int selectedSubtitleIndex = 0;
@Nullable
private OnDismissListener onDismissListener = null;
private StoredDirectoryHelper mainStorageAudio = null; private StoredDirectoryHelper mainStorageAudio = null;
private StoredDirectoryHelper mainStorageVideo = null; private StoredDirectoryHelper mainStorageVideo = null;
private DownloadManager downloadManager = null; private DownloadManager downloadManager = null;
@ -204,6 +208,9 @@ public class DownloadDialog extends DialogFragment
this.selectedSubtitleIndex = ssi; this.selectedSubtitleIndex = ssi;
} }
public void setOnDismissListener(@Nullable final OnDismissListener onDismissListener) {
this.onDismissListener = onDismissListener;
}
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Android lifecycle // Android lifecycle
@ -219,7 +226,7 @@ public class DownloadDialog extends DialogFragment
if (!PermissionHelper.checkStoragePermissions(getActivity(), if (!PermissionHelper.checkStoragePermissions(getActivity(),
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) { PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
getDialog().dismiss(); dismiss();
return; return;
} }
@ -341,7 +348,7 @@ public class DownloadDialog extends DialogFragment
toolbar.setTitle(R.string.download_dialog_title); toolbar.setTitle(R.string.download_dialog_title);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back); toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
toolbar.inflateMenu(R.menu.dialog_url); toolbar.inflateMenu(R.menu.dialog_url);
toolbar.setNavigationOnClickListener(v -> requireDialog().dismiss()); toolbar.setNavigationOnClickListener(v -> dismiss());
toolbar.setNavigationContentDescription(R.string.cancel); toolbar.setNavigationContentDescription(R.string.cancel);
okButton = toolbar.findViewById(R.id.okay); okButton = toolbar.findViewById(R.id.okay);
@ -350,15 +357,20 @@ public class DownloadDialog extends DialogFragment
toolbar.setOnMenuItemClickListener(item -> { toolbar.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.okay) { if (item.getItemId() == R.id.okay) {
prepareSelectedDownload(); prepareSelectedDownload();
if (getActivity() instanceof RouterActivity) {
getActivity().finish();
}
return true; return true;
} }
return false; return false;
}); });
} }
@Override
public void onDismiss(@NonNull final DialogInterface dialog) {
super.onDismiss(dialog);
if (onDismissListener != null) {
onDismissListener.onDismiss(dialog);
}
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -622,7 +634,7 @@ public class DownloadDialog extends DialogFragment
} else { } else {
Toast.makeText(getContext(), R.string.no_streams_available_download, Toast.makeText(getContext(), R.string.no_streams_available_download,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
getDialog().dismiss(); dismiss();
} }
} }