Added abstract class for AppStart implementing all the necessary stuff
This commit is contained in:
Родитель
2dd8ad44c8
Коммит
e808325422
|
@ -3,32 +3,47 @@
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MvvmCross.Exceptions;
|
using MvvmCross.Exceptions;
|
||||||
using MvvmCross.Logging;
|
using MvvmCross.Logging;
|
||||||
using MvvmCross.Navigation;
|
using MvvmCross.Navigation;
|
||||||
|
|
||||||
namespace MvvmCross.ViewModels
|
namespace MvvmCross.ViewModels
|
||||||
{
|
{
|
||||||
public class MvxAppStart<TViewModel>
|
public abstract class MvxAppStart : IMvxAppStart
|
||||||
: IMvxAppStart
|
|
||||||
where TViewModel : IMvxViewModel
|
|
||||||
{
|
{
|
||||||
protected readonly IMvxNavigationService NavigationService;
|
|
||||||
|
|
||||||
private int startHasCommenced;
|
private int startHasCommenced;
|
||||||
|
|
||||||
public MvxAppStart(IMvxNavigationService navigationService)
|
|
||||||
{
|
|
||||||
NavigationService = navigationService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Start(object hint = null)
|
public void Start(object hint = null)
|
||||||
{
|
{
|
||||||
// Check whether Start has commenced, and return if it has
|
// Check whether Start has commenced, and return if it has
|
||||||
if (Interlocked.CompareExchange(ref startHasCommenced, 1, 0) == 1)
|
if (Interlocked.CompareExchange(ref startHasCommenced, 1, 0) == 1)
|
||||||
return;
|
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)
|
if (hint != null)
|
||||||
{
|
{
|
||||||
MvxLog.Instance.Trace("Hint ignored in default MvxAppStart");
|
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);
|
throw exception.MvxWrap("Problem navigating to ViewModel {0}", typeof(TViewModel).Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsStarted => startHasCommenced != 0;
|
|
||||||
|
|
||||||
public void ResetStart()
|
|
||||||
{
|
|
||||||
Interlocked.Exchange(ref startHasCommenced, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче