mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-13 22:06:29 +01:00
68 lines
1.4 KiB
C#
68 lines
1.4 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using Android.App;
|
||
|
using Android.Widget;
|
||
|
using Foundation;
|
||
|
using TINK.Model.Message;
|
||
|
using UIKit;
|
||
|
|
||
|
[assembly: Xamarin.Forms.Dependency(typeof(MessageAndroid))]
|
||
|
[assembly: Xamarin.Forms.Dependency(typeof(MessageIOS))]
|
||
|
namespace TINK.Model.Message
|
||
|
{
|
||
|
public class MessageAndroid : IMessage
|
||
|
{
|
||
|
public void LongAlert(string message)
|
||
|
{
|
||
|
Toast.MakeText(Application.Context, message, ToastLength.Long).Show();
|
||
|
}
|
||
|
|
||
|
public void ShortAlert(string message)
|
||
|
{
|
||
|
Toast.MakeText(Application.Context, message, ToastLength.Short).Show();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public class MessageIOS : IMessage
|
||
|
{
|
||
|
const double LONG_DELAY = 3.5;
|
||
|
const double SHORT_DELAY = 0.75;
|
||
|
|
||
|
public void LongAlert(string message)
|
||
|
{
|
||
|
ShowAlert(message, LONG_DELAY);
|
||
|
}
|
||
|
|
||
|
public void ShortAlert(string message)
|
||
|
{
|
||
|
ShowAlert(message, SHORT_DELAY);
|
||
|
}
|
||
|
|
||
|
void ShowAlert(string message, double seconds)
|
||
|
{
|
||
|
var alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
|
||
|
|
||
|
var alertDelay = NSTimer.CreateScheduledTimer(seconds, obj =>
|
||
|
{
|
||
|
DismissMessage(alert, obj);
|
||
|
});
|
||
|
|
||
|
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null);
|
||
|
}
|
||
|
|
||
|
void DismissMessage(UIAlertController alert, NSTimer alertDelay)
|
||
|
{
|
||
|
if (alert != null)
|
||
|
{
|
||
|
alert.DismissViewController(true, null);
|
||
|
}
|
||
|
|
||
|
if (alertDelay != null)
|
||
|
{
|
||
|
alertDelay.Dispose();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|