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

chore: Disable chromecast behind a local feature flag #1822

Merged
merged 2 commits into from
Sep 25, 2023
Merged
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
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 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 @@

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 @@
* 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 @@
@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 @@

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 @@
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 @@
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to check the config here, cuz before calling the showGoogleCastButton BaseAppActivity has the null check at Line#93

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this check here because this method is calling from multiple places.

// Showing casting button only for native video block
// Currently casting for youtube video isn't available
VideoUtil.isCourseUnitVideo(environment, component)
Expand Down
Loading