Advertisement
FrayxRulez

Untitled

May 8th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. using System;
  2. using System.IO.IsolatedStorage;
  3. using System.Diagnostics;
  4. using System.ComponentModel;
  5. using System.Threading;
  6. using Windows.Storage;
  7. using Telegram.Api.TL;
  8. using Unigram.Core.Services;
  9.  
  10. namespace Unigram.Common
  11. {
  12. public class ApplicationSettings
  13. {
  14. private readonly ApplicationDataContainer isolatedStore;
  15.  
  16. public ApplicationSettings()
  17. {
  18. try
  19. {
  20. isolatedStore = ApplicationData.Current.LocalSettings;
  21. }
  22. catch { }
  23. }
  24.  
  25. public bool AddOrUpdateValue(string key, Object value)
  26. {
  27. bool valueChanged = false;
  28.  
  29. if (isolatedStore.Values.ContainsKey(key))
  30. {
  31. if (isolatedStore.Values[key] != value)
  32. {
  33. isolatedStore.Values[key] = value;
  34. valueChanged = true;
  35. }
  36. }
  37. else
  38. {
  39. isolatedStore.Values.Add(key, value);
  40. valueChanged = true;
  41. }
  42.  
  43. return valueChanged;
  44. }
  45.  
  46. public valueType GetValueOrDefault<valueType>(string key, valueType defaultValue)
  47. {
  48. valueType value;
  49.  
  50. if (isolatedStore.Values.ContainsKey(key))
  51. {
  52. value = (valueType)isolatedStore.Values[key];
  53. }
  54. else
  55. {
  56. value = defaultValue;
  57. }
  58.  
  59. return value;
  60. }
  61.  
  62. public void Clear()
  63. {
  64. isolatedStore.Values.Clear();
  65. }
  66.  
  67. private static ApplicationSettings _current;
  68. public static ApplicationSettings Current
  69. {
  70. get
  71. {
  72. if (_current == null)
  73. _current = new ApplicationSettings();
  74.  
  75. return _current;
  76. }
  77. }
  78.  
  79.  
  80. private bool? _isSendByEnterEnabled;
  81. public bool IsSendByEnterEnabled
  82. {
  83. get
  84. {
  85. if (_isSendByEnterEnabled == null)
  86. _isSendByEnterEnabled = GetValueOrDefault("IsSendByEnterEnabled", true);
  87.  
  88. return _isSendByEnterEnabled ?? true;
  89. }
  90. set
  91. {
  92. _isSendByEnterEnabled = value;
  93. AddOrUpdateValue("IsSendByEnterEnabled", value);
  94. }
  95. }
  96.  
  97. private bool? _isReplaceEmojiEnabled;
  98. public bool IsReplaceEmojiEnabled
  99. {
  100. get
  101. {
  102. if (_isReplaceEmojiEnabled == null)
  103. _isReplaceEmojiEnabled = GetValueOrDefault("IsReplaceEmojiEnabled", true);
  104.  
  105. return _isReplaceEmojiEnabled ?? true;
  106. }
  107. set
  108. {
  109. _isReplaceEmojiEnabled = value;
  110. AddOrUpdateValue("IsReplaceEmojiEnabled", value);
  111. }
  112. }
  113.  
  114. private TLAccountTmpPassword _tmpPassword;
  115. public TLAccountTmpPassword TmpPassword
  116. {
  117. get
  118. {
  119. if (_tmpPassword == null)
  120. {
  121. var payload = GetValueOrDefault<string>("TmpPassword", null);
  122. var data = TLSerializationService.Current.Deserialize<TLAccountTmpPassword>(payload);
  123.  
  124. _tmpPassword = data;
  125. }
  126.  
  127. return _tmpPassword;
  128. }
  129. set
  130. {
  131. var payload = value != null ? TLSerializationService.Current.Serialize(value) : null;
  132. var data = AddOrUpdateValue("TmpPassword", payload);
  133.  
  134. _tmpPassword = value;
  135. }
  136. }
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement