Skip to content

Commit

Permalink
[iOS] There are no subtitles for videos opened from the "Dates" Cours…
Browse files Browse the repository at this point in the history
…e section (#340)

* fix: subtitles for dates tab

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

* fix: merge conflict
  • Loading branch information
forgotvas authored Mar 22, 2024
1 parent 2de1bc5 commit ea50fb1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Core/Core.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
02F6EF4A28D9F0A700835477 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F6EF4928D9F0A700835477 /* DateExtension.swift */; };
02F98A7F28F81EE900DE94C0 /* Container+App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F98A7E28F81EE900DE94C0 /* Container+App.swift */; };
0604C9AA2B22FACF00AD5DBF /* UIComponentsConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0604C9A92B22FACF00AD5DBF /* UIComponentsConfig.swift */; };
06078B702BA49C3100576798 /* Dictionary+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06078B6E2BA49C3100576798 /* Dictionary+JSON.swift */; };
06078B712BA49C3100576798 /* String+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06078B6F2BA49C3100576798 /* String+JSON.swift */; };
064987932B4D69FF0071642A /* DragAndDropCssInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0649878A2B4D69FE0071642A /* DragAndDropCssInjection.swift */; };
064987942B4D69FF0071642A /* WebviewInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0649878B2B4D69FE0071642A /* WebviewInjection.swift */; };
064987952B4D69FF0071642A /* SurveyCssInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0649878C2B4D69FE0071642A /* SurveyCssInjection.swift */; };
Expand Down Expand Up @@ -259,6 +261,8 @@
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>"; };
0604C9A92B22FACF00AD5DBF /* UIComponentsConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIComponentsConfig.swift; sourceTree = "<group>"; };
06078B6E2BA49C3100576798 /* Dictionary+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+JSON.swift"; sourceTree = "<group>"; };
06078B6F2BA49C3100576798 /* String+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+JSON.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>"; };
0649878C2B4D69FE0071642A /* SurveyCssInjection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SurveyCssInjection.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -450,6 +454,8 @@
0283347E28D4DCC100C828FC /* Extensions */ = {
isa = PBXGroup;
children = (
06078B6E2BA49C3100576798 /* Dictionary+JSON.swift */,
06078B6F2BA49C3100576798 /* String+JSON.swift */,
02F164362902A9EB0090DDEF /* StringExtension.swift */,
024BE3DE29B2615500BCDEE2 /* CGColorExtension.swift */,
0283347F28D4DCD200C828FC /* ViewExtension.swift */,
Expand Down Expand Up @@ -1079,10 +1085,12 @@
0283348028D4DCD200C828FC /* ViewExtension.swift in Sources */,
BA8FA66A2AD59B5500EA029A /* GoogleAuthProvider.swift in Sources */,
02A4833529B8A73400D33F33 /* CorePersistenceProtocol.swift in Sources */,
06078B712BA49C3100576798 /* String+JSON.swift in Sources */,
0233D5732AF13EEE00BAC8BD /* AppReviewButton.swift in Sources */,
02512FF0299533DF0024D438 /* CoreDataHandlerProtocol.swift in Sources */,
0260E58028FD792800BBBE18 /* WebUnitViewModel.swift in Sources */,
02A4833A29B8A9AB00D33F33 /* DownloadManager.swift in Sources */,
06078B702BA49C3100576798 /* Dictionary+JSON.swift in Sources */,
027BD3AE2909475000392132 /* KeyboardScrollerOptions.swift in Sources */,
BAFB99922B14E23D007D09F9 /* AppleSignInConfig.swift in Sources */,
141F1D302B7328D4009E81EB /* WebviewCookiesUpdateProtocol.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

0 comments on commit ea50fb1

Please sign in to comment.