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

feat: #798 - now a unique page for preferences, in accordion #820

Merged
merged 9 commits into from
Jan 3, 2022

Conversation

monsieurtanuki
Copy link
Contributor

Deleted file:

  • settings_page.dart: all the code was moved to user_preferences_page.dart

Impacted files:

  • labeler.yml: removed reference to settings_page.dart
  • user_preferences.dart: added bool flags getter and setter
  • user_preferences_page.dart: now displays in accordion the same preferences, plus the former settings_page, plus the former action bar

It's ugly (in the code and on the screen), but it's a start
Simulator Screen Shot - iPhone 8 Plus - 2022-01-02 at 13 11 40

…dion

Deleted file:
* `settings_page.dart`: all the code was moved to `user_preferences_page.dart`

Impacted files:
* `labeler.yml`: removed reference to `settings_page.dart`
* `user_preferences.dart`: added bool flags getter and setter
* `user_preferences_page.dart`: now displays in accordion the same preferences, plus the former settings_page, plus the former action bar
@teolemon
Copy link
Member

teolemon commented Jan 2, 2022

That's great @monsieurtanuki 👍
Eventually, the mocks suggest that food preferences subsections can collapse (ingredients, environment, nutrition), which echoes concerns about potentially excessive scrolling cc @M123-dev

Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

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

First of all (again?) happy new year @monsieurtanuki and @teolemon 🎉

And to the PR there are a few things that I have to put out, see the comments but in general I think the code is much more complex than it needs to be, as can be seen by the fact that even you made a mistake (in profile are the settings items and in vrac are the user things).

ListView(
    children: <Widget>[
      
      _getGroupTitle(0, userPreferences, themeData);
      if(!_isCollapsed(0, userPreferences)) ..._getListItemsUser(...);
      
      _getGroupTitle(1, userPreferences, themeData);
      if(!_isCollapsed(1, userPreferences)) ..._getListItemsUser(...);
      
      _getGroupTitle(2, userPreferences, themeData);
      if(!_isCollapsed(2, userPreferences)) ..._getListItemsUser(...);
      
    ],
  );
  
  

  List<Widget> _getListItemsUser(){  
    return <Widget>[
      
      
      
      
    ];
};

throw Exception('unknown group index: $groupIndex');
}

int _getTotalSize(
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: _getTotalLength

_getTotalSize(groups, userPreferences),
(int index) {
for (int groupIndex = 0; groupIndex < 3; groupIndex++) {
if (index-- == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

This syntax works but it's not so easy to understand, I would prefer something like this but feel free to ignore that

index--;
if(index == 0){

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are indeed things to fix in my code.
But here your suggestion is wrong:

if(index-- == 0){
// do something with index before subtracting 1
}

means

if(index == 0){
  index --;
// do something
} else {
  index--;
}

Comment on lines 310 to 335
if (extra) {
title = Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
title,
Container(
width: 15,
height: 15,
child: Center(
child: Text(
'1',
style: TextStyle(
color: Colors.white,
fontSize: 8,
fontWeight: FontWeight.bold,
),
),
),
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
),
],
);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this red dot from the mocks, it does look good, but only a hardcoded one is confusing. We currently have nothing to display with this so we don't need the additional code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, it was just for the screenshot. Removing it...

Comment on lines 354 to 358
return 5;
case 1:
return groups.length;
case 2:
return 3;
Copy link
Member

Choose a reason for hiding this comment

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

A user items length and settings items length int would certainly be nice for later additions

);
}

int _getCollapsedSize(
Copy link
Member

Choose a reason for hiding this comment

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

_getExpandedLength

case 1:
return 'food';
case 2:
return 'vrac';
Copy link
Member

Choose a reason for hiding this comment

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

Had to use the translator to understand this, would be good to stick with english

) {
switch (groupIndex) {
case 0:
return _getListItemSettings(
Copy link
Member

Choose a reason for hiding this comment

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

_getListItemVrac

themeData,
);
case 2:
return _getListItemVrac(index, appLocalizations);
Copy link
Member

Choose a reason for hiding this comment

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

_getListItemSettings

New files:
* `abstract_user_preferences.dart`: Abstraction of a collapsed/expanded display for the preferences page.
* `user_preferences_attribute_group.dart`: Collapsed/expanded display of attributes for the preferences page.
* `user_preferences_profile.dart`: Collapsed/expanded display of profile for the preferences page.
* `user_preferences_settings.dart`: Collapsed/expanded display of settings for the preferences page.

Impacted file:
* `user_preferences_page.dart`: huge simplification through the use of instances of new class `AbstractUserPreferences`
@monsieurtanuki
Copy link
Contributor Author

Thank you guys for your code review!
@M123-dev I've just cleaned the code "à la Java".
@teolemon I think I could also implement collapsed/expanded attribute groups: that shouldn't be a problem.

@teolemon
Copy link
Member

teolemon commented Jan 2, 2022

@monsieurtanuki there are conflicts to solve

@monsieurtanuki
Copy link
Contributor Author

Conflict resolved.

@teolemon
Copy link
Member

teolemon commented Jan 3, 2022

  • info • The import of 'package:flutter/cupertino.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flutter/material.dart' • packages/smooth_app/lib/pages/user_preferences_attribute_group.dart:1:8 • unnecessary_import
  • info • The import of 'package:flutter/cupertino.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flutter/material.dart' • packages/smooth_app/lib/pages/user_preferences_page.dart:1:8 • unnecessary_import
  • info • The import of 'package:flutter/cupertino.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flutter/material.dart' • packages/smooth_app/lib/pages/user_preferences_profile.dart:1:8 • unnecessary_import

@@ -0,0 +1,168 @@
import 'package:flutter/cupertino.dart';
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import 'package:flutter/cupertino.dart';

@teolemon
Copy link
Member

teolemon commented Jan 3, 2022

I added 3 suggestions to 🟢 the CI @monsieurtanuki @M123-dev

Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @monsieurtanuki, maybe it would be an idea to move the preferences pages to their own subfolder but it's not that important

Comment on lines 7 to 8
abstract class AbstractUserPreferences {
AbstractUserPreferences(this.setState);
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion I think AppPreferences is easier to otherwise it could be mistakely seen as the real user manangement setting, but feel free to ignore that

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 added 3 suggestions to 🟢 the CI @monsieurtanuki @M123-dev

I'll do that. Is there a way we can put the same level of lint checks in dev (Android Studio) and in CI?

Comment on lines 32 to 35
UserPreferencesSettings(setState),
UserPreferencesAttributeGroup(
setState,
productPreferences,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't UserPreferencesProfile be the first one here?

New file:
* `user_preferences_food.dart`: Collapsed/expanded display of attribute groups for the preferences page.

Impacted files:
* `abstract_user_preferences.dart`: refactored for localization
* `app_en.arb`: added 6 labels for preferences titles and subtitles
* `app_fr.arb`: added 6 labels for preferences titles and subtitles
* `user_preferences_attribute_group.dart`: now we manage here only one group at a time, to make it collapsable
* `user_preferences_page.dart`: refactored for localization
* `user_preferences_profile.dart`: refactored for localization
* `user_preferences_settings.dart`: refactored for localization
@monsieurtanuki
Copy link
Contributor Author

Now we have localization and collapsable food preferences:
Simulator Screen Shot - iPhone 8 Plus - 2022-01-03 at 15 25 27

Impacted file:
* `user_preferences_food.dart`
Impacted files:
* `user_preferences_page-blue-dark.png`
* `user_preferences_page-blue-light.png`
* `user_preferences_page-brown-dark.png`
* `user_preferences_page-brown-light.png`
* `user_preferences_page-green-dark.png`
* `user_preferences_page-green-light.png`
@monsieurtanuki
Copy link
Contributor Author

Btw how is "labeler" supposed to work? Every time it fails - is there something to fix, and what?

@teolemon
Copy link
Member

teolemon commented Jan 3, 2022

labeler works if you PR on the main repo, but not on forks :-(
pyrsia/pyrsia#130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants