Skip to content

Commit f3adc3c

Browse files
committed
Merge branch 'master' of github.com:duckduckgo/Android into release/4.1
# Conflicts: # app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt
2 parents 753864e + 0a0bd95 commit f3adc3c

File tree

8 files changed

+66
-42
lines changed

8 files changed

+66
-42
lines changed

app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ apply plugin: 'kotlin-kapt'
66
apply from: '../versioning.gradle'
77

88
ext {
9-
VERSION_NAME = "4.0.8"
9+
VERSION_NAME = "4.0.10"
1010
}
1111

1212
android {
@@ -79,6 +79,9 @@ ext {
7979

8080

8181
dependencies {
82+
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
83+
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
84+
8285
implementation fileTree(dir: 'libs', include: ['*.jar'])
8386
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
8487
implementation "com.android.support:appcompat-v7:$supportLibrary"

app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import android.arch.lifecycle.ViewModelProviders
2424
import android.content.Context
2525
import android.content.Intent
2626
import android.net.Uri
27+
import android.os.Build
2728
import android.os.Bundle
2829
import android.support.v7.widget.LinearLayoutManager
2930
import android.text.Editable
@@ -34,6 +35,7 @@ import android.view.View
3435
import android.view.inputmethod.EditorInfo.IME_ACTION_DONE
3536
import android.webkit.CookieManager
3637
import android.webkit.WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE
38+
import android.webkit.WebView
3739
import android.widget.TextView
3840
import android.widget.Toast
3941
import com.duckduckgo.app.bookmarks.ui.BookmarksActivity
@@ -79,11 +81,43 @@ class BrowserActivity : DuckDuckGoActivity() {
7981
private val fireMenu: MenuItem?
8082
get() = toolbar.menu.findItem(R.id.fire_menu_item)
8183

84+
private lateinit var webView: WebView
85+
8286
override fun onCreate(savedInstanceState: Bundle?) {
8387
super.onCreate(savedInstanceState)
88+
8489
setContentView(R.layout.activity_browser)
90+
91+
createWebView()
92+
createPopupMenu()
93+
configureObservers()
94+
configureToolbar()
95+
configureWebView()
96+
configureOmnibarTextInput()
97+
configureDummyViewTouchHandler()
98+
configureAutoComplete()
99+
100+
if (savedInstanceState == null) {
101+
consumeSharedQuery()
102+
}
103+
}
104+
105+
private fun createPopupMenu() {
85106
popupMenu = BrowserPopupMenu(layoutInflater)
107+
}
86108

109+
private fun createWebView() {
110+
webView = NestedWebView(this)
111+
webView.gone()
112+
webView.isFocusableInTouchMode = true
113+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
114+
webView.focusable = View.FOCUSABLE
115+
}
116+
117+
webViewContainer.addView(webView)
118+
}
119+
120+
private fun configureObservers() {
87121
viewModel.viewState.observe(this, Observer<BrowserViewModel.ViewState> {
88122
it?.let { render(it) }
89123
})
@@ -122,16 +156,6 @@ class BrowserActivity : DuckDuckGoActivity() {
122156
}
123157
}
124158
})
125-
126-
configureToolbar()
127-
configureWebView()
128-
configureOmnibarTextInput()
129-
configureDummyViewTouchHandler()
130-
configureAutoComplete()
131-
132-
if (savedInstanceState == null) {
133-
consumeSharedQuery()
134-
}
135159
}
136160

137161
private fun configureAutoComplete() {
@@ -432,6 +456,9 @@ class BrowserActivity : DuckDuckGoActivity() {
432456
}
433457

434458
override fun onDestroy() {
459+
webViewContainer.removeAllViews()
460+
webView.destroy()
461+
435462
popupMenu.dismiss()
436463
super.onDestroy()
437464
}

app/src/main/java/com/duckduckgo/app/browser/BrowserWebViewClient.kt

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BrowserWebViewClient @Inject constructor(
4242
) : WebViewClient() {
4343

4444
var webViewClientListener: WebViewClientListener? = null
45-
45+
var currentUrl: String? = null
4646

4747
/**
4848
* This is the new method of url overriding available from API 24 onwards
@@ -84,6 +84,7 @@ class BrowserWebViewClient @Inject constructor(
8484
}
8585

8686
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
87+
currentUrl = url
8788
webViewClientListener?.loadingStarted()
8889
webViewClientListener?.urlChanged(url)
8990
}
@@ -94,15 +95,15 @@ class BrowserWebViewClient @Inject constructor(
9495

9596
@WorkerThread
9697
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
97-
Timber.v("Intercepting resource ${request.url} on page ${view.urlFromAnyThread()}}")
98+
Timber.v("Intercepting resource ${request.url} on page ${currentUrl}}")
9899

99100
if (shouldUpgrade(request)) {
100101
val newUri = httpsUpgrader.upgrade(request.url)
101102
view.post { view.loadUrl(newUri.toString()) }
102103
return WebResourceResponse(null, null, null)
103104
}
104105

105-
val documentUrl = view.urlFromAnyThread() ?: return null
106+
val documentUrl = currentUrl ?: return null
106107

107108
if (TrustedSites.isTrusted(documentUrl)) {
108109
return null
@@ -138,26 +139,9 @@ class BrowserWebViewClient @Inject constructor(
138139
* Utility to function to execute a function, and then return true
139140
*
140141
* Useful to reduce clutter in repeatedly including `return true` after doing the real work.
141-
*/
142+
*/
142143
private inline fun consume(function: () -> Unit): Boolean {
143144
function()
144145
return true
145146
}
146-
147-
/**
148-
* Access WebView.url from any thread. If you are on the main thread it is more efficient to use
149-
* WebView.url directly.
150-
*/
151-
@AnyThread
152-
private fun WebView.urlFromAnyThread(): String? {
153-
val latch = CountDownLatch(1)
154-
var safeUrl: String? = null
155-
post {
156-
safeUrl = url
157-
latch.countDown()
158-
}
159-
latch.await()
160-
return safeUrl
161-
}
162-
163147
}

app/src/main/java/com/duckduckgo/app/browser/NestedWebView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.duckduckgo.app.browser
1818

19+
import android.annotation.SuppressLint
1920
import android.content.Context
2021
import android.support.v4.view.NestedScrollingChild
2122
import android.support.v4.view.NestedScrollingChildHelper
@@ -44,6 +45,7 @@ class NestedWebView : WebView, NestedScrollingChild {
4445
isNestedScrollingEnabled = true
4546
}
4647

48+
@SuppressLint("ClickableViewAccessibility")
4749
override fun onTouchEvent(ev: MotionEvent): Boolean {
4850
var returnValue = false
4951

app/src/main/java/com/duckduckgo/app/global/DuckDuckGoApplication.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.duckduckgo.app.di.DaggerAppComponent
2424
import com.duckduckgo.app.job.AppConfigurationSyncer
2525
import com.duckduckgo.app.migration.LegacyMigration
2626
import com.duckduckgo.app.trackerdetection.TrackerDataLoader
27+
import com.squareup.leakcanary.LeakCanary
2728
import dagger.android.AndroidInjector
2829
import dagger.android.DispatchingAndroidInjector
2930
import dagger.android.HasActivityInjector
@@ -56,6 +57,8 @@ class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, Applicati
5657
override fun onCreate() {
5758
super.onCreate()
5859

60+
if (!installLeakCanary()) return
61+
5962
configureDependencyInjection()
6063
configureLogging()
6164
configureCrashReporting()
@@ -66,6 +69,14 @@ class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, Applicati
6669
migrateLegacyDb()
6770
}
6871

72+
private fun installLeakCanary(): Boolean {
73+
if (LeakCanary.isInAnalyzerProcess(this)) {
74+
return false;
75+
}
76+
LeakCanary.install(this);
77+
return true
78+
}
79+
6980
private fun migrateLegacyDb() {
7081
doAsync {
7182
migration.start { favourites, searches ->
@@ -105,7 +116,7 @@ class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, Applicati
105116
.doAfterTerminate({
106117
appConfigurationSyncer.scheduleRegularSync(this)
107118
})
108-
.subscribe({}, { Timber.w(it, "Failed to download initial app configuration") })
119+
.subscribe({}, { Timber.w("Failed to download initial app configuration ${it.localizedMessage}") })
109120
}
110121

111122
override fun activityInjector(): AndroidInjector<Activity> = activityInjector

app/src/main/java/com/duckduckgo/app/job/AppConfigurationDownloader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AppConfigurationDownloader @Inject constructor(
3838
val disconnectDownload = trackerDataDownloader.downloadList(Client.ClientName.DISCONNECT)
3939
val httpsUpgradeDownload = httpsUpgradeListDownloader.downloadList()
4040

41-
return Completable.merge(listOf(
41+
return Completable.mergeDelayError(listOf(
4242
easyListDownload.subscribeOn(Schedulers.io()),
4343
easyPrivacyDownload.subscribeOn(Schedulers.io()),
4444
trackersWhitelist.subscribeOn(Schedulers.io()),

app/src/main/java/com/duckduckgo/app/job/AppConfigurationJobService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ class AppConfigurationJobService : JobService() {
4040
override fun onStartJob(params: JobParameters?): Boolean {
4141
Timber.i("onStartJob")
4242

43-
appConfigurationDownloader.downloadTask()
43+
downloadTask= appConfigurationDownloader.downloadTask()
4444
.subscribeOn(Schedulers.io())
4545
.subscribe({
4646
Timber.i("Successfully downloaded all data")
4747
jobFinishedSuccessfully(params)
4848
}, {
49-
Timber.w(it, "Failed to download app configuration")
49+
Timber.w("Failed to download app configuration ${it.localizedMessage}")
5050
jobFinishedFailed(params)
5151
})
5252

app/src/main/res/layout/activity_browser.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,12 @@
140140
android:layout_height="match_parent"
141141
android:focusableInTouchMode="true" />
142142

143-
<com.duckduckgo.app.browser.NestedWebView
144-
android:id="@+id/webView"
143+
<FrameLayout
144+
android:id="@+id/webViewContainer"
145145
android:layout_width="match_parent"
146146
android:layout_height="match_parent"
147-
android:focusable="true"
148-
android:focusableInTouchMode="true"
149-
android:visibility="gone"
150147
app:layout_behavior="@string/appbar_scrolling_view_behavior"
151-
tools:visibility="visible" />
148+
/>
152149

153150
<android.support.v7.widget.RecyclerView
154151
android:id="@+id/autoCompleteSuggestionsList"

0 commit comments

Comments
 (0)