Skip to content

Commit

Permalink
Merge pull request #16 from ismaelestalayo/develop
Browse files Browse the repository at this point in the history
v6.0.3
  • Loading branch information
ismaelestalayo authored Sep 3, 2021
2 parents 37a61a3 + 14a31f9 commit e7626fa
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 49 deletions.
25 changes: 14 additions & 11 deletions UWP.Shared/Constants/Changelogs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;

namespace UWP.Core.Constants {
/// <summary>
Expand All @@ -7,6 +8,14 @@ namespace UWP.Core.Constants {
public class Changelogs {

public static readonly Dictionary<string, List<string>> LatestChangelogs = new Dictionary<string, List<string>>(){
{
"6.0.3",
new List<string>(){
"Settings: set the currency to all purchases",
"Portfolio: group button shown only when multiple same coin entries exist",
"Portfolio: fixed error saving the Portfolio",
}
},
{
"6.0.0",
new List<string>(){
Expand All @@ -19,25 +28,19 @@ public class Changelogs {
"Configurable auto-refresh and startup page",
"Support for Jump Lists",
"New Compact Overlay",
"Portfolio shows diversification ratios and can group entries",
"Ability to duplicate, add notes and change the currency of purchases"
"Portfolio: diversification ratios, group or duplicate entries, add notes and change purchases' currencies"
}
},
//{
// "5.0.0",
// new List<string>() {
// "a", "b"
// }
//}
}
};

public static readonly List<string> CurrentChangelog = LatestChangelogs["6.0.0"];
public static readonly List<string> CurrentChangelog = LatestChangelogs[LatestChangelogs.Keys.ToList()[0]];
public static readonly List<string> MajorChangelog = LatestChangelogs["6.0.0"];

public static string FormatChangelog(List<string> changelog) {
string message = "";
foreach (var change in changelog)
message += $" • {change} \n";
return message;
return message.TrimEnd('\n');
}
}
}
22 changes: 16 additions & 6 deletions UWP.Shared/Helpers/LocalStorageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using System.Xml;
using Windows.Storage;

namespace UWP.Helpers {
Expand All @@ -14,6 +15,7 @@ public static async Task SaveObject<T>(string key, T obj) {
using (Stream writeStream = await savedStuffFile.OpenStreamForWriteAsync()) {
DataContractSerializer stuffSerializer = new DataContractSerializer(typeof(T));
stuffSerializer.WriteObject(writeStream, obj);

await writeStream.FlushAsync();
writeStream.Dispose();
}
Expand All @@ -25,14 +27,22 @@ public static async Task SaveObject<T>(string key, T obj) {

public static async Task<T> ReadObject<T>(string key) {
try {
var readStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(key);
using (var readStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(key)) {
DataContractSerializer stuffSerializer = new DataContractSerializer(typeof(T));
var setResult = (T)stuffSerializer.ReadObject(readStream);

DataContractSerializer stuffSerializer = new DataContractSerializer(typeof(T));
var setResult = (T)stuffSerializer.ReadObject(readStream);
await readStream.FlushAsync();
readStream.Dispose();
await readStream.FlushAsync();
readStream.Dispose();
return setResult;
}

return setResult;
} catch (XmlException ex) {
var _ = ex.Message;
var file = await ApplicationData.Current.LocalFolder.GetFileAsync(key);
await file.DeleteAsync();
return (T)Activator.CreateInstance(typeof(T));
} catch (FileNotFoundException) {
return (T)Activator.CreateInstance(typeof(T));
}
catch (Exception ex) {
var _ = ex.Message;
Expand Down
4 changes: 2 additions & 2 deletions UWP.Shared/Helpers/PortfolioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public async static Task<List<PurchaseModel>> GetPortfolio(string filterCrypto =
return (portfolio.Count == 0) ? new List<PurchaseModel>() : portfolio;
}

public async static void AddPurchase(PurchaseModel purchase) {
var portfolio = await LocalStorageHelper.ReadObject<List<PurchaseModel>>(UserStorage.Portfolio6);
public async static Task AddPurchase(PurchaseModel purchase) {
var portfolio = await GetPortfolio();
portfolio.Add(purchase);
await LocalStorageHelper.SaveObject(UserStorage.Portfolio6, portfolio);
}
Expand Down
3 changes: 3 additions & 0 deletions UWP.Shared/Models/PurchaseModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Toolkit.Mvvm.DependencyInjection;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
Expand All @@ -15,6 +16,8 @@ namespace UWP.Models {
/// Had to not implement ObservableObject to make it serializable
/// </summary>
[DataContract()]
[KnownType(typeof(PurchaseModel))]
[KnownType(typeof(List<PurchaseModel>))]
public class PurchaseModel : INotifyPropertyChanged {
public PurchaseModel() { }

Expand Down
4 changes: 2 additions & 2 deletions UWP/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp" xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5">
<Identity Name="54989IsmaelEstalayoMena.CoinBaseUnofficial" Publisher="CN=CE0D17DE-AC9B-4B2D-AE14-FFACDE33BF50" Version="6.0.2.0" />
<Identity Name="54989IsmaelEstalayoMena.CoinBaseUnofficial" Publisher="CN=CE0D17DE-AC9B-4B2D-AE14-FFACDE33BF50" Version="6.0.3.0" />
<mp:PhoneIdentity PhoneProductId="9555542a-b2a3-4742-83ff-1a9b2ec43102" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>CryptoTracker</DisplayName>
Expand All @@ -15,7 +15,7 @@
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="CryptoTracker.App">
<uap:VisualElements DisplayName="Crypto Tracker" Square44x44Logo="Assets\Tiles and stuff\AppIcon.png" Description="Simple yet powerful cryptocurrency portfolio tracker designed with simplicity and functionality in mind." BackgroundColor="transparent" Square150x150Logo="Assets\Tiles and stuff\Tile-Medium.png">
<uap:VisualElements DisplayName="CryptoTracker" Square44x44Logo="Assets\Tiles and stuff\AppIcon.png" Description="Simple yet powerful cryptocurrency portfolio tracker designed with simplicity and functionality in mind." BackgroundColor="transparent" Square150x150Logo="Assets\Tiles and stuff\Tile-Medium.png">
<uap:LockScreen Notification="badgeAndTileText" BadgeLogo="Assets\Tiles and stuff\BadgeLogo.png" />
<uap:DefaultTile Wide310x150Logo="Assets\Tiles and stuff\Tile-Wide.png" Square71x71Logo="Assets\Tiles and stuff\Tile-Small.png" Square310x310Logo="Assets\Tiles and stuff\Tile-Large.png" ShortName="CryptoTracker">
<uap:ShowNameOnTiles>
Expand Down
4 changes: 2 additions & 2 deletions UWP/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("6.0.2.0")]
[assembly: AssemblyFileVersion("6.0.2.0")]
[assembly: AssemblyVersion("6.0.3.0")]
[assembly: AssemblyFileVersion("6.0.3.0")]
[assembly: ComVisible(false)]
2 changes: 1 addition & 1 deletion UWP/UserControls/Notification.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Padding="10">
<muxc:InfoBar.Content>
<TextBlock
Margin="2 -10 0 0"
Margin="2 -10 0 15"
TextWrapping="WrapWholeWords"
Visibility="{x:Bind Message, Converter={StaticResource StringToVisibility}}">
<Run Text="{x:Bind Message}"/>
Expand Down
6 changes: 6 additions & 0 deletions UWP/ViewModels/PortfolioViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public string CurrencySymbol {
set => SetProperty(ref currencySym, value);
}

private bool _purchasesAreGroupable = false;
public bool PurchasesAreGroupable {
get => _purchasesAreGroupable;
set => SetProperty(ref _purchasesAreGroupable, value);
}

private bool _purchasesAreGrouped = false;
public bool PurchasesAreGrouped {
get => _purchasesAreGrouped;
Expand Down
20 changes: 13 additions & 7 deletions UWP/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,26 @@ private async void RegisterBackgroundTask() {
/// <summary>
/// Show a notification with the changelog to new users.
/// </summary>
private async void ShowChangelog() {
private void ShowChangelog() {
var v = Package.Current.Id.Version;
var version = $"{v.Major}.{v.Minor}.{v.Build}";
var currentVersion = $"{v.Major}.{v.Minor}.{v.Build}";

var lastVersion = App._LocalSettings.Get<string>(UserSettings.LastVersion);
if (version == lastVersion)
if (currentVersion == lastVersion)
return;
vm.InfoBarTitle = $"Welcome to CryptoTracker v{version}";
vm.InfoBarMessage = "New in this version:\n";

vm.InfoBarMessage += Changelogs.FormatChangelog(Changelogs.CurrentChangelog);
vm.InfoBarTitle = $"Welcome to Crypto Tracker v{currentVersion}";
vm.InfoBarMessage = "New in this version: \n";

if (App._LocalSettings.Get<bool>(UserSettings.IsNewUser)) {
App._LocalSettings.Set(UserSettings.IsNewUser, false);
vm.InfoBarMessage += Changelogs.FormatChangelog(Changelogs.MajorChangelog);
}
else
vm.InfoBarMessage += Changelogs.FormatChangelog(Changelogs.CurrentChangelog);

vm.InfoBarOpened = true;
App._LocalSettings.Set(UserSettings.LastVersion, version);
App._LocalSettings.Set(UserSettings.LastVersion, currentVersion);
}

private async void ColorValuesChanged(UISettings sender, object args) {
Expand Down
4 changes: 3 additions & 1 deletion UWP/Views/Portfolio.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
</userControls:ToggleIconButton.UncheckedIcon>
</userControls:ToggleIconButton>
<userControls:ToggleIconButton
x:Name="GroupPurchasesBtn"
x:Load="{x:Bind vm.PurchasesAreGroupable}"
Background="{ThemeResource ButtonBackground}"
BorderBrush="{ThemeResource ButtonBorderBrush}"
BorderThickness="{ThemeResource ButtonBorderThemeThickness}"
Expand Down Expand Up @@ -237,7 +239,7 @@
ShowDetails="{x:Bind vm.ShowDetails}"
VerticalAlignment="Top"/>

<Grid Visibility="{x:Bind vm.AllPurchasesInCurrency, Converter={StaticResource BoolToVisibility}}">
<Grid Visibility="{x:Bind vm.AllPurchasesInCurrency, Converter={StaticResource BoolToVisibility}}" Margin="22 0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="28"/>
<ColumnDefinition Width="*"/>
Expand Down
8 changes: 6 additions & 2 deletions UWP/Views/Portfolio.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ private async void Page_Loaded(object sender, RoutedEventArgs e) {

public async Task UpdatePage() {
vm.CurrencySymbol = App.currencySymbol;
vm.Portfolio = await RetrievePortfolio();


/// Empty diversification chart and reset the Total amounts
PortfolioChartGrid.ColumnDefinitions.Clear();
Expand All @@ -66,6 +68,7 @@ public async Task UpdatePage() {
vm.TotalDelta = vm.Portfolio.Sum(x => x.Profit);
vm.AllPurchasesInCurrency = vm.Portfolio.Select(x => x.Currency).All(x => x == vm.Portfolio[0].Currency);
vm.AllPurchasesCurrencySym = vm.Portfolio.FirstOrDefault()?.CurrencySymbol ?? App.currencySymbol;
vm.PurchasesAreGroupable = vm.Portfolio.GroupBy(x => x.Crypto).Where(x => x.Count() > 1).Count() > 0;

/// Create the diversification grid
var grouped = vm.Portfolio.GroupBy(x => x.Crypto);
Expand Down Expand Up @@ -225,10 +228,11 @@ private async void AddPurchase_click(object sender, RoutedEventArgs e) {
dialog.NewPurchase.CryptoName = App.coinListPaprika.FirstOrDefault(
x => x.symbol == dialog.NewPurchase.Crypto).name;
vm.Portfolio.Add(dialog.NewPurchase);
PortfolioHelper.AddPurchase(dialog.NewPurchase);

await PortfolioHelper.AddPurchase(dialog.NewPurchase);

// Update everything
UpdatePage();
await UpdatePage();
}
}

Expand Down
48 changes: 33 additions & 15 deletions UWP/Views/Settings/SettingsGeneral.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<Setter Property="Margin" Value="0 25 0 0"/>
</Style>

<Style TargetType="ComboBox" BasedOn="{StaticResource DefaultComboBoxStyle}">
<Setter Property="Height" Value="33"/>
</Style>

<Style TargetType="TextBlock" BasedOn="{StaticResource SettingsSectionDescription}"/>
</Page.Resources>

Expand All @@ -34,21 +38,35 @@

<TextBlock
Text="Choose the currency in which to display prices."/>
<ComboBox
Foreground="{ThemeResource ApplicationPointerOverForegroundThemeBrush}"
Margin="0 5 0 0" Width="110"
ItemsSource="{x:Bind AvailableCurrencies, Mode=OneTime}"
SelectedValue="{x:Bind vm.Currency, Mode=TwoWay}"
SelectedValuePath="Key">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Value}" Width="25"/>
<TextBlock Text="{Binding Key}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

<StackPanel Orientation="Horizontal" Spacing="10">
<ComboBox
Foreground="{ThemeResource ApplicationPointerOverForegroundThemeBrush}"
Margin="0 5 0 0" Width="110"
ItemsSource="{x:Bind AvailableCurrencies, Mode=OneTime}"
SelectedValue="{x:Bind vm.Currency, Mode=TwoWay}"
SelectedValuePath="Key">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Value}" Width="25"/>
<TextBlock Text="{Binding Key}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

<Button Content="Set to all purchases" VerticalAlignment="Bottom" Padding="18 6">
<Button.Flyout>
<Flyout>
<StackPanel Spacing="10">
<TextBlock Text="All of your purchases's currencies will be overwritten." Style="{ThemeResource BaseTextBlockStyle}"/>
<Button Click="SetAllPurchasesCurrency_Click" Content="Yes, override" />
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>
</StackPanel>


<!-- AUTO-REFRESH -->
Expand Down
15 changes: 15 additions & 0 deletions UWP/Views/Settings/SettingsGeneral.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.Collections.Generic;
using UWP.Core.Constants;
using UWP.Helpers;
using UWP.Shared.Constants;
using UWP.Shared.Helpers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

namespace UWP.Views {
public sealed partial class SettingsGeneral : Page {
Expand All @@ -26,5 +29,17 @@ private void startupPage_SelectionChanged(object sender, SelectionChangedEventAr
App._LocalSettings.Set(UserSettings.StartupPage, $"/{startupPage}");
}

private async void SetAllPurchasesCurrency_Click(object sender, RoutedEventArgs e) {
var portfolio = await PortfolioHelper.GetPortfolio();
foreach (var purchase in portfolio)
purchase.Currency = vm.Currency;
await LocalStorageHelper.SaveObject(UserStorage.Portfolio6, portfolio);
var openedpopups = VisualTreeHelper.GetOpenPopups(Window.Current);
foreach (var popup in openedpopups) {
if (popup.Child is ContentDialog)
((ContentDialog)popup.Child).Hide();
}
vm.InAppNotification("Currency of all purchases overrided.", "Please refresh the portfolio.");
}
}
}

0 comments on commit e7626fa

Please sign in to comment.