Skip to content

Commit

Permalink
fix: Webview User-Agent Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaIsrar12 committed Jul 18, 2024
1 parent 2d81e84 commit 386710d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ class HeadersInterceptor(
}.build()
)
}
}
}
10 changes: 9 additions & 1 deletion app/src/main/java/org/openedx/app/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import org.openedx.whatsnew.WhatsNewManager
import org.openedx.whatsnew.WhatsNewRouter
import org.openedx.whatsnew.data.storage.WhatsNewPreferences
import org.openedx.whatsnew.presentation.WhatsNewAnalytics
import org.openedx.core.R as CoreR

val appModule = module {

Expand Down Expand Up @@ -167,7 +168,14 @@ val appModule = module {
DownloadWorkerController(get(), get(), get())
}

single { AppData(versionName = BuildConfig.VERSION_NAME) }
single {
val resourceManager = get<ResourceManager>()
AppData(
appName = resourceManager.getString(CoreR.string.app_name),
versionName = BuildConfig.VERSION_NAME,
applicationId = BuildConfig.APPLICATION_ID,
)
}
factory { (activity: AppCompatActivity) -> AppReviewManager(activity, get(), get()) }

single { TranscriptManager(get()) }
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ val screenModule = module {
get(),
)
}
viewModel { HtmlUnitViewModel(get(), get(), get(), get()) }
viewModel { HtmlUnitViewModel(get(), get(), get(), get(), get()) }

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.openedx.core.presentation.global

data class AppData(
val appName: String,
val applicationId: String,
val versionName: String,
)
) {
val appUserAgent get() = "$appName/$applicationId/$versionName"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -130,6 +129,7 @@ class HtmlUnitFragment : Fragment() {
url = blockUrl,
cookieManager = viewModel.cookieManager,
apiHostURL = viewModel.apiHostURL,
userAgent = viewModel.appUserAgent,
isLoading = uiState is HtmlUnitUIState.Loading,
injectJSList = injectJSList,
onCompletionSet = {
Expand Down Expand Up @@ -200,6 +200,7 @@ private fun HTMLContentView(
url: String,
cookieManager: AppCookieManager,
apiHostURL: String,
userAgent: String,
isLoading: Boolean,
injectJSList: List<String>,
onCompletionSet: () -> Unit,
Expand Down Expand Up @@ -307,7 +308,7 @@ private fun HTMLContentView(
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 @@ -8,6 +8,7 @@ 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.presentation.global.AppData
import org.openedx.core.presentation.global.ErrorType
import org.openedx.core.system.AppCookieManager
import org.openedx.core.system.connection.NetworkConnection
Expand All @@ -16,6 +17,7 @@ import org.openedx.core.system.notifier.CourseNotifier

class HtmlUnitViewModel(
private val config: Config,
private val appData: AppData,
private val edxCookieManager: AppCookieManager,
private val networkConnection: NetworkConnection,
private val notifier: CourseNotifier
Expand All @@ -31,6 +33,7 @@ class HtmlUnitViewModel(
val isCourseUnitProgressEnabled get() = config.getCourseUIConfig().isCourseUnitProgressEnabled
val apiHostURL get() = config.getApiHostURL()
val cookieManager get() = edxCookieManager
val appUserAgent get() = appData.appUserAgent

fun onWebPageLoading() {
_uiState.value = HtmlUnitUIState.Loading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,9 @@ fun AppVersionItemUpgradeRequired(
}

private val mockAppData = AppData(
appName = "openedx",
versionName = "1.0.0",
applicationId = "org.example.com"
)

private val mockConfiguration = Configuration(
Expand Down

0 comments on commit 386710d

Please sign in to comment.