-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SOS functionality for both online and offline device
- Loading branch information
1 parent
1b6c687
commit c858391
Showing
13 changed files
with
203 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
using SOS.Data; | ||
using SOS.Business; | ||
|
||
namespace SOS; | ||
|
||
public partial class App : Application | ||
{ | ||
public static SettingsRepository SettingsRepo { get; private set; } | ||
|
||
public App(SettingsRepository repo) | ||
public static LocationService LocationService { get; private set; } | ||
|
||
public App(SettingsRepository repo, LocationService locationService) | ||
{ | ||
InitializeComponent(); | ||
|
||
MainPage = new AppShell(); | ||
|
||
SettingsRepo = repo; | ||
|
||
LocationService = locationService; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace SOS.Business | ||
{ | ||
public class LocationService | ||
{ | ||
private CancellationTokenSource _cancelTokenSource; | ||
private bool _isCheckingLocation; | ||
|
||
public async Task<Dictionary<string, object>> GetCurrentLocation() | ||
{ | ||
try | ||
{ | ||
_isCheckingLocation = true; | ||
|
||
GeolocationRequest request = new GeolocationRequest(GeolocationAccuracy.Best); | ||
|
||
_cancelTokenSource = new CancellationTokenSource(); | ||
|
||
Location location = await Geolocation.Default.GetLocationAsync(request, _cancelTokenSource.Token); | ||
|
||
if (location != null) | ||
{ | ||
_isCheckingLocation = false; | ||
return new() | ||
{ | ||
{ "found", true }, | ||
{ "latitude", location.Latitude.ToString() }, | ||
{ "longitude", location.Longitude.ToString() } | ||
}; | ||
|
||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new() | ||
{ | ||
{ "found", false }, | ||
{ "error", ex.Message } | ||
}; | ||
} | ||
|
||
return new() | ||
{ | ||
{ "found", false } | ||
}; | ||
} | ||
|
||
public void CancelRequest() | ||
{ | ||
if (_isCheckingLocation && _cancelTokenSource != null && _cancelTokenSource.IsCancellationRequested == false) | ||
_cancelTokenSource.Cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Newtonsoft.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SOS.Models | ||
{ | ||
public class AppwriteApiResponse | ||
{ | ||
[JsonProperty("$id")] | ||
public string Id { get; set; } | ||
|
||
[JsonProperty("$createdAt")] | ||
public DateTime CreatedAt { get; set; } | ||
|
||
[JsonProperty("$updatedAt")] | ||
public DateTime UpdatedAt { get; set; } | ||
|
||
[JsonProperty("$permissions")] | ||
public List<object> Permissions { get; set; } | ||
|
||
[JsonProperty("functionId")] | ||
public string FunctionId { get; set; } | ||
|
||
[JsonProperty("trigger")] | ||
public string Trigger { get; set; } | ||
|
||
[JsonProperty("status")] | ||
public string Status { get; set; } | ||
|
||
[JsonProperty("statusCode")] | ||
public int StatusCode { get; set; } | ||
|
||
[JsonProperty("response")] | ||
public string Response { get; set; } | ||
|
||
[JsonProperty("stdout")] | ||
public string Stdout { get; set; } | ||
|
||
[JsonProperty("stderr")] | ||
public string Stderr { get; set; } | ||
|
||
[JsonProperty("duration")] | ||
public double Duration { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters