Skip to content

Commit

Permalink
update MVVMCrud 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
GiuseppeNovielli committed Mar 5, 2023
1 parent e46361a commit 62d12f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
20 changes: 14 additions & 6 deletions MVVMCrud/xamarin_forms_5/MVVMCrud/MVVMCrudApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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
Expand Down Expand Up @@ -68,9 +67,13 @@ public MVVMCrudApplication()

IdMessagingCenterActiveList = new List<string>();

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;
Expand All @@ -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();


Expand All @@ -109,9 +114,12 @@ public virtual List<JsonConverter> 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) { }

Expand Down Expand Up @@ -162,7 +170,7 @@ public virtual JsonSerializerSettings SetupJsonUploadSettingsSerialize()
{
NullValueHandling = NullValueHandling.Ignore,
};

return settings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void ProcessWithPagination(string response, HttpStatusCode httpStatus, HttpRespo

if (!RootItemBase.IsError)
{
var itemsArray = item.GetValue(MVVMCrudApplication.PAGINATION_RESULT_NAME).ToObject<JArray>();
var itemsArray = item.GetValue(MVVMCrudApplication.GetResultKeyJSON()).ToObject<JArray>();
PaginationItem = new PaginationItem(response, responseHeader);

OnDataArray(itemsArray);
Expand All @@ -236,7 +236,7 @@ void ProcessWithPaginationExtraData(string response, HttpStatusCode httpStatus,

if (!RootItemBase.IsError)
{
var itemsArray = item.GetValue(MVVMCrudApplication.PAGINATION_RESULT_NAME).ToObject<JArray>();
var itemsArray = item.GetValue(MVVMCrudApplication.GetResultKeyJSON()).ToObject<JArray>();
PaginationItem = new PaginationItem(response, responseHeader);

OnDataObject(item);
Expand All @@ -252,7 +252,7 @@ void ProcessWithoutPaginationExtraData(string response, HttpStatusCode httpStatu

if (!RootItemBase.IsError)
{
var itemsArray = item.GetValue(MVVMCrudApplication.RESULT_LIST).ToObject<JArray>();
var itemsArray = item.GetValue(MVVMCrudApplication.GetResultKeyJSON()).ToObject<JArray>();

OnDataObject(item);
OnDataArray(itemsArray);
Expand Down

0 comments on commit 62d12f5

Please sign in to comment.