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

Support changing channels via ADB and other changes. #7

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ android {

defaultConfig {
applicationId "com.workaround.spectv"
minSdk 28
minSdk 25
targetSdk 32
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.2.1gigem1"

}

Expand Down
11 changes: 10 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@
android:exported="true"
android:icon="@drawable/app_icon_your_company"
android:label="@string/title_activity_main"
android:launchMode="singleTask"
android:logo="@drawable/app_icon_your_company"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="watch.spectrum.net"
android:pathPrefix="/livetv" />
</intent-filter>
</activity>
</application>

</manifest>
</manifest>
62 changes: 56 additions & 6 deletions app/src/main/java/com/workaround/spectv/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
Expand Down Expand Up @@ -67,7 +69,30 @@ public class MainActivity extends FragmentActivity {
"$('video')[0].volume = 1.0;" +
// Load Guide
"Spectv.preloadGuide();" +
"clearInterval(loopVar)"+
"clearInterval(loopVar);"+

// Watfor for and click the Still there? Continue button.
"var observer = new MutationObserver(function(mutations) {" +
"for (mutation of mutations) {" +
"for (addedNode of mutation.addedNodes) {" +
"var button = document.evaluate(" +
"\"//button[contains(text(), 'Continue')]\"," +
"addedNode, null," +
"XPathResult.FIRST_ORDERED_NODE_TYPE," +
"null).singleNodeValue;" +
"if (button) {" +
"console.log('clicking continue button');" +
"button.click();" +
"return;" +
"}" +
"}" +
"};" +
"});" +
"observer.observe(document.body, {" +
"subtree: true," +
"childList: true" +
"});" +

"}" +

"}" +
Expand Down Expand Up @@ -111,7 +136,7 @@ public class MainActivity extends FragmentActivity {
"$('.channel-content-list-container').focus();" +
"}" +
"$('.channel-content-list-container').unbind('click');" +
"$('.channel-content-list-container').on('click', function(event) {event.preventDefault(); event.stopImmediatePropagation(); Spectv.navToChannel(new URL(event.target.href).searchParams.get('tmsGuideServiceId'))});" +
"$('.channel-content-list-container').on('click', function(event) {event.preventDefault(); event.stopImmediatePropagation(); Spectv.navToChannel(new URL(event.target.href).searchParams.get('tmsGuideServiceId'), true)});" +

"}" +
"catch (error) {" +
Expand All @@ -127,7 +152,16 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
sharedPref = this.getSharedPreferences("com.workaround.spectv.pref", Context.MODE_PRIVATE);
sharedPrefEdit = sharedPref.edit();
lastChannelURL = sharedPref.getString("lastChannel", "");
Uri intentData = getIntent().getData();
if (intentData != null)
lastChannelURL = intentData.toString();
else {
String channelId = getIntent().getStringExtra("channelId");
if (channelId != null)
lastChannelURL = baseLiveChannelURL + channelId;
else
lastChannelURL = sharedPref.getString("lastChannel", "");
}

initPlayer();
initGuide();
Expand All @@ -136,6 +170,21 @@ public void onCreate(Bundle savedInstanceState) {
spectrumGuide.addJavascriptInterface(this, "Spectv");
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String channelId;
Uri intentData = intent.getData();
if (intentData != null) {
String uriStr = intentData.toString();
int equals = uriStr.lastIndexOf("=");
channelId = uriStr.substring(equals+1);
} else {
channelId = intent.getStringExtra("channelId");
}
navToChannel(channelId, false);
}

@SuppressLint("RestrictedApi")
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
Expand Down Expand Up @@ -229,15 +278,16 @@ public void run() {
}

@JavascriptInterface
public void navToChannel(String channelId) {
public void navToChannel(String channelId, boolean doBack) {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
saveLastChannel(channelId);
spectrumPlayer.loadUrl(baseLiveChannelURL + channelId);
spectrumGuide.setVisibility(View.GONE);
spectrumGuide.evaluateJavascript("history.back();", null);
if (doBack)
spectrumGuide.evaluateJavascript("history.back();", null);
}
});
} catch (Exception e) {
Expand Down Expand Up @@ -378,4 +428,4 @@ public void onPageFinished(WebView view, String url) {
}


}
}