-
-
Save walalm/3f5a1229a6af338004ea3ff3451d0730 to your computer and use it in GitHub Desktop.
HUD Bindings for Xamarin Forms projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Applifting; | |
using Android.Content; | |
using Xamarin.Forms.Labs.Services; | |
namespace Applifting.Droid | |
{ | |
public interface IDroidContextProvider{ | |
Context Context {get;} | |
} | |
public class DroidContextProvider : IDroidContextProvider{ | |
public static DroidContextProvider GlobalProvider; | |
#region IAndroidContextProvider implementation | |
public Context Context { | |
get ; | |
set ; | |
} | |
#endregion | |
} | |
public class HUDProvider : IHUDProvider | |
{ | |
IDroidContextProvider contextProvider; | |
public HUDProvider() | |
{ | |
} | |
private void RetrieveContextIfNeeded(){ | |
if(this.contextProvider == null){ | |
this.contextProvider = Resolver.Resolve<IDroidContextProvider>(); | |
} | |
} | |
#region IHUDProvider implementation | |
public void DisplayProgress(string message) | |
{ | |
RetrieveContextIfNeeded(); | |
AndroidHUD.AndHUD.Shared.Show(contextProvider.Context,message); | |
} | |
public void DisplaySuccess(string message) | |
{ | |
RetrieveContextIfNeeded(); | |
AndroidHUD.AndHUD.Shared.ShowSuccess(contextProvider.Context,message,AndroidHUD.MaskType.Black,TimeSpan.FromSeconds(1)); | |
} | |
public void DisplayError(string message) | |
{ | |
RetrieveContextIfNeeded(); | |
AndroidHUD.AndHUD.Shared.ShowError(contextProvider.Context,message,AndroidHUD.MaskType.Black,TimeSpan.FromSeconds(1)); | |
} | |
public void Dismiss() | |
{ | |
RetrieveContextIfNeeded(); | |
AndroidHUD.AndHUD.Shared.Dismiss(contextProvider.Context); | |
} | |
#endregion | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using BigTed; | |
namespace Applifting.iOS | |
{ | |
public class HUDProvider : IHUDProvider | |
{ | |
#region IHUDProvider implementation | |
public void DisplayProgress(string message) | |
{ | |
if(string.IsNullOrWhiteSpace(message)) { | |
BTProgressHUD.Show(); //shows the spinner | |
} else { | |
BTProgressHUD.Show(message); //show spinner + text | |
} | |
} | |
public void DisplaySuccess(string message) | |
{ | |
BTProgressHUD.ShowSuccessWithStatus(message); | |
} | |
public void DisplayError(string message) | |
{ | |
BTProgressHUD.ShowErrorWithStatus(message); | |
} | |
public void Dismiss() | |
{ | |
BTProgressHUD.Dismiss(); | |
} | |
#endregion | |
public HUDProvider() | |
{ | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Applifting | |
{ | |
public interface IHUDProvider | |
{ | |
void DisplayProgress(string message); | |
void DisplaySuccess(string message); | |
void DisplayError(string message); | |
void Dismiss(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment