Skip to content

Commit

Permalink
Project box - 3 elements per row (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
akrol95 authored Jan 31, 2024
1 parent deb6acb commit 3578731
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
24 changes: 24 additions & 0 deletions BMM.Core/Utils/ProjectBoxUtils.cs
Original file line number Diff line number Diff line change
@@ -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<IBasePO[]> AdjustAchievementsRows(IBmmObservableCollection<IAchievementPO> achievements)
{
var rows = achievements.OfType<IBasePO>().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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,15 +53,8 @@ private void SetItems(IBmmObservableCollection<IAchievementPO> achievements)
if (achievements == null ||achievements.Count == 0)
return;

var rows = achievements.OfType<IBasePO>().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<LinearLayout>(Resource.Id.AchievementsLayout);
achievementsLayout.RemoveAllViews();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
14 changes: 4 additions & 10 deletions BMM.UI.iOS/Application/TableViewCell/ProjectBoxExpandedViewCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,22 +89,15 @@ public IBmmObservableCollection<IAchievementPO> ItemsSource
}
}

private void SetItems(IBmmObservableCollection<IAchievementPO> itemsSource)
private void SetItems(IBmmObservableCollection<IAchievementPO> 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<IBasePO>().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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
</userDefinedRuntimeAttributes>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="pAs-SC-27T">
<rect key="frame" x="132.5" y="56" width="155.5" height="110"/>
<rect key="frame" x="156" y="56" width="132" height="110"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" axis="vertical" spacing="6" translatesAutoresizingMaskIntoConstraints="NO" id="ceP-4Y-aAT">
<rect key="frame" x="20" y="0.0" width="144.5" height="110"/>
Expand All @@ -125,19 +125,19 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="y9S-IE-hXT">
<rect key="frame" x="16" y="56" width="108.5" height="110"/>
<rect key="frame" x="16" y="56" width="132" height="110"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Kbm-y7-d9z">
<rect key="frame" x="0.0" y="32.5" width="108.5" height="45"/>
<rect key="frame" x="0.0" y="32.5" width="132" height="45"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="13" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GC9-Zx-SYz">
<rect key="frame" x="0.0" y="0.0" width="108.5" height="20.5"/>
<rect key="frame" x="0.0" y="0.0" width="132" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Your points" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7vT-FO-6dc">
<rect key="frame" x="0.0" y="24.5" width="108.5" height="20.5"/>
<rect key="frame" x="0.0" y="24.5" width="132" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -182,7 +182,7 @@
<constraint firstItem="5WQ-63-JkF" firstAttribute="centerY" secondItem="Gt6-st-l34" secondAttribute="centerY" id="csV-T0-RD5"/>
<constraint firstItem="Wvn-F1-wxy" firstAttribute="top" secondItem="pAs-SC-27T" secondAttribute="bottom" constant="12" id="dCi-q2-ILM"/>
<constraint firstItem="aAe-vW-t69" firstAttribute="leading" secondItem="twU-W8-rQv" secondAttribute="leading" id="dXE-Zw-Igx"/>
<constraint firstItem="Kbm-y7-d9z" firstAttribute="width" secondItem="pAs-SC-27T" secondAttribute="width" multiplier="0.7" id="eMK-qU-pbb"/>
<constraint firstItem="Kbm-y7-d9z" firstAttribute="width" secondItem="pAs-SC-27T" secondAttribute="width" id="eMK-qU-pbb"/>
<constraint firstItem="JdJ-rM-p42" firstAttribute="leading" secondItem="twU-W8-rQv" secondAttribute="leading" constant="12" id="ecF-Ng-OXz"/>
<constraint firstItem="Gt6-st-l34" firstAttribute="top" secondItem="twU-W8-rQv" secondAttribute="top" constant="12" id="hqM-Vr-PII"/>
<constraint firstAttribute="trailing" secondItem="pAs-SC-27T" secondAttribute="trailing" id="jIl-bT-b71"/>
Expand Down

0 comments on commit 3578731

Please sign in to comment.