channels: pre fin

This commit is contained in:
Yuriy Liskov
2020-09-21 23:53:50 +03:00
parent 922d3d90e1
commit 3ec3c41924
9 changed files with 87 additions and 3 deletions
@@ -80,6 +80,13 @@ public final class Video implements Parcelable {
return video;
}
public static Video from(String videoId) {
Video video = new Video();
video.videoId = videoId;
return video;
}
public static final Creator<Video> CREATOR = new Creator<Video>() {
@Override
public Video createFromParcel(Parcel in) {
@@ -13,6 +13,7 @@ public class StateUpdater extends PlayerEventListenerHelper {
private boolean mIsPlaying;
private int mRepeatMode = 0;
private FormatItem mVideoFormat = FormatItem.HD_AVC;
private static final long MUSIC_VIDEO_LENGTH_MS = 10 * 60 * 1000;
private static class State {
final long positionMs;
@@ -29,7 +30,7 @@ public class StateUpdater extends PlayerEventListenerHelper {
@Override
public boolean onPreviousClicked() {
boolean isShortVideo = mController.getPositionMs() > 10_000 && mController.getLengthMs() < 5*60*1000;
boolean isShortVideo = mController.getPositionMs() > 10_000 && mController.getLengthMs() < MUSIC_VIDEO_LENGTH_MS;
if (isShortVideo) {
mController.setPositionMs(0);
@@ -45,9 +45,18 @@ public class PlaybackPresenter implements Presenter<PlaybackView> {
mView = null;
}
/**
* Opens video item from browser or search views<br/>
* Parent view needed to properly handle auto frame rate changes
*/
public void openVideo(Object parentView, Video item) {
mMainPlayerEventBridge.setParentView(parentView);
mMainPlayerEventBridge.openVideo(item);
mViewManager.startView(parentView, PlaybackView.class);
}
public void openVideo(String videoId) {
mMainPlayerEventBridge.openVideo(Video.from(videoId));
mViewManager.startView(PlaybackView.class);
}
}
@@ -0,0 +1,59 @@
package com.liskovsoft.smartyoutubetv2.common.utils;
import android.content.Intent;
import com.liskovsoft.sharedutils.mylogger.Log;
import com.liskovsoft.sharedutils.querystringparser.UrlQueryString;
import com.liskovsoft.sharedutils.querystringparser.UrlQueryStringFactory;
public class IntentExtractor {
private static final String TAG = IntentExtractor.class.getSimpleName();
/**
* Browser: https://www.youtube.com/results?search_query=twice<br/>
* Amazon: youtube://search?query=linkin+park&isVoice=true
*/
private static final String[] SEARCH_KEYS = {"search_query", "query"};
private static final String VIDEO_ID_KEY = "v";
private static final String CHANNEL_URL = "/channel/";
private static final String USER_URL = "/user/";
public static boolean isVideo(Intent intent) {
if (intent == null) {
return false;
}
return Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getData() != null;
}
public static String getVideoId(Intent intent) {
if (!isVideo(intent)) {
return null;
}
return intent.getData().getQueryParameter(VIDEO_ID_KEY);
}
/**
* Browser: https://www.youtube.com/results?search_query=twice<br/>
* Amazon: youtube://search?query=linkin+park&isVoice=true
*/
private static String extractSearchString(String url) {
UrlQueryString query = UrlQueryStringFactory.parse(url);
String result = null;
for (String key : SEARCH_KEYS) {
result = query.get(key);
if (result != null) {
break;
}
}
if (result == null) {
Log.w(TAG, "Url isn't a search string: " + url);
return null;
}
return result;
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@@ -4,7 +4,10 @@ import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.liskovsoft.sharedutils.mylogger.Log;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.PlaybackPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.views.PlaybackView;
import com.liskovsoft.smartyoutubetv2.common.app.views.ViewManager;
import com.liskovsoft.smartyoutubetv2.common.utils.IntentExtractor;
public class SplashActivity extends Activity {
private static final String TAG = SplashActivity.class.getSimpleName();
@@ -14,8 +17,13 @@ public class SplashActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewManager viewManager = ViewManager.instance(this);
viewManager.startDefaultView(this);
if (IntentExtractor.isVideo(getIntent())) {
PlaybackPresenter playbackPresenter = PlaybackPresenter.instance(this);
playbackPresenter.openVideo(IntentExtractor.getVideoId(getIntent()));
} else {
ViewManager viewManager = ViewManager.instance(this);
viewManager.startDefaultView(this);
}
updateChannels();