Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import android.arch.lifecycle.ViewModelProviders
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.text.Editable
Expand Down Expand Up @@ -73,7 +72,7 @@ class BrowserActivity : DuckDuckGoActivity(), BookmarkDialogCreationListener {

@Inject
lateinit var viewModelFactory: ViewModelFactory

@Inject
lateinit var cookieManagerProvider: Provider<CookieManager>

Expand All @@ -99,8 +98,8 @@ class BrowserActivity : DuckDuckGoActivity(), BookmarkDialogCreationListener {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_browser)

createPopupMenu()
createWebView()
configureObservers()
configureToolbar()
configureWebView()
Expand All @@ -126,17 +125,6 @@ class BrowserActivity : DuckDuckGoActivity(), BookmarkDialogCreationListener {
}
}

private fun createWebView() {
webView = NestedWebView(this)
webView.gone()
webView.isFocusableInTouchMode = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
webView.focusable = View.FOCUSABLE
}

webViewContainer.addView(webView)
}

private fun configureObservers() {
viewModel.viewState.observe(this, Observer<BrowserViewModel.ViewState> {
it?.let { render(it) }
Expand Down Expand Up @@ -345,6 +333,7 @@ class BrowserActivity : DuckDuckGoActivity(), BookmarkDialogCreationListener {

@SuppressLint("SetJavaScriptEnabled")
private fun configureWebView() {
webView = layoutInflater.inflate(R.layout.include_duckduckgo_browser_webview, webViewContainer, true).findViewById(R.id.browserWebView) as WebView
webView.webViewClient = webViewClient
webView.webChromeClient = webChromeClient

Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/com/duckduckgo/app/browser/NestedWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ import android.webkit.WebView
* Based on https://github.com/takahirom/webview-in-coordinatorlayout
*/
class NestedWebView : WebView, NestedScrollingChild {

private var lastY: Int = 0
private val scrollOffset = IntArray(2)
private val scrollConsumed = IntArray(2)
private var nestedOffetY: Int = 0
private var nestedScrollHelper: NestedScrollingChildHelper = NestedScrollingChildHelper(this)

constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
nestedScrollHelper = NestedScrollingChildHelper(this)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
{
isNestedScrollingEnabled = true
}

Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/layout/include_duckduckgo_browser_webview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2018 DuckDuckGo
~
~ 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.
-->

<com.duckduckgo.app.browser.NestedWebView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/browserWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollbarSize="4dp"
android:scrollbarStyle="outsideInset"
android:scrollbarThumbHorizontal="@color/webViewScrollbarThumbColor"
android:scrollbarThumbVertical="@color/webViewScrollbarThumbColor"
android:scrollbarTrackHorizontal="@color/webViewScrollbarTrackColor"
android:scrollbarTrackVertical="@color/webViewScrollbarTrackColor"
android:visibility="gone"
tools:visibility="visible">

</com.duckduckgo.app.browser.NestedWebView>
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@

<color name="white_two">#e4e4e4</color>

<color name="webViewScrollbarTrackColor">#FF333333</color>
<color name="webViewScrollbarThumbColor">#FFABABAB</color>

</resources>