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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.duckduckgo.app.statistics

import android.os.Build
import android.support.test.filters.SdkSuppress
import com.duckduckgo.app.statistics.store.StatisticsDataStore
import com.nhaarman.mockito_kotlin.*
import org.junit.Assert.assertEquals
Expand Down Expand Up @@ -95,8 +93,7 @@ class ExperimentationVariantManagerTest {


@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
fun whenNougatOrLaterAndNoVariantPersistedThenNewVariantAllocated() {
fun whenNoVariantPersistedThenNewVariantAllocated() {
activeVariants.add(Variant("foo", 100.0))

testee.getVariant(activeVariants)
Expand All @@ -105,30 +102,11 @@ class ExperimentationVariantManagerTest {
}

@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
fun whenNougatOrLaterAndNoVariantPersistedThenNewVariantKeyIsAllocatedAndPersisted() {
fun whenNoVariantPersistedThenNewVariantKeyIsAllocatedAndPersisted() {
activeVariants.add(Variant("foo", 100.0))

testee.getVariant(activeVariants)

verify(mockStore).variant = "foo"
}

@Test
@SdkSuppress(maxSdkVersion = Build.VERSION_CODES.M)
fun whenMarshmallowOrEarlierAndNoVariantPersistedThenDefaultVariantAllocated() {
activeVariants.add(Variant("foo", 100.0))

assertEquals(VariantManager.DEFAULT_VARIANT, testee.getVariant(activeVariants))
}

@Test
@SdkSuppress(maxSdkVersion = Build.VERSION_CODES.M)
fun whenMarshmallowOrEarlierAndNoVariantPersistedThenDefaultVariantKeyIsAllocatedAndPersisted() {
activeVariants.add(Variant("foo", 100.0))

testee.getVariant(activeVariants)

verify(mockStore).variant = VariantManager.DEFAULT_VARIANT.key
}
}
6 changes: 2 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:label="@string/appName"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme.Dark"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<meta-data
android:name="android.webkit.WebView.MetricsOptOut"
Expand All @@ -34,7 +34,6 @@
android:label="@string/appName">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down Expand Up @@ -116,8 +115,7 @@
android:theme="@style/ModalCardTheme" />
<activity
android:name="com.duckduckgo.app.fire.FireActivity"
android:process="@string/fireProcessName"
android:theme="@style/SplashTheme" />
android:process="@string/fireProcessName" />

<service
android:name="com.duckduckgo.app.job.AppConfigurationJobService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BrowserTabFragment : Fragment(), FindListener {
lateinit var shortcutBuilder: ShortcutBuilder

@Inject
lateinit var clipboardManager: ClipboardManager
lateinit var clipboardManager: ClipboardManager

val tabId get() = arguments!![TAB_ID_ARG] as String

Expand Down Expand Up @@ -209,6 +209,7 @@ class BrowserTabFragment : Fragment(), FindListener {
override fun onResume() {
super.onResume()
addTextChangedListeners()
appBarLayout.setExpanded(true)
viewModel.onViewVisible()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class BrowserWebViewClient @Inject constructor(

private fun reportHttpsUpgradeSiteError(url: Uri, error: String?) {
val params = mapOf(
APP_VERSION to "${BuildConfig.VERSION_NAME}",
APP_VERSION to BuildConfig.VERSION_NAME,
URL to url.simpleUrl,
ERROR_CODE to error
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ import android.support.v4.app.Fragment
import com.duckduckgo.app.browser.BuildConfig
import com.duckduckgo.app.di.AppComponent
import com.duckduckgo.app.di.DaggerAppComponent
import com.duckduckgo.app.fire.UnsentForgetAllPixelStore
import com.duckduckgo.app.fire.FireActivity
import com.duckduckgo.app.fire.UnsentForgetAllPixelStore
import com.duckduckgo.app.global.Theming.initializeTheme
import com.duckduckgo.app.global.install.AppInstallStore
import com.duckduckgo.app.global.notification.NotificationRegistrar
import com.duckduckgo.app.global.shortcut.AppShortcutCreator
import com.duckduckgo.app.httpsupgrade.HttpsUpgrader
import com.duckduckgo.app.job.AppConfigurationSyncer
import com.duckduckgo.app.migration.LegacyMigration
import com.duckduckgo.app.settings.db.SettingsDataStore
import com.duckduckgo.app.statistics.VariantManager
import com.duckduckgo.app.statistics.api.StatisticsUpdater
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.app.statistics.pixels.Pixel.PixelName.APP_LAUNCH
Expand Down Expand Up @@ -82,9 +85,15 @@ open class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, HasS
@Inject
lateinit var appInstallStore: AppInstallStore

@Inject
lateinit var settingsDataStore: SettingsDataStore

@Inject
lateinit var notificationRegistrar: NotificationRegistrar

@Inject
lateinit var variantManager: VariantManager

@Inject
lateinit var pixel: Pixel

Expand Down Expand Up @@ -118,6 +127,7 @@ open class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, HasS
}

initializeStatistics()
initializeTheme(settingsDataStore, variantManager.getVariant())
loadTrackerData()
configureDataDownloader()
recordInstallationTimestamp()
Expand Down
49 changes: 22 additions & 27 deletions app/src/main/java/com/duckduckgo/app/global/Theming.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import android.content.Intent
import android.content.IntentFilter
import android.support.v4.content.LocalBroadcastManager
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.global.ThemingConstants.BROADCAST_THEME_CHANGED
import com.duckduckgo.app.global.DuckDuckGoTheme.DARK
import com.duckduckgo.app.global.DuckDuckGoTheme.LIGHT
import com.duckduckgo.app.global.Theming.Constants.BROADCAST_THEME_CHANGED
import com.duckduckgo.app.global.Theming.Constants.THEME_MAP
import com.duckduckgo.app.settings.db.SettingsDataStore
import com.duckduckgo.app.statistics.Variant
import com.duckduckgo.app.statistics.VariantManager.VariantFeature.ThemeFeature.LightThemeAsDefault
Expand All @@ -33,16 +36,28 @@ enum class DuckDuckGoTheme {
LIGHT;
}

fun DuckDuckGoActivity.applyTheme(settingsDataStore: SettingsDataStore, variant: Variant): BroadcastReceiver? {
object Theming {

if (settingsDataStore.theme == null) {
settingsDataStore.theme = defaultApplicationTheme(variant)
fun initializeTheme(settingsDataStore: SettingsDataStore, variant: Variant) {
if (settingsDataStore.theme == null) {
settingsDataStore.theme = if (variant.hasFeature(LightThemeAsDefault)) LIGHT else DARK
}
}

if (!isThemeConfigurable()) {
return null
object Constants {

const val BROADCAST_THEME_CHANGED = "BROADCAST_THEME_CHANGED"

val THEME_MAP = mapOf(
Pair(R.style.AppTheme, DuckDuckGoTheme.LIGHT) to R.style.AppTheme_Light,
Pair(R.style.AppTheme, DuckDuckGoTheme.DARK) to R.style.AppTheme_Dark
)
}
setTheme(themeId(settingsDataStore, variant))
}

fun DuckDuckGoActivity.applyTheme(settingsDataStore: SettingsDataStore, variant: Variant): BroadcastReceiver? {
val themeId = THEME_MAP[Pair(manifestThemeId(), settingsDataStore.theme)] ?: return null
setTheme(themeId)
return registerForThemeChangeBroadcast()
}

Expand All @@ -62,26 +77,6 @@ fun DuckDuckGoActivity.sendThemeChangedBroadcast() {
manager.sendBroadcast(Intent(BROADCAST_THEME_CHANGED))
}

private fun themeId(settingsDataStore: SettingsDataStore, variant: Variant): Int {
val theme = settingsDataStore.theme ?: defaultApplicationTheme(variant)
return when (theme) {
DuckDuckGoTheme.LIGHT -> R.style.AppTheme_Light
DuckDuckGoTheme.DARK -> R.style.AppTheme_Dark
}
}

private fun DuckDuckGoActivity.isThemeConfigurable(): Boolean {
return manifestThemeId() == R.style.AppTheme_Dark || manifestThemeId() == R.style.AppTheme_Light
}

private fun DuckDuckGoActivity.manifestThemeId(): Int {
return packageManager.getActivityInfo(componentName, 0).themeResource
}

private fun defaultApplicationTheme(variant: Variant): DuckDuckGoTheme {
return if (variant.hasFeature(LightThemeAsDefault)) DuckDuckGoTheme.LIGHT else DuckDuckGoTheme.DARK
}

object ThemingConstants {
const val BROADCAST_THEME_CHANGED = "BROADCAST_THEME_CHANGED"
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class HttpsUpgradeDataDownloader @Inject constructor(
return@defer complete()
}
val params = mapOf(
APP_VERSION to "${BuildConfig.VERSION_NAME}",
APP_VERSION to BuildConfig.VERSION_NAME,
TOTAL_COUNT to statisticsDataStore.httpsUpgradesTotal.toString(),
FAILURE_COUNT to statisticsDataStore.httpsUpgradesFailures.toString()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,8 @@ class ExperimentationVariantManager(
}

private fun generateVariant(activeVariants: List<Variant>): Variant {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
Timber.i("No variants available for pre-Nougat devices")
return DEFAULT_VARIANT
}

val randomizedIndex = indexRandomizer.random(activeVariants)
return activeVariants[randomizedIndex]

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class TabSwitcherAdapter(private val context: Context, private val itemClickList
holder.url.text = tab.displayUrl()
holder.tabUnread.visibility = if (tab.viewed) View.INVISIBLE else View.VISIBLE
holder.root.setBackgroundResource(if (tab.tabId == selectedTab?.tabId) SELECTED_BACKGROUND else DEFAULT_BACKGROUND)
holder.root.alpha = if (tab.tabId == selectedTab?.tabId) SELECTED_ALPHA else DEFAULT_ALPHA

GlideApp.with(holder.root)
.load(tab.favicon())
Expand Down Expand Up @@ -103,10 +102,6 @@ class TabSwitcherAdapter(private val context: Context, private val itemClickList
private const val SELECTED_BACKGROUND = R.drawable.tab_background_selected
@DrawableRes
private const val DEFAULT_BACKGROUND = R.drawable.tab_background

private const val SELECTED_ALPHA = 1.0f
private const val DEFAULT_ALPHA = 0.77f

}

}
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/tab_background_selected.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
<solid android:color="@color/white" />
<stroke
android:width="2dp"
android:color="@color/skyBlue" />
android:color="?attr/tabSelectedBorderColor" />
<corners android:radius="2dp" />
</shape>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/tab_unread.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#678FFF" />
<solid android:color="@color/cornflowerBlue" />
</shape>
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_tab_switcher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/tabsBackgroundColor"
tools:context="com.duckduckgo.app.tabs.ui.TabSwitcherActivity">

<include layout="@layout/include_toolbar" />
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/layout/content_tab_switcher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
android:id="@+id/tabsRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
tools:itemCount="3"
tools:listitem="@layout/item_tab" />

Expand All @@ -47,7 +49,7 @@
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:text="@string/tapFireDirective"
android:textColor="@color/white"
android:textColor="?attr/tabsFireTextColor"
android:textSize="14sp"
android:textStyle="normal" />

Expand All @@ -58,14 +60,14 @@
android:layout_marginEnd="6dp"
android:contentDescription="@string/tapFireIconDescription"
android:src="@drawable/ic_fire_24dp"
android:tint="@color/white" />
android:tint="?attr/tabsFireTextColor" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:text="@string/tapFireExplanation"
android:textColor="@color/white"
android:textColor="?attr/tabsFireTextColor"
android:textSize="14sp"
android:textStyle="normal" />

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/include_omnibar_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/OmnibarToolbarTheme"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/include_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ToolbarTheme"
app:popupTheme="@style/AppTheme.Dark.PopupOverlay" />

Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/item_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="10dp"
android:background="@drawable/tab_background">
android:layout_marginBottom="5dp"
android:background="@drawable/tab_background"
android:elevation="2dp">

<ImageView
android:id="@+id/tabUnread"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
<attr name="omnibarTextColor" format="color" />
<attr name="omnibarHintColor" format="color" />
<attr name="autoCompleteTextColor" format="color" />
<attr name="tabsBackgroundColor" format="color" />
<attr name="tabTitleTextColor" format="color" />
<attr name="tabSubtitleTextColor" format="color" />
<attr name="tabSelectedBorderColor" format="color" />
<attr name="tabsFireTextColor" format="color" />
<attr name="bookmarkIconColor" format="color" />
<attr name="bookmarkTitleTextColor" format="color" />
<attr name="bookmarkSubtitleTextColor" format="color" />
<attr name="settingsSectionTextColor" format="color" />
<attr name="settingsItemTextColor" format="color" />
<attr name="settingsMinorTextColor" format="color" />
<attr name="settingsSwitchBackgroundColor" format="color" />

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

<style name="SettingsItem.SettingsSwitch">
<item name="colorSwitchThumbNormal">@color/white</item>
<item name="android:colorForeground">@color/subtleGrayTwo</item>
<item name="android:colorForeground">?attr/settingsSwitchBackgroundColor</item>
<item name="android:layout_marginEnd">0dp</item>
<item name="android:layout_marginStart">0dp</item>
<item name="android:layout_marginTop">0dp</item>
Expand Down
Loading