Skip to content

Commit

Permalink
Merge pull request #16918 from wordpress-mobile/Jetpack-Focus-Full-Sc…
Browse files Browse the repository at this point in the history
…reen-Bottom-Sheet-

Jetpack focus full screen bottom sheet
  • Loading branch information
ravishanker authored Jul 26, 2022
2 parents f7897d0 + e45ec43 commit 51280dc
Show file tree
Hide file tree
Showing 19 changed files with 278 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import dagger.hilt.android.AndroidEntryPoint
import org.wordpress.android.R
import org.wordpress.android.databinding.JetpackPoweredBottomSheetBinding
import org.wordpress.android.ui.ActivityLauncherWrapper
import org.wordpress.android.ui.main.WPMainNavigationView.PageType
import org.wordpress.android.ui.main.WPMainNavigationView.PageType.MY_SITE
import org.wordpress.android.ui.main.WPMainNavigationView.PageType.NOTIFS
import org.wordpress.android.ui.main.WPMainNavigationView.PageType.READER
import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredDialogAction.DismissDialog
import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredDialogAction.OpenPlayStore
import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredDialogViewModel.Companion.JETPACK_PACKAGE_NAME
Expand Down Expand Up @@ -56,7 +60,12 @@ class JetpackPoweredBottomSheetFragment : BottomSheetDialogFragment() {

if (fullScreen) {
secondaryButton.visibility = View.VISIBLE
secondaryButton.text = getString(R.string.wp_jetpack_continue_to_reader)
val pageType = arguments?.getSerializable(KEY_SITE_SCREEN) as? PageType ?: MY_SITE
secondaryButton.text = when (pageType) {
MY_SITE -> getString(R.string.wp_jetpack_continue_to_stats)
READER -> getString(R.string.wp_jetpack_continue_to_reader)
NOTIFS -> getString(R.string.wp_jetpack_continue_to_notifications)
}
secondaryButton.setOnClickListener { viewModel.dismissBottomSheet() }
}

Expand Down Expand Up @@ -110,11 +119,16 @@ class JetpackPoweredBottomSheetFragment : BottomSheetDialogFragment() {
companion object {
const val TAG = "JETPACK_POWERED_BOTTOM_SHEET_FRAGMENT"
private const val KEY_FULL_SCREEN = "KEY_FULL_SCREEN"
private const val KEY_SITE_SCREEN = "KEY_SITE_SCREEN"

@JvmStatic
fun newInstance(fullScreen: Boolean = false) = JetpackPoweredBottomSheetFragment().apply {
fun newInstance(
fullScreen: Boolean = false,
pageType: PageType = MY_SITE
) = JetpackPoweredBottomSheetFragment().apply {
arguments = Bundle().apply {
putBoolean(KEY_FULL_SCREEN, fullScreen)
putSerializable(KEY_SITE_SCREEN, pageType)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sealed class JetpackPoweredViewHolder<T : ViewBinding>(
) {
@Suppress("unused")
fun onBind(item: Illustration) = with(binding) {
// illustrationView.setImageResource(item.illustration)
illustrationView.setAnimation(item.illustration)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import org.wordpress.android.util.extensions.viewBinding
class MySiteJetpackBadgeViewHolder(
parent: ViewGroup,
) : MySiteCardAndItemViewHolder<JetpackBadgeBinding>(parent.viewBinding(JetpackBadgeBinding::inflate)) {
@Suppress("UnusedPrivateMember")
fun bind(item: JetpackBadge) {
// itemView.setOnClickListener { item.onClick.click() }
itemView.setOnClickListener { item.onClick.click() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,9 @@ class MySiteTabFragment : Fragment(R.layout.my_site_tab_fragment),
}

private fun showJetpackPoweredBottomSheet() {
JetpackPoweredBottomSheetFragment.newInstance().show(
requireActivity().supportFragmentManager,
JetpackPoweredBottomSheetFragment.TAG
)
JetpackPoweredBottomSheetFragment
.newInstance()
.show(requireActivity().supportFragmentManager, JetpackPoweredBottomSheetFragment.TAG)
}

private fun openQuickStartFullScreenDialog(action: SiteNavigationAction.OpenQuickStartFullScreenDialog) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.appbar.AppBarLayout.LayoutParams
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
Expand All @@ -33,6 +34,8 @@ import org.wordpress.android.ui.RequestCodes
import org.wordpress.android.ui.ScrollableViewInitializedListener
import org.wordpress.android.ui.WPWebViewActivity
import org.wordpress.android.ui.main.WPMainActivity
import org.wordpress.android.ui.main.WPMainNavigationView.PageType
import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredBottomSheetFragment
import org.wordpress.android.ui.notifications.NotificationEvents.NotificationsUnseenStatus
import org.wordpress.android.ui.notifications.adapters.NotesAdapter.FILTERS
import org.wordpress.android.ui.notifications.adapters.NotesAdapter.FILTERS.FILTER_ALL
Expand All @@ -47,20 +50,20 @@ import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T.NOTIFS
import org.wordpress.android.util.JetpackBrandingUtils
import org.wordpress.android.util.NetworkUtils
import org.wordpress.android.util.SiteUtilsWrapper
import org.wordpress.android.util.WPUrlUtils
import org.wordpress.android.util.extensions.setLiftOnScrollTargetViewIdAndRequestLayout
import org.wordpress.android.viewmodel.observeEvent
import javax.inject.Inject

@AndroidEntryPoint
class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment), ScrollableViewInitializedListener {
private var shouldRefreshNotifications = false
private var lastTabPosition = 0

@Inject lateinit var accountStore: AccountStore
@Inject lateinit var jetpackBrandingUtils: JetpackBrandingUtils
@Inject lateinit var siteUtilsWrapper: SiteUtilsWrapper

private val viewModel: NotificationsListViewModel by viewModels()

private var shouldRefreshNotifications = false
private var lastTabPosition = 0
private var binding: NotificationsListFragmentBinding? = null

override fun onActivityCreated(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -114,6 +117,12 @@ class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment)
WPWebViewActivity.openURL(requireContext(), StatsConnectJetpackActivity.FAQ_URL)
}
}

viewModel.showJetpackPoweredBottomSheet.observeEvent(viewLifecycleOwner) {
JetpackPoweredBottomSheetFragment
.newInstance(it, PageType.NOTIFS)
.show(childFragmentManager, JetpackPoweredBottomSheetFragment.TAG)
}
}

private fun buildTitles(): List<String> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.wordpress.android.ui.notifications

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import org.wordpress.android.modules.UI_THREAD
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.config.JetpackPoweredFeatureConfig
import org.wordpress.android.viewmodel.Event
import org.wordpress.android.viewmodel.ScopedViewModel
import javax.inject.Inject
import javax.inject.Named

@HiltViewModel
class NotificationsListViewModel@Inject constructor(
@Named(UI_THREAD) mainDispatcher: CoroutineDispatcher,
private val jetpackPoweredFeatureConfig: JetpackPoweredFeatureConfig,
private val buildConfigWrapper: BuildConfigWrapper
) : ScopedViewModel(mainDispatcher) {
private val _showJetpackPoweredBottomSheet = MutableLiveData<Event<Boolean>>()
val showJetpackPoweredBottomSheet: LiveData<Event<Boolean>> = _showJetpackPoweredBottomSheet

init {
showJetpackPoweredBottomSheet()
}

private fun showJetpackPoweredBottomSheet() {
_showJetpackPoweredBottomSheet.value = Event(
jetpackPoweredFeatureConfig.isEnabled() && !buildConfigWrapper.isJetpackApp
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import org.wordpress.android.R.string
import org.wordpress.android.databinding.ReaderFragmentLayoutBinding
import org.wordpress.android.models.ReaderTagList
import org.wordpress.android.ui.ScrollableViewInitializedListener
import org.wordpress.android.ui.main.WPMainNavigationView.PageType.READER
import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredBottomSheetFragment
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.quickstart.QuickStartEvent
import org.wordpress.android.ui.reader.ReaderTypes.ReaderPostListType
Expand Down Expand Up @@ -209,6 +211,12 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), ScrollableView
)
}

viewModel.showJetpackPoweredBottomSheet.observeEvent(viewLifecycleOwner) {
JetpackPoweredBottomSheetFragment
.newInstance(it, READER)
.show(childFragmentManager, JetpackPoweredBottomSheetFragment.TAG)
}

viewModel.start()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import org.wordpress.android.ui.reader.viewmodels.ReaderViewModel.ReaderUiState.
import org.wordpress.android.ui.reader.viewmodels.ReaderViewModel.ReaderUiState.ContentUiState.TabUiState
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.ui.utils.UiString.UiStringText
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.SnackbarSequencer
import org.wordpress.android.util.config.JetpackPoweredFeatureConfig
import org.wordpress.android.util.distinct
import org.wordpress.android.viewmodel.Event
import org.wordpress.android.viewmodel.ScopedViewModel
Expand All @@ -55,6 +57,8 @@ class ReaderViewModel @Inject constructor(
private val accountStore: AccountStore,
private val quickStartRepository: QuickStartRepository,
private val selectedSiteRepository: SelectedSiteRepository,
private val jetpackPoweredFeatureConfig: JetpackPoweredFeatureConfig,
private val buildConfigWrapper: BuildConfigWrapper,
private val snackbarSequencer: SnackbarSequencer
// todo: annnmarie removed this private val getFollowedTagsUseCase: GetFollowedTagsUseCase
) : ScopedViewModel(mainDispatcher) {
Expand Down Expand Up @@ -87,6 +91,9 @@ class ReaderViewModel @Inject constructor(
private val _quickStartPromptEvent = MutableLiveData<Event<QuickStartReaderPrompt>>()
val quickStartPromptEvent = _quickStartPromptEvent as LiveData<Event<QuickStartReaderPrompt>>

private val _showJetpackPoweredBottomSheet = MutableLiveData<Event<Boolean>>()
val showJetpackPoweredBottomSheet: LiveData<Event<Boolean>> = _showJetpackPoweredBottomSheet

init {
EventBus.getDefault().register(this)
}
Expand All @@ -95,6 +102,13 @@ class ReaderViewModel @Inject constructor(
if (tagsRequireUpdate()) _updateTags.value = Event(Unit)
if (initialized) return
loadTabs()
showJetpackPoweredBottomSheet()
}

private fun showJetpackPoweredBottomSheet() {
_showJetpackPoweredBottomSheet.value = Event(
jetpackPoweredFeatureConfig.isEnabled() && !buildConfigWrapper.isJetpackApp
)
}

private fun loadTabs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.wordpress.android.R
import org.wordpress.android.WordPress
import org.wordpress.android.databinding.StatsFragmentBinding
import org.wordpress.android.ui.ScrollableViewInitializedListener
import org.wordpress.android.ui.main.WPMainNavigationView.PageType.MY_SITE
import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredBottomSheetFragment
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.stats.refresh.StatsViewModel.StatsModuleUiModel
import org.wordpress.android.ui.stats.refresh.lists.StatsListFragment
Expand Down Expand Up @@ -127,6 +129,14 @@ class StatsFragment : Fragment(R.layout.stats_fragment), ScrollableViewInitializ
}
return@setOnTouchListener false
}

viewModel.showJetpackPoweredBottomSheet.observeEvent(viewLifecycleOwner) {
if (isFirstStart) {
JetpackPoweredBottomSheetFragment
.newInstance(it, MY_SITE)
.show(childFragmentManager, JetpackPoweredBottomSheetFragment.TAG)
}
}
}

private fun StatsFragmentBinding.setupObservers(activity: FragmentActivity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
import org.wordpress.android.ui.stats.refresh.utils.toStatsGranularity
import org.wordpress.android.ui.stats.refresh.utils.trackGranular
import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.NetworkUtilsWrapper
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import org.wordpress.android.util.config.JetpackPoweredFeatureConfig
import org.wordpress.android.util.config.MySiteDashboardTodaysStatsCardFeatureConfig
import org.wordpress.android.util.config.StatsRevampV2FeatureConfig
import org.wordpress.android.util.mapNullable
Expand Down Expand Up @@ -85,7 +87,9 @@ class StatsViewModel
private val statsModuleActivateUseCase: StatsModuleActivateUseCase,
private val notificationsTracker: SystemNotificationsTracker,
private val todaysStatsCardFeatureConfig: MySiteDashboardTodaysStatsCardFeatureConfig,
private val statsRevampV2FeatureConfig: StatsRevampV2FeatureConfig
private val statsRevampV2FeatureConfig: StatsRevampV2FeatureConfig,
private val jetpackPoweredFeatureConfig: JetpackPoweredFeatureConfig,
private val buildConfigWrapper: BuildConfigWrapper
) : ScopedViewModel(mainDispatcher) {
private val _isRefreshing = MutableLiveData<Boolean>()
val isRefreshing: LiveData<Boolean> = _isRefreshing
Expand Down Expand Up @@ -113,6 +117,9 @@ class StatsViewModel
private val _showUpgradeAlert = MutableLiveData<Event<Boolean>>()
val showUpgradeAlert: LiveData<Event<Boolean>> = _showUpgradeAlert

private val _showJetpackPoweredBottomSheet = MutableLiveData<Event<Boolean>>()
val showJetpackPoweredBottomSheet: LiveData<Event<Boolean>> = _showJetpackPoweredBottomSheet

fun start(intent: Intent, restart: Boolean = false) {
val localSiteId = intent.getIntExtra(WordPress.LOCAL_SITE_ID, 0)

Expand Down Expand Up @@ -208,6 +215,14 @@ class StatsViewModel
updateRevampedInsights()
}
if (statsSectionManager.getSelectedSection() == INSIGHTS) showInsightsUpdateAlert()

showJetpackPoweredBottomSheet()
}

private fun showJetpackPoweredBottomSheet() {
_showJetpackPoweredBottomSheet.value = Event(
jetpackPoweredFeatureConfig.isEnabled() && !buildConfigWrapper.isJetpackApp
)
}

private fun showInsightsUpdateAlert() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:animateLayoutChanges="true"
android:background="@color/jetpack_powered_bottom_sheet_background"
android:orientation="vertical">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_end="130dp" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/content_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin_extra_extra_medium_large"
android:layout_marginStart="@dimen/margin_extra_extra_medium_large"
android:layout_marginTop="@dimen/margin_medium"
android:clipToPadding="false"
android:descendantFocusability="beforeDescendants"
android:scrollbars="vertical"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="@+id/primary_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/handle"
app:layout_constraintVertical_bias="0.0" />

<com.google.android.material.button.MaterialButton
android:id="@+id/primary_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/margin_extra_extra_medium_large"
android:layout_marginStart="@dimen/margin_extra_extra_medium_large"
android:backgroundTint="@color/jetpack_green_40"
android:gravity="center"
android:minHeight="@dimen/margin_extra_extra_large"
android:text="@string/wp_jetpack_get_new_jetpack_app"
android:textAppearance="?attr/textAppearanceSubtitle2"
android:textColor="?attr/colorOnSecondary"
app:layout_constraintTop_toBottomOf="@id/content_recycler_view"
app:layout_constraintBottom_toTopOf="@id/secondary_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_goneMarginBottom="@dimen/margin_extra_large" />

<com.google.android.material.button.MaterialButton
android:id="@+id/secondary_button"
android:visibility="gone"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/margin_extra_extra_medium_large"
android:layout_marginEnd="@dimen/margin_extra_extra_medium_large"
android:layout_marginStart="@dimen/margin_extra_extra_medium_large"
android:gravity="center"
android:minHeight="@dimen/margin_extra_extra_large"
android:textAppearance="?attr/textAppearanceSubtitle2"
android:textAllCaps="false"
android:textColor="@color/jetpack_green"
app:layout_constraintTop_toBottomOf="@id/primary_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="Continue to Reader"
tools:visibility="visible"/>

<include
android:id="@+id/handle"
layout="@layout/bottom_sheet_handle_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion WordPress/src/main/res/layout/jetpack_badge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
android:paddingTop="@dimen/margin_large">

<com.google.android.material.button.MaterialButton
android:id="@+id/jetpack_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:enabled="false"
android:importantForAccessibility="no"
android:paddingEnd="15dp"
android:paddingStart="5dp"
Expand Down
Loading

0 comments on commit 51280dc

Please sign in to comment.