|
@ -12,14 +12,6 @@ namespace eShopOnContainers.Services |
|
|
{ |
|
|
{ |
|
|
public class NavigationService : INavigationService |
|
|
public class NavigationService : INavigationService |
|
|
{ |
|
|
{ |
|
|
protected Application CurrentApplication |
|
|
|
|
|
{ |
|
|
|
|
|
get |
|
|
|
|
|
{ |
|
|
|
|
|
return Application.Current; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Task InitializeAsync() |
|
|
public Task InitializeAsync() |
|
|
{ |
|
|
{ |
|
|
if(string.IsNullOrEmpty(Settings.AuthAccessToken)) |
|
|
if(string.IsNullOrEmpty(Settings.AuthAccessToken)) |
|
@ -38,32 +30,9 @@ namespace eShopOnContainers.Services |
|
|
return InternalNavigateToAsync(typeof(TViewModel), parameter); |
|
|
return InternalNavigateToAsync(typeof(TViewModel), parameter); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Task NavigateToAsync(Type viewModelType) |
|
|
|
|
|
{ |
|
|
|
|
|
return InternalNavigateToAsync(viewModelType, null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Task NavigateToAsync(Type viewModelType, object parameter) |
|
|
|
|
|
{ |
|
|
|
|
|
return InternalNavigateToAsync(viewModelType, parameter); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task NavigateBackAsync() |
|
|
|
|
|
{ |
|
|
|
|
|
if (CurrentApplication.MainPage is CatalogView) |
|
|
|
|
|
{ |
|
|
|
|
|
var mainPage = CurrentApplication.MainPage as CatalogView; |
|
|
|
|
|
await mainPage.Navigation.PopAsync(); |
|
|
|
|
|
} |
|
|
|
|
|
else if (CurrentApplication.MainPage != null) |
|
|
|
|
|
{ |
|
|
|
|
|
await CurrentApplication.MainPage.Navigation.PopAsync(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual Task RemoveLastFromBackStackAsync() |
|
|
|
|
|
|
|
|
public Task RemoveLastFromBackStackAsync() |
|
|
{ |
|
|
{ |
|
|
var mainPage = CurrentApplication.MainPage as CustomNavigationView; |
|
|
|
|
|
|
|
|
var mainPage = Application.Current.MainPage as CustomNavigationView; |
|
|
|
|
|
|
|
|
if (mainPage != null) |
|
|
if (mainPage != null) |
|
|
{ |
|
|
{ |
|
@ -74,9 +43,9 @@ namespace eShopOnContainers.Services |
|
|
return Task.FromResult(true); |
|
|
return Task.FromResult(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public virtual Task RemoveBackStackAsync() |
|
|
|
|
|
|
|
|
public Task RemoveBackStackAsync() |
|
|
{ |
|
|
{ |
|
|
var mainPage = CurrentApplication.MainPage as CustomNavigationView; |
|
|
|
|
|
|
|
|
var mainPage = Application.Current.MainPage as CustomNavigationView; |
|
|
|
|
|
|
|
|
if (mainPage != null) |
|
|
if (mainPage != null) |
|
|
{ |
|
|
{ |
|
@ -90,31 +59,31 @@ namespace eShopOnContainers.Services |
|
|
return Task.FromResult(true); |
|
|
return Task.FromResult(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected virtual async Task InternalNavigateToAsync(Type viewModelType, object parameter) |
|
|
|
|
|
|
|
|
private async Task InternalNavigateToAsync(Type viewModelType, object parameter) |
|
|
{ |
|
|
{ |
|
|
Page page = CreatePage(viewModelType, parameter); |
|
|
Page page = CreatePage(viewModelType, parameter); |
|
|
|
|
|
|
|
|
if (page is LoginView) |
|
|
if (page is LoginView) |
|
|
{ |
|
|
{ |
|
|
CurrentApplication.MainPage = new CustomNavigationView(page); |
|
|
|
|
|
|
|
|
Application.Current.MainPage = new CustomNavigationView(page); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
|
|
|
var navigationPage = CurrentApplication.MainPage as CustomNavigationView; |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
var navigationPage = Application.Current.MainPage as CustomNavigationView; |
|
|
if (navigationPage != null) |
|
|
if (navigationPage != null) |
|
|
{ |
|
|
{ |
|
|
await navigationPage.PushAsync(page); |
|
|
await navigationPage.PushAsync(page); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
CurrentApplication.MainPage = new CustomNavigationView(page); |
|
|
|
|
|
|
|
|
Application.Current.MainPage = new CustomNavigationView(page); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await (page.BindingContext as ViewModelBase).InitializeAsync(parameter); |
|
|
await (page.BindingContext as ViewModelBase).InitializeAsync(parameter); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected Type GetPageTypeForViewModel(Type viewModelType) |
|
|
|
|
|
|
|
|
private Type GetPageTypeForViewModel(Type viewModelType) |
|
|
{ |
|
|
{ |
|
|
var viewName = viewModelType.FullName.Replace("Model", string.Empty); |
|
|
var viewName = viewModelType.FullName.Replace("Model", string.Empty); |
|
|
var viewModelAssemblyName = viewModelType.GetTypeInfo().Assembly.FullName; |
|
|
var viewModelAssemblyName = viewModelType.GetTypeInfo().Assembly.FullName; |
|
@ -123,7 +92,7 @@ namespace eShopOnContainers.Services |
|
|
return viewType; |
|
|
return viewType; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected Page CreatePage(Type viewModelType, object parameter) |
|
|
|
|
|
|
|
|
private Page CreatePage(Type viewModelType, object parameter) |
|
|
{ |
|
|
{ |
|
|
Type pageType = GetPageTypeForViewModel(viewModelType); |
|
|
Type pageType = GetPageTypeForViewModel(viewModelType); |
|
|
if (pageType == null) |
|
|
if (pageType == null) |
|
|