Skip to content

Commit

Permalink
fix: Minor Improvements for Videos, Webviews an Bottom Navigation Bar (
Browse files Browse the repository at this point in the history
…#19)

- Auto-play videos when ready
- Update the Bottom Navigation Icon and Colors
- Webview No Network Error
  • Loading branch information
HamzaIsrar12 authored Jul 30, 2024
1 parent d21009c commit d9f2da8
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 21 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ val screenModule = module {
get(),
get(),
get(),
get(),
)
}

Expand Down Expand Up @@ -238,6 +239,7 @@ val screenModule = module {
get(),
get(),
get(),
get(),
)
}
viewModel { (courseId: String) ->
Expand Down Expand Up @@ -473,6 +475,6 @@ val screenModule = module {
}
viewModel { HtmlUnitViewModel(get(), get(), get(), get(), get()) }

viewModel { ProgramViewModel(get(), get(), get(), get(), get(), get(), get()) }
viewModel { ProgramViewModel(get(), get(), get(), get(), get(), get(), get(), get()) }

}
2 changes: 1 addition & 1 deletion app/src/main/res/menu/bottom_view_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<item
android:id="@+id/fragmentLearn"
android:enabled="true"
android:icon="@drawable/app_ic_rows"
android:icon="@drawable/dashboard_ic_book"
android:title="@string/app_navigation_learn" />

<item
Expand Down
4 changes: 2 additions & 2 deletions core/src/edx/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<!-- Primary 500 | Dark 500 | Elm -->
<color name="primary">#00262B</color>
<color name="splash">#FFFFFF</color>
<color name="checked_tab_item">#00262B</color>
<color name="unchecked_tab_item">#454545</color>
<color name="checked_tab_item">#002326</color>
<color name="unchecked_tab_item">#ADADAD</color>
</resources>
9 changes: 0 additions & 9 deletions core/src/main/java/org/openedx/core/extension/StringExt.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.openedx.core.extension

import android.util.Patterns
import java.net.URL
import java.util.Locale
import java.util.regex.Pattern

Expand Down Expand Up @@ -38,11 +37,3 @@ fun String.tagId(): String = this.replaceSpace("_").lowercase(Locale.getDefault(
fun String.takeIfNotEmpty(): String? {
return if (this.isEmpty().not()) this else null
}

fun String?.equalsHost(host: String?): Boolean {
return try {
host?.startsWith(URL(this).host, ignoreCase = true) == true
} catch (e: Exception) {
false
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/openedx/core/ui/ComposeCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ fun FullScreenErrorView(
modifier = Modifier
.widthIn(Dp.Unspecified, 162.dp),
text = stringResource(id = errorType.actionResId),
textColor = MaterialTheme.appColors.primaryButtonText,
textColor = MaterialTheme.appColors.secondaryButtonText,
backgroundColor = MaterialTheme.appColors.secondaryButtonBackground,
onClick = onReloadClick,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import androidx.fragment.app.Fragment
import kotlinx.coroutines.launch
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.openedx.core.extension.applyDarkModeIfEnabled
import org.openedx.core.extension.equalsHost
import org.openedx.core.extension.isEmailValid
import org.openedx.core.extension.loadUrl
import org.openedx.core.system.AppCookieManager
Expand Down Expand Up @@ -293,7 +292,7 @@ private fun HTMLContentView(
request: WebResourceRequest,
error: WebResourceError
) {
if (view.url.equalsHost(request.url.host)) {
if (request.url.toString() == view.url) {
onWebPageLoadError()
}
super.onReceivedError(view, request, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class VideoUnitFragment : Fragment(R.layout.fragment_video_unit) {
mediaItem,
viewModel.exoPlayer?.currentPosition ?: 0L
)
viewModel.castPlayer?.playWhenReady = false
viewModel.castPlayer?.playWhenReady = true
showVideoControllerIndefinitely(true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ open class VideoUnitViewModel(

var videoUrl = ""
var transcripts = emptyMap<String, String>()
var isPlaying = false
var isPlaying = true
var transcriptLanguage = AppDataConstants.defaultLocale.language ?: "en"
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class WebViewDiscoveryFragment : Fragment() {
isPreLogin = viewModel.isPreLogin,
contentUrl = viewModel.discoveryUrl,
uriScheme = viewModel.uriScheme,
userAgent = viewModel.appUserAgent,
hasInternetConnection = hasInternetConnection,
onWebViewUIAction = { action ->
when (action) {
Expand Down Expand Up @@ -199,6 +200,7 @@ private fun WebViewDiscoveryScreen(
isPreLogin: Boolean,
contentUrl: String,
uriScheme: String,
userAgent: String,
hasInternetConnection: Boolean,
onWebViewUIAction: (WebViewUIAction) -> Unit,
onWebPageUpdated: (String) -> Unit,
Expand Down Expand Up @@ -278,6 +280,7 @@ private fun WebViewDiscoveryScreen(
DiscoveryWebView(
contentUrl = contentUrl,
uriScheme = uriScheme,
userAgent = userAgent,
isPreLogin = isPreLogin,
onWebPageLoaded = {
if ((uiState is WebViewUIState.Error).not()) {
Expand Down Expand Up @@ -320,6 +323,7 @@ private fun WebViewDiscoveryScreen(
private fun DiscoveryWebView(
contentUrl: String,
uriScheme: String,
userAgent: String,
isPreLogin: Boolean,
onWebPageLoaded: () -> Unit,
onWebPageUpdated: (String) -> Unit,
Expand All @@ -329,6 +333,7 @@ private fun DiscoveryWebView(
val webView = CatalogWebViewScreen(
url = contentUrl,
uriScheme = uriScheme,
userAgent = userAgent,
onWebPageLoaded = onWebPageLoaded,
onWebPageUpdated = onWebPageUpdated,
onUriClick = onUriClick,
Expand Down Expand Up @@ -412,6 +417,7 @@ private fun WebViewDiscoveryScreenPreview() {
isPreLogin = false,
contentUrl = "https://www.example.com/",
uriScheme = "",
userAgent = "",
hasInternetConnection = false,
onWebViewUIAction = {},
onWebPageUpdated = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import kotlinx.coroutines.flow.asStateFlow
import org.openedx.core.BaseViewModel
import org.openedx.core.config.Config
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.presentation.global.AppData
import org.openedx.core.presentation.global.ErrorType
import org.openedx.core.presentation.global.webview.WebViewUIState
import org.openedx.core.system.connection.NetworkConnection
import org.openedx.core.utils.UrlUtils

class WebViewDiscoveryViewModel(
private val querySearch: String,
private val appData: AppData,
private val config: Config,
private val networkConnection: NetworkConnection,
private val corePreferences: CorePreferences,
Expand All @@ -29,6 +31,8 @@ class WebViewDiscoveryViewModel(

val isPreLogin get() = config.isPreLoginExperienceEnabled() && corePreferences.user == null

val appUserAgent get() = appData.appUserAgent

private var _discoveryUrl = webViewConfig.baseUrl
val discoveryUrl: String
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import org.openedx.core.extension.applyDarkModeIfEnabled
import org.openedx.core.extension.equalsHost
import org.openedx.discovery.presentation.catalog.WebViewLink.Authority as linkAuthority

@SuppressLint("SetJavaScriptEnabled", "ComposableNaming")
@Composable
fun CatalogWebViewScreen(
url: String,
uriScheme: String,
userAgent: String,
isAllLinksExternal: Boolean = false,
onWebPageLoaded: () -> Unit,
refreshSessionCookie: () -> Unit = {},
Expand Down Expand Up @@ -90,7 +90,7 @@ fun CatalogWebViewScreen(
request: WebResourceRequest,
error: WebResourceError
) {
if (view.url.equalsHost(request.url.host)) {
if (request.url.toString() == view.url) {
onWebPageLoadError()
}
super.onReceivedError(view, request, error)
Expand All @@ -104,6 +104,7 @@ fun CatalogWebViewScreen(
setSupportZoom(true)
loadsImagesAutomatically = true
domStorageEnabled = true
userAgentString = "$userAgentString $userAgent"
}
isVerticalScrollBarEnabled = false
isHorizontalScrollBarEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class CourseInfoFragment : Fragment() {
webViewUIState = webViewState,
uiMessage = uiMessage,
uriScheme = viewModel.uriScheme,
userAgent = viewModel.appUserAgent,
hasInternetConnection = hasInternetConnection,
onWebViewUIAction = { action ->
when (action) {
Expand Down Expand Up @@ -248,6 +249,7 @@ private fun CourseInfoScreen(
webViewUIState: WebViewUIState,
uiMessage: UIMessage?,
uriScheme: String,
userAgent: String,
hasInternetConnection: Boolean,
onWebViewUIAction: (WebViewUIAction) -> Unit,
onRegisterClick: () -> Unit,
Expand Down Expand Up @@ -322,6 +324,7 @@ private fun CourseInfoScreen(
CourseInfoWebView(
contentUrl = (uiState as CourseInfoUIState.CourseInfo).initialUrl,
uriScheme = uriScheme,
userAgent = userAgent,
isPreLogin = uiState.isPreLogin,
onWebPageLoaded = { onWebViewUIAction(WebViewUIAction.WEB_PAGE_LOADED) },
onUriClick = onUriClick,
Expand Down Expand Up @@ -359,6 +362,7 @@ private fun CourseInfoScreen(
private fun CourseInfoWebView(
contentUrl: String,
uriScheme: String,
userAgent: String,
isPreLogin: Boolean,
onWebPageLoaded: () -> Unit,
onUriClick: (String, linkAuthority) -> Unit,
Expand All @@ -368,6 +372,7 @@ private fun CourseInfoWebView(
val webView = CatalogWebViewScreen(
url = contentUrl,
uriScheme = uriScheme,
userAgent = userAgent,
isAllLinksExternal = true,
onWebPageLoaded = onWebPageLoaded,
onUriClick = onUriClick,
Expand Down Expand Up @@ -410,6 +415,7 @@ fun CourseInfoScreenPreview() {
),
uiMessage = null,
uriScheme = "",
userAgent = "",
hasInternetConnection = false,
onWebViewUIAction = {},
onRegisterClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.openedx.core.config.Config
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.extension.isInternetError
import org.openedx.core.presentation.CoreAnalyticsKey
import org.openedx.core.presentation.global.AppData
import org.openedx.core.presentation.global.ErrorType
import org.openedx.core.presentation.global.webview.WebViewUIState
import org.openedx.core.system.ResourceManager
Expand All @@ -37,6 +38,7 @@ import org.openedx.core.R as CoreR
class CourseInfoViewModel(
val pathId: String,
val infoType: String,
private val appData: AppData,
private val config: Config,
private val networkConnection: NetworkConnection,
private val router: DiscoveryRouter,
Expand Down Expand Up @@ -73,6 +75,8 @@ class CourseInfoViewModel(

val uriScheme: String get() = config.getUriScheme()

val appUserAgent get() = appData.appUserAgent

private val webViewConfig get() = config.getDiscoveryConfig().webViewConfig

private fun getInitialUrl(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.ViewCompositionStrategy
Expand Down Expand Up @@ -133,6 +132,7 @@ class ProgramFragment : Fragment() {
?.isNotEmpty() == true,
isNestedFragment = isNestedFragment,
uriScheme = viewModel.uriScheme,
userAgent = viewModel.appUserAgent,
hasInternetConnection = hasInternetConnection,
onWebViewUIAction = { action ->
when (action) {
Expand Down Expand Up @@ -244,6 +244,7 @@ private fun ProgramInfoScreen(
contentUrl: String,
cookieManager: AppCookieManager,
uriScheme: String,
userAgent: String,
canShowBackBtn: Boolean,
isNestedFragment: Boolean,
hasInternetConnection: Boolean,
Expand Down Expand Up @@ -321,6 +322,7 @@ private fun ProgramInfoScreen(
val webView = CatalogWebViewScreen(
url = contentUrl,
uriScheme = uriScheme,
userAgent = userAgent,
isAllLinksExternal = true,
onWebPageLoaded = { onWebViewUIAction(WebViewUIAction.WEB_PAGE_LOADED) },
refreshSessionCookie = {
Expand Down Expand Up @@ -380,6 +382,7 @@ fun MyProgramsPreview() {
contentUrl = "https://www.example.com/",
cookieManager = koinViewModel<ProgramViewModel>().cookieManager,
uriScheme = "",
userAgent = "",
canShowBackBtn = false,
isNestedFragment = false,
hasInternetConnection = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.openedx.core.R
import org.openedx.core.UIMessage
import org.openedx.core.config.Config
import org.openedx.core.extension.isInternetError
import org.openedx.core.presentation.global.AppData
import org.openedx.core.presentation.global.ErrorType
import org.openedx.core.system.AppCookieManager
import org.openedx.core.system.ResourceManager
Expand All @@ -22,6 +23,7 @@ import org.openedx.discovery.domain.interactor.DiscoveryInteractor
import org.openedx.discovery.presentation.DiscoveryRouter

class ProgramViewModel(
private val appData: AppData,
private val config: Config,
private val networkConnection: NetworkConnection,
private val router: DiscoveryRouter,
Expand All @@ -38,6 +40,8 @@ class ProgramViewModel(

val hasInternetConnection: Boolean get() = networkConnection.isOnline()

val appUserAgent get() = appData.appUserAgent

private val _uiState = MutableStateFlow<ProgramUIState>(ProgramUIState.Loading)
val uiState: StateFlow<ProgramUIState> get() = _uiState.asStateFlow()

Expand Down

0 comments on commit d9f2da8

Please sign in to comment.