fix backstack issue with mediaccc

This commit is contained in:
Christian Schabesberger 2019-01-31 13:24:02 +01:00
parent 6edbfe2a6f
commit 14043c86f5
1 changed files with 35 additions and 19 deletions

View File

@ -363,7 +363,8 @@ public class VideoDetailFragment
} }
break; break;
case R.id.detail_controls_download: case R.id.detail_controls_download:
if (PermissionHelper.checkStoragePermissions(activity, PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) { if (PermissionHelper.checkStoragePermissions(activity,
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
this.openDownloadDialog(); this.openDownloadDialog();
} }
break; break;
@ -447,7 +448,6 @@ public class VideoDetailFragment
return; return;
} }
//Log.d(TAG, "toggleExpandRelatedVideos() called with: info = [" + info + "], from = [" + INITIAL_RELATED_VIDEOS + "]");
for (int i = INITIAL_RELATED_VIDEOS; i < info.getRelatedStreams().size(); i++) { for (int i = INITIAL_RELATED_VIDEOS; i < info.getRelatedStreams().size(); i++) {
InfoItem item = info.getRelatedStreams().get(i); InfoItem item = info.getRelatedStreams().get(i);
//Log.d(TAG, "i = " + i); //Log.d(TAG, "i = " + i);
@ -520,7 +520,9 @@ public class VideoDetailFragment
infoItemBuilder.setOnStreamSelectedListener(new OnClickGesture<StreamInfoItem>() { infoItemBuilder.setOnStreamSelectedListener(new OnClickGesture<StreamInfoItem>() {
@Override @Override
public void selected(StreamInfoItem selectedItem) { public void selected(StreamInfoItem selectedItem) {
selectAndLoadVideo(selectedItem.getServiceId(), selectedItem.getUrl(), selectedItem.getName()); selectAndLoadVideo(selectedItem.getServiceId(),
selectedItem.getUrl(),
selectedItem.getName());
} }
@Override @Override
@ -743,10 +745,16 @@ public class VideoDetailFragment
boolean isExternalPlayerEnabled = PreferenceManager.getDefaultSharedPreferences(activity) boolean isExternalPlayerEnabled = PreferenceManager.getDefaultSharedPreferences(activity)
.getBoolean(activity.getString(R.string.use_external_video_player_key), false); .getBoolean(activity.getString(R.string.use_external_video_player_key), false);
sortedVideoStreams = ListHelper.getSortedStreamVideosList(activity, info.getVideoStreams(), info.getVideoOnlyStreams(), false); sortedVideoStreams = ListHelper.getSortedStreamVideosList(
activity,
info.getVideoStreams(),
info.getVideoOnlyStreams(),
false);
selectedVideoStreamIndex = ListHelper.getDefaultResolutionIndex(activity, sortedVideoStreams); selectedVideoStreamIndex = ListHelper.getDefaultResolutionIndex(activity, sortedVideoStreams);
final StreamItemAdapter<VideoStream, Stream> streamsAdapter = new StreamItemAdapter<>(activity, new StreamSizeWrapper<>(sortedVideoStreams, activity), isExternalPlayerEnabled); final StreamItemAdapter<VideoStream, Stream> streamsAdapter =
new StreamItemAdapter<>(activity,
new StreamSizeWrapper<>(sortedVideoStreams, activity), isExternalPlayerEnabled);
spinnerToolbar.setAdapter(streamsAdapter); spinnerToolbar.setAdapter(streamsAdapter);
spinnerToolbar.setSelection(selectedVideoStreamIndex); spinnerToolbar.setSelection(selectedVideoStreamIndex);
spinnerToolbar.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { spinnerToolbar.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@ -771,17 +779,17 @@ public class VideoDetailFragment
*/ */
protected final LinkedList<StackItem> stack = new LinkedList<>(); protected final LinkedList<StackItem> stack = new LinkedList<>();
public void clearHistory() {
stack.clear();
}
public void pushToStack(int serviceId, String videoUrl, String name) { public void pushToStack(int serviceId, String videoUrl, String name) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "pushToStack() called with: serviceId = [" + serviceId + "], videoUrl = [" + videoUrl + "], name = [" + name + "]"); Log.d(TAG, "pushToStack() called with: serviceId = ["
+ serviceId + "], videoUrl = [" + videoUrl + "], name = [" + name + "]");
} }
if (stack.size() > 0 && stack.peek().getServiceId() == serviceId && stack.peek().getUrl().equals(videoUrl)) { if (stack.size() > 0
Log.d(TAG, "pushToStack() called with: serviceId == peek.serviceId = [" + serviceId + "], videoUrl == peek.getUrl = [" + videoUrl + "]"); && stack.peek().getServiceId() == serviceId
&& stack.peek().getUrl().equals(videoUrl)) {
Log.d(TAG, "pushToStack() called with: serviceId == peek.serviceId = ["
+ serviceId + "], videoUrl == peek.getUrl = [" + videoUrl + "]");
return; return;
} else { } else {
Log.d(TAG, "pushToStack() wasn't equal"); Log.d(TAG, "pushToStack() wasn't equal");
@ -812,7 +820,11 @@ public class VideoDetailFragment
// Get stack item from the new top // Get stack item from the new top
StackItem peek = stack.peek(); StackItem peek = stack.peek();
selectAndLoadVideo(peek.getServiceId(), peek.getUrl(), !TextUtils.isEmpty(peek.getTitle()) ? peek.getTitle() : ""); selectAndLoadVideo(peek.getServiceId(),
peek.getUrl(),
!TextUtils.isEmpty(peek.getTitle())
? peek.getTitle()
: "");
return true; return true;
} }
@ -832,9 +844,10 @@ public class VideoDetailFragment
} }
public void prepareAndHandleInfo(final StreamInfo info, boolean scrollToTop) { public void prepareAndHandleInfo(final StreamInfo info, boolean scrollToTop) {
if (DEBUG) Log.d(TAG, "prepareAndHandleInfo() called with: info = [" + info + "], scrollToTop = [" + scrollToTop + "]"); if (DEBUG) Log.d(TAG, "prepareAndHandleInfo() called with: info = ["
+ info + "], scrollToTop = [" + scrollToTop + "]");
setInitialData(info.getServiceId(), info.getOriginalUrl(), info.getName()); setInitialData(info.getServiceId(), info.getUrl(), info.getName());
pushToStack(serviceId, url, name); pushToStack(serviceId, url, name);
showLoading(); showLoading();
@ -1027,7 +1040,8 @@ public class VideoDetailFragment
private void showContentWithAnimation(long duration, private void showContentWithAnimation(long duration,
long delay, long delay,
@FloatRange(from = 0.0f, to = 1.0f) float translationPercent) { @FloatRange(from = 0.0f, to = 1.0f)
float translationPercent) {
int translationY = (int) (getResources().getDisplayMetrics().heightPixels * int translationY = (int) (getResources().getDisplayMetrics().heightPixels *
(translationPercent > 0.0f ? translationPercent : .06f)); (translationPercent > 0.0f ? translationPercent : .06f));
@ -1135,7 +1149,7 @@ public class VideoDetailFragment
super.handleResult(info); super.handleResult(info);
setInitialData(info.getServiceId(), info.getOriginalUrl(), info.getName()); setInitialData(info.getServiceId(), info.getOriginalUrl(), info.getName());
pushToStack(serviceId, url, name); //pushToStack(serviceId, url, name);
animateView(thumbnailPlayButton, true, 200); animateView(thumbnailPlayButton, true, 200);
videoTitleTextView.setText(name); videoTitleTextView.setText(name);
@ -1186,11 +1200,13 @@ public class VideoDetailFragment
if (info.getDuration() > 0) { if (info.getDuration() > 0) {
detailDurationView.setText(Localization.getDurationString(info.getDuration())); detailDurationView.setText(Localization.getDurationString(info.getDuration()));
detailDurationView.setBackgroundColor(ContextCompat.getColor(activity, R.color.duration_background_color)); detailDurationView.setBackgroundColor(
ContextCompat.getColor(activity, R.color.duration_background_color));
animateView(detailDurationView, true, 100); animateView(detailDurationView, true, 100);
} else if (info.getStreamType() == StreamType.LIVE_STREAM) { } else if (info.getStreamType() == StreamType.LIVE_STREAM) {
detailDurationView.setText(R.string.duration_live); detailDurationView.setText(R.string.duration_live);
detailDurationView.setBackgroundColor(ContextCompat.getColor(activity, R.color.live_duration_background_color)); detailDurationView.setBackgroundColor(
ContextCompat.getColor(activity, R.color.live_duration_background_color));
animateView(detailDurationView, true, 100); animateView(detailDurationView, true, 100);
} else { } else {
detailDurationView.setVisibility(View.GONE); detailDurationView.setVisibility(View.GONE);