| | 1 | | using System; |
| | 2 | |
|
| | 3 | | namespace DCL.SettingsCommon |
| | 4 | | { |
| | 5 | | public class ProxySettingsRepository<T> : ISettingsRepository<T> where T : struct |
| | 6 | | { |
| | 7 | | private readonly ISettingsRepository<T> latestRepository; |
| | 8 | | private readonly ISettingsRepository<T> recoveryRepository; |
| | 9 | |
|
| | 10 | | public event Action<T> OnChanged |
| | 11 | | { |
| 327 | 12 | | add => latestRepository.OnChanged += value; |
| 142 | 13 | | remove => latestRepository.OnChanged -= value; |
| | 14 | | } |
| | 15 | |
|
| | 16 | | public T Data |
| | 17 | | { |
| | 18 | | get |
| | 19 | | { |
| 310 | 20 | | if (!latestRepository.HasAnyData() && recoveryRepository.HasAnyData()) |
| 0 | 21 | | latestRepository.Apply(recoveryRepository.Data); |
| 310 | 22 | | return latestRepository.Data; |
| | 23 | | } |
| | 24 | | } |
| | 25 | |
|
| 1920 | 26 | | public ProxySettingsRepository(ISettingsRepository<T> latestRepository, |
| | 27 | | ISettingsRepository<T> recoveryRepository) |
| | 28 | | { |
| 1920 | 29 | | this.latestRepository = latestRepository; |
| 1920 | 30 | | this.recoveryRepository = recoveryRepository; |
| 1920 | 31 | | } |
| | 32 | |
|
| 36 | 33 | | public void Apply(T settings) => latestRepository.Apply(settings); |
| | 34 | |
|
| 75 | 35 | | public void Reset() => latestRepository.Reset(); |
| | 36 | |
|
| 3 | 37 | | public void Save() => latestRepository.Save(); |
| | 38 | |
|
| 0 | 39 | | public bool HasAnyData() => latestRepository.HasAnyData(); |
| | 40 | | } |
| | 41 | | } |