using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using TINK.View;
using Xamarin.Forms;
namespace TINK.ViewModel.WhatsNew
{
public class WhatsNewViewModel
{
/// Constructs view model.
///
///
///
/// Delegate to invoke master detail.
/// View service to show agb- page.
public WhatsNewViewModel(
Version currentVersion,
IDictionary whatsNewText,
bool isShowAgbRequired,
Action showMasterDetail,
IViewService p_oViewService)
{
ViewService = p_oViewService
?? throw new ArgumentException($"Can not instantiate {typeof(WhatsNewViewModel)}-object. No view available.");
ShowMasterDetail = showMasterDetail
?? throw new ArgumentException($"Can not instantiate {typeof(WhatsNewViewModel)}-object. No delegate to activated maste detail page available.");
CurrentVersion = currentVersion;
WhatsNewText = new FormattedString();
WhatsNewText.Spans.Add(new Span { Text = GetWhatNextHtmlText(whatsNewText) });
IsAgbChangedVisible = isShowAgbRequired;
}
public Version CurrentVersion { get; }
public FormattedString WhatsNewText { get; }
///
/// Title of the WhatsNewPage.
///
public string WhatsNewTitle
{
get
{
// Get version info.
return $"Neu in Version {CurrentVersion}";
}
}
/// Text saying that AGBs were modified.
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" });
return l_oHint;
}
}
public bool IsAgbChangedVisible { get; }
/// Command object to bind agb link to view model.
public ICommand OnShowAgbTapped
{
get
{
return new Command(async () => await ViewService.PushModalAsync(ViewTypes.GtcPage));
}
}
/// Called when dialog is disappearing.
///
public void OnDisappearing(Action setWhatsNewWasShown)
{
setWhatsNewWasShown();
}
#if !SHOWFEEDBACK
public bool IsFeedbackVisible => false;
#else
public bool IsFeedbackVisible => true;
#endif
/// User clicks rate button.
public ICommand OnOk
{
get
{
return new Command(() => ShowMasterDetail());
}
}
/// Reference to view service object.
private readonly IViewService ViewService;
/// Reference to view service object.
private Action ShowMasterDetail { get; }
public static string GetWhatNextHtmlText(IDictionary whatsNew)
=> string.Join("", whatsNew.Select(element => $"