Skip to content

Commit

Permalink
Manage needJoin + needSign separately (fix #265)
Browse files Browse the repository at this point in the history
- like the mobile app, a notice could show a join & sign button at the same time
  • Loading branch information
Gabboxl committed May 25, 2024
1 parent 700e1de commit b8fe78c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 77 deletions.
24 changes: 16 additions & 8 deletions ClassevivaPCTO/Dialogs/NoticeDialogContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@
ItemContainerStyle="{StaticResource ListViewFullStretchStyle}"
ItemTemplate="{StaticResource AttachmentListViewDataTemplate}" />

<StackPanel Visibility="{x:Bind ShowJoinAlert, Converter={StaticResource BetterBoolToVisibilityConverter}, ConverterParameter=True}">
<StackPanel Visibility="{x:Bind ShowSignAlert, Converter={StaticResource BetterBoolToVisibilityConverter}, ConverterParameter=True}">
<Rectangle Fill="{ThemeResource ControlStrongStrokeColorDisabledBrush}" Height="1" Margin="0,8,0,8"/>

<controls:InfoBar
IsOpen="True"
Severity="{x:Bind JoinAlertSeverityStatus}"
Title="{x:Bind JoinAlertMessage}" IsClosable="False"/>
Severity="{x:Bind SignAlertSeverityStatus}"
Title="{x:Bind SignAlertMessage}" IsClosable="False"/>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Visibility="{x:Bind JoinButtonsVisibility}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Visibility="{x:Bind SignButtonsVisibility}">
<StackPanel Orientation="Horizontal" Visibility="{x:Bind CurrentNotice.needSign, Converter={StaticResource BetterBoolToVisibilityConverter}, ConverterParameter=True}">

<AppBarButton x:Name="ButtonSign" Icon="Accept" VerticalAlignment="Center"
Expand All @@ -145,14 +145,22 @@
<AppBarButton x:Name="ButtonRefuse" VerticalAlignment="Center" Icon="Cancel"
Label="Rifiuta" />
</StackPanel>

<AppBarButton x:Name="ButtonJoin" VerticalAlignment="Center" Icon="AddFriend"
Visibility="{x:Bind CurrentNotice.needJoin, Converter={StaticResource BetterBoolToVisibilityConverter}, ConverterParameter=True}"
Label="Aderisci" />

</StackPanel>
</StackPanel>

<StackPanel Visibility="{x:Bind CurrentNotice.needJoin, Converter={StaticResource BetterBoolToVisibilityConverter}, ConverterParameter=True}">
<Rectangle Fill="{ThemeResource ControlStrongStrokeColorDisabledBrush}" Height="1" Margin="0,8,0,8"/>

<controls:InfoBar
IsOpen="True"
Severity="{x:Bind JoinAlertSeverity}"
Title="{x:Bind JoinAlertMessage}" IsClosable="False"/>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Visibility="{x:Bind JoinButtonVisibility}">
<AppBarButton x:Name="ButtonJoin" VerticalAlignment="Center" Icon="AddFriend" Label="Aderisci" />
</StackPanel>
</StackPanel>

</StackPanel>
</ScrollViewer>
Expand Down
145 changes: 77 additions & 68 deletions ClassevivaPCTO/Dialogs/NoticeDialogContent.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ClassevivaPCTO.Helpers;
using Microsoft.AppCenter.Channel;
using Microsoft.UI.Xaml.Controls;

namespace ClassevivaPCTO.Dialogs
Expand All @@ -18,9 +19,8 @@ public sealed partial class NoticeDialogContent : Page

private readonly IClassevivaAPI _apiWrapper;

enum SignJoinNoticeType
enum SignNoticeType
{
JOIN,
SIGN,
SIGN_MESSAGE,
SIGN_FILE,
Expand All @@ -33,12 +33,11 @@ enum SignJoinNoticeType
// REQUESTED
//}

private bool ShowJoinAlert
private bool ShowSignAlert
{
get
{
return CurrentNotice.needJoin ||
CurrentNotice.needSign ||
return CurrentNotice.needSign ||
CurrentNotice.needFile ||
CurrentNotice.needReply;
}
Expand All @@ -56,6 +55,22 @@ private string JoinAlertMessage
return "JoinRequestedMessage".GetLocalizedStr();
}

return "JoinRequestedMessage".GetLocalizedStr();
}
}

private string SignAlertMessage
{
get
{
if (CurrentNotice.needJoin)
{
if (CurrentReadResult.reply.replJoin.GetValueOrDefault())
return "JoinSuccessMessage".GetLocalizedStr();

return "JoinRequestedMessage".GetLocalizedStr();
}

if (CurrentNotice.needSign)
{
if (CurrentReadResult.reply.replSign == null)
Expand All @@ -70,15 +85,21 @@ private string JoinAlertMessage
}
}

private InfoBarSeverity JoinAlertSeverityStatus //status
private InfoBarSeverity JoinAlertSeverity
{
get
{
if (CurrentNotice.needJoin)
{
if (CurrentReadResult.reply.replJoin.GetValueOrDefault())
return InfoBarSeverity.Success;
} // a join can't be refused
return CurrentReadResult.reply.replJoin.GetValueOrDefault() ? InfoBarSeverity.Success : InfoBarSeverity.Informational;

return InfoBarSeverity.Informational;
}
}

private InfoBarSeverity SignAlertSeverityStatus
{
get
{

if (CurrentNotice.needFile)
{
Expand All @@ -103,11 +124,11 @@ private InfoBarSeverity JoinAlertSeverityStatus //status
}
}

private Visibility JoinButtonsVisibility
private Visibility SignButtonsVisibility
{
get
{
switch (JoinAlertSeverityStatus)
switch (SignAlertSeverityStatus)
{
case InfoBarSeverity.Success:
return Visibility.Collapsed;
Expand All @@ -121,6 +142,14 @@ private Visibility JoinButtonsVisibility
}
}

private Visibility JoinButtonVisibility
{
get
{
return JoinAlertSeverity == InfoBarSeverity.Success ? Visibility.Collapsed : Visibility.Visible;
}
}


public NoticeDialogContent(Notice notice, NoticeReadResult noticeReadResult)
{
Expand All @@ -144,9 +173,9 @@ public NoticeDialogContent(Notice notice, NoticeReadResult noticeReadResult)

AttachmentsListView.ItemsSource = notice.attachments;

ButtonSign.Click += (sender, e) => ShowSignJoinRefuseFlyout(sender, e, false);
ButtonJoin.Click += (sender, e) => ShowSignJoinRefuseFlyout(sender, e, false);
ButtonRefuse.Click += (sender, e) => ShowSignJoinRefuseFlyout(sender, e, true);
ButtonSign.Click += (sender, e) => ShowSignJoinRefuseFlyout(sender, e, false, false);
ButtonJoin.Click += (sender, e) => ShowSignJoinRefuseFlyout(sender, e, true, false);
ButtonRefuse.Click += (sender, e) => ShowSignJoinRefuseFlyout(sender, e, false, true);

App app = (App) App.Current;
var apiClient = app.Container.GetService<IClassevivaAPI>();
Expand Down Expand Up @@ -242,20 +271,20 @@ private async Task<byte[]> GetAttachmentAsBytes(NoticeAttachment attachment)
return bytes;
}

private void ShowSignJoinRefuseFlyout(object sender, RoutedEventArgs e, bool isRefuse)
private void ShowSignJoinRefuseFlyout(object sender, RoutedEventArgs e, bool isJoin, bool isRefuse)
{
var flyout = new Flyout();

var textBlock = new TextBlock
{
Text = GetActionText(isRefuse),
Text = GetActionText(isJoin, isRefuse),
TextWrapping = TextWrapping.WrapWholeWords,
Margin = new Thickness(0, 0, 0, 12)
};

var finalButton = new Button
{
Content = GetActionButtonContent(isRefuse),
Content = GetActionButtonContent(isJoin, isRefuse),
MinWidth = 90,
Style = (Style) Application.Current.Resources["AccentButtonStyle"],
HorizontalAlignment = HorizontalAlignment.Center,
Expand All @@ -269,23 +298,23 @@ private void ShowSignJoinRefuseFlyout(object sender, RoutedEventArgs e, bool isR

var noticeReadSignRequest = new NoticeReadSignRequest();

switch (GetSignJoinType())
if(isJoin)
noticeReadSignRequest.join = !isRefuse;
else
{
case SignJoinNoticeType.SIGN_FILE:
if (CurrentNotice.needFile)
{
noticeReadSignRequest.sign = !isRefuse;
noticeReadSignRequest.file = "file"; //TODO: implement file picker!!
noticeReadSignRequest.filename = "filename";
break;
case SignJoinNoticeType.SIGN:
}else if (CurrentNotice.needSign)
{
noticeReadSignRequest.sign = !isRefuse;
break;
case SignJoinNoticeType.SIGN_MESSAGE:
}else if (CurrentNotice.needReply)
{
noticeReadSignRequest.sign = !isRefuse;
noticeReadSignRequest.text = "message"; //TODO: implement message edit!!
break;
case SignJoinNoticeType.JOIN:
noticeReadSignRequest.join = !isRefuse;
break;
}
}

var result = await _apiWrapper.ReadNotice(cardResult.usrId.ToString(), CurrentNotice.pubId.ToString(),
Expand All @@ -312,57 +341,37 @@ private void ShowSignJoinRefuseFlyout(object sender, RoutedEventArgs e, bool isR
flyout.ShowAt((FrameworkElement) sender);
}

private string GetActionText(bool isRefuse)
private string GetActionText(bool isJoin, bool isRefuse)
{
if (isRefuse)
return "Per rifiutare la comunicazione, premi il pulsante sottostante.";

switch (GetSignJoinType())
{
case SignJoinNoticeType.SIGN_FILE:
return "Per firmare con file allegato, premi il pulsante sottostante.";
case SignJoinNoticeType.SIGN:
return "Per firmare la comunicazione, premi il pulsante sottostante.";
case SignJoinNoticeType.SIGN_MESSAGE:
return "Per firmare con messaggio, premi il pulsante sottostante.";
case SignJoinNoticeType.JOIN:
return "Per unirti alla comunicazione, premi il pulsante sottostante.";
default:
return string.Empty;
}
}
if(isJoin)
return "Per unirti alla comunicazione, premi il pulsante sottostante.";

private string GetActionButtonContent(bool isRefuse)
{
if (isRefuse)
return "Rifiuta";
if(CurrentNotice.needFile)
return "Per firmare con file allegato, premi il pulsante sottostante.";
if(CurrentNotice.needSign)
return "Per firmare la comunicazione, premi il pulsante sottostante.";
if(CurrentNotice.needReply)
return "Per firmare con messaggio, premi il pulsante sottostante.";

switch (GetSignJoinType())
{
case SignJoinNoticeType.SIGN_FILE or SignJoinNoticeType.SIGN or SignJoinNoticeType.SIGN_MESSAGE:
return "Firma";
case SignJoinNoticeType.JOIN:
return "Unisciti";
default:
return string.Empty;
}
return string.Empty;

}

private SignJoinNoticeType? GetSignJoinType()
private string GetActionButtonContent(bool isJoin, bool isRefuse)
{
if (CurrentNotice.needJoin)
return SignJoinNoticeType.JOIN;

if (CurrentNotice.needReply)
return SignJoinNoticeType.SIGN_MESSAGE;

if (CurrentNotice.needFile)
return SignJoinNoticeType.SIGN_FILE;
if (isRefuse)
return "Rifiuta";

if (CurrentNotice.needSign)
return SignJoinNoticeType.SIGN;
if(isJoin)
return "Unisciti";

return null;
if(CurrentNotice.needReply || CurrentNotice.needFile || CurrentNotice.needSign)
return "Firma";

return string.Empty;
}
}
}
2 changes: 1 addition & 1 deletion ClassevivaPCTO/Strings/it-it/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,6 @@ Errore: </value>
<value>Per questa comunicazione è richiesta una conferma e firma di accettazione</value>
</data>
<data name="SignSuccessMessage" xml:space="preserve">
<value>Confermato e firmato correttamente</value>
<value>Comunicazione confermata e firmata</value>
</data>
</root>

0 comments on commit b8fe78c

Please sign in to comment.