Commit d07528aa authored by Matthew Finkel's avatar Matthew Finkel
Browse files

Bug 40028: Implement new home screen

parent 3cff3fb2
Loading
Loading
Loading
Loading
+87 −5
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID
import androidx.constraintlayout.widget.ConstraintSet.TOP
import androidx.constraintlayout.widget.ConstraintSet.TOP
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.core.view.doOnLayout
import androidx.core.view.doOnLayout
import androidx.core.view.isGone
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.isVisible
@@ -42,6 +43,7 @@ import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.fragment_home.*
import kotlinx.android.synthetic.main.fragment_home.*
import kotlinx.android.synthetic.main.fragment_home.view.*
import kotlinx.android.synthetic.main.fragment_home.view.*
@@ -190,6 +192,15 @@ class HomeFragment : Fragment() {
        val activity = activity as HomeActivity
        val activity = activity as HomeActivity
        val components = requireComponents
        val components = requireComponents


        // Splits by full stops or commas and puts the parts in different lines.
        // Ignoring separators at the end of the string, it is expected
        // that there are at most two parts (e.g. "Explore. Privately.").
        view.exploreprivately.text = view
            .exploreprivately
            .text
            ?.replace(" *([.,。।]) *".toRegex(), "$1\n")
            ?.trim()

        currentMode = CurrentMode(
        currentMode = CurrentMode(
            view.context,
            view.context,
            onboarding,
            onboarding,
@@ -270,6 +281,7 @@ class HomeFragment : Fragment() {
        activity.themeManager.applyStatusBarTheme(activity)
        activity.themeManager.applyStatusBarTheme(activity)


        adjustHomeFragmentView(currentMode.getCurrentMode(), view)
        adjustHomeFragmentView(currentMode.getCurrentMode(), view)
        showSessionControlView(view)


        return view
        return view
    }
    }
@@ -342,14 +354,29 @@ class HomeFragment : Fragment() {
        }
        }
    }
    }


    // This function should be paired with showSessionControlView()
    @SuppressWarnings("ComplexMethod", "NestedBlockDepth", "LongMethod")
    private fun adjustHomeFragmentView(mode: Mode, view: View?) {
    private fun adjustHomeFragmentView(mode: Mode, view: View?) {
        view?.sessionControlRecyclerView?.apply {
                visibility = View.INVISIBLE
        }

        if (mode == Mode.Bootstrap) {
        if (mode == Mode.Bootstrap) {
            view?.sessionControlRecyclerView?.apply {
            view?.sessionControlRecyclerView?.apply {
                setPadding(0, 0, 0, 0)
                setPadding(0, 0, 0, 0)
                (getLayoutParams() as ViewGroup.MarginLayoutParams).setMargins(0, 0, 0, 0)
                (layoutParams as ViewGroup.MarginLayoutParams).setMargins(0, 0, 0, 0)
            }
            }
            view?.homeAppBar?.apply {
            view?.homeAppBar?.apply {
                visibility = View.GONE
                visibility = View.GONE

                // Reset this as SCROLL in case it was previously set as NO_SCROLL after bootstrap
                children.forEach {
                    (it.layoutParams as AppBarLayout.LayoutParams).scrollFlags =
                        AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
                }
            }
            view?.onion_pattern_image?.apply {
                visibility = View.GONE
            }
            }
            view?.toolbarLayout?.apply {
            view?.toolbarLayout?.apply {
                visibility = View.GONE
                visibility = View.GONE
@@ -364,22 +391,71 @@ class HomeFragment : Fragment() {
                    SESSION_CONTROL_VIEW_PADDING
                    SESSION_CONTROL_VIEW_PADDING
                )
                )
                // Default margin until it is re-set below (either set immediately or after Layout)
                // Default margin until it is re-set below (either set immediately or after Layout)
                (getLayoutParams() as ViewGroup.MarginLayoutParams).setMargins(
                (layoutParams as ViewGroup.MarginLayoutParams).setMargins(
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    DEFAULT_ONBOARDING_FINISH_MARGIN
                    DEFAULT_ONBOARDING_FINISH_MARGIN
                )
                )
            }
            }
            view?.homeAppBar?.apply {
            view?.toolbarLayout?.apply {
                visibility = View.VISIBLE
                visibility = View.VISIBLE
                // If the Layout rendering pass was completed, then we have a |height| value,
                // if it wasn't completed then we have 0.
                if (height == 0) {
                    // Set the bottom margin after the toolbar height is defined during Layout
                    doOnLayout {
                        val toolbarLayoutHeight = view.toolbarLayout.height
                        view.sessionControlRecyclerView?.apply {
                            (layoutParams as ViewGroup.MarginLayoutParams).setMargins(
                                0,
                                0,
                                0,
                                toolbarLayoutHeight - SESSION_CONTROL_VIEW_PADDING
                            )
                        }
                        }
            view?.toolbarLayout?.apply {
                    }
                } else {
                    view.sessionControlRecyclerView?.apply {
                        (layoutParams as ViewGroup.MarginLayoutParams).setMargins(
                            0,
                            0,
                            0,
                            height - SESSION_CONTROL_VIEW_PADDING
                        )
                    }
                }
            }
            // Hide the onion pattern during Onboarding, too.
            view?.onion_pattern_image?.apply {
                visibility = if (onboarding.userHasBeenOnboarded()) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }
            view?.homeAppBar?.apply {
                visibility = View.VISIBLE
                visibility = View.VISIBLE

                children.forEach {
                    (it.layoutParams as AppBarLayout.LayoutParams).scrollFlags =
                        if (onboarding.userHasBeenOnboarded()) {
                            AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL
                        } else {
                            AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
                        }
                }
            }
            }
        }
        }
    }
    }


    // This function should be paired with adjustHomeFragmentView()
    private fun showSessionControlView(view: View?) {
        view?.sessionControlRecyclerView?.apply {
                visibility = View.VISIBLE
        }
    }

    @Suppress("LongMethod", "ComplexMethod")
    @Suppress("LongMethod", "ComplexMethod")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        super.onViewCreated(view, savedInstanceState)
@@ -659,9 +735,10 @@ class HomeFragment : Fragment() {
        homeFragmentStore.dispatch(HomeFragmentAction.ModeChange(mode))
        homeFragmentStore.dispatch(HomeFragmentAction.ModeChange(mode))


        val localView = view
        val localView = view
        adjustHomeFragmentView(mode, view)
        if (localView != null) {
        if (localView != null) {
            adjustHomeFragmentView(mode, localView)
            updateSessionControlView(localView)
            updateSessionControlView(localView)
            showSessionControlView(localView)
        }
        }
    }
    }


@@ -775,6 +852,11 @@ class HomeFragment : Fragment() {
                    mode = currentMode.getCurrentMode()
                    mode = currentMode.getCurrentMode()
                )
                )
            )
            )
            adjustHomeFragmentView(
                currentMode.getCurrentMode(),
                view
            )
            showSessionControlView(view)
        }
        }
    }
    }


+12 −14
Original line number Original line Diff line number Diff line
@@ -4,12 +4,10 @@


package org.mozilla.fenix.home.sessioncontrol.viewholders
package org.mozilla.fenix.home.sessioncontrol.viewholders


import android.text.method.LinkMovementMethod
import android.view.View
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.private_browsing_description.view.*
import kotlinx.android.synthetic.main.private_browsing_description.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.addUnderline
import org.mozilla.fenix.home.sessioncontrol.TabSessionInteractor
import org.mozilla.fenix.home.sessioncontrol.TabSessionInteractor


class PrivateBrowsingDescriptionViewHolder(
class PrivateBrowsingDescriptionViewHolder(
@@ -18,18 +16,18 @@ class PrivateBrowsingDescriptionViewHolder(
) : RecyclerView.ViewHolder(view) {
) : RecyclerView.ViewHolder(view) {


    init {
    init {
        val resources = view.resources
        // val resources = view.resources
        val appName = resources.getString(R.string.app_name)
        // val appName = resources.getString(R.string.app_name)
        view.private_session_description.text = resources.getString(
        // view.private_session_description.text = resources.getString(
            R.string.private_browsing_placeholder_description_2, appName
        //     R.string.private_browsing_placeholder_description_2, appName
        )
        // )
        with(view.private_session_common_myths) {
        // with(view.private_session_common_myths) {
            movementMethod = LinkMovementMethod.getInstance()
        //     movementMethod = LinkMovementMethod.getInstance()
            addUnderline()
        //     addUnderline()
            setOnClickListener {
        //     setOnClickListener {
                interactor.onPrivateBrowsingLearnMoreClicked()
        //         interactor.onPrivateBrowsingLearnMoreClicked()
            }
        //     }
        }
        // }
    }
    }


    companion object {
    companion object {
+806 −0

File added.

Preview size limit exceeded, changes collapsed.

+48 −1
Original line number Original line Diff line number Diff line
@@ -54,12 +54,48 @@
                android:contentDescription="@string/app_name"
                android:contentDescription="@string/app_name"
                android:focusable="false"
                android:focusable="false"
                android:importantForAccessibility="no"
                android:importantForAccessibility="no"
                app:srcCompat="?fenixLogo"
                app:srcCompat="@mipmap/ic_launcher"
                app:layout_collapseMode="parallax"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier=".1"/>
                app:layout_collapseParallaxMultiplier=".1"/>


            <TextView
                android:id="@+id/app_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="80dp"
                android:layout_marginTop="9dp"
                android:gravity="center_vertical"
                android:width="130dp"
                android:height="60dp"
                android:clickable="false"
                android:focusable="false"
                android:importantForAccessibility="no"
                android:lines="2"
                android:text="@string/app_name"
                android:fontFamily="Roboto-Medium"
                android:textColor="#DEFFFFFF"
                android:textSize="20sp"
                android:lineSpacingMultiplier="1.2" />

        </com.google.android.material.appbar.CollapsingToolbarLayout>
        </com.google.android.material.appbar.CollapsingToolbarLayout>


        <TextView
            android:id="@+id/exploreprivately"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center|center_vertical"
            android:gravity="center_horizontal"
            android:clickable="false"
            android:ellipsize="end"
            android:focusable="false"
            android:importantForAccessibility="no"
            android:text="@string/tor_explore_privately"
            android:fontFamily="Roboto-Medium"
            android:textColor="#DEFFFFFF"
            android:textSize="40sp"
            android:lineSpacingMultiplier="1.1"
            app:layout_scrollFlags="scroll" />

    </com.google.android.material.appbar.AppBarLayout>
    </com.google.android.material.appbar.AppBarLayout>


    <androidx.recyclerview.widget.RecyclerView
    <androidx.recyclerview.widget.RecyclerView
@@ -79,6 +115,17 @@
        tools:itemCount="3"
        tools:itemCount="3"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>


    <ImageView
        android:id="@+id/onion_pattern_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:srcCompat="@drawable/ic_onion_pattern"
        tools:ignore="ContentDescription"
        app:layout_constraintBottom_toTopOf="@id/toolbarLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <androidx.constraintlayout.widget.ConstraintLayout
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/toolbarLayout"
        android:id="@+id/toolbarLayout"
        android:elevation="5dp"
        android:elevation="5dp"
+2 −2
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@
        android:textColor="?primaryText"
        android:textColor="?primaryText"
        android:textDirection="locale"
        android:textDirection="locale"
        android:textSize="14sp"
        android:textSize="14sp"
        tools:text="@string/private_browsing_placeholder_description_2" />
        tools:text="" />


    <org.mozilla.fenix.utils.LinkTextView
    <org.mozilla.fenix.utils.LinkTextView
        android:id="@+id/private_session_common_myths"
        android:id="@+id/private_session_common_myths"
@@ -37,7 +37,7 @@
        android:paddingTop="10dp"
        android:paddingTop="10dp"
        android:paddingBottom="19dp"
        android:paddingBottom="19dp"
        android:scrollHorizontally="false"
        android:scrollHorizontally="false"
        android:text="@string/private_browsing_common_myths"
        android:text=""
        android:textColor="?primaryText"
        android:textColor="?primaryText"
        android:textSize="14sp" />
        android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
Loading