sharee.bike-App/TINKLib/ViewModel/WhatsNew/WhatsNewViewModel.cs

108 lines
3 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
2021-05-13 20:03:07 +02:00
using System.Windows.Input;
2022-08-30 15:42:25 +02:00
using TINK.View;
2021-05-13 20:03:07 +02:00
using Xamarin.Forms;
namespace TINK.ViewModel.WhatsNew
{
2022-09-06 16:08:19 +02:00
public class WhatsNewViewModel
{
/// <summary> Constructs view model. </summary>
/// <param name="currentVersion"></param>
/// <param name="whatsNewText"></param>
/// <param name="isShowAgbRequired"></param>
/// <param name="showMasterDetail">Delegate to invoke master detail.</param>
/// <param name="p_oViewService">View service to show agb- page.</param>
public WhatsNewViewModel(
Version currentVersion,
IDictionary<Version, string> whatsNewText,
bool isShowAgbRequired,
Action showMasterDetail,
IViewService p_oViewService)
{
ViewService = p_oViewService
?? throw new ArgumentException($"Can not instantiate {typeof(WhatsNewViewModel)}-object. No view available.");
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
ShowMasterDetail = showMasterDetail
?? throw new ArgumentException($"Can not instantiate {typeof(WhatsNewViewModel)}-object. No delegate to activated maste detail page avilable.");
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
CurrentVersion = currentVersion;
WhatsNewText = new FormattedString();
WhatsNewText.Spans.Add(new Span { Text = GetWhatNextHtmlText(whatsNewText) });
IsAgbChangedVisible = isShowAgbRequired;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public Version CurrentVersion { get; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public FormattedString WhatsNewText { get; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Title of the WhatsNewPage.
/// </summary>
public string WhatsNewTitle
{
get
{
// Get version info.
return $"Neu in Version {CurrentVersion}";
}
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Text saying that AGBs were modified.</summary>
public FormattedString AgbChangedText
{
get
{
var l_oHint = new FormattedString();
l_oHint.Spans.Add(new Span { Text = "AGBs ", ForegroundColor = ViewModelHelper.LINK_COLOR });
l_oHint.Spans.Add(new Span { Text = "überarbeitet.\r\n" });
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
return l_oHint;
}
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public bool IsAgbChangedVisible { get; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Command object to bind agb link to view model.</summary>
public ICommand OnShowAgbTapped
{
get
{
return new Command(async () => await ViewService.PushModalAsync(ViewTypes.AgbPage));
}
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Called when dialog is disappearing.</summary>
/// <param name="setWhatsNewWasShown"></param>
public void OnDisappearing(Action setWhatsNewWasShown)
{
setWhatsNewWasShown();
}
2021-05-13 20:03:07 +02:00
#if !SHOWFEEDBACK
2022-09-06 16:08:19 +02:00
public bool IsFeedbackVisible => false;
2021-05-13 20:03:07 +02:00
#else
public bool IsFeedbackVisible => true;
#endif
2022-09-06 16:08:19 +02:00
/// <summary> User clicks rate button.</summary>
public ICommand OnOk
{
get
{
return new Command(() => ShowMasterDetail());
}
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>Reference to view service object.</summary>
private readonly IViewService ViewService;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>Reference to view service object.</summary>
private Action ShowMasterDetail { get; }
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
public static string GetWhatNextHtmlText(IDictionary<Version, string> whatsNew)
=> string.Join("", whatsNew.Select(element => $"<p><b>{element.Key}</b><br/>{element.Value}</p>").ToArray());
}
2021-05-13 20:03:07 +02:00
}