From 2211a4f5737dd9f8d1007349abbd59e37cd8d06e Mon Sep 17 00:00:00 2001 From: Akos Hermann <72087159+hermannakos@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:34:05 +0100 Subject: [PATCH 1/5] [MBL-17212][Student][Teacher] Open external routes from discussions (#2258) refs: MBL-17212 affects: Student, Teacher release note: none test plan: Navigate to an external route from the discussion redesign page. --- .../student/navigation/StudentWebViewRouter.kt | 5 +++++ .../teacher/navigation/TeacherWebViewRouter.kt | 14 ++++++++++++++ .../details/DiscussionDetailsWebViewFragment.kt | 2 +- .../pandautils/navigation/WebViewRouter.kt | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/student/src/main/java/com/instructure/student/navigation/StudentWebViewRouter.kt b/apps/student/src/main/java/com/instructure/student/navigation/StudentWebViewRouter.kt index 6eb681b270..7ae5299c74 100644 --- a/apps/student/src/main/java/com/instructure/student/navigation/StudentWebViewRouter.kt +++ b/apps/student/src/main/java/com/instructure/student/navigation/StudentWebViewRouter.kt @@ -19,6 +19,7 @@ package com.instructure.student.navigation import androidx.fragment.app.FragmentActivity import com.instructure.canvasapi2.utils.ApiPrefs import com.instructure.pandautils.navigation.WebViewRouter +import com.instructure.student.fragment.InternalWebviewFragment import com.instructure.student.router.RouteMatcher class StudentWebViewRouter(val activity: FragmentActivity) : WebViewRouter { @@ -34,4 +35,8 @@ class StudentWebViewRouter(val activity: FragmentActivity) : WebViewRouter { override fun openMedia(url: String) { RouteMatcher.openMedia(activity, url) } + + override fun routeExternally(url: String) { + RouteMatcher.route(activity, InternalWebviewFragment.makeRoute(url, url, false, "")) + } } \ No newline at end of file diff --git a/apps/teacher/src/main/java/com/instructure/teacher/navigation/TeacherWebViewRouter.kt b/apps/teacher/src/main/java/com/instructure/teacher/navigation/TeacherWebViewRouter.kt index 2f457b39c3..07c508bb48 100644 --- a/apps/teacher/src/main/java/com/instructure/teacher/navigation/TeacherWebViewRouter.kt +++ b/apps/teacher/src/main/java/com/instructure/teacher/navigation/TeacherWebViewRouter.kt @@ -17,8 +17,12 @@ package com.instructure.teacher.navigation import androidx.fragment.app.FragmentActivity +import com.instructure.canvasapi2.models.CanvasContext import com.instructure.canvasapi2.utils.ApiPrefs +import com.instructure.interactions.router.Route import com.instructure.pandautils.navigation.WebViewRouter +import com.instructure.teacher.fragments.FullscreenInternalWebViewFragment +import com.instructure.teacher.fragments.InternalWebViewFragment import com.instructure.teacher.router.RouteMatcher class TeacherWebViewRouter(val activity: FragmentActivity) : WebViewRouter { @@ -34,4 +38,14 @@ class TeacherWebViewRouter(val activity: FragmentActivity) : WebViewRouter { override fun openMedia(url: String) { RouteMatcher.openMedia(activity, url) } + + override fun routeExternally(url: String) { + val bundle = InternalWebViewFragment.makeBundle(url, url, false, "") + RouteMatcher.route( + activity, Route( + FullscreenInternalWebViewFragment::class.java, + CanvasContext.emptyUserContext(), bundle + ) + ) + } } \ No newline at end of file diff --git a/libs/pandautils/src/main/java/com/instructure/pandautils/features/discussion/details/DiscussionDetailsWebViewFragment.kt b/libs/pandautils/src/main/java/com/instructure/pandautils/features/discussion/details/DiscussionDetailsWebViewFragment.kt index 3d706811c4..c402282c08 100644 --- a/libs/pandautils/src/main/java/com/instructure/pandautils/features/discussion/details/DiscussionDetailsWebViewFragment.kt +++ b/libs/pandautils/src/main/java/com/instructure/pandautils/features/discussion/details/DiscussionDetailsWebViewFragment.kt @@ -96,7 +96,7 @@ class DiscussionDetailsWebViewFragment : Fragment() { override fun routeInternallyCallback(url: String) { if (!webViewRouter.canRouteInternally(url, routeIfPossible = true)) { - webViewRouter.routeInternally(url) + webViewRouter.routeExternally(url) } } diff --git a/libs/pandautils/src/main/java/com/instructure/pandautils/navigation/WebViewRouter.kt b/libs/pandautils/src/main/java/com/instructure/pandautils/navigation/WebViewRouter.kt index 2816a16f53..f577adddc1 100644 --- a/libs/pandautils/src/main/java/com/instructure/pandautils/navigation/WebViewRouter.kt +++ b/libs/pandautils/src/main/java/com/instructure/pandautils/navigation/WebViewRouter.kt @@ -23,4 +23,6 @@ interface WebViewRouter { fun routeInternally(url: String) fun openMedia(url: String) + + fun routeExternally(url: String) } \ No newline at end of file From 1c2a47ba6b56d593d8ba1c703de5e131b61aeb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Hermann?= Date: Thu, 23 Nov 2023 12:42:52 +0100 Subject: [PATCH 2/5] file null url error handling --- .../com/instructure/student/fragment/ParentFragment.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/student/src/main/java/com/instructure/student/fragment/ParentFragment.kt b/apps/student/src/main/java/com/instructure/student/fragment/ParentFragment.kt index 4cbdbeb85e..24f868fa74 100644 --- a/apps/student/src/main/java/com/instructure/student/fragment/ParentFragment.kt +++ b/apps/student/src/main/java/com/instructure/student/fragment/ParentFragment.kt @@ -60,6 +60,7 @@ import com.instructure.pandautils.utils.LoaderUtils import com.instructure.pandautils.utils.PermissionUtils import com.instructure.pandautils.utils.getDrawableCompat import com.instructure.pandautils.utils.hasPermissions +import com.instructure.pandautils.utils.toast import com.instructure.pandautils.views.EmptyView import com.instructure.student.R import com.instructure.student.activity.VideoViewActivity @@ -381,7 +382,12 @@ abstract class ParentFragment : DialogFragment(), FragmentInteractions, Navigati } onMainThread { - LoaderUtils.restartLoaderWithBundle>(LoaderManager.getInstance(owner), openMediaBundle, loaderCallbacks, R.id.openMediaLoaderID) + try { + LoaderUtils.restartLoaderWithBundle>(LoaderManager.getInstance(owner), openMediaBundle, loaderCallbacks, R.id.openMediaLoaderID) + } catch (e: Exception) { + toast(R.string.unexpectedErrorOpeningFile) + onMediaLoadingComplete() + } } } From 4fb93c6df99bd52f177d5f84df2c250f26758cf4 Mon Sep 17 00:00:00 2001 From: "kristof.nemere" Date: Thu, 23 Nov 2023 12:55:25 +0100 Subject: [PATCH 3/5] Wait for user --- .../loginapi/login/viewmodel/LoginViewModel.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/login-api-2/src/main/java/com/instructure/loginapi/login/viewmodel/LoginViewModel.kt b/libs/login-api-2/src/main/java/com/instructure/loginapi/login/viewmodel/LoginViewModel.kt index 6bfee40ec4..35e523ced4 100644 --- a/libs/login-api-2/src/main/java/com/instructure/loginapi/login/viewmodel/LoginViewModel.kt +++ b/libs/login-api-2/src/main/java/com/instructure/loginapi/login/viewmodel/LoginViewModel.kt @@ -24,10 +24,10 @@ import com.instructure.canvasapi2.managers.OAuthManager import com.instructure.canvasapi2.managers.UserManager import com.instructure.canvasapi2.utils.ApiPrefs import com.instructure.pandautils.mvvm.Event -import com.instructure.pandautils.utils.FEATURE_FLAG_OFFLINE import com.instructure.pandautils.utils.FeatureFlagProvider import com.instructure.pandautils.utils.NetworkStateProvider import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import javax.inject.Inject @@ -49,6 +49,7 @@ class LoginViewModel @Inject constructor( fun checkLogin(checkToken: Boolean, checkElementary: Boolean): LiveData> { viewModelScope.launch { try { + waitForUser() val offlineEnabled = featureFlagProvider.offlineEnabled() val offlineLogin = offlineEnabled && !networkStateProvider.isOnline() if (checkToken && !offlineLogin) { @@ -70,6 +71,14 @@ class LoginViewModel @Inject constructor( return loginResultAction } + // We need to wait for the user to be set in ApiPrefs + private suspend fun waitForUser() { + repeat(30) { + if (ApiPrefs.user != null) return + delay(100) + } + } + private suspend fun checkTermsAcceptance(canvasForElementary: Boolean, offlineLogin: Boolean = false) { val authenticatedSession = oauthManager.getAuthenticatedSessionAsync("${apiPrefs.fullDomain}/users/self").await() val requiresTermsAcceptance = authenticatedSession.dataOrNull?.requiresTermsAcceptance ?: false From 8cf5726fd5ca6ea0df0b95636cb57554429e9df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Hermann?= Date: Thu, 23 Nov 2023 13:02:25 +0100 Subject: [PATCH 4/5] version bump --- apps/student/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/student/build.gradle b/apps/student/build.gradle index 9aa4e3023d..644403aff7 100644 --- a/apps/student/build.gradle +++ b/apps/student/build.gradle @@ -50,8 +50,8 @@ android { applicationId "com.instructure.candroid" minSdkVersion Versions.MIN_SDK targetSdkVersion Versions.TARGET_SDK - versionCode = 256 - versionName = '7.0.0' + versionCode = 257 + versionName = '7.0.1' vectorDrawables.useSupportLibrary = true multiDexEnabled = true From e30d261ad73744bacdb64288eb62a3f49121dd36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Hermann?= Date: Thu, 23 Nov 2023 13:18:06 +0100 Subject: [PATCH 5/5] fix tests --- .../com/instructure/loginapi/login/viewmodel/LoginViewModel.kt | 2 +- .../instructure/loginapi/login/viewmodel/LoginViewModelTest.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/login-api-2/src/main/java/com/instructure/loginapi/login/viewmodel/LoginViewModel.kt b/libs/login-api-2/src/main/java/com/instructure/loginapi/login/viewmodel/LoginViewModel.kt index 35e523ced4..562e9cf516 100644 --- a/libs/login-api-2/src/main/java/com/instructure/loginapi/login/viewmodel/LoginViewModel.kt +++ b/libs/login-api-2/src/main/java/com/instructure/loginapi/login/viewmodel/LoginViewModel.kt @@ -74,7 +74,7 @@ class LoginViewModel @Inject constructor( // We need to wait for the user to be set in ApiPrefs private suspend fun waitForUser() { repeat(30) { - if (ApiPrefs.user != null) return + if (apiPrefs.user != null) return delay(100) } } diff --git a/libs/login-api-2/src/test/java/com/instructure/loginapi/login/viewmodel/LoginViewModelTest.kt b/libs/login-api-2/src/test/java/com/instructure/loginapi/login/viewmodel/LoginViewModelTest.kt index 7d8548de08..0e576df331 100644 --- a/libs/login-api-2/src/test/java/com/instructure/loginapi/login/viewmodel/LoginViewModelTest.kt +++ b/libs/login-api-2/src/test/java/com/instructure/loginapi/login/viewmodel/LoginViewModelTest.kt @@ -67,6 +67,8 @@ class LoginViewModelTest { fun setUp() { lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE) Dispatchers.setMain(testDispatcher) + + every { apiPrefs.user } returns mockk() } @After