2019-04-10 06:33:12 +03:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Android.App;
|
|
|
|
|
using Bit.App.Abstractions;
|
2019-04-10 06:24:03 +03:00
|
|
|
|
using Plugin.CurrentActivity;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Droid.Services
|
|
|
|
|
{
|
|
|
|
|
public class DeviceActionService : IDeviceActionService
|
|
|
|
|
{
|
2019-04-10 06:33:12 +03:00
|
|
|
|
private ProgressDialog _progressDialog;
|
2019-04-10 06:24:03 +03:00
|
|
|
|
private Android.Widget.Toast _toast;
|
|
|
|
|
|
|
|
|
|
public void Toast(string text, bool longDuration = false)
|
|
|
|
|
{
|
|
|
|
|
if(_toast != null)
|
|
|
|
|
{
|
|
|
|
|
_toast.Cancel();
|
|
|
|
|
_toast.Dispose();
|
|
|
|
|
_toast = null;
|
|
|
|
|
}
|
|
|
|
|
_toast = Android.Widget.Toast.MakeText(CrossCurrentActivity.Current.Activity, text,
|
|
|
|
|
longDuration ? Android.Widget.ToastLength.Long : Android.Widget.ToastLength.Short);
|
|
|
|
|
_toast.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool LaunchApp(string appName)
|
|
|
|
|
{
|
|
|
|
|
var activity = CrossCurrentActivity.Current.Activity;
|
|
|
|
|
appName = appName.Replace("androidapp://", string.Empty);
|
|
|
|
|
var launchIntent = activity.PackageManager.GetLaunchIntentForPackage(appName);
|
|
|
|
|
if(launchIntent != null)
|
|
|
|
|
{
|
|
|
|
|
activity.StartActivity(launchIntent);
|
|
|
|
|
}
|
|
|
|
|
return launchIntent != null;
|
|
|
|
|
}
|
2019-04-10 06:33:12 +03:00
|
|
|
|
|
|
|
|
|
public async Task ShowLoadingAsync(string text)
|
|
|
|
|
{
|
|
|
|
|
if(_progressDialog != null)
|
|
|
|
|
{
|
|
|
|
|
await HideLoadingAsync();
|
|
|
|
|
}
|
|
|
|
|
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
|
|
|
|
|
_progressDialog = new ProgressDialog(activity);
|
|
|
|
|
_progressDialog.SetMessage(text);
|
|
|
|
|
_progressDialog.SetCancelable(false);
|
|
|
|
|
_progressDialog.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task HideLoadingAsync()
|
|
|
|
|
{
|
|
|
|
|
if(_progressDialog != null)
|
|
|
|
|
{
|
|
|
|
|
_progressDialog.Dismiss();
|
|
|
|
|
_progressDialog.Dispose();
|
|
|
|
|
_progressDialog = null;
|
|
|
|
|
}
|
|
|
|
|
return Task.FromResult(0);
|
|
|
|
|
}
|
2019-04-10 06:24:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|