1
0
Fork 0

For #2390 - Adds the start browser button

master
Jeff Boek 2019-05-15 22:56:13 -07:00
parent b2e6b59e91
commit 95af2ddcc6
10 changed files with 149 additions and 40 deletions

View File

@ -45,6 +45,7 @@ import org.mozilla.fenix.ext.share
import org.mozilla.fenix.ext.urlToTrimmedHost
import org.mozilla.fenix.home.sessioncontrol.CollectionAction
import org.mozilla.fenix.home.sessioncontrol.Mode
import org.mozilla.fenix.home.sessioncontrol.OnboardingAction
import org.mozilla.fenix.home.sessioncontrol.SessionControlAction
import org.mozilla.fenix.home.sessioncontrol.SessionControlChange
import org.mozilla.fenix.home.sessioncontrol.SessionControlComponent
@ -219,6 +220,7 @@ class HomeFragment : Fragment(), CoroutineScope {
when (it) {
is SessionControlAction.Tab -> handleTabAction(it.action)
is SessionControlAction.Collection -> handleCollectionAction(it.action)
is SessionControlAction.Onboarding -> handleOnboardingAction(it.action)
}
}
}
@ -237,6 +239,17 @@ class HomeFragment : Fragment(), CoroutineScope {
super.onStop()
}
private fun handleOnboardingAction(action: OnboardingAction) {
Do exhaustive when (action) {
is OnboardingAction.Finish -> {
onboarding.finish()
val mode = currentMode()
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.ModeChange(mode))
}
}
}
@SuppressWarnings("ComplexMethod")
private fun handleTabAction(action: TabAction) {
Do exhaustive when (action) {

View File

@ -20,6 +20,7 @@ import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionHeaderViewHol
import org.mozilla.fenix.home.sessioncontrol.viewholders.NoCollectionMessageViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabInCollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingFinishViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingFirefoxAccountViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingHeaderViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingPrivacyNoticeViewHolder
@ -50,6 +51,7 @@ sealed class AdapterItem {
object OnboardingTrackingProtection : AdapterItem()
object OnboardingPrivateBrowsing : AdapterItem()
object OnboardingPrivacyNotice : AdapterItem()
object OnboardingFinish : AdapterItem()
val viewType: Int
get() = when (this) {
@ -70,6 +72,7 @@ sealed class AdapterItem {
OnboardingTrackingProtection -> OnboardingTrackingProtectionViewHolder.LAYOUT_ID
OnboardingPrivateBrowsing -> OnboardingPrivateBrowsingViewHolder.LAYOUT_ID
OnboardingPrivacyNotice -> OnboardingPrivacyNoticeViewHolder.LAYOUT_ID
OnboardingFinish -> OnboardingFinishViewHolder.LAYOUT_ID
}
}
@ -107,6 +110,7 @@ class SessionControlAdapter(
OnboardingTrackingProtectionViewHolder.LAYOUT_ID -> OnboardingTrackingProtectionViewHolder(view)
OnboardingPrivateBrowsingViewHolder.LAYOUT_ID -> OnboardingPrivateBrowsingViewHolder(view)
OnboardingPrivacyNoticeViewHolder.LAYOUT_ID -> OnboardingPrivacyNoticeViewHolder(view)
OnboardingFinishViewHolder.LAYOUT_ID -> OnboardingFinishViewHolder(view, actionEmitter)
else -> throw IllegalStateException()
}
}

View File

@ -92,9 +92,14 @@ sealed class CollectionAction : Action {
data class RemoveTab(val collection: TabCollection, val tab: Tab) : CollectionAction()
}
sealed class OnboardingAction : Action {
object Finish : OnboardingAction()
}
sealed class SessionControlAction : Action {
data class Tab(val action: TabAction) : SessionControlAction()
data class Collection(val action: CollectionAction) : SessionControlAction()
data class Onboarding(val action: OnboardingAction) : SessionControlAction()
}
fun Observer<SessionControlAction>.onNext(tabAction: TabAction) {
@ -105,6 +110,10 @@ fun Observer<SessionControlAction>.onNext(collectionAction: CollectionAction) {
onNext(SessionControlAction.Collection(collectionAction))
}
fun Observer<SessionControlAction>.onNext(onboardingAction: OnboardingAction) {
onNext(SessionControlAction.Onboarding(onboardingAction))
}
sealed class SessionControlChange : Change {
data class TabsChange(val tabs: List<Tab>) : SessionControlChange()
data class ModeChange(val mode: Mode) : SessionControlChange()

View File

@ -71,7 +71,8 @@ private fun onboardingAdapterItems(): List<AdapterItem> = listOf(
AdapterItem.OnboardingThemePicker,
AdapterItem.OnboardingTrackingProtection,
AdapterItem.OnboardingPrivateBrowsing,
AdapterItem.OnboardingPrivacyNotice
AdapterItem.OnboardingPrivacyNotice,
AdapterItem.OnboardingFinish
)
private fun SessionControlState.toAdapterList(): List<AdapterItem> = when (mode) {

View File

@ -0,0 +1,29 @@
/* 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 io.reactivex.Observer
import kotlinx.android.synthetic.main.onboarding_finish.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.home.sessioncontrol.OnboardingAction
import org.mozilla.fenix.home.sessioncontrol.SessionControlAction
import org.mozilla.fenix.home.sessioncontrol.onNext
class OnboardingFinishViewHolder(
view: View,
private val actionEmitter: Observer<SessionControlAction>
) : RecyclerView.ViewHolder(view) {
init {
view.finish_button.setOnClickListener {
actionEmitter.onNext(OnboardingAction.Finish)
}
}
companion object {
const val LAYOUT_ID = R.layout.onboarding_finish
}
}

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.onboarding
import android.content.Context
import android.content.SharedPreferences
import org.mozilla.fenix.BuildConfig
class FenixOnboarding(private val context: Context) {
private val onboardingPrefs = context.applicationContext.getSharedPreferences(
@ -17,11 +18,23 @@ class FenixOnboarding(private val context: Context) {
get() = getInt(OnboardingKeys.LAST_VERSION.key, 0)
set(version) { edit().putInt(OnboardingKeys.LAST_VERSION.key, version).apply() }
// Temporary variable to keep track for building purposes only
private var tempFinish = false
fun finish() {
if (BuildConfig.DEBUG) {
tempFinish = true
return
}
onboardingPrefs.onboardedVersion = CURRENT_ONBOARDING_VERSION
}
fun userHasBeenOnboarded(): Boolean = onboardingPrefs.onboardedVersion == CURRENT_ONBOARDING_VERSION
fun userHasBeenOnboarded(): Boolean {
if (!BuildConfig.DEBUG || tempFinish) return true
return onboardingPrefs.onboardedVersion == CURRENT_ONBOARDING_VERSION
}
private enum class OnboardingKeys(val key: String) {
PREF_NAME("fenix.onboarding"),

View File

@ -0,0 +1,9 @@
<?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">
<corners android:radius="8dp"/>
<solid android:color="?inset" />
</shape>

View File

@ -0,0 +1,29 @@
<?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/. -->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/finish_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="@drawable/onboarding_button_background"
android:backgroundTint="?accent"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:textStyle="bold"
android:gravity="center"
android:text="@string/onboarding_finish"
android:textColor="?contrastText"
android:textSize="16sp" />
</FrameLayout>

View File

@ -17,4 +17,44 @@
%1$s puts you in control.
\n\n%1$s is produced by Mozilla.
</string>
<!-- Onboarding -->
<!-- Text for onboarding welcome message
The first parameter is the name of the app defined in app_name (for example: Firefox Preview) -->
<string name="onboarding_header" translatable="false">Welcome to %s!</string>
<!-- text for the Firefox Accounts section header -->
<string name="onboarding_fxa_section_header" translatable="false">Already have an account?</string>
<!-- 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" translatable="false">Get to know %s</string>
<!-- text for the theme picker onboarding card header -->
<string name="onboarding_theme_picker_header" translatable="false">Choose your theme</string>
<!-- text for the theme picker onboarding card description -->
<string name="onboarding_theme_picker_description" translatable="false">Save some battery and your eyesight by enabling dark mode.</string>
<!-- text for the firefox account onboarding card header
The first parameter is the name of the app defined in app_name (for example: Firefox Preview) -->
<string name="onboarding_firefox_account_header" translatable="false">Get the most out of %s</string>
<!-- text for the tracking protection onboarding card header -->
<string name="onboarding_tracking_protection_header" translatable="false">Protect yourself</string>
<!-- text for the tracking protection card description
The first parameter is the name of the app defined in app_name (for example: Firefox Preview) -->
<string name="onboarding_tracking_protection_description" translatable="false">%s helps stop websites from tracking you online, making it
harder for ads to follow you around the web
</string>
<!-- text for the private browsing onboarding card header -->
<string name="onboarding_private_browsing_header" translatable="false">Browse Privately</string>
<!-- text for the private browsing onboarding card description
The first parameter is an icon that represents private browsing -->
<string name="onboarding_private_browsing_description" translatable="false">Private Browsing is always just a tap or two away, just look
for the private browsing icon (%s)
</string>
<!-- text for the privacy notice onboarding card header -->
<string name="onboarding_privacy_notice_header" translatable="false">Your Privacy</string>
<!-- text for the privacy notice onboarding card description
The first parameter is the name of the app defined in app_name (for example: Firefox Preview) -->
<string name="onboarding_privacy_notice_description" translatable="false">We\'ve designed %s to give you control over what you share
online and what you share with us.
</string>
<!-- text for the button to finish onboarding -->
<string name="onboarding_finish" translatable="false">Start browsing</string>
</resources>

View File

@ -485,42 +485,4 @@
<string name="full_screen_notification">Entering full screen mode</string>
<!-- Message for copying the URL via long press on the toolbar -->
<string name="url_copied">URL copied</string>
<!-- Onboarding -->
<!-- Text for onboarding welcome message
The first parameter is the name of the app defined in app_name (for example: Firefox Preview) -->
<string name="onboarding_header">Welcome to %s!</string>
<!-- text for the Firefox Accounts section header -->
<string name="onboarding_fxa_section_header">Already have an account?</string>
<!-- 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>
<!-- text for the firefox account onboarding card header
The first parameter is the name of the app defined in app_name (for example: Firefox Preview) -->
<string name="onboarding_firefox_account_header">Get the most out of %s</string>
<!-- text for the tracking protection onboarding card header -->
<string name="onboarding_tracking_protection_header">Protect yourself</string>
<!-- text for the tracking protection card description
The first parameter is the name of the app defined in app_name (for example: Firefox Preview) -->
<string name="onboarding_tracking_protection_description">%s helps stop websites from tracking you online, making it
harder for ads to follow you around the web
</string>
<!-- text for the private browsing onboarding card header -->
<string name="onboarding_private_browsing_header">Browse Privately</string>
<!-- text for the private browsing onboarding card description
The first parameter is an icon that represents private browsing -->
<string name="onboarding_private_browsing_description">Private Browsing is always just a tap or two away, just look
for the private browsing icon (%s)
</string>
<!-- text for the privacy notice onboarding card header -->
<string name="onboarding_privacy_notice_header">Your Privacy</string>
<!-- text for the privacy notice onboarding card description
The first parameter is the name of the app defined in app_name (for example: Firefox Preview) -->
<string name="onboarding_privacy_notice_description">We\'ve designed %s to give you control over what you share
online and what you share with us.
</string>
</resources>