From 3578731dcd94bbcb1d0f47b39c52745f3d53f8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20Kr=C3=B3l?= Date: Wed, 31 Jan 2024 15:55:50 +0100 Subject: [PATCH] Project box - 3 elements per row (#530) --- BMM.Core/Utils/ProjectBoxUtils.cs | 24 +++++++++++++++++++ .../ProjectBoxExpandedViewHolder.cs | 10 ++------ .../layout/listitem_project_box_expanded.xml | 2 +- .../ProjectBoxExpandedViewCell.cs | 14 ++++------- .../ProjectBoxExpandedViewCell.xib | 12 +++++----- 5 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 BMM.Core/Utils/ProjectBoxUtils.cs diff --git a/BMM.Core/Utils/ProjectBoxUtils.cs b/BMM.Core/Utils/ProjectBoxUtils.cs new file mode 100644 index 000000000..5e19e0088 --- /dev/null +++ b/BMM.Core/Utils/ProjectBoxUtils.cs @@ -0,0 +1,24 @@ +using BMM.Core.Helpers.Interfaces; +using BMM.Core.Models.POs.Base; +using BMM.Core.Models.POs.Base.Interfaces; +using BMM.Core.Models.POs.BibleStudy.Interfaces; + +namespace BMM.Core.Utils; + +public class ProjectBoxUtils +{ + private const int ItemsInRow = 3; + + public static IList AdjustAchievementsRows(IBmmObservableCollection achievements) + { + var rows = achievements.OfType().Chunk(ItemsInRow).ToList(); + var toFillInLastRow = ItemsInRow - rows.Last().Length; + var lastRow = rows.Last().ToList(); + + for (int i = 0; i < toFillInLastRow; i++) + lastRow.Add(new EmptyPO()); + + rows[^1] = lastRow.ToArray(); + return rows; + } +} \ No newline at end of file diff --git a/BMM.UI.Android/Application/ViewHolders/ProjectBoxExpandedViewHolder.cs b/BMM.UI.Android/Application/ViewHolders/ProjectBoxExpandedViewHolder.cs index 447a34b00..18936aa5c 100644 --- a/BMM.UI.Android/Application/ViewHolders/ProjectBoxExpandedViewHolder.cs +++ b/BMM.UI.Android/Application/ViewHolders/ProjectBoxExpandedViewHolder.cs @@ -8,6 +8,7 @@ using BMM.Core.Models.POs.Base.Interfaces; using BMM.Core.Models.POs.BibleStudy; using BMM.Core.Models.POs.BibleStudy.Interfaces; +using BMM.Core.Utils; using BMM.UI.Droid.Application.Adapters; using BMM.UI.Droid.Application.Listeners; using FFImageLoading.Cross; @@ -52,15 +53,8 @@ private void SetItems(IBmmObservableCollection achievements) if (achievements == null ||achievements.Count == 0) return; - var rows = achievements.OfType().Chunk(4).ToList(); - var toFillInLastRow = 4 - rows.Last().Length; - var lastRow = rows.Last().ToList(); + var rows = ProjectBoxUtils.AdjustAchievementsRows(achievements); - for (int i = 0; i < toFillInLastRow; i++) - lastRow.Add(new EmptyPO()); - - rows[^1] = lastRow.ToArray(); - var achievementsLayout = ItemView.FindViewById(Resource.Id.AchievementsLayout); achievementsLayout.RemoveAllViews(); diff --git a/BMM.UI.Android/Resources/layout/listitem_project_box_expanded.xml b/BMM.UI.Android/Resources/layout/listitem_project_box_expanded.xml index 923c597e7..a24594f5f 100644 --- a/BMM.UI.Android/Resources/layout/listitem_project_box_expanded.xml +++ b/BMM.UI.Android/Resources/layout/listitem_project_box_expanded.xml @@ -181,7 +181,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" - local:layout_constraintGuide_percent="0.4" /> + local:layout_constraintGuide_percent="0.5" /> \ No newline at end of file diff --git a/BMM.UI.iOS/Application/TableViewCell/ProjectBoxExpandedViewCell.cs b/BMM.UI.iOS/Application/TableViewCell/ProjectBoxExpandedViewCell.cs index 7fa5d55b1..ef5df1594 100644 --- a/BMM.UI.iOS/Application/TableViewCell/ProjectBoxExpandedViewCell.cs +++ b/BMM.UI.iOS/Application/TableViewCell/ProjectBoxExpandedViewCell.cs @@ -9,6 +9,7 @@ using BMM.Core.Models.POs.BibleStudy; using BMM.Core.Models.POs.BibleStudy.Interfaces; using BMM.Core.Models.POs.YearInReview; +using BMM.Core.Utils; using BMM.UI.iOS.Constants; using BMM.UI.iOS.Extensions; using BMM.UI.iOS.TableViewCell.Base; @@ -88,22 +89,15 @@ public IBmmObservableCollection ItemsSource } } - private void SetItems(IBmmObservableCollection itemsSource) + private void SetItems(IBmmObservableCollection achievements) { - if (itemsSource == null ||itemsSource.Count == 0) + if (achievements == null ||achievements.Count == 0) return; foreach (var view in AchievementStackView.ArrangedSubviews) view.RemoveFromSuperview(); - - var rows = itemsSource.OfType().Chunk(4).ToList(); - var toFillInLastRow = 4 - rows.Last().Length; - var lastRow = rows.Last().ToList(); - - for (int i = 0; i < toFillInLastRow; i++) - lastRow.Add(new EmptyPO()); - rows[^1] = lastRow.ToArray(); + var rows = ProjectBoxUtils.AdjustAchievementsRows(achievements); foreach (var row in rows) { diff --git a/BMM.UI.iOS/Application/TableViewCell/ProjectBoxExpandedViewCell.xib b/BMM.UI.iOS/Application/TableViewCell/ProjectBoxExpandedViewCell.xib index 2f9d82aba..791cdb855 100644 --- a/BMM.UI.iOS/Application/TableViewCell/ProjectBoxExpandedViewCell.xib +++ b/BMM.UI.iOS/Application/TableViewCell/ProjectBoxExpandedViewCell.xib @@ -109,7 +109,7 @@ - + @@ -125,19 +125,19 @@ - + - +