Skip to content

Commit 000e15e

Browse files
author
Chris Bellew
committed
Allow limited playback (one minute) on chromecasts if chromecast support has not been purchased.
1 parent 8ed542c commit 000e15e

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

mobile/src/main/java/com/atomjack/vcfp/CastPlayerManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public static final class PARAMS {
9999
public static final String SERVERS = "servers";
100100
public static final String ACTIVE_CONNECTIONS = "active_connections";
101101

102+
public static final String PLAYBACK_LIMITED = "playback_limited"; // Whether or not playback should stop after 1 minute
103+
102104
};
103105

104106
public static final class RECEIVER_EVENTS {
@@ -163,7 +165,8 @@ public void run() {
163165
JSONObject obj = new JSONObject();
164166
try {
165167
obj.put(PARAMS.ACTION, PARAMS.RECEIVE_SERVERS);
166-
168+
if(!VoiceControlForPlexApplication.getInstance().hasChromecast())
169+
obj.put(PARAMS.PLAYBACK_LIMITED, true);
167170
Type serverType = new TypeToken<ConcurrentHashMap<String, PlexServer>>(){}.getType();
168171
PlexServer server = VoiceControlForPlexApplication.gsonRead.fromJson(VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.SERVER, ""), PlexServer.class);
169172
if(server.name.equals(mContext.getString(R.string.scan_all)))

mobile/src/main/java/com/atomjack/vcfp/activities/MainActivity.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,10 +1482,10 @@ public void run() {
14821482
if(VoiceControlForPlexApplication.getInstance().hasLocalmedia())
14831483
hidePurchaseLocalmediaMenuItem();
14841484

1485-
if(VoiceControlForPlexApplication.getInstance().hasChromecast()) {
1486-
MenuItem chromecastOptionsItem = menu.findItem(R.id.menu_chromecast_video);
1487-
chromecastOptionsItem.setVisible(true);
1488-
}
1485+
MenuItem chromecastOptionsItem = menu.findItem(R.id.menu_chromecast_video);
1486+
MenuItem chromecastPurchaseItem = menu.findItem(R.id.menu_purchase_chromecast);
1487+
chromecastPurchaseItem.setVisible(!VoiceControlForPlexApplication.getInstance().hasChromecast());
1488+
chromecastOptionsItem.setVisible(VoiceControlForPlexApplication.getInstance().hasChromecast());
14891489

14901490
SwitchCompat usageExamplesSwitch = (SwitchCompat)menu.findItem(R.id.menu_usage_hints_switch).getActionView();
14911491
usageExamplesSwitch.setChecked(prefs.get(Preferences.SHOW_USAGE_HINTS, true));
@@ -1640,7 +1640,7 @@ public void onDeviceSelected(PlexDevice device, boolean resume) {
16401640
animateCastIcon();
16411641

16421642
if (clientSelected.isCastClient) {
1643-
if(VoiceControlForPlexApplication.getInstance().hasChromecast()) {
1643+
if(VoiceControlForPlexApplication.getInstance().hasChromecast() || prefs.get(Preferences.HAS_SHOWN_INITIAL_CHROMECAST_PURCHASE, false)) {
16441644
client = clientSelected;
16451645
logger.d("subscribing to %s", client.name);
16461646
castPlayerManager.subscribe(client, !castPlayerManager.isSubscribed());
@@ -2210,15 +2210,20 @@ public void run() {
22102210

22112211
}
22122212

2213-
protected void showChromecastPurchase(PlexClient client, Runnable onSuccess) {
2213+
public void purchaseChromecast(MenuItem item) {
2214+
VoiceControlForPlexApplication.getInstance().getIabHelper().launchPurchaseFlow(MainActivity.this, VoiceControlForPlexApplication.SKU_CHROMECAST, 10001, mPurchaseFinishedListener, VoiceControlForPlexApplication.SKU_TEST_PURCHASED == VoiceControlForPlexApplication.SKU_CHROMECAST ? VoiceControlForPlexApplication.getInstance().getEmailHash() : "");
2215+
}
2216+
2217+
protected void showChromecastPurchase(PlexClient client, final Runnable onSuccess) {
22142218
postChromecastPurchaseClient = client;
22152219
postChromecastPurchaseAction = onSuccess;
2220+
prefs.put(Preferences.HAS_SHOWN_INITIAL_CHROMECAST_PURCHASE, true);
22162221
AlertDialog.Builder builder = new AlertDialog.Builder(this);
22172222
View view = getLayoutInflater().inflate(R.layout.popup_chromecast_purchase, null);
22182223
builder.setView(view);
22192224
final AlertDialog dialog = builder.setCancelable(false).create();
22202225
TextView popupChromecastPurchaseMessage = (TextView)view.findViewById(R.id.popupChromecastPurchaseMessage);
2221-
popupChromecastPurchaseMessage.setText(String.format(getString(R.string.must_purchase_chromecast), VoiceControlForPlexApplication.getChromecastPrice()));
2226+
popupChromecastPurchaseMessage.setText(String.format(getString(R.string.must_purchase_chromecast2), VoiceControlForPlexApplication.getChromecastPrice()));
22222227
Button popupChromecastPurchaseOKButton = (Button)view.findViewById(R.id.popupChromecastPurchaseOKButton);
22232228
popupChromecastPurchaseOKButton.setOnClickListener(new View.OnClickListener() {
22242229
@Override
@@ -2232,7 +2237,7 @@ public void onClick(View v) {
22322237
@Override
22332238
public void onClick(View v) {
22342239
dialog.cancel();
2235-
setCastIconInactive();
2240+
onSuccess.run();
22362241
}
22372242
});
22382243
dialog.show();

mobile/src/main/res/menu/nav_items_settings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
android:title="@string/cinema_trailers"
3636
android:icon="@drawable/menu_trailers"
3737
android:onClick="cinemaTrailers"/>
38+
<item android:id="@+id/menu_purchase_chromecast"
39+
android:title="@string/purchase_chromecast"
40+
android:icon="@drawable/menu_chromecast"
41+
android:visibility="gone"
42+
android:onClick="purchaseChromecast" />
3843
<item android:id="@+id/menu_purchase_localmedia"
3944
android:title="@string/purchase_localmedia"
4045
android:icon="@drawable/menu_local_video"

mobile/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,6 @@
206206
<string name="tutorial1_nav_button">Tap the Navigation button to show the Navigation Menu, where you can choose a Plex server, and customize settings.</string>
207207
<string name="tutorial1_mic_button">Finally, tap the mic to tell Plex to play something!</string>
208208

209+
<string name="must_purchase_chromecast2">Playback to Chromecasts are restricted to one minute. Would you like to unlock it(%s)?</string>
210+
<string name="purchase_chromecast">Purchase Chromecast Playback</string>
209211
</resources>

shared/src/main/java/com/atomjack/shared/Preferences.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class Preferences {
6060
public final static String HAS_FINISHED_TUTORIAL1 = "pref.has_finished_tutorial1";
6161

6262
public final static String HAS_SHOWN_INITIAL_LOCALMEDIA_PURCHASE = "pref.has_shown_initial_localmedia_purchase";
63+
public final static String HAS_SHOWN_INITIAL_CHROMECAST_PURCHASE = "pref.has_shown_initial_chromecast_purchase";
6364

6465

6566

0 commit comments

Comments
 (0)