2023-08-31 12:20:06 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using Android.App;
|
|
|
|
using Android.Widget;
|
|
|
|
using Foundation;
|
2024-04-09 12:53:23 +02:00
|
|
|
using ShareeBike.Model.Message;
|
2023-08-31 12:20:06 +02:00
|
|
|
using UIKit;
|
|
|
|
|
|
|
|
[assembly: Xamarin.Forms.Dependency(typeof(MessageAndroid))]
|
|
|
|
[assembly: Xamarin.Forms.Dependency(typeof(MessageIOS))]
|
2024-04-09 12:53:23 +02:00
|
|
|
namespace ShareeBike.Model.Message
|
2023-08-31 12:20:06 +02:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|