Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recording #2

Merged
merged 14 commits into from
Feb 17, 2017
Prev Previous commit
Next Next commit
Integration of ChannelSurfer
  • Loading branch information
Fleker committed Oct 29, 2016
commit dcdeeaa51fb2bf5602cc9f8dbcfea60f0fe2b512
27 changes: 25 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,36 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/plexus/components.xml'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile('com.github.jreddit:jreddit:1.0.3') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude module: 'junit'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
// compile 'com.github.itvlab:youtube-tv-player:0.1.0'
compile 'com.github.itvlab:youtube-tv-player:-SNAPSHOT'
compile 'com.github.fleker:channelsurfer:0.2.12'

testCompile 'junit:junit:4.10'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
}
31 changes: 30 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="news.androidtv.subchannel" >
package="news.androidtv.subchannel">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand All @@ -15,6 +17,33 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name=".AbstractTvService"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BIND_TV_INPUT">
<intent-filter>
<action android:name="android.media.tv.TvInputService" />
</intent-filter>
<meta-data
android:name="android.media.tv.input"
android:resource="@xml/channel_surfer_tv_input" />
</service>

<meta-data
android:name="TvInputService"
android:value="news.androidtv.subchannel.AbstractTvService" />

<activity
android:name=".SampleTvSetup"
android:exported="true"
android:enabled="true"
android:label="Init">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>

</manifest>
113 changes: 113 additions & 0 deletions app/src/main/java/news/androidtv/subchannel/AbstractTvService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package news.androidtv.subchannel;

import android.content.Context;
import android.net.Uri;
import android.view.Surface;
import android.view.View;

import com.felkertech.channelsurfer.model.Channel;
import com.felkertech.channelsurfer.model.Program;
import com.felkertech.channelsurfer.service.TvInputProvider;
import com.felkertech.channelsurfer.sync.SyncAdapter;
import com.felkertech.channelsurfer.utils.TvContractUtils;
import com.github.jreddit.entity.Submission;
import com.github.jreddit.retrieval.Submissions;
import com.github.jreddit.utils.restclient.PoliteHttpRestClient;
import com.github.jreddit.utils.restclient.RestClient;

import java.util.ArrayList;
import java.util.List;

import news.androidtv.libs.player.AbstractWebPlayer;
import news.androidtv.libs.player.YouTubePlayerView;
import news.androidtv.subchannel.utils.YoutubeUtils;

/**
* Created by Nick on 10/28/2016.
*/

public class AbstractTvService extends TvInputProvider {
private List<Submission> submissions;
private YouTubePlayerView youTubePlayerView;

public AbstractTvService() {
}

@Override
public void performCustomSync(final SyncAdapter syncAdapter, final String inputId) {
submissions = new ArrayList<>();
new Thread(new Runnable() {
@Override
public void run() {
RestClient restClient = new PoliteHttpRestClient();
restClient.setUserAgent("bot/1.0 by name");
Submissions subs = new Submissions(restClient);
submissions = subs.ofSubreddit("youtubehaiku", null, -1, 100, null, null, true);
syncAdapter.performSync(AbstractTvService.this, inputId);
}
}).start();
}

@Override
public List<Channel> getAllChannels(Context context) {
List<Channel> channelList = new ArrayList<>();
channelList.add(new Channel()
.setName("/r/YouTubeHaiku")
.setNumber("1"));
return channelList;
}

@Override
public List<Program> getProgramsForChannel(Context context, Uri channelUri, Channel channelInfo, long startTimeMs, long endTimeMs) {
List<Program> programList = new ArrayList<>();
for (int i = 0; i < submissions.size(); i++) {
Submission s = submissions.get(i);
programList.add(new Program.Builder()
.setTitle(s.getTitle())
.setThumbnailUri(s.getThumbnail())
.setDescription("Posted by " + s.getAuthor())
.setInternalProviderData(s.getUrl())
.setStartTimeUtcMillis(startTimeMs)
.setEndTimeUtcMillis(startTimeMs + 1000 * 60 * i) // Don't know the video duration
.build());
}
return programList;
}

@Override
public boolean onSetSurface(Surface surface) {
return true;
}

@Override
public void onSetStreamVolume(float volume) {
// Maybe
}

@Override
public void onRelease() {

}

@Override
public View onCreateOverlayView() {
if (youTubePlayerView == null) {
youTubePlayerView = new YouTubePlayerView(getApplicationContext());
}
return youTubePlayerView;
}

@Override
public boolean onTune(final Channel channel) {
Program program = getProgramRightNow(channel);
setOverlayEnabled(true);
youTubePlayerView.setVideoEventsListener(new AbstractWebPlayer.VideoEventsListener() {
@Override
public void onVideoEnded() {
onTune(channel);
}
});
youTubePlayerView.loadVideo(YoutubeUtils.parseVideoId(program.getInternalProviderData()));
return true;
}
}
51 changes: 51 additions & 0 deletions app/src/main/java/news/androidtv/subchannel/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package news.androidtv.subchannel;

import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.github.jreddit.entity.Submission;
import com.github.jreddit.retrieval.Submissions;
import com.github.jreddit.utils.restclient.PoliteHttpRestClient;
import com.github.jreddit.utils.restclient.RestClient;

import org.sonatype.guice.bean.containers.Main;

import java.util.LinkedList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();

private RestClient restClient = new PoliteHttpRestClient();
private Submissions subs;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

restClient.setUserAgent("bot/1.0 by name");

subs = new Submissions(restClient);

Log.d(TAG, "Get some posts");
getPosts();
}

public void getPosts() {
new Thread(new Runnable() {
@Override
public void run() {
List<Submission> posts = subs.ofSubreddit("youtubehaiku", null, -1, 100, null, null, true);
Log.d(TAG, "Posts gotten: " + posts.size());
for (Submission s : posts) {
Log.d(TAG, s.getTitle());
Log.d(TAG, " " + s.getUrl());
}
}
}).start();
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/news/androidtv/subchannel/SetupActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package news.androidtv.subchannel;

import com.felkertech.channelsurfer.setup.SimpleTvSetup;

/**
* Created by Nick on 10/28/2016.
*/

public class SetupActivity extends SimpleTvSetup {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package news.androidtv.subchannel.shims;

/**
* Created by Nick on 10/27/2016.
*/

public interface Function<T> {
void run(T result);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package news.androidtv.subchannel.utils;

/**
* Created by Nick on 10/28/2016.
*/

public class YoutubeUtils {
public static String parseVideoId(String videoUrl) {
if (videoUrl.contains("youtube.com/watch?v=")) {
return videoUrl.substring(videoUrl.indexOf("youtube.com/watch?v=") + 20, videoUrl.indexOf("youtube.com/watch?v=") + 33);
} else if (videoUrl.contains("youtu.be/")) {
return videoUrl.substring(videoUrl.indexOf("youtu.be/") + 9, videoUrl.indexOf("youtu.be/") + 24);
}
return "";
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">SubChannel</string>
<string name="tv_input_activity">news.androidtv.subchannel.AbstractTvService</string>
</resources>
24 changes: 24 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
17 changes: 17 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ':app'