2023-02-22 14:03:35 +01:00
|
|
|
using System;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Threading.Tasks;
|
2024-04-09 12:53:23 +02:00
|
|
|
using ShareeBike.MultilingualResources;
|
2023-02-22 14:03:35 +01:00
|
|
|
using Xamarin.Essentials;
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
namespace SharedGui.ViewModel
|
2023-02-22 14:03:35 +01:00
|
|
|
{
|
|
|
|
public class NotConnectedToNetViewModel : INotifyPropertyChanged
|
|
|
|
{
|
|
|
|
|
|
|
|
public bool IsNotConnectedToNet { get; set; }
|
|
|
|
|
|
|
|
private bool _isBikesDataOutdatedLabelVisible = false;
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
public bool IsBikesDataOutdatedLabelVisible
|
|
|
|
{
|
|
|
|
get { return _isBikesDataOutdatedLabelVisible; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_isBikesDataOutdatedLabelVisible = value;
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsBikesDataOutdatedLabelVisible)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public NotConnectedToNetViewModel()
|
|
|
|
{
|
|
|
|
IsNotConnectedToNet = Connectivity.NetworkAccess != NetworkAccess.Internet;
|
|
|
|
// Register for connectivity changes, be sure to unsubscribe when finished
|
|
|
|
Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
|
|
|
|
{
|
|
|
|
IsNotConnectedToNet = e.NetworkAccess != NetworkAccess.Internet;
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsNotConnectedToNet)));
|
|
|
|
|
|
|
|
if (IsNotConnectedToNet)
|
|
|
|
{
|
|
|
|
IsBikesDataOutdatedLabelVisible = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IsBikesDataOutdatedLabelVisible = true;
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(5));
|
|
|
|
IsBikesDataOutdatedLabelVisible = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsBikesDataOutdatedLabelVisible)));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|