Skip to content
This repository has been archived by the owner on Aug 17, 2020. It is now read-only.

Commit

Permalink
Added missing entity
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-Apps committed Nov 11, 2016
1 parent 5de1bbd commit 84b6460
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions PokemonGo-UWP/Entities/AppliedItemWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using Newtonsoft.Json;
using PokemonGo_UWP.Utils;
using PokemonGo_UWP.Utils.Helpers;
using PokemonGo_UWP.Views;
using POGOProtos.Inventory.Item;
using Template10.Common;
using Template10.Mvvm;
using System.ComponentModel;
using POGOProtos.Inventory;
using System;
using PokemonGo.RocketAPI.Extensions;

namespace PokemonGo_UWP.Entities
{
public class AppliedItemWrapper : INotifyPropertyChanged
{
private AppliedItem _wrappedData;

public AppliedItemWrapper(AppliedItem appliedItem)
{
_wrappedData = appliedItem;
}

[JsonProperty, JsonConverter(typeof(ProtobufJsonNetConverter))]
public AppliedItem WrappedData { get { return _wrappedData; } }

public void Update(AppliedItem update)
{
_wrappedData = update;

OnPropertyChanged(nameof(ItemId));
OnPropertyChanged(nameof(ItemType));
OnPropertyChanged(nameof(AppliedMs));
OnPropertyChanged(nameof(ExpireMs));
OnPropertyChanged(nameof(MaxSeconds));
OnPropertyChanged(nameof(RemainingMs));
OnPropertyChanged(nameof(RemainingSeconds));
OnPropertyChanged(nameof(RemainingTime));
}

#region Wrapped Properties

public ItemId ItemId => _wrappedData.ItemId;

public ItemType ItemType => _wrappedData.ItemType;

public long AppliedMs => _wrappedData.AppliedMs;

public long ExpireMs => _wrappedData.ExpireMs;

public long RemainingMs
{
get
{
long nowMs = DateTime.UtcNow.ToUnixTime();
long remainingMs = ExpireMs - nowMs;
if (remainingMs < 0) remainingMs = 0;
return remainingMs;
}
}

public int RemainingSeconds
{
get
{
return (int)(RemainingMs / 1000);
}
}

public string RemainingTime
{
get
{
DateTime remainingTime = new DateTime().AddMilliseconds(RemainingMs);
return remainingTime.ToString("mm:ss");
}
}

public bool IsExpired
{
get
{
if (RemainingMs <= 0) return true;
return false;
}
}
#endregion

public int MaxSeconds
{
get
{
long maxMs = ExpireMs - AppliedMs;
int maxSeconds = (int)maxMs / 1000;
return maxSeconds;
}
}

#region INotifyPropertyChanged

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

#endregion
}
}

0 comments on commit 84b6460

Please sign in to comment.