Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
chore: Disable chromecast behind a local feature flag (#1822)
Browse files Browse the repository at this point in the history
chore: Disable Chromecast behind a local feature flag

- Configure Chromecast based on locally defined feature flag
fix: LEARNER-9610
  • Loading branch information
omerhabib26 authored Sep 25, 2023
1 parent 36a0e15 commit ee01956
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
18 changes: 12 additions & 6 deletions OpenEdXMobile/src/main/java/org/edx/mobile/base/BaseAppActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import com.google.android.gms.cast.framework.CastStateListener
import org.edx.mobile.R
import org.edx.mobile.googlecast.GoogleCastDelegate
import org.edx.mobile.logger.Logger
import org.edx.mobile.util.Config
import javax.inject.Inject

abstract class BaseAppActivity : AppCompatActivity(), CastStateListener {

@Inject
lateinit var config: Config
private var googleCastDelegate: GoogleCastDelegate? = null
private var mediaRouteMenuItem: MenuItem? = null
private val logger = Logger(
Expand All @@ -22,11 +26,13 @@ abstract class BaseAppActivity : AppCompatActivity(), CastStateListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
googleCastDelegate = GoogleCastDelegate.getInstance(
MainApplication.getEnvironment(this)
.analyticsRegistry
)
googleCastDelegate?.addCastStateListener(this)
if (config.isChromeCastEnabled) {
googleCastDelegate = GoogleCastDelegate.getInstance(
MainApplication.getEnvironment(this)
.analyticsRegistry

Check warning on line 32 in OpenEdXMobile/src/main/java/org/edx/mobile/base/BaseAppActivity.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/base/BaseAppActivity.kt#L30-L32

Added lines #L30 - L32 were not covered by tests
)
googleCastDelegate?.addCastStateListener(this)
}
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down Expand Up @@ -83,7 +89,7 @@ abstract class BaseAppActivity : AppCompatActivity(), CastStateListener {
* as part of the Jira story: https://openedx.atlassian.net/browse/LEARNER-7722
*/
try {
if (isInForeground) {
if (config.isChromeCastEnabled && isInForeground) {
if (mediaRouteMenuItem != null) {
googleCastDelegate?.showIntroductoryOverlay(this, mediaRouteMenuItem)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ public void setPlayWhenReady(boolean playWhenReady) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
googleCastDelegate = GoogleCastDelegate.getInstance(environment.getAnalyticsRegistry());
if (environment.getConfig().isChromeCastEnabled()) {
googleCastDelegate = GoogleCastDelegate.getInstance(environment.getAnalyticsRegistry());

Check warning on line 186 in OpenEdXMobile/src/main/java/org/edx/mobile/player/PlayerFragment.java

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/player/PlayerFragment.java#L186

Added line #L186 was not covered by tests
}
}

@Override
Expand Down Expand Up @@ -547,7 +549,7 @@ public synchronized void playOrPrepare(DownloadEntry video, TranscriptModel trMo

final long seekTo = videoEntry.getLastPlayedOffset();
logger.debug("playing [seek=" + seekTo + "]: " + path);
if (googleCastDelegate.isConnected()) {
if (googleCastDelegate != null && googleCastDelegate.isConnected()) {
playVideoOnRemoteDevice(lastSavedPosition, true);
player.setUri(path, seekTo);
} else if (prepareOnly)
Expand Down
6 changes: 6 additions & 0 deletions OpenEdXMobile/src/main/java/org/edx/mobile/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class Config {
private static final String COURSE_VIDEOS_ENABLED = "COURSE_VIDEOS_ENABLED";
private static final String DOWNLOAD_TO_SD_CARD_ENABLED = "DOWNLOAD_TO_SD_CARD_ENABLED";
private static final String ANNOUNCEMENTS_ENABLED = "ANNOUNCEMENTS_ENABLED";
private static final String CHROMECAST_ENABLED = "CHROMECAST_ENABLED";

public static class DiscoveryConfig {
@SerializedName("TYPE")
Expand Down Expand Up @@ -629,6 +630,11 @@ public boolean isAnnouncementEnabled() {
return getBoolean(ANNOUNCEMENTS_ENABLED, true);
}

// locally defined flag to disable the chromecast
public boolean isChromeCastEnabled() {
return getBoolean(CHROMECAST_ENABLED, false);

Check warning on line 635 in OpenEdXMobile/src/main/java/org/edx/mobile/util/Config.java

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/util/Config.java#L635

Added line #L635 was not covered by tests
}

public boolean isDownloadToSDCardEnabled() {
return getBoolean(DOWNLOAD_TO_SD_CARD_ENABLED, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ class CourseUnitNavigationActivity : BaseFragmentActivity(), CourseUnitFragment.

override fun showGoogleCastButton(): Boolean {
val component = getCurrentComponent()
return if (component is VideoBlockModel) {
return if (config.isChromeCastEnabled && component is VideoBlockModel) {
// Showing casting button only for native video block
// Currently casting for youtube video isn't available
VideoUtil.isCourseUnitVideo(environment, component)
Expand Down

0 comments on commit ee01956

Please sign in to comment.