-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: enabled the survey content type and moved all js injections to the asset folder * refactor: added comments in js files * refactor: added a new line in the AssetExt file * refactor: added ViewModel for the HtmlUnitFragment class * fix: bug when unable to see Survey content, minor fixes * refactor: renamed and moved the onWebPageStartLoad function call to the onPageStarted function
- Loading branch information
Showing
9 changed files
with
153 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.openedx.core.extension | ||
|
||
import android.content.res.AssetManager | ||
import android.util.Log | ||
import java.io.BufferedReader | ||
|
||
fun AssetManager.readAsText(fileName: String): String? { | ||
return try { | ||
open(fileName).bufferedReader().use(BufferedReader::readText) | ||
} catch (e: Exception) { | ||
Log.e("AssetExt", "Unable to load file $fileName from assets") | ||
e.printStackTrace() | ||
null | ||
} | ||
} |
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,8 @@ | ||
//Injection to intercept completion state for xBlocks | ||
$(document).on("ajaxSuccess", function(event, request, settings) { | ||
console.log("loaded url is = " + settings.url); | ||
if (settings.url.includes("publish_completion") && | ||
request.responseText.includes("ok")) { | ||
javascript:window.callback.completionSet(); | ||
} | ||
}); |
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,28 @@ | ||
//Injection to fix CSS issues for Survey xBlock | ||
var css = ` | ||
.survey-table:not(.poll-results) .survey-option label { | ||
margin-bottom: 0px !important; | ||
} | ||
.survey-table:not(.poll-results) .survey-option .visible-mobile-only { | ||
width: calc(100% - 21px) !important; | ||
} | ||
.survey-table:not(.poll-results) .survey-option input { | ||
width: 13px !important; | ||
height: 13px !important; | ||
} | ||
.survey-percentage .percentage { | ||
width: 54px !important; | ||
}`; | ||
var head = document.head || document.getElementsByTagName('head')[0]; | ||
var style = document.createElement('style'); | ||
|
||
head.appendChild(style); | ||
style.type = 'text/css'; | ||
if (style.styleSheet) { | ||
style.styleSheet.cssText = css; | ||
} else { | ||
style.appendChild(document.createTextNode(css)); | ||
} |
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
49 changes: 49 additions & 0 deletions
49
course/src/main/java/org/openedx/course/presentation/unit/html/HtmlUnitViewModel.kt
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,49 @@ | ||
package org.openedx.course.presentation.unit.html | ||
|
||
import android.content.res.AssetManager | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import org.openedx.core.BaseViewModel | ||
import org.openedx.core.config.Config | ||
import org.openedx.core.extension.readAsText | ||
import org.openedx.core.system.AppCookieManager | ||
import org.openedx.core.system.connection.NetworkConnection | ||
import org.openedx.core.system.notifier.CourseCompletionSet | ||
import org.openedx.core.system.notifier.CourseNotifier | ||
|
||
class HtmlUnitViewModel( | ||
private val config: Config, | ||
private val edxCookieManager: AppCookieManager, | ||
private val networkConnection: NetworkConnection, | ||
private val notifier: CourseNotifier | ||
) : BaseViewModel() { | ||
|
||
private val _injectJSList = MutableStateFlow<List<String>>(listOf()) | ||
val injectJSList = _injectJSList.asStateFlow() | ||
|
||
val isOnline get() = networkConnection.isOnline() | ||
val isCourseUnitProgressEnabled get() = config.isCourseUnitProgressEnabled() | ||
val apiHostURL get() = config.getApiHostURL() | ||
val cookieManager get() = edxCookieManager | ||
|
||
fun setWebPageLoaded(assets: AssetManager) { | ||
if (_injectJSList.value.isNotEmpty()) return | ||
|
||
val jsList = mutableListOf<String>() | ||
|
||
//Injection to intercept completion state for xBlocks | ||
assets.readAsText("js_injection/completions.js")?.let { jsList.add(it) } | ||
//Injection to fix CSS issues for Survey xBlock | ||
assets.readAsText("js_injection/survey_css.js")?.let { jsList.add(it) } | ||
|
||
_injectJSList.value = jsList | ||
} | ||
|
||
fun notifyCompletionSet() { | ||
viewModelScope.launch { | ||
notifier.send(CourseCompletionSet()) | ||
} | ||
} | ||
} |