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

feat: Add and update analytics for discussion+video modules #67

Merged
merged 4 commits into from
Nov 27, 2024
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
16 changes: 13 additions & 3 deletions app/src/main/java/org/openedx/app/AppRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
fm: FragmentManager,
videoUrl: String,
videoTime: Long,
videoDuration: Long,
blockId: String,
courseId: String,
isPlaying: Boolean,
Expand All @@ -277,6 +278,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
VideoFullScreenFragment.newInstance(
videoUrl = videoUrl,
videoTime = videoTime,
videoDuration = videoDuration,
blockId = blockId,
courseId = courseId,
isPlaying = isPlaying,
Expand All @@ -289,6 +291,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
fm: FragmentManager,
videoUrl: String,
videoTime: Long,
videoDuration: Long,
blockId: String,
courseId: String,
isPlaying: Boolean,
Expand All @@ -298,6 +301,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
YoutubeVideoFullScreenFragment.newInstance(
videoUrl,
videoTime,
videoDuration,
blockId,
courseId,
isPlaying
Expand Down Expand Up @@ -332,21 +336,27 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
)
}

override fun navigateToDiscussionComments(fm: FragmentManager, thread: Thread) {
override fun navigateToDiscussionComments(
fm: FragmentManager,
courseId: String,
thread: Thread,
) {
replaceFragmentWithBackStack(
fm,
DiscussionCommentsFragment.newInstance(thread)
DiscussionCommentsFragment.newInstance(courseId, thread)
)
}

override fun navigateToDiscussionResponses(
fm: FragmentManager,
courseId: String,
threadId: String,
comment: DiscussionComment,
isClosed: Boolean,
) {
replaceFragmentWithBackStack(
fm,
DiscussionResponsesFragment.newInstance(comment, isClosed)
DiscussionResponsesFragment.newInstance(courseId, threadId, comment, isClosed)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.openedx.core.data.model.User
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.data.storage.InAppReviewPreferences
import org.openedx.core.domain.model.AppConfig
import org.openedx.core.domain.model.VideoPlaybackSpeed
import org.openedx.core.domain.model.VideoQuality
import org.openedx.core.domain.model.VideoSettings
import org.openedx.core.extension.replaceSpace
Expand Down Expand Up @@ -109,18 +110,22 @@ class PreferencesManager(context: Context) : CorePreferences, ProfilePreferences
saveBoolean(VIDEO_SETTINGS_WIFI_DOWNLOAD_ONLY, value.wifiDownloadOnly)
saveString(VIDEO_SETTINGS_STREAMING_QUALITY, value.videoStreamingQuality.name)
saveString(VIDEO_SETTINGS_DOWNLOAD_QUALITY, value.videoDownloadQuality.name)
saveString(VIDEO_PLAYBACK_SPEED, value.videoPlaybackSpeed.name)
}
get() {
val wifiDownloadOnly = getBoolean(VIDEO_SETTINGS_WIFI_DOWNLOAD_ONLY, defValue = true)
val streamingQualityString =
getString(VIDEO_SETTINGS_STREAMING_QUALITY, defValue = VideoQuality.AUTO.name)
val downloadQualityString =
getString(VIDEO_SETTINGS_DOWNLOAD_QUALITY, defValue = VideoQuality.AUTO.name)
val videoPlaybackSpeed =
getString(VIDEO_PLAYBACK_SPEED, defValue = VideoPlaybackSpeed.SPEED_1_0X.name)

return VideoSettings(
wifiDownloadOnly = wifiDownloadOnly,
videoStreamingQuality = VideoQuality.valueOf(streamingQualityString),
videoDownloadQuality = VideoQuality.valueOf(downloadQualityString)
videoDownloadQuality = VideoQuality.valueOf(downloadQualityString),
videoPlaybackSpeed = VideoPlaybackSpeed.valueOf(videoPlaybackSpeed)
)
}

Expand Down Expand Up @@ -194,6 +199,7 @@ class PreferencesManager(context: Context) : CorePreferences, ProfilePreferences
private const val VIDEO_SETTINGS_WIFI_DOWNLOAD_ONLY = "video_settings_wifi_download_only"
private const val VIDEO_SETTINGS_STREAMING_QUALITY = "video_settings_streaming_quality"
private const val VIDEO_SETTINGS_DOWNLOAD_QUALITY = "video_settings_download_quality"
private const val VIDEO_PLAYBACK_SPEED = "video_playback_speed"
private const val APP_CONFIG = "app_config"
private const val RESET_APP_DIRECTORY = "reset_app_directory"
private const val LAST_SIGN_IN_TYPE = "last_sign_in_type"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/org/openedx/app/deeplink/DeepLinkRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ class DeepLinkRouter(
launch(Dispatchers.Main) {
appRouter.navigateToDiscussionComments(
fm = fm,
courseId = courseId,
thread = thread
)
}
Expand Down Expand Up @@ -500,13 +501,16 @@ class DeepLinkRouter(
launch(Dispatchers.Main) {
appRouter.navigateToDiscussionComments(
fm = fm,
courseId = courseId,
thread = thread
)
}
val response = discussionInteractor.getResponse(commentId)
launch(Dispatchers.Main) {
appRouter.navigateToDiscussionResponses(
fm = fm,
courseId = courseId,
threadId = threadId,
comment = response,
isClosed = false
)
Expand Down Expand Up @@ -549,13 +553,16 @@ class DeepLinkRouter(
launch(Dispatchers.Main) {
appRouter.navigateToDiscussionComments(
fm = fm,
courseId = courseId,
thread = thread
)
}
val comment = discussionInteractor.getResponse(parentId)
launch(Dispatchers.Main) {
appRouter.navigateToDiscussionResponses(
fm = fm,
courseId = courseId,
threadId = threadId,
comment = comment,
isClosed = false
)
Expand Down
52 changes: 41 additions & 11 deletions app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.openedx.discovery.presentation.search.CourseSearchViewModel
import org.openedx.discussion.data.repository.DiscussionRepository
import org.openedx.discussion.domain.interactor.DiscussionInteractor
import org.openedx.discussion.domain.model.DiscussionComment
import org.openedx.discussion.domain.model.Thread
import org.openedx.discussion.presentation.comments.DiscussionCommentsViewModel
import org.openedx.discussion.presentation.responses.DiscussionResponsesViewModel
import org.openedx.discussion.presentation.search.DiscussionSearchThreadViewModel
Expand Down Expand Up @@ -335,11 +336,27 @@ val screenModule = module {
get()
)
}
viewModel { (courseId: String) -> BaseVideoViewModel(courseId, get()) }
viewModel { (courseId: String) -> VideoViewModel(courseId, get(), get(), get(), get()) }
viewModel { (courseId: String) ->
viewModel { (courseId: String, blockId: String) ->
BaseVideoViewModel(
courseId,
blockId,
get()
)
}
viewModel { (courseId: String, blockId: String) ->
VideoViewModel(
courseId,
blockId,
get(),
get(),
get(),
get()
)
}
viewModel { (courseId: String, blockId: String) ->
VideoUnitViewModel(
courseId,
blockId,
get(),
get(),
get(),
Expand Down Expand Up @@ -402,31 +419,44 @@ val screenModule = module {
}
viewModel { (courseId: String, topicId: String, threadType: String) ->
DiscussionThreadsViewModel(
courseId,
topicId,
threadType,
get(),
get(),
get(),
courseId,
topicId,
threadType
)
}
viewModel { (thread: org.openedx.discussion.domain.model.Thread) ->
viewModel { (courseId: String, thread: Thread) ->
DiscussionCommentsViewModel(
courseId,
thread,
get(),
get(),
get(),
get(),
thread
)
}
viewModel { (comment: DiscussionComment) ->
viewModel { (courseId: String, threadId: String, comment: DiscussionComment) ->
DiscussionResponsesViewModel(
courseId,
threadId,
comment,
get(),
get(),
get(),
get(),
comment
)
}
viewModel { (courseId: String) -> DiscussionAddThreadViewModel(get(), get(), get(), courseId) }
viewModel { (courseId: String) ->
DiscussionAddThreadViewModel(
courseId,
get(),
get(),
get(),
get()
)
}
viewModel { (courseId: String) ->
DiscussionSearchThreadViewModel(
get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ data class VideoSettings(
val wifiDownloadOnly: Boolean,
val videoStreamingQuality: VideoQuality,
val videoDownloadQuality: VideoQuality,
val videoPlaybackSpeed: VideoPlaybackSpeed,
) {
companion object {
val default = VideoSettings(true, VideoQuality.AUTO, VideoQuality.AUTO)
val default =
VideoSettings(true, VideoQuality.AUTO, VideoQuality.AUTO, VideoPlaybackSpeed.SPEED_1_0X)
}
}

Expand Down Expand Up @@ -48,3 +50,15 @@ enum class VideoQuality(
tagId = "high",
);
}

enum class VideoPlaybackSpeed(val speedValue: Float) {
SPEED_0_25X(0.25f), SPEED_0_50X(0.5f), SPEED_0_75X(0.75f),
SPEED_1_0X(1.0f), SPEED_1_25X(1.25f), SPEED_1_50X(1.5f),
SPEED_1_75X(1.75f), SPEED_2_0X(2.0f);

companion object {
fun getVideoPlaybackSpeed(speedValue: Float): VideoPlaybackSpeed {
return entries.find { it.speedValue == speedValue } ?: SPEED_1_0X
}
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/openedx/core/extension/StringExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun String.replaceSpace(target: String = ""): String = this.replace(" ", target)
fun String.tagId(): String = this.replaceSpace("_").lowercase(Locale.getDefault())

fun String.takeIfNotEmpty(): String? {
return if (this.isEmpty().not()) this else null
return if (this.isNotNullOrEmpty()) this else null
}

fun String?.isNotNullOrEmpty(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package org.openedx.core.system.notifier
data class CourseVideoPositionChanged(
val videoUrl: String,
val videoTime: Long,
val videoDuration: Long,
val isPlaying: Boolean
) : CourseEvent
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ enum class CourseAnalyticsKey(val key: String) {
NAME("name"),
COURSE_ID("course_id"),
COURSE_NAME("course_name"),
OPEN_IN_BROWSER("open_in_browser_url"),
COMPONENT("component"),
VIDEO_PLAYER("video_player"),
VIDEO_URL("video_url"),
VIDEOS("videos"),
DURATION("duration"),
ENROLLMENT_MODE("enrollment_mode"),
PACING("pacing"),
SCREEN_NAME("screen_name"),
Expand All @@ -167,12 +167,10 @@ enum class CourseAnalyticsKey(val key: String) {
BLOCK_NAME("block_name"),
BLOCK_TYPE("block_type"),
PLAY_MEDIUM("play_medium"),
NATIVE("native"),
YOUTUBE("youtube"),
GOOGLE_CAST("google_cast"),
CURRENT_TIME("current_time"),
SKIP_INTERVAL("requested_skip_interval"),
SPEED("speed"),
OLD_SPEED("old_speed"),
NEW_SPEED("new_speed"),
NAVIGATION("navigation"),
DIALOG("dialog"),
ACTION("action"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface CourseRouter {
fm: FragmentManager,
videoUrl: String,
videoTime: Long,
videoDuration: Long,
blockId: String,
courseId: String,
isPlaying: Boolean,
Expand All @@ -51,6 +52,7 @@ interface CourseRouter {
fm: FragmentManager,
videoUrl: String,
videoTime: Long,
videoDuration: Long,
blockId: String,
courseId: String,
isPlaying: Boolean
Expand Down
Loading
Loading