From 62d12f56421d90359dc4a9a544c035243b9e50e8 Mon Sep 17 00:00:00 2001 From: GiuseppeNovielli Date: Sun, 5 Mar 2023 16:23:17 +0100 Subject: [PATCH] update MVVMCrud 0.0.2 --- .../Utils/MVVMCrud/CustomMVVMCrud.cs | 7 ++++++- .../MVVMCrud/MVVMCrudApplication.cs | 20 +++++++++++++------ .../MVVMCrud/Models/Base/BaseModelRoot.cs | 6 +++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/MVVMCrud/xamarin_forms_5/MVVMCrud.Example/MVVMCrud.Example/Utils/MVVMCrud/CustomMVVMCrud.cs b/MVVMCrud/xamarin_forms_5/MVVMCrud.Example/MVVMCrud.Example/Utils/MVVMCrud/CustomMVVMCrud.cs index 45de2d6..b1cace0 100644 --- a/MVVMCrud/xamarin_forms_5/MVVMCrud.Example/MVVMCrud.Example/Utils/MVVMCrud/CustomMVVMCrud.cs +++ b/MVVMCrud/xamarin_forms_5/MVVMCrud.Example/MVVMCrud.Example/Utils/MVVMCrud/CustomMVVMCrud.cs @@ -3,6 +3,7 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Net.Security; +using System.Resources; using System.Security.Cryptography.X509Certificates; using MVVMCrud.Models.ItemRoot; using MVVMCrud.Utils; @@ -15,11 +16,15 @@ public class CustomMVVMCrud : MVVMCrudApplication { public CustomMVVMCrud() { - AppResourceManager = AppResources.ResourceManager; } public override BaseRequestSetupResponse SetupBaseRequestSetupResponse() => new CustomBaseRequestSetupResponse(); + public override ResourceManager SetupAppResourceManager() + { + return AppResources.ResourceManager; + } + public override HttpClient SetupHttpClient() { HttpClientHandler handler = new HttpClientHandler diff --git a/MVVMCrud/xamarin_forms_5/MVVMCrud/MVVMCrudApplication.cs b/MVVMCrud/xamarin_forms_5/MVVMCrud/MVVMCrudApplication.cs index 6193215..3f30e3c 100644 --- a/MVVMCrud/xamarin_forms_5/MVVMCrud/MVVMCrudApplication.cs +++ b/MVVMCrud/xamarin_forms_5/MVVMCrud/MVVMCrudApplication.cs @@ -20,8 +20,7 @@ namespace MVVMCrud { public class MVVMCrudApplication { - public const string PAGINATION_RESULT_NAME = "results"; - public const string RESULT_LIST = "results"; + public string RESULT_LIST { get; set; } #region EmptyView public ContentView EmptyView { get; set; } @@ -32,7 +31,7 @@ public class MVVMCrudApplication #endregion #region AppResource Host App - public ResourceManager AppResourceManager { get; set; } + public ResourceManager AppResourceManager { get; } #endregion #region Message resources @@ -68,9 +67,13 @@ public MVVMCrudApplication() IdMessagingCenterActiveList = new List(); + AppResourceManager = SetupAppResourceManager(); + RESULT_LIST = SetupResultKeyJSON(); HttpClient = SetupHttpClient(); } + public virtual ResourceManager SetupAppResourceManager() => AppResources.ResourceManager; + public virtual HttpClient SetupHttpClient() => new HttpClient(); public static string GetConfirmDeleteText() => Instance?.ConfirmDeleteText != null ? Instance.ConfirmDeleteText : AppResources.msg_confirm_delete; @@ -97,6 +100,8 @@ public MVVMCrudApplication() public static ContentView GetLoadingMoreView() => Instance?.LoadingMoreView != null ? Instance.LoadingMoreView : new LoadingMoreView(); public static ResourceManager GetAppResourceManager() => Instance?.AppResourceManager != null ? Instance.AppResourceManager : AppResources.ResourceManager; + public static string GetResultKeyJSON() => Instance?.RESULT_LIST != null ? "results" : Instance.SetupResultKeyJSON(); + public virtual BaseRequestSetupResponse SetupBaseRequestSetupResponse() => new BaseRequestSetupResponse(); @@ -109,9 +114,12 @@ public virtual List GetJsonConverters() return l; } - public virtual void SetupPaginationItem(string item, HttpResponseHeaders responseHeader, PaginationItem paginationItem) { } - public virtual void SetupRootItemBase(RootItemBase rootItemBase) { } + public virtual string SetupResultKeyJSON() => "results"; + + public virtual void SetupPaginationItem(string item, HttpResponseHeaders responseHeader, PaginationItem paginationItem){} + + public virtual void SetupRootItemBase(RootItemBase rootItemBase){} public virtual void SetupPaginationRequest(RootItemBase rootItemBase) { } @@ -162,7 +170,7 @@ public virtual JsonSerializerSettings SetupJsonUploadSettingsSerialize() { NullValueHandling = NullValueHandling.Ignore, }; - + return settings; } diff --git a/MVVMCrud/xamarin_forms_5/MVVMCrud/Models/Base/BaseModelRoot.cs b/MVVMCrud/xamarin_forms_5/MVVMCrud/Models/Base/BaseModelRoot.cs index 297d86a..33f0a06 100644 --- a/MVVMCrud/xamarin_forms_5/MVVMCrud/Models/Base/BaseModelRoot.cs +++ b/MVVMCrud/xamarin_forms_5/MVVMCrud/Models/Base/BaseModelRoot.cs @@ -209,7 +209,7 @@ void ProcessWithPagination(string response, HttpStatusCode httpStatus, HttpRespo if (!RootItemBase.IsError) { - var itemsArray = item.GetValue(MVVMCrudApplication.PAGINATION_RESULT_NAME).ToObject(); + var itemsArray = item.GetValue(MVVMCrudApplication.GetResultKeyJSON()).ToObject(); PaginationItem = new PaginationItem(response, responseHeader); OnDataArray(itemsArray); @@ -236,7 +236,7 @@ void ProcessWithPaginationExtraData(string response, HttpStatusCode httpStatus, if (!RootItemBase.IsError) { - var itemsArray = item.GetValue(MVVMCrudApplication.PAGINATION_RESULT_NAME).ToObject(); + var itemsArray = item.GetValue(MVVMCrudApplication.GetResultKeyJSON()).ToObject(); PaginationItem = new PaginationItem(response, responseHeader); OnDataObject(item); @@ -252,7 +252,7 @@ void ProcessWithoutPaginationExtraData(string response, HttpStatusCode httpStatu if (!RootItemBase.IsError) { - var itemsArray = item.GetValue(MVVMCrudApplication.RESULT_LIST).ToObject(); + var itemsArray = item.GetValue(MVVMCrudApplication.GetResultKeyJSON()).ToObject(); OnDataObject(item); OnDataArray(itemsArray);