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

[iOS] There are no subtitles for videos opened from the "Dates" Course section #340

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions Core/Core.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
02F6EF3B28D9B8EC00835477 /* CourseCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F6EF3A28D9B8EC00835477 /* CourseCellView.swift */; };
02F6EF4A28D9F0A700835477 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F6EF4928D9F0A700835477 /* DateExtension.swift */; };
02F98A7F28F81EE900DE94C0 /* Container+App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F98A7E28F81EE900DE94C0 /* Container+App.swift */; };
06041B222BA1DB720092F85B /* String+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06041B212BA1DB720092F85B /* String+JSON.swift */; };
06041B242BA1DB9A0092F85B /* Dictionary+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06041B232BA1DB9A0092F85B /* Dictionary+JSON.swift */; };
0604C9AA2B22FACF00AD5DBF /* UIComponentsConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0604C9A92B22FACF00AD5DBF /* UIComponentsConfig.swift */; };
064987932B4D69FF0071642A /* DragAndDropCssInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0649878A2B4D69FE0071642A /* DragAndDropCssInjection.swift */; };
064987942B4D69FF0071642A /* WebviewInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0649878B2B4D69FE0071642A /* WebviewInjection.swift */; };
Expand Down Expand Up @@ -252,6 +254,8 @@
02F6EF3A28D9B8EC00835477 /* CourseCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseCellView.swift; sourceTree = "<group>"; };
02F6EF4928D9F0A700835477 /* DateExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateExtension.swift; sourceTree = "<group>"; };
02F98A7E28F81EE900DE94C0 /* Container+App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+App.swift"; sourceTree = "<group>"; };
06041B212BA1DB720092F85B /* String+JSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+JSON.swift"; sourceTree = "<group>"; };
06041B232BA1DB9A0092F85B /* Dictionary+JSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+JSON.swift"; sourceTree = "<group>"; };
0604C9A92B22FACF00AD5DBF /* UIComponentsConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIComponentsConfig.swift; sourceTree = "<group>"; };
0649878A2B4D69FE0071642A /* DragAndDropCssInjection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DragAndDropCssInjection.swift; sourceTree = "<group>"; };
0649878B2B4D69FE0071642A /* WebviewInjection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebviewInjection.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -456,6 +460,8 @@
BADB3F5A2AD6EC56004D5CFA /* ResultExtension.swift */,
02D400602B0678190029D168 /* SKStoreReviewControllerExtension.swift */,
E0D5861B2B2FF85B009B4BA7 /* RawStringExtactable.swift */,
06041B212BA1DB720092F85B /* String+JSON.swift */,
06041B232BA1DB9A0092F85B /* Dictionary+JSON.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1071,6 +1077,7 @@
07DDFCBD29A780BB00572595 /* UINavigationController+Animation.swift in Sources */,
023A4DD4299E66BD006C0E48 /* OfflineSnackBarView.swift in Sources */,
021D925728DCF12900ACC565 /* AlertView.swift in Sources */,
06041B242BA1DB9A0092F85B /* Dictionary+JSON.swift in Sources */,
027BD3A82909474200392132 /* KeyboardAvoidingViewController.swift in Sources */,
02E93F852AEBAEBC006C4750 /* AppReviewViewModel.swift in Sources */,
A595689B2B6173DF00ED4F90 /* BranchConfig.swift in Sources */,
Expand Down Expand Up @@ -1111,6 +1118,7 @@
BA8FA6682AD59A5700EA029A /* SocialAuthButton.swift in Sources */,
02D400612B0678190029D168 /* SKStoreReviewControllerExtension.swift in Sources */,
02A4833C29B8C57800D33F33 /* DownloadView.swift in Sources */,
06041B222BA1DB720092F85B /* String+JSON.swift in Sources */,
027BD3AD2909475000392132 /* KeyboardScroller.swift in Sources */,
070019A528F6F17900D5FC78 /* Data_Media.swift in Sources */,
024D723529C8BB1A006D36ED /* NavigationBar.swift in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions Core/Core/Extensions/Dictionary+JSON.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Dictionary+JSON.swift
// Core
//
// Created by Vadim Kuznetsov on 13.03.24.
//

import Foundation

public extension Dictionary where Key == String, Value == String {
public func toJson() -> String? {
guard let jsonData = try? JSONSerialization.data(withJSONObject: self, options: []) else {
return nil
}

return String(data: jsonData, encoding: .utf8)
}
}
23 changes: 23 additions & 0 deletions Core/Core/Extensions/String+JSON.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// String+JSON.swift
// Core
//
// Created by Vadim Kuznetsov on 13.03.24.
//

import Foundation

public extension String {
public func jsonStringToDictionary() -> [String: Any]? {
guard let jsonData = self.data(using: .utf8) else {
return nil
}

guard let jsonObject = try? JSONSerialization.jsonObject(with: jsonData, options: []),
let dictionary = jsonObject as? [String: Any] else {
return nil
}

return dictionary
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22522" systemVersion="23D56" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22757" systemVersion="23D56" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="CDCourseBlock" representedClassName="CDCourseBlock" syncable="YES" codeGenerationType="class">
<attribute name="allSources" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" customClassName="[String]"/>
<attribute name="blockId" optional="YES" attributeType="String"/>
Expand All @@ -11,6 +11,7 @@
<attribute name="id" optional="YES" attributeType="String"/>
<attribute name="multiDevice" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="studentUrl" optional="YES" attributeType="String"/>
<attribute name="transcripts" optional="YES" attributeType="String"/>
<attribute name="type" optional="YES" attributeType="String"/>
<relationship name="desktopMP4" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="CDCourseBlockVideo"/>
<relationship name="fallback" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="CDCourseBlockVideo"/>
Expand Down
6 changes: 5 additions & 1 deletion OpenEdX/Data/CoursePersistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class CoursePersistence: CoursePersistenceProtocol {

let blocks = try? context.fetch(requestBlocks).map {
let userViewData = DataLayer.CourseDetailUserViewData(
transcripts: nil,
transcripts: $0.transcripts?.jsonStringToDictionary() as? [String: String],
encodedVideo: DataLayer.CourseDetailEncodedVideoData(
youTube: DataLayer.EncodedVideoData(
url: $0.youTube?.url,
Expand Down Expand Up @@ -213,6 +213,10 @@ public class CoursePersistence: CoursePersistenceProtocol {
courseDetail.hls = hls
}

if let transcripts = block.userViewData?.transcripts {
courseDetail.transcripts = transcripts.toJson()
}

do {
try context.save()
} catch {
Expand Down
Loading