Added abstract class for AppStart implementing all the necessary stuff

This commit is contained in:
nmilcoff 2018-03-26 21:55:33 -03:00
Родитель 2dd8ad44c8
Коммит e808325422
1 изменённых файлов: 26 добавлений и 18 удалений

Просмотреть файл

@ -3,32 +3,47 @@
// See the LICENSE file in the project root for more information.
using System.Threading;
using System.Threading.Tasks;
using MvvmCross.Exceptions;
using MvvmCross.Logging;
using MvvmCross.Navigation;
namespace MvvmCross.ViewModels
{
public class MvxAppStart<TViewModel>
: IMvxAppStart
where TViewModel : IMvxViewModel
public abstract class MvxAppStart : IMvxAppStart
{
protected readonly IMvxNavigationService NavigationService;
private int startHasCommenced;
public MvxAppStart(IMvxNavigationService navigationService)
{
NavigationService = navigationService;
}
public void Start(object hint = null)
{
// Check whether Start has commenced, and return if it has
if (Interlocked.CompareExchange(ref startHasCommenced, 1, 0) == 1)
return;
Startup(hint);
}
protected abstract void Startup(object hint = null);
public virtual bool IsStarted => startHasCommenced != 0;
public virtual void ResetStart()
{
Interlocked.Exchange(ref startHasCommenced, 0);
}
}
public class MvxAppStart<TViewModel> : MvxAppStart
where TViewModel : IMvxViewModel
{
protected readonly IMvxNavigationService NavigationService;
public MvxAppStart(IMvxNavigationService navigationService)
{
NavigationService = navigationService;
}
protected override void Startup(object hint = null)
{
if (hint != null)
{
MvxLog.Instance.Trace("Hint ignored in default MvxAppStart");
@ -43,12 +58,5 @@ namespace MvvmCross.ViewModels
throw exception.MvxWrap("Problem navigating to ViewModel {0}", typeof(TViewModel).Name);
}
}
public bool IsStarted => startHasCommenced != 0;
public void ResetStart()
{
Interlocked.Exchange(ref startHasCommenced, 0);
}
}
}