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 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() + } } } 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/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..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 @@ -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 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 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