Skip to content

Commit

Permalink
Merge branch '#38-Favorite-item-list'
Browse files Browse the repository at this point in the history
Close #38
  • Loading branch information
Triky313 committed May 14, 2021
2 parents f75e990 + ce2ff12 commit 2d1a044
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 49 deletions.
3 changes: 3 additions & 0 deletions StatisticsAnalysisTool/StatisticsAnalysisTool/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
<setting name="LootChestDataSourceUrl" serializeAs="String">
<value>https://raw.githubusercontent.com/Triky313/AlbionOnline-StatisticsAnalysis/master/StatisticsAnalysisTool/StatisticsAnalysisTool/GameFiles/lootchests.json</value>
</setting>
<setting name="FavoriteItemsFileName" serializeAs="String">
<value>FavoriteItems.json</value>
</setting>
</StatisticsAnalysisTool.Properties.Settings>
</userSettings>
<applicationSettings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using log4net;
using Newtonsoft.Json;
using StatisticsAnalysisTool.Enumerations;
using StatisticsAnalysisTool.Models;
Expand All @@ -9,6 +10,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -19,6 +21,8 @@ namespace StatisticsAnalysisTool.Common
{
public class ItemController
{
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

public static ObservableCollection<Item> Items;

private static readonly string FullItemInformationFilePath =
Expand Down Expand Up @@ -81,7 +85,7 @@ public static int GetItemLevel(string uniqueName)

return int.TryParse(uniqueName.Split('@')[1], out var number) ? number : 0;
}

public static int GetItemTier(Item item)
{
if (item?.UniqueName == null) return -1;
Expand Down Expand Up @@ -269,6 +273,47 @@ private static async Task<bool> GetItemListFromWebAsync(string url)
}
}

public static void SetFavoriteItemsFromLocalFile()
{
var localFilePath = $"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.FavoriteItemsFileName}";
if (File.Exists(localFilePath))
{
try
{
var localItemString = File.ReadAllText(localFilePath, Encoding.UTF8);
foreach (var uniqueName in JsonConvert.DeserializeObject<List<string>>(localItemString))
{
var item = Items.FirstOrDefault(i => i.UniqueName == uniqueName);
if (item != null)
{
item.IsFavorite = true;
}
}
}
catch (Exception e)
{
Log.Error(MethodBase.GetCurrentMethod().Name, e);
}
}
}

public static void SaveFavoriteItemsToLocalFile()
{
var localFilePath = $"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.FavoriteItemsFileName}";
var favoriteItems = Items.Where(x => x.IsFavorite);
var toSaveFavoriteItems = favoriteItems.Select(x => x.UniqueName);
var fileString = JsonConvert.SerializeObject(toSaveFavoriteItems);

try
{
File.WriteAllText(localFilePath, fileString, Encoding.UTF8);
}
catch (Exception e)
{
Log.Error(MethodBase.GetCurrentMethod().Name, e);
}
}

#endregion Item list

#region ItemInformation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@
<translation name="ITEM_PRICE_UNDERCUT">Item Preis unterboten</translation>
<translation name="THE_PRICE_OF">Der Preis von</translation>
<translation name="IN">in</translation>
<translation name="SHOW_ONLY_ITEMS_WITH_ALERT_ON">Zeige nur Items mit Alarm AN</translation>
<translation name="SHOW_ONLY_ITEMS_WITH_ALERT_ON">Nur Items mit Alarm AN zeigen</translation>
<translation name="SHOW_ONLY_FAVORITES">Nur Favoriten zeigen</translation>
<translation name="HAS_BEEN_UNDERCUT">ist unterboten worden</translation>
<translation name="IS_ALERT_ACTIVATE">Ist Alarm aktiv</translation>
<translation name="UNDERCUTTING_PRICE">Zu unterbietender Preis</translation>
Expand Down
25 changes: 0 additions & 25 deletions StatisticsAnalysisTool/StatisticsAnalysisTool/Languages/en-GB.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
<translation name="THE_PRICE_OF">The price of</translation>
<translation name="IN">in</translation>
<translation name="SHOW_ONLY_ITEMS_WITH_ALERT_ON">Show only items with alert on</translation>
<translation name="SHOW_ONLY_FAVORITES">Show only favorites</translation>
<translation name="HAS_BEEN_UNDERCUT">has been undercut</translation>
<translation name="IS_ALERT_ACTIVATE">Is alert activate</translation>
<translation name="UNDERCUTTING_PRICE">Undercutting price</translation>
Expand Down
7 changes: 4 additions & 3 deletions StatisticsAnalysisTool/StatisticsAnalysisTool/Models/Item.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using FontAwesome5;
using FontAwesome5;
using StatisticsAnalysisTool.Common;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace StatisticsAnalysisTool.Models
{
Expand Down Expand Up @@ -29,6 +29,7 @@ public class Item

public int AlertModeMinSellPriceIsUndercutPrice { get; set; }
public bool IsAlertActive { get; set; }
public bool IsFavorite { get; set; }
public EFontAwesomeIcon AlertToggle => IsAlertActive ? EFontAwesomeIcon.Solid_ToggleOn : EFontAwesomeIcon.Solid_ToggleOff;
public Brush AlertToggleColor => IsAlertActive ? ItemController.ToggleOnColor : ItemController.ToggleOffColor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class MainWindowTranslation
public string Name => LanguageController.Translation("NAME");
public string LoadFullItemInfo => LanguageController.Translation("LOAD_FULL_ITEM_INFO");
public string ShowOnlyItemsWithAlertOn => LanguageController.Translation("SHOW_ONLY_ITEMS_WITH_ALERT_ON");
public string ShowOnlyFavorites => LanguageController.Translation("SHOW_ONLY_FAVORITES");
public string IsAlertActive => LanguageController.Translation("IS_ALERT_ACTIVATE");
public string UndercuttingPrice => LanguageController.Translation("UNDERCUTTING_PRICE");
public string IsTrackingActive => LanguageController.Translation("IS_TRACKING_ACTIVE");
Expand Down Expand Up @@ -44,5 +45,6 @@ public class MainWindowTranslation
public string SortByDps => LanguageController.Translation("SORT_BY_DPS");
public string SortByName => LanguageController.Translation("SORT_BY_NAME");
public string Settings => LanguageController.Translation("SETTINGS");

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,8 @@
<Setting Name="DiscordUrl" Type="System.String" Scope="Application">
<Value Profile="(Default)">https://discord.com/invite/sahSrSPmaJ</Value>
</Setting>
<Setting Name="FavoriteItemsFileName" Type="System.String" Scope="User">
<Value Profile="(Default)">FavoriteItems.json</Value>
</Setting>
</Settings>
</SettingsFile>
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="ao-update-check.xml" />
<Content Include="Languages\en-GB.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Languages\pt-BR.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class MainWindowViewModel : INotifyPropertyChanged
private ObservableCollection<MainStatObject> _factionPointStats = new ObservableCollection<MainStatObject>() { new MainStatObject() { Value = "0", ValuePerHour = "0", CityFaction = CityFaction.Unknown } };
private string _mainTrackerTimer;
private Visibility _isMainTrackerPopupVisible = Visibility.Hidden;
private bool _isShowOnlyFavoritesActive;

public MainWindowViewModel(MainWindow mainWindow)
{
Expand Down Expand Up @@ -378,10 +379,14 @@ private async void InitMainWindowData()

var isItemListLoaded = await ItemController.GetItemListFromJsonAsync().ConfigureAwait(true);
if (!isItemListLoaded)
{
MessageBox.Show(LanguageController.Translation("ITEM_LIST_CAN_NOT_BE_LOADED"), LanguageController.Translation("ERROR"));
}

if (isItemListLoaded)
{
ItemController.SetFavoriteItemsFromLocalFile();

await ItemController.GetItemInformationListFromLocalAsync();
IsFullItemInformationCompleteCheck();

Expand Down Expand Up @@ -737,22 +742,39 @@ public void SetDamageMeterSort()

private void ItemsViewFilter()
{
if (ItemsView == null) return;
if (ItemsView == null)
{
return;
}

if (IsFullItemInfoSearchActive)
ItemsView.Filter = i =>
{
var item = i as Item;
if (IsShowOnlyItemsWithAlertOnActive)
{
return item?.FullItemInformation != null &&
item.LocalizedNameAndEnglish.ToLower().Contains(SearchText?.ToLower() ?? string.Empty)
&& (item.FullItemInformation?.CategoryObject?.ParentCategory == SelectedItemParentCategory ||
SelectedItemParentCategory == ParentCategory.Unknown)
&& (item.FullItemInformation?.CategoryObject?.Category == SelectedItemCategory ||
SelectedItemCategory == Category.Unknown)
&& (item.FullItemInformation?.CategoryObject?.Category == SelectedItemCategory || SelectedItemCategory == Category.Unknown)
&& ((ItemTier) item.FullItemInformation?.Tier == SelectedItemTier || SelectedItemTier == ItemTier.Unknown)
&& ((ItemLevel) item.FullItemInformation?.Level == SelectedItemLevel || SelectedItemLevel == ItemLevel.Unknown)
&& item.IsAlertActive;
}

if (IsShowOnlyFavoritesActive)
{
return item?.FullItemInformation != null &&
item.LocalizedNameAndEnglish.ToLower().Contains(SearchText?.ToLower() ?? string.Empty)
&& (item.FullItemInformation?.CategoryObject?.ParentCategory == SelectedItemParentCategory ||
SelectedItemParentCategory == ParentCategory.Unknown)
&& (item.FullItemInformation?.CategoryObject?.Category == SelectedItemCategory || SelectedItemCategory == Category.Unknown)
&& ((ItemTier)item.FullItemInformation?.Tier == SelectedItemTier || SelectedItemTier == ItemTier.Unknown)
&& ((ItemLevel)item.FullItemInformation?.Level == SelectedItemLevel || SelectedItemLevel == ItemLevel.Unknown)
&& item.IsFavorite;
}

return item?.FullItemInformation != null &&
item.LocalizedNameAndEnglish.ToLower().Contains(SearchText?.ToLower() ?? string.Empty)
&& (item.FullItemInformation?.CategoryObject?.ParentCategory == SelectedItemParentCategory ||
Expand All @@ -767,8 +789,15 @@ private void ItemsViewFilter()
var item = i as Item;

if (IsShowOnlyItemsWithAlertOnActive)
return (item?.LocalizedNameAndEnglish.ToLower().Contains(SearchText?.ToLower() ?? string.Empty) ?? false) &&
item.IsAlertActive;
{
return (item?.LocalizedNameAndEnglish.ToLower().Contains(SearchText?.ToLower() ?? string.Empty) ?? false) && item.IsAlertActive;
}

if (IsShowOnlyFavoritesActive)
{
return (item?.LocalizedNameAndEnglish.ToLower().Contains(SearchText?.ToLower() ?? string.Empty) ?? false) && item.IsFavorite;
}

return item?.LocalizedNameAndEnglish.ToLower().Contains(SearchText?.ToLower() ?? string.Empty) ?? false;
};

Expand Down Expand Up @@ -1189,6 +1218,28 @@ public bool IsShowOnlyItemsWithAlertOnActive
set
{
_isShowOnlyItemsWithAlertOnActive = value;

if (value)
{
IsShowOnlyFavoritesActive = false;
}

ItemsViewFilter();
ItemsView?.Refresh();
OnPropertyChanged();
}
}

public bool IsShowOnlyFavoritesActive {
get => _isShowOnlyFavoritesActive;
set {
_isShowOnlyFavoritesActive = value;

if (value)
{
IsShowOnlyItemsWithAlertOnActive = false;
}

ItemsViewFilter();
ItemsView?.Refresh();
OnPropertyChanged();
Expand Down
Loading

0 comments on commit 2d1a044

Please sign in to comment.