mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Threading.Tasks;
|
|
using TINK.MultilingualResources;
|
|
using Xamarin.Essentials;
|
|
|
|
namespace ShareeSharedGuiLib.ViewModel
|
|
{
|
|
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)));
|
|
|
|
}
|
|
}
|
|
}
|