Skip to content

Commit

Permalink
Merge branch 'hotfix/4.0.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
subsymbolic committed Jan 24, 2018
2 parents 0a0bd95 + d7cf123 commit 4d0d3ce
Show file tree
Hide file tree
Showing 32 changed files with 216 additions and 199 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'kotlin-kapt'
apply from: '../versioning.gradle'

ext {
VERSION_NAME = "4.0.10"
VERSION_NAME = "4.0.11"
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ import android.arch.persistence.room.Room
import android.net.Uri
import android.support.test.InstrumentationRegistry
import com.duckduckgo.app.autocomplete.api.AutoCompleteApi
import com.duckduckgo.app.blockingObserve
import com.duckduckgo.app.bookmarks.db.BookmarkEntity
import com.duckduckgo.app.bookmarks.db.BookmarksDao
import com.duckduckgo.app.bookmarks.ui.BookmarksActivity
import com.duckduckgo.app.browser.BrowserViewModel.Command
import com.duckduckgo.app.browser.BrowserViewModel.Command.LandingPage
import com.duckduckgo.app.browser.BrowserViewModel.Command.Navigate
import com.duckduckgo.app.browser.omnibar.OmnibarEntryConverter
import com.duckduckgo.app.global.StringResolver
import com.duckduckgo.app.global.db.AppDatabase
import com.duckduckgo.app.privacymonitor.db.NetworkLeaderboardDao
import com.duckduckgo.app.privacymonitor.db.NetworkLeaderboardEntry
Expand All @@ -46,10 +43,7 @@ import com.duckduckgo.app.settings.db.SettingsDataStore
import com.duckduckgo.app.trackerdetection.model.TrackerNetwork
import com.duckduckgo.app.trackerdetection.model.TrackerNetworks
import com.duckduckgo.app.trackerdetection.model.TrackingEvent
import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.doReturn
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.whenever
import com.nhaarman.mockito_kotlin.*
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
Expand All @@ -70,8 +64,6 @@ class BrowserViewModelTest {

private var lastNetworkLeaderboardEntry: NetworkLeaderboardEntry? = null

private val testStringResolver: StringResolver = object : StringResolver {}

private val testNetworkLeaderboardDao: NetworkLeaderboardDao = object : NetworkLeaderboardDao {
override fun insert(leaderboardEntry: NetworkLeaderboardEntry) {
lastNetworkLeaderboardEntry = leaderboardEntry
Expand Down Expand Up @@ -122,7 +114,6 @@ class BrowserViewModelTest {
termsOfServiceStore = mockTermsOfServiceStore,
trackerNetworks = TrackerNetworks(),
privacyMonitorRepository = PrivacyMonitorRepository(),
stringResolver = testStringResolver,
networkLeaderboardDao = testNetworkLeaderboardDao,
autoCompleteApi = mockAutoCompleteApi,
appSettingsPreferencesStore = mockSettingsStore,
Expand Down Expand Up @@ -151,15 +142,6 @@ class BrowserViewModelTest {
assertEquals("nytimes.com", testee.viewState.value!!.omnibarText)
}

@Test
fun whenBookmarksResultCodeIsOpenUrlThenNavigate() {
testee.receivedBookmarksResult(BookmarksActivity.OPEN_URL_RESULT_CODE, "www.example.com")
val captor: ArgumentCaptor<Command> = ArgumentCaptor.forClass(Command::class.java)
verify(mockNavigationObserver).onChanged(captor.capture())
assertNotNull(captor.value)
assertTrue(captor.value is Navigate)
}

@Test
fun whenUrlPresentThenAddBookmarkButtonEnabled() {
testee.urlChanged("www.example.com")
Expand Down Expand Up @@ -261,7 +243,7 @@ class BrowserViewModelTest {
fun whenSharedTextReceivedThenNavigationTriggered() {
testee.onSharedTextReceived("http://example.com")
val captor: ArgumentCaptor<Command> = ArgumentCaptor.forClass(Command::class.java)
verify(mockNavigationObserver).onChanged(captor.capture())
verify(mockNavigationObserver, times(2)).onChanged(captor.capture())
assertNotNull(captor.value)
assertTrue(captor.value is Navigate)
}
Expand Down
31 changes: 14 additions & 17 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/appName"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config"
tools:ignore="GoogleAppIndexingWarning">

<meta-data
android:name="android.webkit.WebView.MetricsOptOut"
android:value="true" />
Expand All @@ -25,10 +24,10 @@
android:label="@string/appName">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.duckduckgo.app.home.HomeActivity"
android:label="@string/appName"
Expand All @@ -48,60 +47,58 @@
<!-- Allows apps to consume links and text shared from other apps e.g chrome -->
<intent-filter>
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>

</activity>

<activity
android:name=".BrowserActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleTask"
android:parentActivityName="com.duckduckgo.app.home.HomeActivity" />

<activity
android:name="com.duckduckgo.app.privacymonitor.ui.PrivacyDashboardActivity"
android:label="@string/privacyDashboardActivityTitle"
android:parentActivityName=".BrowserActivity" />

<activity
android:name="com.duckduckgo.app.privacymonitor.ui.ScorecardActivity"
android:label="@string/scorecardActivityTitle"
android:parentActivityName="com.duckduckgo.app.privacymonitor.ui.PrivacyDashboardActivity" />

<activity
android:name="com.duckduckgo.app.privacymonitor.ui.TrackerNetworksActivity"
android:label="@string/networksActivityTitle"
android:parentActivityName="com.duckduckgo.app.privacymonitor.ui.PrivacyDashboardActivity" />

<activity
android:name="com.duckduckgo.app.privacymonitor.ui.PrivacyPracticesActivity"
android:label="@string/privacyTermsActivityTitle"
android:parentActivityName="com.duckduckgo.app.privacymonitor.ui.PrivacyDashboardActivity" />

<activity
android:name="com.duckduckgo.app.settings.SettingsActivity"
android:label="@string/settingsActivityTitle"
android:parentActivityName=".BrowserActivity" />
android:label="@string/settingsActivityTitle"/>

<activity
android:name="com.duckduckgo.app.about.AboutDuckDuckGoActivity"
android:label="@string/aboutActivityTitle"
android:parentActivityName="com.duckduckgo.app.settings.SettingsActivity"

android:theme="@style/AppTheme" />

<activity
android:name="com.duckduckgo.app.bookmarks.ui.BookmarksActivity"
android:label="@string/bookmarksActivityTitle"
android:parentActivityName=".BrowserActivity" />
android:label="@string/bookmarksActivityTitle" />

<service
android:name="com.duckduckgo.app.job.AppConfigurationJobService"
android:permission="android.permission.BIND_JOB_SERVICE" />

<receiver android:name="com.duckduckgo.widget.SearchWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/search_widget_info" />
</receiver>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.home.HomeActivity
import kotlinx.android.synthetic.main.content_about_duck_duck_go.*
import kotlinx.android.synthetic.main.include_toolbar.*

Expand All @@ -32,7 +33,7 @@ class AboutDuckDuckGoActivity : AppCompatActivity() {
configureActionBar()

learnMoreLink.setOnClickListener {
setResult(RESULT_CODE_LOAD_ABOUT_DDG_WEB_PAGE)
startActivity(HomeActivity.intent(this, getString(R.string.aboutUrl)))
finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.duckduckgo.app.bookmarks.db.BookmarkEntity
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.global.DuckDuckGoActivity
import com.duckduckgo.app.global.ViewModelFactory
import com.duckduckgo.app.home.HomeActivity
import kotlinx.android.synthetic.main.content_bookmarks.*
import kotlinx.android.synthetic.main.include_toolbar.*
import kotlinx.android.synthetic.main.view_bookmark_entry.view.*
Expand Down Expand Up @@ -85,8 +86,7 @@ class BookmarksActivity : DuckDuckGoActivity() {
}

private fun openBookmark(bookmark: BookmarkEntity) {
val intent = Intent(bookmark.url)
setResult(OPEN_URL_RESULT_CODE, intent)
startActivity(HomeActivity.intent(this, bookmark.url))
finish()
}

Expand Down Expand Up @@ -116,8 +116,6 @@ class BookmarksActivity : DuckDuckGoActivity() {
fun intent(context: Context): Intent {
return Intent(context, BookmarksActivity::class.java)
}

val OPEN_URL_RESULT_CODE = Activity.RESULT_FIRST_USER
}

class BookmarksAdapter(val context: Context, val viewModel: BookmarksViewModel) : Adapter<BookmarksViewHolder>() {
Expand Down
53 changes: 30 additions & 23 deletions app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class BrowserActivity : DuckDuckGoActivity() {
configureAutoComplete()

if (savedInstanceState == null) {
consumeSharedTextExtra()
consumeSharedQuery()
}
}

Expand All @@ -122,12 +122,6 @@ class BrowserActivity : DuckDuckGoActivity() {
it?.let { render(it) }
})

viewModel.privacyGrade.observe(this, Observer<PrivacyGrade> {
it?.let {
privacyGradeMenu?.icon = getDrawable(it.icon())
}
})

viewModel.url.observe(this, Observer {
it?.let { webView.loadUrl(it) }
})
Expand All @@ -154,6 +148,13 @@ class BrowserActivity : DuckDuckGoActivity() {
val intent = Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:${it.telephoneNumber}"))
startActivity(intent)
}
is BrowserViewModel.Command.ShowKeyboard -> {
Timber.i("Command: showing keyboard")
omnibarTextInput.postDelayed({omnibarTextInput.showKeyboard()}, 300)
}
is BrowserViewModel.Command.ReinitialiseWebView -> {
webView.clearHistory()
}
}
})
}
Expand All @@ -171,8 +172,8 @@ class BrowserActivity : DuckDuckGoActivity() {
autoCompleteSuggestionsList.adapter = autoCompleteSuggestionsAdapter
}

private fun consumeSharedTextExtra() {
val sharedText = intent.getStringExtra(SHARED_TEXT_EXTRA)
private fun consumeSharedQuery() {
val sharedText = intent.getStringExtra(QUERY_EXTRA)
if (sharedText != null) {
viewModel.onSharedTextReceived(sharedText)
}
Expand Down Expand Up @@ -293,7 +294,7 @@ class BrowserActivity : DuckDuckGoActivity() {
setSupportZoom(true)
}

webView.setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
webView.setDownloadListener { url, _, _, _, _ ->
val request = DownloadManager.Request(Uri.parse(url))
request.allowScanningByMediaScanner()
request.setNotificationVisibility(VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
Expand Down Expand Up @@ -342,6 +343,11 @@ class BrowserActivity : DuckDuckGoActivity() {

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_browser_activity, menu)
viewModel.privacyGrade.observe(this, Observer<PrivacyGrade> {
it?.let {
privacyGradeMenu?.icon = getDrawable(it.icon())
}
})
return true
}

Expand Down Expand Up @@ -379,31 +385,37 @@ class BrowserActivity : DuckDuckGoActivity() {
popupMenu.show(rootView, anchorView)
}

@Suppress("UNUSED_PARAMETER")
fun onGoForwardClicked(view: View) {
webView.goForward()
popupMenu.dismiss()
}

@Suppress("UNUSED_PARAMETER")
fun onGoBackClicked(view: View) {
webView.goBack()
popupMenu.dismiss()
}

@Suppress("UNUSED_PARAMETER")
fun onRefreshClicked(view: View) {
webView.reload()
popupMenu.dismiss()
}

@Suppress("UNUSED_PARAMETER")
fun onBookmarksClicked(view: View) {
launchBookmarksView()
popupMenu.dismiss()
}

@Suppress("UNUSED_PARAMETER")
fun onAddBookmarkClicked(view: View) {
addBookmark()
popupMenu.dismiss()
}

@Suppress("UNUSED_PARAMETER")
fun onSettingsClicked(view: View) {
launchSettingsView()
popupMenu.dismiss()
Expand All @@ -421,19 +433,16 @@ class BrowserActivity : DuckDuckGoActivity() {
}

private fun launchSettingsView() {
startActivityForResult(SettingsActivity.intent(this), SETTINGS_REQUEST_CODE)
startActivity(SettingsActivity.intent(this))
}

private fun launchBookmarksView() {
startActivityForResult(BookmarksActivity.intent(this), BOOKMARKS_REQUEST_CODE)
startActivity(BookmarksActivity.intent(this))
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
DASHBOARD_REQUEST_CODE -> viewModel.receivedDashboardResult(resultCode)
SETTINGS_REQUEST_CODE -> viewModel.receivedSettingsResult(resultCode)
BOOKMARKS_REQUEST_CODE -> viewModel.receivedBookmarksResult(resultCode, data?.action)
else -> super.onActivityResult(requestCode, resultCode, data)
if (requestCode == DASHBOARD_REQUEST_CODE ) {
viewModel.receivedDashboardResult(resultCode)
}
}

Expand Down Expand Up @@ -468,16 +477,14 @@ class BrowserActivity : DuckDuckGoActivity() {

companion object {

fun intent(context: Context, sharedText: String? = null): Intent {
fun intent(context: Context, queryExtra: String? = null): Intent {
val intent = Intent(context, BrowserActivity::class.java)
intent.putExtra(SHARED_TEXT_EXTRA, sharedText)
intent.putExtra(QUERY_EXTRA, queryExtra)
return intent
}

private const val SHARED_TEXT_EXTRA = "SHARED_TEXT_EXTRA"
private const val SETTINGS_REQUEST_CODE = 100
private const val DASHBOARD_REQUEST_CODE = 101
private const val BOOKMARKS_REQUEST_CODE = 102
private const val QUERY_EXTRA = "QUERY_EXTRA"
private const val DASHBOARD_REQUEST_CODE = 100
}

}
Loading

0 comments on commit 4d0d3ce

Please sign in to comment.