-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create basic html content screen to show global announcements.
- Loading branch information
1 parent
e90b869
commit 376959c
Showing
5 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
libs/pandautils/src/main/java/com/instructure/pandautils/fragments/HtmlContentFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
libs/pandautils/src/main/res/layout/fragment_html_content.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |