Skip to content

Commit

Permalink
Clean xml layout and ensure we keep the same logic in the DashboardFr…
Browse files Browse the repository at this point in the history
…agment
  • Loading branch information
JorgeMucientes committed Dec 5, 2024
1 parent 0eca83c commit 2b7fbfc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.woocommerce.android.R
import com.woocommerce.android.e2e.helpers.util.Screen
import com.woocommerce.android.ui.dashboard.stats.DashboardStatsTestTags

class StatsComponent : Screen(R.id.dashboardStats_root) {
class StatsComponent : Screen(R.id.my_store_stats_container) {
override fun recover() {
super.recover()
clickOn(R.id.dashboard)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.woocommerce.android.R
import com.woocommerce.android.e2e.helpers.util.Screen
import com.woocommerce.android.ui.dashboard.stats.DashboardStatsTestTags

class TopPerformersComponent : Screen(R.id.dashboardStats_root) {
class TopPerformersComponent : Screen(R.id.my_store_stats_container) {
override fun recover() {
super.recover()
clickOn(R.id.dashboard)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import com.woocommerce.android.extensions.getColorCompat
import com.woocommerce.android.extensions.handleNotice
import com.woocommerce.android.extensions.handleResult
import com.woocommerce.android.extensions.navigateSafely
import com.woocommerce.android.extensions.scrollStartEvents
import com.woocommerce.android.extensions.showDateRangePicker
import com.woocommerce.android.extensions.startHelpActivity
import com.woocommerce.android.extensions.verticalOffsetChanges
Expand All @@ -52,6 +51,7 @@ import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.Fe
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.FeedbackPositiveAction
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.OpenEditWidgets
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.OpenRangePicker
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.RefreshJitm
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.ShareStore
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.ShowPrivacyBanner
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetUiModel
Expand Down Expand Up @@ -145,18 +145,8 @@ class DashboardFragment :
}
}

binding.myStoreRefreshLayout.setOnRefreshListener {
binding.myStoreRefreshLayout.isRefreshing = false
dashboardViewModel.onPullToRefresh()
refreshJitm()
}

prepareJetpackBenefitsBanner()

binding.statsScrollView.scrollStartEvents()
.onEach { usageTracksEventEmitter.interacted() }
.launchIn(viewLifecycleOwner.lifecycleScope)

setupStateObservers()
setupResultHandlers()
}
Expand Down Expand Up @@ -190,6 +180,8 @@ class DashboardFragment :

is ShowSnackbar -> ToastUtils.showToast(requireContext(), event.message)

is RefreshJitm -> refreshJitm()

else -> event.isHandled = false
}
}
Expand Down Expand Up @@ -324,10 +316,6 @@ class DashboardFragment :

override fun getFragmentSubtitle(): String = dashboardViewModel.storeName.value ?: ""

override fun scrollToTop() {
binding.statsScrollView.smoothScrollTo(0, 0)
}

private fun handleFeedbackRequestPositiveClick() {
// Request a ReviewInfo object from the Google Reviews API. If this fails
// we just move on as there isn't anything we can do.
Expand Down Expand Up @@ -361,7 +349,11 @@ class DashboardFragment :
)
}

override fun shouldExpandToolbar() = binding.statsScrollView.scrollY == 0
override fun shouldExpandToolbar() = true

override fun scrollToTop() {
return
}

@OptIn(ExperimentalBadgeUtils::class)
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.woocommerce.android.tools.SiteConnectionType
import com.woocommerce.android.tools.connectionType
import com.woocommerce.android.ui.analytics.ranges.StatsTimeRangeSelection.SelectionType
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.OpenEditWidgets
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.RefreshJitm
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetUiModel.NewWidgetsCard
import com.woocommerce.android.ui.dashboard.data.DashboardRepository
import com.woocommerce.android.ui.prefs.privacy.banner.domain.ShouldShowPrivacyBanner
Expand Down Expand Up @@ -170,6 +171,7 @@ class DashboardViewModel @Inject constructor(
usageTracksEventEmitter.interacted()
analyticsTrackerWrapper.track(AnalyticsEvent.DASHBOARD_PULLED_TO_REFRESH)
_refreshTrigger.tryEmit(RefreshEvent(isForced = true))
triggerEvent(RefreshJitm)
}

fun onResume() {
Expand Down Expand Up @@ -355,6 +357,8 @@ class DashboardViewModel @Inject constructor(
data object FeedbackPositiveAction : DashboardEvent()

data object FeedbackNegativeAction : DashboardEvent()

data object RefreshJitm : DashboardEvent()
}

data class RefreshEvent(val isForced: Boolean = false)
Expand Down
66 changes: 18 additions & 48 deletions WooCommerce/src/main/res/layout/fragment_dashboard.xml
Original file line number Diff line number Diff line change
@@ -1,59 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dashboardStats_root"
android:id="@+id/my_store_stats_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@color/color_surface"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
tools:context="com.woocommerce.android.ui.dashboard.DashboardFragment">

<androidx.appcompat.widget.LinearLayoutCompat
<androidx.fragment.app.FragmentContainerView
android:id="@+id/jitmFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:id="@+id/my_store_stats_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/jitmFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/minor_100" />

<!-- Dynamic dashboard container -->
<androidx.compose.ui.platform.ComposeView
android:id="@+id/dashboard_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<include
android:id="@+id/jetpack_benefits_banner"
layout="@layout/view_jetpack_benefits_bottom_banner" />
</LinearLayout>
android:layout_marginBottom="@dimen/minor_100" />

<com.woocommerce.android.widgets.ScrollChildSwipeRefreshLayout
android:id="@+id/my_store_refresh_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<androidx.core.widget.NestedScrollView
android:id="@+id/stats_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionGroup="true">

</androidx.core.widget.NestedScrollView>

</com.woocommerce.android.widgets.ScrollChildSwipeRefreshLayout>
<!-- Dynamic dashboard container -->
<androidx.compose.ui.platform.ComposeView
android:id="@+id/dashboard_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</androidx.appcompat.widget.LinearLayoutCompat>
</RelativeLayout>
<include
android:id="@+id/jetpack_benefits_banner"
layout="@layout/view_jetpack_benefits_bottom_banner" />
</LinearLayout>

0 comments on commit 2b7fbfc

Please sign in to comment.