Skip to content

Commit

Permalink
Merge branch 'release/5.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
subsymbolic committed Apr 17, 2018
2 parents 1b8e5bf + 61dcf7a commit 49b4f44
Show file tree
Hide file tree
Showing 18 changed files with 212 additions and 27 deletions.
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributing to DuckDuckGo

Thank you for taking the time to contribute to DuckDuckGo! :sparkles:

We are pleased to open up the project to you - our community. How can you contribute?

## Share feedback and bug reports
See [README.md](README.md)

## Contribute Code

We have labeled tasks you can help with as [help wanted](https://github.com/duckduckgo/Android/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22).
As we are still opening up our repo, we cannot yet accept PRs outside this list. If you have a great idea
you really want to implement, start by logging an issue for us and mention that you are interested in helping.
If it fits with our product direction and is a good candidate for community development we may be able to bend
the rules and work with you to develop it.

## Style Guide

We care about clean code. Refer to our [style guide](styleguide/STYLEGUIDE.md).


## Commit Messages

See Chris Beams' guide to writing good commit messages https://chris.beams.io/posts/git-commit/
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# DuckDuckGo Android

Welcome to our android application. While it is still too early to accept contributions, we are excited to engage the community in development and will open up this project to contributions in the future.
Welcome to our android application. We are excited to engage the community in development, see [CONTRIBUTING.md](CONTRIBUTING.md).

If you are trying to contribute in other ways, that happens over at [DuckDuckHack](http://duckduckhack.com) or on [GitHub](http://github.com/duckduckgo).

## Discuss

Contact us at [email protected] if you want to get more involved, have questions or want to chat.
Contact us at [email protected] if you have questions, feedback or want to chat.

## Reporting Bugs

We want our app to be as stable as possible thus your bug reports are immensely valuable. When reporting bugs let us know the:
* App version
* Device make and model
* Android version
* Steps to reproduce the bug
* Expected behavior
* Actual behavior

Email bug reports to [email protected]


## License
DuckDuckGo android is distributed under the Apache 2.0 [license](https://github.com/duckduckgo/ios/blob/master/LICENSE).
DuckDuckGo android is distributed under the Apache 2.0 [license](LICENSE).
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 = "5.1.0"
VERSION_NAME = "5.2.0"
USE_ORCHESTRATOR = project.hasProperty('orchestrator') ? project.property('orchestrator') : false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.app.browser

import android.support.test.InstrumentationRegistry
import android.webkit.CookieManager
import android.webkit.ValueCallback
import android.webkit.WebStorage
Expand All @@ -36,10 +37,9 @@ class WebDataManagerTest {

private val testee = WebDataManager(host)


@Test
fun whenDataClearedThenCacheHistoryAndStorageDataCleared() {
testee.clearData(mockWebView, mockStorage)
testee.clearData(mockWebView, mockStorage, InstrumentationRegistry.getTargetContext())
verify(mockWebView).clearHistory()
verify(mockWebView).clearCache(true)
verify(mockStorage).deleteAllData()
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import com.duckduckgo.app.global.ViewModelFactory
import com.duckduckgo.app.global.view.*
import com.duckduckgo.app.privacy.model.PrivacyGrade
import com.duckduckgo.app.privacy.renderer.icon
import com.duckduckgo.app.tabs.model.TabEntity
import com.duckduckgo.app.tabs.ui.TabIconRenderer
import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_browser_tab.*
import kotlinx.android.synthetic.main.fragment_browser_tab.view.*
Expand Down Expand Up @@ -103,7 +105,6 @@ class BrowserTabFragment : Fragment(), FindListener {

private lateinit var autoCompleteSuggestionsAdapter: BrowserAutoCompleteSuggestionsAdapter


// Used to represent a file to download, but may first require permission
private var pendingFileDownload: PendingFileDownload? = null

Expand Down Expand Up @@ -165,7 +166,10 @@ class BrowserTabFragment : Fragment(), FindListener {
configureFindInPage()
configureAutoComplete()
configureKeyboardAwareLogoAnimation()
consumeSharedText()

if (savedInstanceState == null) {
consumeSharedText()
}
}

private fun consumeSharedText() {
Expand Down Expand Up @@ -206,6 +210,10 @@ class BrowserTabFragment : Fragment(), FindListener {
it?.let { render(it) }
})

viewModel.tabs.observe(this, Observer<List<TabEntity>> {
it?.let { renderTabIcon(it)}
})

viewModel.url.observe(this, Observer {
it?.let { navigate(it) }
})
Expand Down Expand Up @@ -394,6 +402,12 @@ class BrowserTabFragment : Fragment(), FindListener {
popupMenu.contentView.findInPageMenuItem?.isEnabled = viewState.canFindInPage
}

private fun renderTabIcon(tabs: List<TabEntity>) {
context?.let {
tabsButton?.icon = TabIconRenderer.icon(it, tabs.count())
}
}

private fun hideFindInPage() {
if (findInPageContainer.visibility != View.GONE) {
focusDummy.requestFocus()
Expand Down Expand Up @@ -793,4 +807,6 @@ class BrowserTabFragment : Fragment(), FindListener {
return fragment
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.app.browser

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModel
Expand Down Expand Up @@ -52,6 +53,7 @@ import com.duckduckgo.app.privacy.model.PrivacyGrade
import com.duckduckgo.app.privacy.model.improvedGrade
import com.duckduckgo.app.settings.db.SettingsDataStore
import com.duckduckgo.app.statistics.api.StatisticsUpdater
import com.duckduckgo.app.tabs.model.TabEntity
import com.duckduckgo.app.tabs.model.TabRepository
import com.duckduckgo.app.trackerdetection.model.TrackingEvent
import com.jakewharton.rxrelay2.PublishRelay
Expand Down Expand Up @@ -113,6 +115,7 @@ class BrowserTabViewModel(
}

val viewState: MutableLiveData<ViewState> = MutableLiveData()
val tabs: LiveData<List<TabEntity>> = tabRepository.liveTabs
val privacyGrade: MutableLiveData<PrivacyGrade> = MutableLiveData()
val url: SingleLiveEvent<String> = SingleLiveEvent()
val command: SingleLiveEvent<Command> = SingleLiveEvent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,4 @@ class BrowserViewModel(private val tabRepository: TabRepository) : ViewModel() {
fun onClearComplete() {
command.value = DisplayMessage(R.string.fireDataCleared)
}
}



}
18 changes: 17 additions & 1 deletion app/src/main/java/com/duckduckgo/app/browser/WebDataManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,32 @@

package com.duckduckgo.app.browser

import android.content.Context
import android.os.Build
import android.webkit.CookieManager
import android.webkit.WebStorage
import android.webkit.WebView
import android.webkit.WebViewDatabase

class WebDataManager(private val host: String) {

fun clearData(webView: WebView, webStorage: WebStorage) {
fun clearData(webView: WebView, webStorage: WebStorage, context: Context) {
webView.clearCache(true)
webView.clearHistory()
webStorage.deleteAllData()
webView.clearFormData()

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
clearFormData(WebViewDatabase.getInstance(context))
}
}

/**
* Deprecated and not needed on Oreo or later
*/
@Suppress("DEPRECATION")
private fun clearFormData(webViewDatabase: WebViewDatabase) {
webViewDatabase.clearFormData()
}

fun clearExternalCookies(cookieManager: CookieManager, clearAllCallback: (() -> Unit)) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/duckduckgo/app/global/job/JobBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.duckduckgo.app.global.job

import android.app.job.JobInfo
import android.app.job.JobInfo.BACKOFF_POLICY_EXPONENTIAL
import android.content.ComponentName
import android.content.Context
import com.duckduckgo.app.job.AppConfigurationJobService
Expand All @@ -32,6 +33,7 @@ class JobBuilder @Inject constructor(){
return JobInfo.Builder(APP_CONFIGURATION_JOB_ID, ComponentName(context, AppConfigurationJobService::class.java))
.setPeriodic(TimeUnit.HOURS.toMillis(3))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setBackoffCriteria(TimeUnit.MINUTES.toMillis(30), BACKOFF_POLICY_EXPONENTIAL)
.setPersisted(true)
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FireDialog(context: Context, clearStarted: (() -> Unit), clearComplete: ((

clearAllOption.setOnClickListener {
clearStarted()
dataManager.clearData(WebView(context), WebStorage.getInstance())
dataManager.clearData(WebView(context), WebStorage.getInstance(), context)
dataManager.clearExternalCookies(CookieManager.getInstance(), clearComplete)
dismiss()
}
Expand Down
70 changes: 70 additions & 0 deletions app/src/main/java/com/duckduckgo/app/tabs/ui/TabIconRenderer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.
*/

package com.duckduckgo.app.tabs.ui

import android.content.Context
import android.graphics.*
import android.graphics.drawable.Drawable
import android.support.v4.content.ContextCompat
import androidx.graphics.drawable.toBitmap
import androidx.graphics.drawable.toDrawable
import com.duckduckgo.app.browser.R

class TabIconRenderer {

companion object {

fun icon(context: Context, count: Int): Drawable {
val text = if (count < 100) "$count" else "~"
return makeDrawable(context, text)
}

private fun makeDrawable(context: Context, text: String): Drawable {
val drawable = context.getDrawable(R.drawable.ic_tabs_gray_24dp)
val bitmap = drawable.toBitmap().copy(Bitmap.Config.ARGB_8888, true)
val paint = createPaint(context)
val bounds = Rect()
paint.getTextBounds(text, 0, text.length, bounds)

val canvas = Canvas(bitmap)
val x = (bitmap.width / 2f) - bounds.centerX() - xOffset(context)
val y = (bitmap.height / 2f) - bounds.centerY() + yOffset(context)
canvas.drawText(text, x, y, paint)
return bitmap.toDrawable(context.resources)
}

private fun createPaint(context: Context): Paint {
val paint = Paint()
paint.apply {
color = ContextCompat.getColor(context, R.color.colorPrimary)
style = Paint.Style.FILL
textSize = context.resources.getDimensionPixelSize(R.dimen.tabIconTextSize).toFloat()
isAntiAlias = true
typeface = Typeface.DEFAULT_BOLD
}
return paint
}

private fun xOffset(context: Context): Int {
return context.resources.getDimensionPixelSize(R.dimen.tabIconXOffset)
}

private fun yOffset(context: Context): Int {
return context.resources.getDimensionPixelSize(R.dimen.tabIconYOffset)
}
}
}
11 changes: 5 additions & 6 deletions app/src/main/res/drawable/ic_fire_gray_24dp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="20dp"
android:viewportWidth="16"
android:viewportHeight="20">
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M5.843,19.778c-1.12,-0.644 -1.921,-1.778 -1.968,-3.112 -0.068,-2.488 1.716,-3.71 2.769,-5.377C8.154,8.889 7.742,7.4 7.742,7.4s1.258,0.69 1.99,3.245c0.229,0.755 0.275,1.511 0.206,2.222 -0.115,1.8 -0.915,3.422 -0.915,3.422s1.395,-0.29 1.784,-2.755c0.64,0.644 1.235,1.578 1.304,2.555 0.114,1.689 -0.915,3.244 -2.47,3.911 2.699,-0.6 4.62,-2.822 5.284,-4.444 0.846,-2.045 0.617,-3.867 0.48,-5.445 -0.183,-2.155 0.595,-3.755 0.595,-3.755s-1.487,0.422 -2.585,2.178c-0.503,0.8 -0.71,1.977 -0.71,1.977s0.115,-1.044 -0.595,-2.955c-0.71,-1.867 -1.35,-2.533 -1.739,-3.912C9.869,1.8 10.991,0 10.991,0S6.55,0.8 4.537,4.556C2.754,7.889 3.486,9.889 3.486,9.889s-0.755,-0.69 -1.144,-1.644c-0.389,-0.956 -0.298,-1.822 -0.298,-1.822S-1.113,9.8 0.42,14.045c1.03,2.978 3.021,4.932 5.423,5.733z"
android:pathData="M9.573,23.744c-1.26,-0.74 -2.16,-2.044 -2.213,-3.578 -0.078,-2.862 1.93,-4.267 3.114,-6.184 1.7,-2.76 1.236,-4.472 1.236,-4.472s1.415,0.793 2.239,3.732c0.257,0.868 0.308,1.738 0.23,2.555 -0.128,2.07 -1.029,3.935 -1.029,3.935s1.57,-0.332 2.008,-3.168c0.72,0.74 1.39,1.815 1.467,2.939 0.129,1.941 -1.03,3.73 -2.78,4.497 3.037,-0.69 5.199,-3.245 5.946,-5.111 0.952,-2.351 0.694,-4.446 0.54,-6.261 -0.206,-2.479 0.669,-4.319 0.669,-4.319s-1.673,0.485 -2.908,2.505c-0.566,0.92 -0.799,2.274 -0.799,2.274s0.13,-1.2 -0.67,-3.4c-0.797,-2.145 -1.517,-2.912 -1.956,-4.497 -0.565,-2.12 0.697,-4.191 0.697,-4.191s-4.993,0.92 -7.258,5.239c-2.008,3.833 -1.184,6.133 -1.184,6.133s-0.85,-0.793 -1.287,-1.89c-0.437,-1.1 -0.335,-2.096 -0.335,-2.096s-3.552,3.885 -1.828,8.766c1.16,3.424 3.4,5.672 6.101,6.592z"
android:fillColor="#AAA"
android:fillType="evenOdd"/>
</vector>
10 changes: 5 additions & 5 deletions app/src/main/res/drawable/ic_tabs_gray_24dp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M17.922,0A2.08,2.08 0,0 1,20 2.078v10.39a2.08,2.08 0,0 1,-2.078 2.077h-0.787a1.037,1.037 0,0 1,-1.038 -1.039,1.04 1.04,0 0,1 1.046,-1.039h0.78l-0.002,-10.39 -10.389,0.002v0.77a1.036,1.036 0,0 1,-1.039 1.054,1.039 1.039,0 0,1 -1.039,-1.046v-0.78A2.08,2.08 0,0 1,7.532 0h10.39zM12.468,5.455L2.078,5.455A2.08,2.08 0,0 0,0 7.533v10.39A2.08,2.08 0,0 0,2.078 20h10.39a2.08,2.08 0,0 0,2.078 -2.078L14.546,7.532a2.08,2.08 0,0 0,-2.078 -2.077z"
android:pathData="M16.712,5.17H7.945V3.385H20.63V14.98h-1.885V7.213c0,-1.128 -0.91,-2.042 -2.032,-2.042zM23,2.193C23,1.536 22.467,1 21.815,1H6.907c-0.025,0 -0.047,0.013 -0.074,0.015 -0.025,0 -0.048,-0.015 -0.074,-0.015 -0.652,0 -1.185,0.536 -1.185,1.192V5.17H3.033A2.037,2.037 0,0 0,1 7.213v13.744C1,22.085 1.91,23 3.033,23h13.679a2.038,2.038 0,0 0,2.032 -2.043v-3.592h3.07c0.653,0 1.186,-0.536 1.186,-1.192 0,-0.027 -0.013,-0.048 -0.014,-0.075 0,-0.025 0.014,-0.048 0.014,-0.074V2.192z"
android:fillColor="#AAA"
android:fillType="evenOdd"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
<dimen name="onboardingButtonPadding">10dp</dimen>
<dimen name="onboardingTitleTextSize">21sp</dimen>
<dimen name="onboardingSubtitleTextSize">16sp</dimen>

<dimen name="tabIconTextSize">12dp</dimen> <!-- Intentional use of dp not sp -->
<dimen name="tabIconXOffset">2.3dp</dimen>
<dimen name="tabIconYOffset">2dp</dimen>

</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

<!-- AutoComplete Suggestions -->
<string name="editQueryBeforeSubmitting">Edit query before searching</string>
<string name="settings_autocomplete_enabled">Autcomplete Suggestions</string>
<string name="settings_autocomplete_enabled">Autocomplete Suggestions</string>

<!-- Tabs -->
<string name="homeTab">DuckDuckGo</string>
Expand Down
Binary file added styleguide/IDE_kotlin_style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added styleguide/IDE_line_wrap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 49b4f44

Please sign in to comment.