-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit progress navigation style (#258)
* chore: add lesson line progress view * chore: add colors and config to course unit view model * chore: add ajax provider and refactor code, fix crash on Config resolve * chore: update when back if some changed * chore: hide progress dots when line show * chore: padding and separate views * chore: added one more state and change inset what fixes dark mode * fix: arrow buttons in unit content set next and prev buttons in unit content to be horizontal if COURSE_UNIT_PROGRESS_ENABLED key is true * fix: animation set next and prev animation in unit content to be horizontal if COURSE_UNIT_PROGRESS_ENABLED key is true * fix: different navigation stacks * fix: offset in landscape mode * fix: offset on orientation change * fix: unit tests * chore: fixed warnings * chore: fixed warnings * chore: fixed rounded corners and padding for progress line * fix: paddings * chore: moved rounded corners to view extension * chore: delete unused code * fix: use full width if we are using horizontal navigation * chore: refactor of ajax completion handler * chore: warning fix * chore: added forMainFrameOnly parameter * fix: previous button for horizontal navigation * chore: resolve PR comments * chore: update course struct after complete unit * chore: down up dropdown button * chore: remove refresh course --------- Co-authored-by: Eugene Yatsenko <[email protected]> Co-authored-by: Vadim Kuznetsov <[email protected]>
- Loading branch information
1 parent
a050bf0
commit 02fcec9
Showing
41 changed files
with
1,131 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// AjaxProvider.swift | ||
// Core | ||
// | ||
// Created by Eugene Yatsenko on 12.12.2023. | ||
// | ||
|
||
import Foundation | ||
import WebKit | ||
import Swinject | ||
|
||
struct AjaxInjection: WebViewScriptInjectionProtocol { | ||
private struct AJAXCallbackData { | ||
private enum Keys: String { | ||
case url = "url" | ||
case statusCode = "status" | ||
case responseText = "response_text" | ||
} | ||
|
||
let url: String | ||
let statusCode: Int | ||
let responseText: String | ||
|
||
init(data: [AnyHashable: Any]) { | ||
url = data[Keys.url.rawValue] as? String ?? "" | ||
statusCode = data[Keys.statusCode.rawValue] as? Int ?? 0 | ||
responseText = data[Keys.responseText.rawValue] as? String ?? "" | ||
} | ||
} | ||
|
||
private enum XBlockCompletionCallbackType: String { | ||
case html = "publish_completion" | ||
case problem = "problem_check" | ||
case dragAndDrop = "do_attempt" | ||
case ora = "render_grade" | ||
} | ||
|
||
private let AJAXCallBackHandler = "ajaxCallbackHandler" | ||
private let ajaxScriptFile = "ajaxHandler" | ||
|
||
var id: String = "AjaxInjection" | ||
var script: String { | ||
guard let url = Bundle(for: CoreBundle.self).url(forResource: ajaxScriptFile, withExtension: "js"), | ||
let script = try? String(contentsOf: url, encoding: .utf8) else { return "" } | ||
return script | ||
} | ||
|
||
var messages: [WebviewMessage]? { | ||
[ | ||
WebviewMessage(name: AJAXCallBackHandler) { result, _ in | ||
guard let data = result as? [AnyHashable: Any] else { return } | ||
let callback = AJAXCallbackData(data: data) | ||
let requestURL = callback.url | ||
|
||
if callback.statusCode != 200 { | ||
return | ||
} | ||
|
||
var complete = false | ||
if isBlockOf(type: .ora, with: requestURL) { | ||
complete = callback.responseText.contains("is--complete") | ||
} else { | ||
complete = isBlockOf(type: .html, with: requestURL) | ||
|| isBlockOf(type: .problem, with: requestURL) | ||
|| isBlockOf(type: .dragAndDrop, with: requestURL) | ||
} | ||
if complete { | ||
NotificationCenter.default.post( | ||
name: NSNotification.blockCompletion, | ||
object: nil | ||
) | ||
} | ||
} | ||
] | ||
} | ||
var forMainFrameOnly: Bool = false | ||
|
||
var injectionTime: WKUserScriptInjectionTime = .atDocumentEnd | ||
|
||
private func isBlockOf(type: XBlockCompletionCallbackType, with requestURL: String) -> Bool { | ||
return requestURL.contains(type.rawValue) | ||
} | ||
} | ||
|
||
public extension NSNotification { | ||
static let blockCompletion = Notification.Name.init("block_completion") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//Every time an Ajax call is being invoked the listener will recognize it and will call the native app with the request details | ||
|
||
$(document).ajaxSuccess(function(event, request, settings) { | ||
callNativeApp({ | ||
"status": request.status, | ||
"url":settings.url, | ||
"response_text": request.responseText | ||
}); | ||
}); | ||
|
||
function callNativeApp(data) { | ||
try { | ||
webkit.messageHandlers.ajaxCallbackHandler.postMessage(data); | ||
} | ||
catch(err) { | ||
console.log('The native context does not exist yet'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.