Cleaned code, downloaddialog now also appears after giving storage permission.
This commit is contained in:
parent
8f35a56ec8
commit
f3e029c3f6
|
@ -7,11 +7,13 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
@ -86,7 +88,7 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
protected String currentUrl;
|
protected String currentUrl;
|
||||||
protected CompositeDisposable disposables = new CompositeDisposable();
|
protected CompositeDisposable disposables = new CompositeDisposable();
|
||||||
|
|
||||||
private boolean notDownload = true;
|
private boolean selectionIsDownload = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -106,16 +108,10 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
? R.style.RouterActivityThemeLight : R.style.RouterActivityThemeDark);
|
? R.style.RouterActivityThemeLight : R.style.RouterActivityThemeDark);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingSuperCall")
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
}
|
Icepick.saveInstanceState(this, outState);
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
|
|
||||||
super.onPause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -257,7 +253,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(notDownload) finish();
|
if(!selectionIsDownload) finish();
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
|
@ -358,7 +354,6 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
positiveButton.setEnabled(state);
|
positiveButton.setEnabled(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
|
||||||
private void handleChoice(final String selectedChoiceKey) {
|
private void handleChoice(final String selectedChoiceKey) {
|
||||||
final List<String> validChoicesList = Arrays.asList(getResources().getStringArray(R.array.preferred_open_action_values_list));
|
final List<String> validChoicesList = Arrays.asList(getResources().getStringArray(R.array.preferred_open_action_values_list));
|
||||||
if (validChoicesList.contains(selectedChoiceKey)) {
|
if (validChoicesList.contains(selectedChoiceKey)) {
|
||||||
|
@ -374,29 +369,10 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedChoiceKey.equals(getString(R.string.download_key))) {
|
if (selectedChoiceKey.equals(getString(R.string.download_key))) {
|
||||||
ExtractorHelper.getStreamInfo(currentServiceId, currentUrl, true)
|
if (PermissionHelper.checkStoragePermissions(this, PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
|
||||||
.subscribeOn(Schedulers.io())
|
selectionIsDownload = true;
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
openDownloadDialog();
|
||||||
.subscribe((@NonNull StreamInfo result) -> {
|
}
|
||||||
StreamInfo currentInfo = result;
|
|
||||||
List<VideoStream> sortedVideoStreams = ListHelper.getSortedStreamVideosList(this, currentInfo.getVideoStreams(), currentInfo.getVideoOnlyStreams(), false);
|
|
||||||
int selectedVideoStreamIndex = ListHelper.getDefaultResolutionIndex(this, sortedVideoStreams);
|
|
||||||
|
|
||||||
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
|
|
||||||
|
|
||||||
DownloadDialog downloadDialog = DownloadDialog.newInstance(currentInfo);
|
|
||||||
downloadDialog.setVideoStreams(sortedVideoStreams);
|
|
||||||
downloadDialog.setAudioStreams(currentInfo.getAudioStreams());
|
|
||||||
downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex);
|
|
||||||
downloadDialog.show(fm, "downloadDialog");
|
|
||||||
fm.executePendingTransactions();
|
|
||||||
downloadDialog.getDialog().setOnDismissListener(dialog -> {
|
|
||||||
finish();
|
|
||||||
});
|
|
||||||
}, (@NonNull Throwable throwable) -> {
|
|
||||||
onError();
|
|
||||||
});
|
|
||||||
notDownload = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,6 +402,47 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
|
private void openDownloadDialog() {
|
||||||
|
ExtractorHelper.getStreamInfo(currentServiceId, currentUrl, true)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe((@NonNull StreamInfo result) -> {
|
||||||
|
List<VideoStream> sortedVideoStreams = ListHelper.getSortedStreamVideosList(this,
|
||||||
|
result.getVideoStreams(),
|
||||||
|
result.getVideoOnlyStreams(),
|
||||||
|
false);
|
||||||
|
int selectedVideoStreamIndex = ListHelper.getDefaultResolutionIndex(this,
|
||||||
|
sortedVideoStreams);
|
||||||
|
|
||||||
|
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
|
||||||
|
DownloadDialog downloadDialog = DownloadDialog.newInstance(result);
|
||||||
|
downloadDialog.setVideoStreams(sortedVideoStreams);
|
||||||
|
downloadDialog.setAudioStreams(result.getAudioStreams());
|
||||||
|
downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex);
|
||||||
|
downloadDialog.show(fm, "downloadDialog");
|
||||||
|
fm.executePendingTransactions();
|
||||||
|
downloadDialog.getDialog().setOnDismissListener(dialog -> {
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
}, (@NonNull Throwable throwable) -> {
|
||||||
|
onError();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
for (int i: grantResults){
|
||||||
|
if (i == PackageManager.PERMISSION_DENIED){
|
||||||
|
finish();
|
||||||
|
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;
|
||||||
|
|
Loading…
Reference in New Issue