Skip to content

Commit

Permalink
♻️ Mobile | Update My QR Code button to use new scanner page (#1028)
Browse files Browse the repository at this point in the history
* Set flyout button to open scan page with qr code tab selected

* Remove old QR code popup

* Set brightness on qr code

* Fix camera on scan detection

* Move to variable

* Cleanup
  • Loading branch information
zacharykeeping authored Sep 6, 2024
1 parent baf5575 commit b72f2bc
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 171 deletions.
26 changes: 15 additions & 11 deletions src/MobileUI/Controls/SegmentedControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ public SegmentedControl()

public event EventHandler<Segment> SelectionChanged;

[AutoBindable(DefaultBindingMode = "TwoWay")]
[AutoBindable(DefaultBindingMode = "TwoWay", OnChanged = nameof(SegmentChanged))]
private Segment _selectedSegment;

private void SegmentChanged(Segment segment)
{
SetSelected(segment);
}

[AutoBindable(OnChanged = nameof(SegmentsChanged))]
private List<Segment> _segments;
private void SegmentsChanged(List<Segment> segments)
Expand All @@ -43,26 +48,25 @@ private void Segment_Tapped(object sender, TappedEventArgs e)
{
var segment = e.Parameter as Segment;

SetSelected(segment);

SelectedSegment = segment;
SelectionChanged?.Invoke(this, segment);
}

private void SetSelected(Segment segment)
{
if (segment == null)
{
return;
}

foreach (var item in Segments)
{
if (item == segment)
{
item.IsSelected = true;
}
else
{
item.IsSelected = false;
}
item.IsSelected = item == segment;
}

segment.IsSelected = true;
SelectedSegment = segment;
SelectionChanged?.Invoke(this, segment);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/MobileUI/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public static IServiceCollection AddDependencies(this IServiceCollection service
typeof(OthersProfileViewModel),
typeof(ProfileViewModelBase),
typeof(QuizDetailsPage),
typeof(QuizDetailsViewModel)
typeof(QuizDetailsViewModel),
typeof(ScanPage),
typeof(ScanViewModel)
};

var definedTypes = Assembly.GetExecutingAssembly().DefinedTypes
Expand All @@ -44,6 +46,8 @@ public static IServiceCollection AddDependencies(this IServiceCollection service
services.AddTransient<OthersProfileViewModel>();
services.AddTransient<QuizDetailsPage>();
services.AddTransient<QuizDetailsViewModel>();
services.AddTransient<ScanPage>();
services.AddTransient<ScanViewModel>();

services.AddSingleton<ILeaderService, LeaderService>();
services.AddSingleton<IUserService, UserService>();
Expand Down
15 changes: 8 additions & 7 deletions src/MobileUI/Features/Flyout/FlyoutFooterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ public partial class FlyoutFooterViewModel : ObservableObject
private readonly IUserService _userService;
private readonly IAuthenticationService _authService;
private readonly IFirebaseAnalyticsService _firebaseAnalyticsService;
private readonly IPermissionsService _permissionsService;

[ObservableProperty]
private bool _isStaff;

[ObservableProperty]
private string _versionNumber;

public FlyoutFooterViewModel(IUserService userService, IAuthenticationService authService, IFirebaseAnalyticsService firebaseAnalyticsService)
public FlyoutFooterViewModel(IUserService userService, IAuthenticationService authService, IFirebaseAnalyticsService firebaseAnalyticsService, IPermissionsService permissionsService)
{
_userService = userService;
_authService = authService;
_firebaseAnalyticsService = firebaseAnalyticsService;
_permissionsService = permissionsService;

VersionNumber = $"Version {AppInfo.VersionString}";

Expand All @@ -31,12 +33,11 @@ public FlyoutFooterViewModel(IUserService userService, IAuthenticationService au
[RelayCommand]
private async Task MyQrCodeTapped()
{
if (!IsStaff)
return;

Application.Current.Resources.TryGetValue("Background", out var statusBarColor);
var popup = new QrCodePage(new QrCodeViewModel(_userService), _firebaseAnalyticsService, statusBarColor as Color);
await MopupService.Instance.PushAsync(popup);
var granted = await _permissionsService.CheckAndRequestPermission<Permissions.Camera>();
if (granted)
{
await App.Current.MainPage.Navigation.PushModalAsync<ScanPage>(ScanPageSegments.MyCode);
}
}

[RelayCommand]
Expand Down
3 changes: 2 additions & 1 deletion src/MobileUI/Features/Redeem/RedeemRewardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class RedeemRewardViewModel(
{
private Reward _reward;
private float _defaultBrightness;
private const float MaxBrightness = 1.0f;

[ObservableProperty]
private string _image;
Expand Down Expand Up @@ -101,7 +102,7 @@ public void OnDisappearing()

private void ShowQrCode(string qrCode = null)
{
ScreenBrightness.Default.Brightness = 1;
ScreenBrightness.Default.Brightness = MaxBrightness;

IsHeaderVisible = false;
IsBalanceVisible = false;
Expand Down
58 changes: 0 additions & 58 deletions src/MobileUI/Features/Scanner/QrCodePage.xaml

This file was deleted.

42 changes: 0 additions & 42 deletions src/MobileUI/Features/Scanner/QrCodePage.xaml.cs

This file was deleted.

25 changes: 0 additions & 25 deletions src/MobileUI/Features/Scanner/QrCodeViewModel.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/MobileUI/Features/Scanner/ScanPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
Segments="{Binding Segments}"
VerticalOptions="End"
HeightRequest="50"
SelectedSegment="{Binding SelectedSegment, Mode=OneWayToSource}">
SelectedSegment="{Binding SelectedSegment}">
<controls:SegmentedControl.Behaviors>
<toolkit:EventToCommandBehavior
EventName="SelectionChanged"
Expand Down
7 changes: 5 additions & 2 deletions src/MobileUI/Features/Scanner/ScanPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ public partial class ScanPage
{
private readonly ScanViewModel _viewModel;
private readonly IFirebaseAnalyticsService _firebaseAnalyticsService;

public ScanPage(ScanViewModel viewModel, IFirebaseAnalyticsService firebaseAnalyticsService)

public ScanPage(ScanViewModel viewModel, IFirebaseAnalyticsService firebaseAnalyticsService,
ScanPageSegments segment = ScanPageSegments.Scan)
{
InitializeComponent();
_viewModel = viewModel;
_viewModel.Navigation = Navigation;
_firebaseAnalyticsService = firebaseAnalyticsService;
BindingContext = _viewModel;

_viewModel.SetSegment(segment);
}

protected override void OnDisappearing()
Expand Down
Loading

0 comments on commit b72f2bc

Please sign in to comment.