Skip to content

Commit

Permalink
Secondary Title Language support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltanar committed Nov 6, 2023
1 parent 8a259e9 commit 7112934
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 334 deletions.
1 change: 1 addition & 0 deletions Happy Reader/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<view:OwnedStatusToTextConverter x:Key="OwnedStatusToTextConverter" />
<view:DateToWeightConverter x:Key="DateToWeightConverter" />
<view:DateToBrushConverter x:Key="DateToBrushConverter" />
<view:VnToReleaseDateStringConverter x:Key="VnToReleaseDateStringConverter" />
<converters:UserVnToBackgroundConverter x:Key="UserVnToBackgroundConverter" />
<converters:RunningStatusToBrushConverter x:Key="RunningStatusToBrushConverter" />
<converters:GameDisplayNameConverter x:Key="GameDisplayNameConverter" />
Expand Down
1 change: 1 addition & 0 deletions Happy Reader/Happy Reader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<Compile Include="ViewModel\NamedFunction.cs" />
<Compile Include="ViewModel\ProducersTabViewModel.cs" />
<Compile Include="ViewModel\SettingsViewModel.cs" />
<Compile Include="ViewModel\TitleOrderingType.cs" />
<Compile Include="ViewModel\UserGamesViewModel.cs" />
<Compile Include="View\ColorSelector.xaml.cs">
<DependentUpon>ColorSelector.xaml</DependentUpon>
Expand Down
9 changes: 8 additions & 1 deletion Happy Reader/Model/StaticMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,14 @@ public static ImageSource GetFlag(string language)
}
return exists;
}
}

public static void GetDateFromVisualNovel(ListedVN vn, out DateTime releaseDate, out string releaseDateString)
{
var secondary = MainWindow.ViewModel.DatabaseViewModel.OrderingType == TitleOrderingType.SecondaryDate;
releaseDate = secondary ? vn.ReleaseDateSecondary : vn.ReleaseDate;
releaseDateString = secondary ? releaseDate.ToString("yyyy-MM-dd") : vn.ReleaseDateString;
}
}

public class FiltersData : SettingsJsonFile
{
Expand Down
585 changes: 300 additions & 285 deletions Happy Reader/View/Converters.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Happy Reader/View/Tabs/DatabaseTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<TextBox Margin="65,0,321,0" TextWrapping="Wrap" VerticalContentAlignment="Center" PreviewKeyUp="SearchByText" Height="30" VerticalAlignment="Stretch" Grid.Row="1"/>
<ComboBox HorizontalAlignment="Right" Margin="0,0,125,0" Width="191" Grid.Row="1" SelectedIndex="0" VerticalContentAlignment="Center">
<ComboBoxItem Content="Sort by Release Date" Selected="SortByRelease"/>
<ComboBoxItem Content="Sort by Release Date (Secondary)" Selected="SortByReleaseSecondary"/>
<ComboBoxItem Content="Sort by ID" Selected="SortByID"/>
<ComboBoxItem Content="Sort by Suggestion Score" Selected="SortByRecommended"/>
<ComboBoxItem Content="Sort by My Score" Selected="SortByMyScore"/>
Expand Down
15 changes: 10 additions & 5 deletions Happy Reader/View/Tabs/DatabaseTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,17 @@ private async void SortByMyScore(object sender, RoutedEventArgs e)
if (ViewModel != null) await ViewModel.SortByMyScore();
}

private async void SortByRelease(object sender, RoutedEventArgs e)
{
if (ViewModel != null) await ViewModel.SortByReleaseDate();
}
private async void SortByRelease(object sender, RoutedEventArgs e)
{
if (ViewModel != null) await ViewModel.SortByReleaseDate(true);
}

private async void SortByReleaseSecondary(object sender, RoutedEventArgs e)
{
if (ViewModel != null) await ViewModel.SortByReleaseDate(false);
}

private async void SortByRating(object sender, RoutedEventArgs e)
private async void SortByRating(object sender, RoutedEventArgs e)
{
if (ViewModel != null) await ViewModel.SortByRating();
}
Expand Down
9 changes: 5 additions & 4 deletions Happy Reader/View/Tabs/SettingsTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
<TabControl TabStripPlacement="Top">
<TabItem Header="Core Settings" DataContext="{Binding CoreSettings}">
<StackPanel>
<view:LabeledTextBox LabelWidth="120" Label="UserID:" Text="{Binding UserID}"/>
<view:LabeledTextBox LabelWidth="120" Label="Username:" Text="{Binding Username}"/>
<Grid>
<view:LabeledTextBox LabelWidth="150" Label="UserID:" Text="{Binding UserID}"/>
<view:LabeledTextBox LabelWidth="150" Label="Username:" Text="{Binding Username}"/>
<view:LabeledTextBox LabelWidth="150" Label="Secondary Title Language:" Text="{Binding SecondaryTitleLanguage}" ToolTip="Secondary language (2 letter form) to sort titles by release date in that language"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="150"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="Password:"/>
Expand Down
2 changes: 1 addition & 1 deletion Happy Reader/View/Tiles/CharacterTile.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<TextBox x:Name="VisualNovelNameBox" Text="{Binding VisualNovel.Title, Mode=OneWay}" Foreground="Black" Padding="5,0,0,0" />
<TextBox x:Name="ProducerBox" Text="{Binding VisualNovel.Producer.Name, Mode=OneWay}" Foreground="Black" Padding="5,0,0,0" />
<Border Padding="5,0,0,0" BorderBrush="{Binding NewSinceUpdate, Converter={StaticResource NewlyAddedBorderBrushConverter}}" BorderThickness="1">
<TextBox x:Name="VisualNovelReleaseBox" Text="{Binding VisualNovel.ReleaseDateString, Mode=OneWay}" Foreground="{Binding VisualNovel.ReleaseDate, Converter={StaticResource DateToBrushConverter}}"/>
<TextBox x:Name="VisualNovelReleaseBox" Text="{Binding VisualNovel, Converter={StaticResource VnToReleaseDateStringConverter}, Mode=OneWay}" Foreground="{Binding VisualNovel, Converter={StaticResource DateToBrushConverter}}"/>
</Border>
</StackPanel>
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions Happy Reader/View/Tiles/VNTile.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
</TextBlock>
</Label>
<Label Margin="0,0,10,31" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="82" HorizontalContentAlignment="Right"
Foreground="{Binding Path=ReleaseDate, Converter={StaticResource DateToBrushConverter}, NotifyOnSourceUpdated=True, Mode=OneWay}" Padding="0">
Foreground="{Binding Path=., Converter={StaticResource DateToBrushConverter}, NotifyOnSourceUpdated=True, Mode=OneWay}" Padding="0">
<Border BorderBrush="{Binding NewSinceUpdate, Converter={StaticResource NewlyAddedBorderBrushConverter}}" BorderThickness="1">
<TextBlock Text="{Binding ReleaseDateString}" FontWeight="{Binding ReleaseDate, Converter={StaticResource DateToWeightConverter}}"/>
<TextBlock Text="{Binding ., Converter={StaticResource VnToReleaseDateStringConverter}}" FontWeight="{Binding ., Converter={StaticResource DateToWeightConverter}}"/>
</Border>
</Label>
<Label Content="{Binding UserVN, Converter={StaticResource UserRelatedStatusConverter}}"
Expand Down
58 changes: 33 additions & 25 deletions Happy Reader/ViewModel/DatabaseViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public abstract class DatabaseViewModelBase : INotifyPropertyChanged
private const int PageSize = 50;
private int _currentPage;
private bool _finalPage;
private bool _orderingByRating;
private string _replyText;
private Brush _replyColor;
private Brush _vndbConnectionBackground;
Expand Down Expand Up @@ -105,9 +104,10 @@ public SuggestionScorer SuggestionScorer
StaticHelpers.LocalDatabase);
return _suggestionScorer;
}
}
}
public TitleOrderingType OrderingType { get; private set; }

protected DatabaseViewModelBase(MainWindowViewModel mainWindowViewModel)
protected DatabaseViewModelBase(MainWindowViewModel mainWindowViewModel)
{
_ordering = items => items.OrderByDescending(i => GetVisualNovel(i)?.ReleaseDate ?? DateTime.MaxValue);
MainViewModel = mainWindowViewModel;
Expand Down Expand Up @@ -190,10 +190,14 @@ protected async Task RefreshTiles()
{
var items = DbFunction.SelectAndInvoke(StaticHelpers.LocalDatabase, this);
OnPropertyChanged(nameof(SelectedFunctionIndex));
if (_orderingByRating && StaticMethods.Settings.GuiSettings.ExcludeLowVotesForRatingSort)
if (OrderingType == TitleOrderingType.Rating && StaticMethods.Settings.GuiSettings.ExcludeLowVotesForRatingSort)
{
items = items.Where(i => !((GetVisualNovel(i)?.VoteCount ?? 0) < GuiSettings.VotesRequiredForRatingSort));
}
else if (OrderingType == TitleOrderingType.SecondaryDate)
{
items = items.Where(i => GetVisualNovel(i).ReleaseDateSecondary != DateTime.MaxValue);
}
var filteredResults = items.Intersect(FiltersViewModel.PermanentFilter.GetAllResults(StaticHelpers.LocalDatabase, GetAll, GetAllWithKeyIn));
AllResults = _ordering(filteredResults).ToArray();
var firstPage = AllResults.Take(PageSize).ToArray();
Expand Down Expand Up @@ -330,67 +334,71 @@ public void ShowForCharacter(CharacterItem character)

public void ShowSuggested()
{
_ordering = lvn => lvn.OrderByDescending(i => GetSuggestion(i));
_orderingByRating = false;
var cf = new CustomFilter("Suggested");
_ordering = lvn => lvn.OrderByDescending(i => GetSuggestion(i));
OrderingType = TitleOrderingType.Normal;
var cf = new CustomFilter("Suggested");
cf.AndFilters.Add(new GeneralFilter(GeneralFilterType.SuggestionScore, ">0"));
SelectedFilter = cf;
}

public async Task SortBySuggestion()
{
_ordering = items => items.OrderByDescending(i => GetSuggestion(i));
_orderingByRating = false;
await RefreshTiles();
OrderingType = TitleOrderingType.Normal;
await RefreshTiles();
}

public async Task SortByRating()
{
_ordering = items => items.OrderByDescending(i => GetVisualNovel(i)?.Rating ?? 0d).ThenByDescending(i => GetVisualNovel(i)?.ReleaseDate ?? DateTime.MinValue);
_orderingByRating = true;
await RefreshTiles();
OrderingType = TitleOrderingType.Rating;
await RefreshTiles();
}

public async Task SortByMyScore()
{
_ordering = items => items.OrderByDescending(i => GetVisualNovel(i)?.UserVN?.Vote ?? 0);
_orderingByRating = false;
await RefreshTiles();
OrderingType = TitleOrderingType.Normal;
await RefreshTiles();
}

public async Task SortByReleaseDate()
public async Task SortByReleaseDate(bool primary)
{
_ordering = items => items.OrderByDescending(i => GetVisualNovel(i).ReleaseDate);
_orderingByRating = false;
_ordering = items => items.OrderByDescending(i =>
{
var vn = GetVisualNovel(i);
return primary ? vn.ReleaseDate : vn.ReleaseDateSecondary;
});
OrderingType = primary ? TitleOrderingType.Normal : TitleOrderingType.SecondaryDate;
await RefreshTiles();
}

public async Task SortByName()
{
_ordering = items => items.OrderBy(i => GetName(i)).ThenByDescending(i => GetVisualNovel(i).ReleaseDate);
_orderingByRating = false;
await RefreshTiles();
OrderingType = TitleOrderingType.Normal;
await RefreshTiles();
}

public async Task SortByUserAdded()
{
_ordering = items => items.OrderByDescending(i => GetVisualNovel(i)?.UserVN?.Added);
_orderingByRating = true;
await RefreshTiles();
OrderingType = TitleOrderingType.Normal;
await RefreshTiles();
}

public async Task SortByUserModified()
{
_ordering = items => items.OrderByDescending(i => GetVisualNovel(i)?.UserVN?.LastModified);
_orderingByRating = true;
await RefreshTiles();
OrderingType = TitleOrderingType.Normal;
await RefreshTiles();
}

public async Task SortByID()
{
_ordering = items => items.OrderByDescending(i => i.Key);
_orderingByRating = false;
await RefreshTiles();
OrderingType = TitleOrderingType.Normal;
await RefreshTiles();
}

public void ShowAll()
Expand Down Expand Up @@ -437,5 +445,5 @@ private int[] GetRelatedTitles(IDataItem<int> item)
if (vn == null) return Array.Empty<int>();
return vn.GetAllRelations()?.Select(i => i.ID).Concat(new [] {vn.VNID}).Distinct().ToArray() ?? Array.Empty<int>();
}
}
}
}
9 changes: 6 additions & 3 deletions Happy Reader/ViewModel/InformationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ namespace Happy_Reader.ViewModel
public class InformationViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private DateTime OldTranslationsTime = DateTime.UtcNow.AddMonths(-2);
/// <summary>
/// Currently hard coded to 2 months.
/// </summary>
private readonly DateTime _oldTranslationsTime = DateTime.UtcNow.AddMonths(-2);

public string About { get; } = $"{StaticHelpers.ClientName} {StaticHelpers.ClientVersion}";
public string DatabaseDate { get; private set; }
Expand Down Expand Up @@ -137,7 +140,7 @@ private void SetUserDatabaseData(HappyReaderDatabase userGameData)
{
UserDatabaseSize = $"User Database Size: {GetFileSizeStringForDb(userGameData.Connection)}";
var cachedTranslations = userGameData.Translations.Count();
var cachedTranslationsOld = userGameData.Translations.Count(t => t.Timestamp < OldTranslationsTime);
var cachedTranslationsOld = userGameData.Translations.Count(t => t.Timestamp < _oldTranslationsTime);
TranslationsData = $"Cached Translations: {cachedTranslations}, 2+ Months Old: {cachedTranslationsOld}";
var mostUsedTranslation = userGameData.Translations.OrderByDescending(t => t.Count).FirstOrDefault();
if (mostUsedTranslation != null) TranslationsData += $", Most Used: {mostUsedTranslation.Input}>{mostUsedTranslation.Output} ({mostUsedTranslation.Count} times)";
Expand Down Expand Up @@ -218,7 +221,7 @@ private static bool HasPlayed(ListedVN userGameVN, out double ratio)
public void DeletedCachedTranslations(bool deleteAll)
{
if (deleteAll) UserDatabase.DeleteAllCachedTranslations();
else UserDatabase.DeleteCachedTranslationsOlderThan(OldTranslationsTime);
else UserDatabase.DeleteCachedTranslationsOlderThan(_oldTranslationsTime);
SetUserDatabaseData(UserDatabase);
OnPropertyChanged(null);
}
Expand Down
8 changes: 8 additions & 0 deletions Happy Reader/ViewModel/TitleOrderingType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Happy_Reader.ViewModel;

public enum TitleOrderingType
{
Normal,
Rating,
SecondaryDate
}
26 changes: 19 additions & 7 deletions HappySearchObjectClasses/CoreSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ public class CoreSettings : SettingsJsonFile
private bool _clearOldDumpsAndBackups = true;
private string _imageFolderPath = Path.Combine(StaticHelpers.StoredDataFolder, "vndb-img\\");
private ImageSyncMode _imageSync = ImageSyncMode.None;
private string _secondaryTitleLanguage = "en";

/// <summary>
/// Username of user.
/// </summary>
public string Username
/// <summary>
/// Username of user.
/// </summary>
public string Username
{
get => _username;
set
Expand Down Expand Up @@ -95,10 +96,21 @@ public ImageSyncMode SyncImages
_imageSync = value;
if (Loaded) Save();
}
}
}

//todo make editable
public List<int> AlertTagIDs { get; set; } = new();
public string SecondaryTitleLanguage
{
get => _secondaryTitleLanguage;
set
{
if (_secondaryTitleLanguage == value) return;
_secondaryTitleLanguage = value;
if (Loaded) Save();
}
}

//todo make editable
public List<int> AlertTagIDs { get; set; } = new();

//todo make editable
public List<int> AlertTraitIDs { get; set; } = new();
Expand Down
20 changes: 19 additions & 1 deletion HappySearchObjectClasses/Database/ListedVN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public ListedProducer Producer

public UserVN UserVN => StaticHelpers.LocalDatabase.UserVisualNovels[(StaticHelpers.CSettings.UserID, VNID)];

public DateTime ReleaseDate { get; set; }
public DateTime ReleaseDate { get; private set; }
public DateTime ReleaseDateSecondary { get; private set; }

public IEnumerable<DbTag> Tags => StaticHelpers.LocalDatabase.Tags[VNID];

Expand Down Expand Up @@ -434,13 +435,30 @@ void IDataItem<int>.LoadFromReader(IDataRecord reader)
ReleaseLink = Convert.ToString(reader["ReleaseLink"]);
Suggestion = new SuggestionScoreObject(StaticHelpers.GetNullableDouble(reader["TagScore"]), StaticHelpers.GetNullableDouble(reader["TraitScore"]));
NewSinceUpdate = Convert.ToInt32(reader["NewSinceUpdate"]) == 1;
ReleaseDateSecondary = GetLatestDate(LanguagesObject.All);
}
catch (Exception ex)
{
StaticHelpers.Logger.ToFile(ex);
throw;
}
}

private DateTime GetLatestDate(IEnumerable<LangRelease> languages)
{
var alreadyReleased = languages.OrderBy(release=> release.ReleaseDate)
.LastOrDefault(release => release.ReleaseDate <= DateTime.UtcNow && release.Lang == StaticHelpers.CSettings.SecondaryTitleLanguage);
if (alreadyReleased != null)
{
return alreadyReleased.ReleaseDate;
}
return languages.OrderBy(release => release.ReleaseDate)
.FirstOrDefault(release => release.Lang == StaticHelpers.CSettings.SecondaryTitleLanguage)?
.ReleaseDate ?? DateTime.MaxValue;


}

#endregion
}

Expand Down

0 comments on commit 7112934

Please sign in to comment.