1
0
Fork 0

For #2390 - Adds a theme picker card

- applies generic styling to cards
- adds margins to headers and onboarding cards
master
Jeff Boek 2019-05-15 21:53:31 -07:00
parent fe16810ddb
commit 8928b19079
9 changed files with 77 additions and 3 deletions

View File

@ -22,6 +22,7 @@ import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabInCollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingHeaderViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingSectionHeaderViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingThemePickerViewHolder
import java.lang.IllegalStateException
sealed class AdapterItem {
@ -40,6 +41,7 @@ sealed class AdapterItem {
object OnboardingHeader : AdapterItem()
data class OnboardingSectionHeader(val labelBuilder: (Context) -> String) : AdapterItem()
object OnboardingThemePicker : AdapterItem()
val viewType: Int
get() = when (this) {
@ -55,6 +57,7 @@ sealed class AdapterItem {
is TabInCollectionItem -> TabInCollectionViewHolder.LAYOUT_ID
OnboardingHeader -> OnboardingHeaderViewHolder.LAYOUT_ID
is OnboardingSectionHeader -> OnboardingSectionHeaderViewHolder.LAYOUT_ID
OnboardingThemePicker -> OnboardingThemePickerViewHolder.LAYOUT_ID
}
}
@ -87,6 +90,7 @@ class SessionControlAdapter(
TabInCollectionViewHolder.LAYOUT_ID -> TabInCollectionViewHolder(view, actionEmitter, job)
OnboardingHeaderViewHolder.LAYOUT_ID -> OnboardingHeaderViewHolder(view)
OnboardingSectionHeaderViewHolder.LAYOUT_ID -> OnboardingSectionHeaderViewHolder(view)
OnboardingThemePickerViewHolder.LAYOUT_ID -> OnboardingThemePickerViewHolder(view)
else -> throw IllegalStateException()
}
}

View File

@ -66,7 +66,8 @@ private fun onboardingAdapterItems(): List<AdapterItem> = listOf(
AdapterItem.OnboardingSectionHeader() {
val appName = it.getString(R.string.app_name)
it.getString(R.string.onboarding_feature_section_header, appName)
}
},
AdapterItem.OnboardingThemePicker
)
private fun SessionControlState.toAdapterList(): List<AdapterItem> = when (mode) {

View File

@ -0,0 +1,22 @@
/* 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.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.onboarding_section_header.view.*
import org.mozilla.fenix.R
class OnboardingThemePickerViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
fun bind(labelBuilder: (Context) -> String) {
view.section_header_text.text = labelBuilder(view.context)
}
companion object {
const val LAYOUT_ID = R.layout.onboarding_theme_picker
}
}

View File

@ -0,0 +1,10 @@
<?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/. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp" android:color="?shadow" />
<solid android:color="?inset" />
<corners android:radius="8dp" />
</shape>

View File

@ -6,7 +6,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/onboarding_header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginBottom="8dp">
<TextView
android:id="@+id/header_text"
android:layout_width="match_parent"

View File

@ -6,7 +6,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/onboarding_header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<TextView
android:id="@+id/section_header_text"
android:layout_width="match_parent"

View File

@ -0,0 +1,25 @@
<?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/. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/onboarding_header"
style="@style/OnboardingCardLight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/theme_picker_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="14dp"
android:text="@string/onboarding_theme_picker_header"
android:textAppearance="@style/HeaderTextStyle" />
<TextView
android:id="@+id/theme_picker_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/onboarding_theme_picker_description"
android:textAppearance="@style/Body14TextStyle" />
</LinearLayout>

View File

@ -494,4 +494,8 @@
<!-- text for the Firefox Preview feature section header
The first parameter is the name of the app defined in app_name (for example: Firefox Preview) -->
<string name="onboarding_feature_section_header">Get to know %s</string>
<!-- text for the theme picker onboarding card header -->
<string name="onboarding_theme_picker_header">Choose your theme</string>
<!-- text for the theme picker onboarding card description -->
<string name="onboarding_theme_picker_description">Save some battery and your eyesight by enabling dark mode.</string>
</resources>

View File

@ -225,4 +225,10 @@
<item name="android:background">?android:attr/selectableItemBackground</item>
<item name="android:textColor">?accentBright</item>
</style>
<style name="OnboardingCardLight">
<item name="android:background">@drawable/onboarding_card_background_light</item>
<item name="android:padding">16dp</item>
<item name="android:layout_marginBottom">16dp</item>
</style>
</resources>