-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from RightToAskOrg/IndividualParticipant-refa…
…ctoring Individual participant refactoring
- Loading branch information
Showing
32 changed files
with
760 additions
and
378 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
142 changes: 142 additions & 0 deletions
142
RightToAskClient/RightToAskClient/RightToAskClient/Helpers/XamarinPreferences.cs
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,142 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Xamarin.Essentials; | ||
|
||
namespace RightToAskClient.Helpers | ||
{ | ||
public class XamarinPreferences | ||
{ | ||
private Dictionary<string, object> storage = new Dictionary<string, object>(); | ||
|
||
public void Clear() | ||
{ | ||
if (DeviceInfo.Platform == DevicePlatform.Unknown) | ||
{ | ||
storage.Clear(); | ||
} | ||
else | ||
{ | ||
Preferences.Clear(); | ||
} | ||
} | ||
|
||
public bool ContainsKey(string key) | ||
{ | ||
if (DeviceInfo.Platform == DevicePlatform.Unknown) | ||
{ | ||
return storage.ContainsKey(key); | ||
} | ||
else | ||
{ | ||
return Preferences.ContainsKey(key); | ||
} | ||
} | ||
|
||
public string Get(string key, string defaultValue, string? sharedName = null) | ||
{ | ||
if (DeviceInfo.Platform == DevicePlatform.Unknown) | ||
{ | ||
try | ||
{ | ||
return (string)storage[key]; | ||
} | ||
catch (KeyNotFoundException) | ||
{ | ||
return defaultValue; | ||
} | ||
} | ||
else | ||
{ | ||
if (sharedName == null) | ||
{ | ||
return Preferences.Get(key, defaultValue); | ||
} | ||
else | ||
{ | ||
return Preferences.Get(key, defaultValue, sharedName); | ||
} | ||
} | ||
} | ||
public bool Get(string key, bool defaultValue, string? sharedName = null) | ||
{ | ||
if (DeviceInfo.Platform == DevicePlatform.Unknown) | ||
{ | ||
try | ||
{ | ||
return (bool)storage[key]; | ||
} | ||
catch (KeyNotFoundException) | ||
{ | ||
return defaultValue; | ||
} | ||
} | ||
else | ||
{ | ||
if (sharedName == null) | ||
{ | ||
return Preferences.Get(key, defaultValue); | ||
} | ||
else | ||
{ | ||
return Preferences.Get(key, defaultValue, sharedName); | ||
} | ||
} | ||
} | ||
|
||
public void Set(string key, string value, string? sharedName = null) | ||
{ | ||
if (DeviceInfo.Platform == DevicePlatform.Unknown) | ||
{ | ||
if (storage.ContainsKey(key)) | ||
{ | ||
storage[key] = value; | ||
} | ||
else | ||
{ | ||
storage.Add(key, value); | ||
} | ||
} | ||
else | ||
{ | ||
if (sharedName == null) | ||
{ | ||
Preferences.Set(key, value); | ||
} | ||
else | ||
{ | ||
Preferences.Set(key, value, sharedName); | ||
} | ||
} | ||
} | ||
|
||
public void Set(string key, bool value, string? sharedName = null) | ||
{ | ||
if (DeviceInfo.Platform == DevicePlatform.Unknown) | ||
{ | ||
if (storage.ContainsKey(key)) | ||
{ | ||
storage[key] = value; | ||
} | ||
else | ||
{ | ||
storage.Add(key, value); | ||
} | ||
} | ||
else | ||
{ | ||
if (sharedName == null) | ||
{ | ||
Preferences.Set(key, value); | ||
} | ||
else | ||
{ | ||
Preferences.Set(key, value, sharedName); | ||
} | ||
} | ||
} | ||
|
||
// XamarinPrefernces.shared. | ||
// Preferences. | ||
public static XamarinPreferences shared = new XamarinPreferences(); | ||
} | ||
} |
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
Oops, something went wrong.