Commit f9aea110 authored by Dan Ballard's avatar Dan Ballard Committed by Richard Pospesel
Browse files

yec22 home fragment, theming, and timegate toggle

parent 8b67442c
Loading
Loading
Loading
Loading
+146 −25
Original line number Diff line number Diff line
@@ -10,11 +10,8 @@ import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.StrictMode
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.util.Log
import android.view.*
import android.widget.Button
import android.widget.LinearLayout
import android.widget.PopupWindow
@@ -22,16 +19,10 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.constraintlayout.widget.ConstraintSet.BOTTOM
import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID
import androidx.constraintlayout.widget.ConstraintSet.TOP
import androidx.constraintlayout.widget.ConstraintSet.*
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.core.view.doOnLayout
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.*
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
@@ -66,15 +57,13 @@ import mozilla.components.service.glean.private.NoExtras
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.content.res.resolveAttribute
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
import mozilla.components.support.locale.LocaleManager
import mozilla.components.ui.tabcounter.TabCounterMenu
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config
import org.mozilla.fenix.*
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.HomeScreen
import org.mozilla.fenix.GleanMetrics.StartOnHome
import org.mozilla.fenix.GleanMetrics.Wallpapers
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserAnimator.Companion.getToolbarNavOptions
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.FenixSnackbar
@@ -84,12 +73,7 @@ import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.components.toolbar.FenixTabCounterMenu
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.databinding.FragmentHomeBinding
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.hideToolbar
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.runIfFragmentIsAttached
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.*
import org.mozilla.fenix.gleanplumb.DefaultMessageController
import org.mozilla.fenix.gleanplumb.MessagingFeature
import org.mozilla.fenix.home.mozonline.showPrivacyPopWindow
@@ -110,6 +94,7 @@ import org.mozilla.fenix.home.topsites.DefaultTopSitesView
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.onboarding.FenixOnboarding
import org.mozilla.fenix.perf.MarkersFragmentLifecycleCallbacks
import org.mozilla.fenix.settings.advanced.getSelectedLocale
import org.mozilla.fenix.tabstray.TabsTrayAccessPoint
import org.mozilla.fenix.tor.bootstrap.TorQuickStart
import org.mozilla.fenix.utils.Settings.Companion.TOP_SITES_PROVIDER_MAX_THRESHOLD
@@ -117,6 +102,8 @@ import org.mozilla.fenix.utils.ToolbarPopupWindow
import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.wallpapers.WallpaperManager
import java.lang.ref.WeakReference
import java.util.*
import kotlin.concurrent.schedule
import kotlin.math.min

@Suppress("TooManyFunctions", "LargeClass")
@@ -229,6 +216,13 @@ class HomeFragment : Fragment() {
            ?.replace(" *([.,。।]) *".toRegex(), "$1\n")
            ?.trim()

        binding.yecPoweredbyprivacy.text = localBinding
            .yecPoweredbyprivacy
            .text
            ?.replace(" *([.,。।]) *".toRegex(), "$1\n")
            ?.trim()


        currentMode = CurrentMode(
            requireContext(),
            onboarding,
@@ -411,6 +405,20 @@ class HomeFragment : Fragment() {
        adjustHomeFragmentView(currentMode.getCurrentMode())
        showSessionControlView()

        binding.donateNowButton.setOnClickListener {
            val country = LocaleManager.getSelectedLocale(requireContext()).country
            var locale = LocaleManager.getSelectedLocale(requireContext()).language
            if (country != "") {
                locale = "${locale}-${country}"
            }
            val localeUrl = "https://www.torproject.org/pbp-${locale}-mobile"
            activity.openToBrowserAndLoad(
                searchTermOrURL = localeUrl,
                newTab = true,
                from = BrowserDirection.FromHome
            )
        }

        // DO NOT MOVE ANYTHING BELOW THIS addMarker CALL!
        requireComponents.core.engine.profiler?.addMarker(
            MarkersFragmentLifecycleCallbacks.MARKER_NAME, profilerStartTime, "HomeFragment.onCreateView",
@@ -424,8 +432,34 @@ class HomeFragment : Fragment() {

        getMenuButton()?.dismissMenu()
        displayWallpaperIfEnabled()

        //view.donationmatch.setOnClickListener {
        //    activity.openToBrowserAndLoad(
        //        searchTermOrURL = "https://blog.torproject.org/friends-of-tor-match-2020",
        //        newTab = true,
        //        from = BrowserDirection.FromHome
        //    )
        //}

        binding.donateNowButton.setOnClickListener {
            val country = LocaleManager.getSelectedLocale(requireContext()).country
            var locale = LocaleManager.getSelectedLocale(requireContext()).language
            if (country != "") {
                locale = "${locale}-${country}"
            }
            val localeUrl = "https://www.torproject.org/pbp-${locale}-mobile"
            (activity as HomeActivity).openToBrowserAndLoad(
                searchTermOrURL = localeUrl,
                newTab = true,
                from = BrowserDirection.FromHome
            )
        }
    }

    //private fun dismissTip(tip: Tip) {
    //    sessionControlInteractor.onCloseTip(tip)
    //}

    /**
     * Returns a [TopSitesConfig] which specifies how many top sites to display and whether or
     * not frequently visited sites should be displayed.
@@ -577,14 +611,97 @@ class HomeFragment : Fragment() {
                    }
                }
            }
            val yec22launched = (activity as? HomeActivity)?.themeManager?.isYECActive ?: false

            // Hide the onion pattern during Onboarding, too.
            binding.onionPatternImage.apply {
                visibility = if (onboarding.userHasBeenOnboarded()) {
                visibility = if (onboarding.userHasBeenOnboarded() && !yec22launched) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }

            // Hide tor browser header during onboarding and EOY event
            binding.exploreprivately.apply {
                    visibility = if (onboarding.userHasBeenOnboarded() && !yec22launched) {
                        View.VISIBLE
                    } else {
                        View.GONE
                    }
                }



            // Hide EOY header text during onboarding and before event
            binding.yecPoweredbyprivacy.apply {
                visibility = if (onboarding.userHasBeenOnboarded() && yec22launched) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }



            // Hide the EOY image during Onboarding, and before event
            binding.yecActivistImage.apply {
                visibility = if (onboarding.userHasBeenOnboarded() && yec22launched) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }

            binding.yecResistanceImage.apply {
                visibility = if (onboarding.userHasBeenOnboarded() && yec22launched) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }
            binding.yecChangeImage.apply {
                visibility = if (onboarding.userHasBeenOnboarded() && yec22launched) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }
            binding.yecFreedomImage.apply {
                visibility = if (onboarding.userHasBeenOnboarded() && yec22launched) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }

            // Hide the EOY donate button during Onboarding, and before event
            binding.donateNowButton.apply {
                visibility = if (onboarding.userHasBeenOnboarded() && yec22launched) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }

            // Hide EOY donation match text during onboarding and before event
            binding.donationmatch.apply {
                visibility = if (onboarding.userHasBeenOnboarded() && yec22launched) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }

            // Hide the EOY image during Onboarding, and before event
            binding.yecImageLayout.apply {
                visibility = if (onboarding.userHasBeenOnboarded() && yec22launched) {
                    View.VISIBLE
                } else {
                    View.GONE
                }
            }

            binding.homeAppBar.apply {
                visibility = View.VISIBLE

@@ -932,8 +1049,12 @@ class HomeFragment : Fragment() {
    override fun onResume() {
        super.onResume()
        if (browsingModeManager.mode == BrowsingMode.Private) {
            if ((activity as? HomeActivity)?.themeManager?.isYECActive ?: false) {
                activity?.window?.setBackgroundDrawableResource(R.color.tor_yec_home_background)
            } else {
                activity?.window?.setBackgroundDrawableResource(R.drawable.private_home_background_gradient)
            }
        }

        // fenix#40176: Ensure the Home fragment is rendered correctly when we resume.
        val mode = currentMode.getCurrentMode()
+16 −1
Original line number Diff line number Diff line
@@ -23,18 +23,33 @@ import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.customtabs.ExternalAppBrowserActivity
import org.mozilla.fenix.home.HomeFragment
import java.util.*

abstract class ThemeManager {
    // 1663979387091 // 2022 9 21 - testing
    // 1665619200000 // 2022 10 13
    private val yec2022LaunchDate = Date(1665619200000)
    // 1672531200000 // 2023 01 01
    private val yec2022EndDate = Date(1672531200000)

    abstract var currentTheme: BrowsingMode

    val isYECActive get() = Date().after(yec2022LaunchDate) && Date().before(yec2022EndDate)

    /**
     * Returns the style resource corresponding to the [currentTheme].
     */
    @get:StyleRes
    val currentThemeResource get() = when (currentTheme) {
        BrowsingMode.Normal -> R.style.NormalTheme
        BrowsingMode.Private -> R.style.PrivateTheme
        BrowsingMode.Private -> {
            if (isYECActive) {
                R.style.PrivateEOYTheme
            } else {
                R.style.PrivateTheme
            }
        }
    }

    /**
+147 KiB
Loading image diff...
+11 −0
Original line number Diff line number Diff line
<?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/.  -->

<!-- Used for rounding the corners of a button -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid android:color="#C0FF00" />
    <corners android:radius="10dp" />
</shape>
+84.5 KiB

File added.

No diff preview for this file type.

Loading