From 1414abf9f9555853e832bbb6da45d3ca459983f9 Mon Sep 17 00:00:00 2001 From: Jordan Marshall Date: Fri, 12 Apr 2019 09:22:56 -0600 Subject: [PATCH] [Student][MBL-11328] View URL submissions --- .../student/espresso/StudentRenderTest.kt | 2 + .../renderPages/UrlSubmissionRenderPage.kt | 29 ++++++++ .../ui/renderTests/UrlSubmissionRenderTest.kt | 45 ++++++++++++ .../content/UrlSubmissionFragment.kt | 62 ++++++++++++++++ .../ui/SubmissionDetailsView.kt | 11 +-- .../res/layout/fragment_url_submission.xml | 70 +++++++++++++++++++ libs/pandares/src/main/res/values/strings.xml | 1 + 7 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 apps/student/src/androidTest/java/com/instructure/student/ui/pages/renderPages/UrlSubmissionRenderPage.kt create mode 100644 apps/student/src/androidTest/java/com/instructure/student/ui/renderTests/UrlSubmissionRenderTest.kt create mode 100644 apps/student/src/main/java/com/instructure/student/mobius/assignmentDetails/submissionDetails/content/UrlSubmissionFragment.kt create mode 100644 apps/student/src/main/res/layout/fragment_url_submission.xml diff --git a/apps/student/src/androidTest/java/com/instructure/student/espresso/StudentRenderTest.kt b/apps/student/src/androidTest/java/com/instructure/student/espresso/StudentRenderTest.kt index 07a0d5a5ba..e63e5e2c92 100644 --- a/apps/student/src/androidTest/java/com/instructure/student/espresso/StudentRenderTest.kt +++ b/apps/student/src/androidTest/java/com/instructure/student/espresso/StudentRenderTest.kt @@ -20,6 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.instructure.student.SingleFragmentTestActivity import com.instructure.student.ui.pages.renderPages.AssignmentDetailsRenderPage import com.instructure.student.ui.pages.renderPages.SubmissionDetailsRenderPage +import com.instructure.student.ui.pages.renderPages.UrlSubmissionRenderPage import com.instructure.student.ui.utils.StudentActivityTestRule import com.instructure.student.ui.utils.StudentTest import org.junit.runner.RunWith @@ -36,5 +37,6 @@ abstract class StudentRenderTest : StudentTest() { val assignmentDetailsRenderPage = AssignmentDetailsRenderPage() val submissionDetailsRenderPage = SubmissionDetailsRenderPage() + val urlSubmissionRenderPage = UrlSubmissionRenderPage() } diff --git a/apps/student/src/androidTest/java/com/instructure/student/ui/pages/renderPages/UrlSubmissionRenderPage.kt b/apps/student/src/androidTest/java/com/instructure/student/ui/pages/renderPages/UrlSubmissionRenderPage.kt new file mode 100644 index 0000000000..7b68b9eed5 --- /dev/null +++ b/apps/student/src/androidTest/java/com/instructure/student/ui/pages/renderPages/UrlSubmissionRenderPage.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2019 - present Instructure, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.instructure.student.ui.pages.renderPages + +import com.instructure.espresso.OnViewWithId +import com.instructure.espresso.OnViewWithText +import com.instructure.espresso.page.BasePage +import com.instructure.student.R + +class UrlSubmissionRenderPage : BasePage(R.id.urlSubmission) { + + val disclaimer by OnViewWithText(R.string.urlSubmissionDisclaimer) + val url by OnViewWithId(R.id.urlTextView) + val previewImage by OnViewWithId(R.id.urlPreviewImageView) + +} diff --git a/apps/student/src/androidTest/java/com/instructure/student/ui/renderTests/UrlSubmissionRenderTest.kt b/apps/student/src/androidTest/java/com/instructure/student/ui/renderTests/UrlSubmissionRenderTest.kt new file mode 100644 index 0000000000..43af727912 --- /dev/null +++ b/apps/student/src/androidTest/java/com/instructure/student/ui/renderTests/UrlSubmissionRenderTest.kt @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2019 - present Instructure, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.instructure.student.ui.renderTests + +import com.instructure.espresso.assertCompletelyDisplayed +import com.instructure.espresso.assertHasText +import com.instructure.student.espresso.StudentRenderTest +import com.instructure.student.mobius.assignmentDetails.submissionDetails.content.UrlSubmissionFragment +import org.junit.Test + +class UrlSubmissionRenderTest : StudentRenderTest() { + + private val testUrl = "https://www.instructure.com" + + @Test + fun displaysDisclaimer() { + loadPageWithData(testUrl, "") + urlSubmissionRenderPage.disclaimer.assertCompletelyDisplayed() + } + + @Test + fun displaysUrl() { + loadPageWithData(testUrl, "") + urlSubmissionRenderPage.url.assertHasText(testUrl) + } + + private fun loadPageWithData(url: String, previewUrl: String) { + val fragment = UrlSubmissionFragment.newInstance(url, previewUrl) + activityRule.activity.loadFragment(fragment) + } + +} diff --git a/apps/student/src/main/java/com/instructure/student/mobius/assignmentDetails/submissionDetails/content/UrlSubmissionFragment.kt b/apps/student/src/main/java/com/instructure/student/mobius/assignmentDetails/submissionDetails/content/UrlSubmissionFragment.kt new file mode 100644 index 0000000000..cb4ae2aee4 --- /dev/null +++ b/apps/student/src/main/java/com/instructure/student/mobius/assignmentDetails/submissionDetails/content/UrlSubmissionFragment.kt @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2019 - present Instructure, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.instructure.student.mobius.assignmentDetails.submissionDetails.content + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import com.bumptech.glide.Glide +import com.instructure.pandautils.utils.NullableStringArg +import com.instructure.pandautils.utils.StringArg +import com.instructure.pandautils.utils.ThemePrefs +import com.instructure.pandautils.utils.onClick +import com.instructure.student.R +import com.instructure.student.activity.InternalWebViewActivity +import kotlinx.android.synthetic.main.fragment_url_submission.* + +class UrlSubmissionFragment : Fragment() { + + private var url by StringArg() + private var previewUrl by NullableStringArg() + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_url_submission, container, false) + } + + override fun onStart() { + super.onStart() + Glide.with(requireContext()).load(previewUrl).into(urlPreviewImageView) + urlTextView.text = url + urlTextView.setTextColor(ThemePrefs.buttonColor) + val launchUrl = { _: View -> + val title = getString(R.string.urlSubmission) + val intent = InternalWebViewActivity.createIntent(requireActivity(), url, title, true) + requireActivity().startActivity(intent) + } + urlTextView.onClick(launchUrl) + urlPreviewImageView.onClick(launchUrl) + } + + companion object { + @JvmStatic + fun newInstance(url: String, previewUrl: String?) = UrlSubmissionFragment().apply { + this.url = url + this.previewUrl = previewUrl + } + } +} diff --git a/apps/student/src/main/java/com/instructure/student/mobius/assignmentDetails/submissionDetails/ui/SubmissionDetailsView.kt b/apps/student/src/main/java/com/instructure/student/mobius/assignmentDetails/submissionDetails/ui/SubmissionDetailsView.kt index 20b17c408b..48bf133784 100644 --- a/apps/student/src/main/java/com/instructure/student/mobius/assignmentDetails/submissionDetails/ui/SubmissionDetailsView.kt +++ b/apps/student/src/main/java/com/instructure/student/mobius/assignmentDetails/submissionDetails/ui/SubmissionDetailsView.kt @@ -35,6 +35,7 @@ import com.instructure.pandautils.utils.* import com.instructure.student.R import com.instructure.student.mobius.assignmentDetails.submissionDetails.SubmissionDetailsContentType import com.instructure.student.mobius.assignmentDetails.submissionDetails.SubmissionDetailsEvent +import com.instructure.student.mobius.assignmentDetails.submissionDetails.content.UrlSubmissionFragment import com.instructure.student.mobius.common.ui.MobiusView import com.sothree.slidinguppanel.SlidingUpPanelLayout import com.spotify.mobius.functions.Consumer @@ -181,10 +182,12 @@ class SubmissionDetailsView( } private fun getFragmentForContent(type: SubmissionDetailsContentType): Fragment { - // TODO - return PlaceholderFragment().apply { - typeName = type::class.java.simpleName - typeContents = type.toString() + return when (type) { + is SubmissionDetailsContentType.UrlContent -> UrlSubmissionFragment.newInstance(type.url, type.previewUrl) + else -> PlaceholderFragment().apply { + typeName = type::class.java.simpleName + typeContents = type.toString() + } } } diff --git a/apps/student/src/main/res/layout/fragment_url_submission.xml b/apps/student/src/main/res/layout/fragment_url_submission.xml new file mode 100644 index 0000000000..9a7397ed5e --- /dev/null +++ b/apps/student/src/main/res/layout/fragment_url_submission.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + diff --git a/libs/pandares/src/main/res/values/strings.xml b/libs/pandares/src/main/res/values/strings.xml index 140ca8c7a8..dad5ba3b65 100644 --- a/libs/pandares/src/main/res/values/strings.xml +++ b/libs/pandares/src/main/res/values/strings.xml @@ -58,6 +58,7 @@ Files (%d) Rubric Submission Error + This submission was a URL to an external page. We\'ve included a snapshot of what the page looked like when it was submitted. Version: