Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2 pane layout] Tablet mode detection logic change #13228

Merged
merged 10 commits into from
Jan 30, 2025

Conversation

AnirudhBhat
Copy link
Contributor

@AnirudhBhat AnirudhBhat commented Dec 31, 2024

Closes: #12861

Description

This PR refactors the tablet detection logic to account for both width and height dimensions when determining if a device qualifies as a tablet. The updated logic improves compatibility with larger phones especially in landscape mode.

Changes Introduced:
New Size Class Determination Method:

Introduced determineWindowSizeClassByDimensions(widthDp: Int, heightDp: Int).
Evaluates both shortSize and longSize (smallest and largest dimensions, respectively) to classify devices as Compact, Medium, or ExpandedAndBigger.

Steps to reproduce

  1. Open WooCommerce app
  2. Navigate to orders screen
  3. Rotate your device
  4. Observe the Behaviour:
    On smaller devices: The screen remains in single-pane mode and does not split into tablet mode.
    On larger phones and tablets: The screen transitions to split-pane (tablet) mode as expected.

The tests that have been performed

Verified behaviour on below emulators:
Tablets (portrait and landscape)
Large phones in landscape mode

Images/gif

tablet_detection_logic.mp4
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@AnirudhBhat AnirudhBhat added type: bug A confirmed bug. category: tablet Specific to tablet devices such as a Galaxy Tab or an iPad. labels Dec 31, 2024
@AnirudhBhat AnirudhBhat added this to the 21.4 milestone Dec 31, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Dec 31, 2024

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commit7e2c9bc
Direct Downloadwoocommerce-wear-prototype-build-pr13228-7e2c9bc.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Dec 31, 2024

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commit7e2c9bc
Direct Downloadwoocommerce-prototype-build-pr13228-7e2c9bc.apk

@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 56.33803% with 31 lines in your changes missing coverage. Please review.

Project coverage is 41.22%. Comparing base (ca38ed6) to head (7e2c9bc).
Report is 20 commits behind head on trunk.

Files with missing lines Patch % Lines
...n/com/woocommerce/android/extensions/ContextExt.kt 0.00% 9 Missing ⚠️
...oid/ui/orders/creation/OrderCreateEditViewModel.kt 80.00% 6 Missing and 2 partials ⚠️
...oocommerce/android/util/TabletLayoutSetupHelper.kt 0.00% 8 Missing ⚠️
...ers/creation/totals/OrderCreateEditTotalsHelper.kt 0.00% 0 Missing and 2 partials ⚠️
...merce/android/ui/orders/list/OrderListViewModel.kt 0.00% 2 Missing ⚠️
.../com/woocommerce/android/analytics/AnalyticsExt.kt 75.00% 1 Missing ⚠️
...n/kotlin/com/woocommerce/android/util/UiHelpers.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #13228      +/-   ##
============================================
- Coverage     41.23%   41.22%   -0.01%     
+ Complexity     6548     6547       -1     
============================================
  Files          1326     1326              
  Lines         77731    77730       -1     
  Branches      10706    10701       -5     
============================================
- Hits          32049    32046       -3     
- Misses        42836    42839       +3     
+ Partials       2846     2845       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AnirudhBhat AnirudhBhat requested a review from samiuelson January 2, 2025 04:10
@AnirudhBhat AnirudhBhat marked this pull request as ready for review January 2, 2025 04:10
@AnirudhBhat AnirudhBhat changed the title [Woo POS][Non-Simple Products] Tablet mode detection logic change [2 pane layout] Tablet mode detection logic change Jan 3, 2025
@kidinov kidinov requested review from kidinov and removed request for samiuelson January 6, 2025 09:40
@@ -7,6 +7,7 @@
- [*] Fixed overlap issue in Settings > WooCommerce Version [https://github.com/woocommerce/woocommerce-android/pull/13183]
- [*] Fixed a crash on the order details [https://github.com/woocommerce/woocommerce-android/pull/13191]
- [**] Fixed a crash when a shop manager was trying to install or activate plugin in the POS onboarding [https://github.com/woocommerce/woocommerce-android/pull/13203]
- [*] Refactored tablet detection logic to consider both width and height dimensions, enhancing compatibility with larger phones and tablets, particularly in landscape mode [https://github.com/woocommerce/woocommerce-android/pull/13228]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np: I think this is not a refactoring, but change of the logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here: dd61dda


val Context.windowSizeClass: WindowSizeClass
get() = determineWindowWidthSizeClassByGivenSize(resources.configuration.screenWidthDp)
get() = determineWindowSizeClassByDimensions(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnirudhBhat I think we can not use the same semantics here if we change the logic. Window classes we use here are from https://m3.material.io/foundations/layout/applying-layout/window-size-classes and those are determined based on the width of a device. Reusing the same concept but with different logic may bring confusion and errors

I am thinking that:

  • We should either simplify all of this and end up with something "isTwoPaneShouldBeUsed" with logic similar/the same as WooPosIsScreenSizeAllowed. I'd say this is preferred, as I think we learned that the use of those size classes doesn't work well at all
  • Or at least refactor all of this and call it in not attaching to the material design size classes name (remove comments etc) to make sure that we don't mix the concepts

wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response.

I agree with your opinion that mixing Window classes and our custom detection logic would create confusion. I've updated the logic to remove Window class reference. Please take a look.

f43bda8

Base automatically changed from issue/13221-remove-variation-quantity to trunk January 10, 2025 04:14
@wpmobilebot wpmobilebot modified the milestones: 21.4, 21.5 Jan 10, 2025
@wpmobilebot
Copy link
Collaborator

Version 21.4 has now entered code-freeze, so the milestone of this PR has been updated to 21.5.

@kidinov kidinov self-assigned this Jan 13, 2025
@wpmobilebot wpmobilebot modified the milestones: 21.5, 21.6 Jan 24, 2025
@wpmobilebot
Copy link
Collaborator

Version 21.5 has now entered code-freeze, so the milestone of this PR has been updated to 21.6.

@dangermattic
Copy link
Collaborator

dangermattic commented Jan 28, 2025

2 Warnings
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ This PR is assigned to the milestone 21.6. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

…-logic-change

# Conflicts:
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/OrderDetailFragment.kt
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/OrderListFragment.kt
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/OrderListViewModel.kt
@AnirudhBhat AnirudhBhat requested a review from kidinov January 28, 2025 09:59

val Context.deviceTypeToAnalyticsString: String
get() = buildAnalyticsDeviceTypeValue(
IsScreenLargerThanCompactValue(value = windowSizeClass != WindowSizeClass.Compact)
IsScreenLargerThanCompactValue(value = isTwoPanesShouldBeUsed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsScreenLargerThanCompactValue should probably be renamed? I see that we track:

const val VALUE_DEVICE_TYPE_REGULAR = "regular"
        const val VALUE_DEVICE_TYPE_COMPACT = "compact"

But is this the same as 2 panes and 1 pane?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically it seems that what we want to track -> either 2 panes or 1 pane used, but naming is old so maybe confusing. Wdyt regarding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed variables used for analytics here: 91c4324

I've commented for more clarity on why we had kept the values for analytics as it is.

@@ -568,8 +567,8 @@ class OrderCreateEditViewModel @Inject constructor(
handleCouponEditResult(couponEditResult)
}

private fun getScreenSizeClassNameForAnalytics(windowSize: WindowSizeClass) =
IsScreenLargerThanCompactValue(windowSize != WindowSizeClass.Compact).deviceTypeToAnalyticsString
private fun getScreenSizeClassNameForAnalytics(isTwoPane: Boolean) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed: 91c4324

@@ -580,7 +579,7 @@ class OrderCreateEditViewModel @Inject constructor(
KEY_STATUS to order.status,
KEY_TYPE to CUSTOMER,
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.windowSizeClass)
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
Copy link
Contributor

@kidinov kidinov Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I am thinking about how we could keep the naming that we send to Tracks (for backward compatibility) but at the same time make it clear what we track in the code 🤔 I think maybe just renaming the variables to something that make it clear that we track 1/2 panes, but the values keep the same?

Copy link
Contributor Author

@AnirudhBhat AnirudhBhat Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've commented for more clarity on why we had kept the values for analytics as it is -91c4324


class IsWindowClassExpandedAndBigger @Inject constructor(val context: Context) {
operator fun invoke() = context.windowSizeClass >= WindowSizeClass.ExpandedAndBigger
operator fun invoke() = context.isTwoPanesShouldBeUsed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming here could be changed too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed: 91c4324

Copy link
Contributor

@kidinov kidinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I'd just recommend to improve the naming of the variables, to make it clear what are we doing, especially in tracking

@AnirudhBhat AnirudhBhat merged commit 32dd18c into trunk Jan 30, 2025
15 checks passed
@AnirudhBhat AnirudhBhat deleted the issue/12861-windowsize-detection-logic-change branch January 30, 2025 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: tablet Specific to tablet devices such as a Galaxy Tab or an iPad. type: bug A confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Order List] Squeezed Orders list on phone landscape mode
5 participants