For #21413 - Remove unused OnboardingPrivateBrowsingViewHolder and OnboardingWhatsNewViewHolder
parent
87e4a250f1
commit
98b218d964
@ -1,95 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.text.SpannableString
|
||||
import android.text.Spanned
|
||||
import android.text.style.ImageSpan
|
||||
import android.view.View
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import mozilla.components.support.ktx.android.content.getColorFromAttr
|
||||
import mozilla.components.support.ktx.android.content.getDrawableWithTint
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.databinding.OnboardingPrivateBrowsingBinding
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.setBounds
|
||||
import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor
|
||||
|
||||
class OnboardingPrivateBrowsingViewHolder(
|
||||
view: View,
|
||||
private val interactor: OnboardingInteractor
|
||||
) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
init {
|
||||
val binding = OnboardingPrivateBrowsingBinding.bind(view)
|
||||
binding.headerText.setOnboardingIcon(R.drawable.ic_onboarding_private_browsing)
|
||||
|
||||
// Display a private browsing icon as a character inside the description text.
|
||||
val inlineIcon = PrivateBrowsingImageSpan(
|
||||
view.context,
|
||||
R.drawable.ic_private_browsing,
|
||||
tint = view.context.getColorFromAttr(R.attr.primaryText),
|
||||
size = binding.descriptionTextOnce.lineHeight
|
||||
)
|
||||
|
||||
val text = SpannableString(view.context.getString(R.string.onboarding_private_browsing_description1)).apply {
|
||||
val spanStartIndex = indexOf(IMAGE_PLACEHOLDER)
|
||||
setSpan(
|
||||
inlineIcon,
|
||||
spanStartIndex,
|
||||
spanStartIndex + IMAGE_PLACEHOLDER.length,
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
}
|
||||
|
||||
binding.descriptionTextOnce.text = text
|
||||
binding.descriptionTextOnce.contentDescription = String.format(text.toString(), binding.headerText.text)
|
||||
binding.openSettingsButton.setOnClickListener {
|
||||
it.context.components.analytics.metrics.track(Event.OnboardingPrivateBrowsing)
|
||||
interactor.onOpenSettingsClicked()
|
||||
}
|
||||
}
|
||||
|
||||
class PrivateBrowsingImageSpan(
|
||||
context: Context,
|
||||
@DrawableRes drawableId: Int,
|
||||
@ColorInt tint: Int,
|
||||
size: Int
|
||||
) : ImageSpan(
|
||||
context.getDrawableWithTint(drawableId, tint)!!.apply { setBounds(size) }
|
||||
) {
|
||||
override fun draw(
|
||||
canvas: Canvas,
|
||||
text: CharSequence?,
|
||||
start: Int,
|
||||
end: Int,
|
||||
x: Float,
|
||||
top: Int,
|
||||
y: Int,
|
||||
bottom: Int,
|
||||
paint: Paint
|
||||
) {
|
||||
canvas.save()
|
||||
val fmPaint = paint.fontMetricsInt
|
||||
val fontHeight = fmPaint.descent - fmPaint.ascent
|
||||
val centerY = y + fmPaint.descent - fontHeight / 2
|
||||
val transY = (centerY - (drawable.bounds.bottom - drawable.bounds.top) / 2).toFloat()
|
||||
canvas.translate(x, transY)
|
||||
drawable.draw(canvas)
|
||||
canvas.restore()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val IMAGE_PLACEHOLDER = "%s"
|
||||
const val LAYOUT_ID = R.layout.onboarding_private_browsing
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding
|
||||
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.databinding.OnboardingWhatsNewBinding
|
||||
import org.mozilla.fenix.ext.addUnderline
|
||||
import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor
|
||||
|
||||
class OnboardingWhatsNewViewHolder(
|
||||
view: View,
|
||||
private val interactor: OnboardingInteractor
|
||||
) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
init {
|
||||
val binding = OnboardingWhatsNewBinding.bind(view)
|
||||
binding.headerText.setOnboardingIcon(R.drawable.ic_whats_new)
|
||||
|
||||
val appName = view.context.getString(R.string.app_name)
|
||||
binding.descriptionText.text = view.context.getString(R.string.onboarding_whats_new_description, appName)
|
||||
|
||||
binding.getAnswers.addUnderline()
|
||||
binding.getAnswers.setOnClickListener {
|
||||
interactor.onWhatsNewGetAnswersClicked()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val LAYOUT_ID = R.layout.onboarding_whats_new
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M17.5 17c-2.1 0-3.5-2.5-5.5-2.5S8.4 17 6.5 17C3.9 17 2 14.6 2 10.4 2 7.8 2.8 7 6.1 7s4.3 1.4 5.9 1.4c1.6 0 2.6-1.4 5.9-1.4 3.3 0 4.1 0.8 4.1 3.4 0 4.2-1.9 6.6-4.5 6.6zm-9.8-6.8c-2 0.1-2.9 1.3-2.9 1.6 0 0.3 1.3 1.1 2.7 1.1 1.3 0 2.9-0.5 2.9-0.9 0-0.5-0.8-1.9-2.7-1.8zm8.6 0c-1.9-0.1-2.7 1.3-2.7 1.8 0 0.4 1.5 0.9 2.9 0.9s2.7-0.8 2.7-1.1c-0.1-0.3-0.9-1.5-2.9-1.6z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:type="linear"
|
||||
android:tileMode="clamp"
|
||||
android:startX="23.24"
|
||||
android:startY="-0.94"
|
||||
android:endX="1.81"
|
||||
android:endY="16.33">
|
||||
<item android:color="#5C29CC" android:offset="0" />
|
||||
<item android:color="#7A145C" android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
</vector>
|
@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/ic_whats_new" />
|
||||
<item
|
||||
android:left="200dp"
|
||||
android:bottom="200dp">
|
||||
<shape
|
||||
android:shape="oval">
|
||||
|
||||
<solid android:color="@color/whats_new_notification_color" />
|
||||
<size
|
||||
android:width="48dp"
|
||||
android:height="48dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/onboarding_card"
|
||||
style="@style/OnboardingCardLightWithPadding"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/header_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
tools:drawableStart="@drawable/ic_onboarding_private_browsing"
|
||||
android:drawablePadding="12dp"
|
||||
android:text="@string/onboarding_private_browsing_header"
|
||||
android:textAppearance="@style/HeaderTextStyle"
|
||||
android:gravity="center_vertical"
|
||||
android:lines="1"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
<TextView
|
||||
android:id="@+id/description_text_once"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/Body14TextStyle"
|
||||
android:layout_marginTop="14dp"
|
||||
tools:text="@string/onboarding_private_browsing_description1"
|
||||
app:layout_constraintTop_toBottomOf="@id/header_text"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/description_text_always" />
|
||||
<TextView
|
||||
android:id="@+id/description_text_always"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/Body14TextStyle"
|
||||
android:layout_marginTop="14dp"
|
||||
android:text="@string/onboarding_private_browsing_always_description"
|
||||
app:layout_constraintTop_toBottomOf="@id/description_text_once"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/open_settings_button" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/open_settings_button"
|
||||
style="@style/NeutralOnboardingButton"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/onboarding_private_browsing_button"
|
||||
app:layout_constraintTop_toBottomOf="@id/description_text_always"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,55 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/onboarding_card"
|
||||
style="@style/OnboardingCardLight"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/header_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawablePadding="12dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/onboarding_whats_new_header1"
|
||||
android:textAppearance="@style/HeaderTextStyle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:drawableStart="@drawable/ic_whats_new" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:textAppearance="@style/Body14TextStyle"
|
||||
app:layout_constraintBottom_toTopOf="@id/get_answers"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/header_text"
|
||||
tools:text="@string/onboarding_whats_new_description" />
|
||||
|
||||
<org.mozilla.fenix.utils.LinkTextView
|
||||
android:id="@+id/get_answers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="18dp"
|
||||
android:text="@string/onboarding_whats_new_description_linktext"
|
||||
android:textAppearance="@style/Body14TextStyle"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/description_text" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,40 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.databinding.OnboardingPrivateBrowsingBinding
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class OnboardingPrivacyBrowsingViewHolderTest {
|
||||
|
||||
private lateinit var binding: OnboardingPrivateBrowsingBinding
|
||||
private lateinit var interactor: OnboardingInteractor
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
val context = ContextThemeWrapper(testContext, R.style.NormalTheme)
|
||||
binding = OnboardingPrivateBrowsingBinding.inflate(LayoutInflater.from(context))
|
||||
interactor = mockk(relaxed = true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `call interactor on click`() {
|
||||
OnboardingPrivateBrowsingViewHolder(binding.root, interactor)
|
||||
|
||||
binding.openSettingsButton.performClick()
|
||||
verify { interactor.onOpenSettingsClicked() }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue