Skip to content

Commit

Permalink
Create basic html content screen to show global announcements.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaskozmer committed Dec 7, 2022
1 parent e90b869 commit 376959c
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ package com.instructure.teacher.features.dashboard.notifications
import androidx.fragment.app.FragmentActivity
import com.instructure.interactions.router.Route
import com.instructure.pandautils.features.dashboard.notifications.DashboardRouter
import com.instructure.pandautils.fragments.HtmlContentFragment
import com.instructure.teacher.fragments.InternalWebViewFragment
import com.instructure.teacher.router.RouteMatcher

class TeacherDashboardRouter(private val activity: FragmentActivity) : DashboardRouter {
override fun routeToGlobalAnnouncement(subject: String, message: String) {
val args = InternalWebViewFragment.makeBundle(
url ="",
val args = HtmlContentFragment.makeBundle(
title = subject,
html = message
)
val route = Route(null, InternalWebViewFragment::class.java, null, args)
val route = Route(null, HtmlContentFragment::class.java, null, args)
RouteMatcher.route(activity, route)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.instructure.interactions.router.RouterParams
import com.instructure.pandautils.activities.BaseViewMediaActivity
import com.instructure.pandautils.features.discussion.details.DiscussionDetailsWebViewFragment
import com.instructure.pandautils.features.discussion.router.DiscussionRouterFragment
import com.instructure.pandautils.fragments.HtmlContentFragment
import com.instructure.pandautils.loaders.OpenMediaAsyncTaskLoader
import com.instructure.pandautils.utils.*
import com.instructure.teacher.PSPDFKit.AnnotationComments.AnnotationCommentListFragment
Expand Down Expand Up @@ -369,6 +370,7 @@ object RouteMatcher : BaseRouteMatcher() {
CreateOrEditPageDetailsFragment::class.java.isAssignableFrom(cls) -> fragment = CreateOrEditPageDetailsFragment.newInstance(route.arguments)
FullscreenInternalWebViewFragment::class.java.isAssignableFrom(cls) -> fragment = FullscreenInternalWebViewFragment.newInstance(route.arguments)
InternalWebViewFragment::class.java.isAssignableFrom(cls) -> fragment = InternalWebViewFragment.newInstance(route.arguments)
HtmlContentFragment::class.java.isAssignableFrom(cls) -> fragment = HtmlContentFragment.newInstance(route.arguments)
} //NOTE: These should remain at or near the bottom to give fragments that extend InternalWebViewFragment the chance first

return fragment as Type?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.instructure.pandautils.features.discussion.details.DiscussionDetailsW
import com.instructure.pandautils.features.discussion.router.DiscussionRouterFragment
import com.instructure.pandautils.features.notification.preferences.EmailNotificationPreferencesFragment
import com.instructure.pandautils.features.notification.preferences.PushNotificationPreferencesFragment
import com.instructure.pandautils.fragments.HtmlContentFragment
import com.instructure.pandautils.fragments.RemoteConfigParamsFragment
import com.instructure.pandautils.utils.Const
import com.instructure.pandautils.utils.argsWithContext
Expand Down Expand Up @@ -187,6 +188,8 @@ object RouteResolver {
fragment = FullscreenInternalWebViewFragment.newInstance(route.arguments)
} else if (InternalWebViewFragment::class.java.isAssignableFrom(cls)) {
fragment = InternalWebViewFragment.newInstance(route.arguments)
} else if (HtmlContentFragment::class.java.isAssignableFrom(cls)) {
fragment = HtmlContentFragment.newInstance(route.arguments)
}//NOTE: These should remain at or near the bottom to give fragments that extend InternalWebViewFragment the chance first

return fragment as Type?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2022 - 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 <http://www.gnu.org/licenses/>.
*
*/
package com.instructure.pandautils.fragments

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebView
import androidx.fragment.app.Fragment
import com.instructure.canvasapi2.utils.ApiPrefs
import com.instructure.pandautils.databinding.FragmentHtmlContentBinding
import com.instructure.pandautils.navigation.WebViewRouter
import com.instructure.pandautils.utils.StringArg
import com.instructure.pandautils.utils.ThemePrefs
import com.instructure.pandautils.utils.ViewStyler
import com.instructure.pandautils.utils.setDarkModeSupport
import com.instructure.pandautils.utils.setupAsCloseButton
import com.instructure.pandautils.views.CanvasWebView
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class HtmlContentFragment : Fragment() {

var html: String by StringArg()
var title: String by StringArg()

@Inject
lateinit var webViewRouter: WebViewRouter

private lateinit var binding: FragmentHtmlContentBinding

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
binding = FragmentHtmlContentBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupToolbar()
setupWebView(binding.canvasWebViewWrapper.webView)

binding.canvasWebViewWrapper.loadHtml(html, title)
}

private fun setupToolbar() {
binding.toolbar.setTitle(title)
binding.toolbar.setupAsCloseButton(this)
ViewStyler.themeToolbarColored(requireActivity(), binding.toolbar, ThemePrefs.primaryColor, ThemePrefs.primaryTextColor)
}

private fun setupWebView(canvasWebView: CanvasWebView) {
canvasWebView.setDarkModeSupport(webThemeDarkeningOnly = true)
canvasWebView.settings.loadWithOverviewMode = true
canvasWebView.settings.displayZoomControls = false
canvasWebView.settings.setSupportZoom(true)
canvasWebView.settings.userAgentString = ApiPrefs.userAgent
canvasWebView.addVideoClient(requireActivity())
canvasWebView.setInitialScale(100)

canvasWebView.canvasWebViewClientCallback = object : CanvasWebView.CanvasWebViewClientCallback {
override fun openMediaFromWebView(mime: String, url: String, filename: String) {
webViewRouter.openMedia(url)
}

override fun onPageFinishedCallback(webView: WebView, url: String) = Unit

override fun onPageStartedCallback(webView: WebView, url: String) = Unit

override fun canRouteInternallyDelegate(url: String): Boolean = webViewRouter.canRouteInternally(url)

override fun routeInternallyCallback(url: String) {
webViewRouter.routeInternally(url)
}
}
}

companion object {
const val TITLE = "title"
const val HTML = "html"

fun newInstance(args: Bundle) = HtmlContentFragment().apply {
title = args.getString(TITLE) ?: ""
html = args.getString(HTML) ?: ""
}

fun makeBundle(title: String, html: String): Bundle {
val args = Bundle()
args.putString(TITLE, title)
args.putString(HTML, html)
return args
}
}
}
51 changes: 51 additions & 0 deletions libs/pandautils/src/main/res/layout/fragment_html_content.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2022 - 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 <http://www.gnu.org/licenses/>.
~
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundLightest"
android:orientation="vertical">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:background="@color/textDarkest"
android:elevation="6dp"
app:popupTheme="@style/ToolBarPopupStyle"
app:theme="@style/ToolBarStyle"
tools:targetApi="lollipop" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbarStyle="outsideOverlay"
android:clipToPadding="false">

<com.instructure.pandautils.views.CanvasWebViewWrapper
android:id="@+id/canvasWebViewWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/backgroundLightest"/>

</ScrollView>

</LinearLayout>

0 comments on commit 376959c

Please sign in to comment.