Skip to content

Commit

Permalink
account self query service
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jan 5, 2025
1 parent 939d47d commit 9a29738
Show file tree
Hide file tree
Showing 9 changed files with 1,500 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Starward/Features/GameFeatureConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Starward.Features.GameRecord;
using Starward.Features.GameSetting;
using Starward.Features.Screenshot;
using Starward.Features.SelfQuery;
using System.Collections.Generic;

namespace Starward.Features;
Expand Down Expand Up @@ -82,6 +83,7 @@ public static GameFeatureConfig FromGameId(GameId? gameId)
nameof(ScreenshotPage),
nameof(GachaLogPage),
nameof(GameRecordPage),
nameof(SelfQueryPage),
],
InGameNoticesWindow = true,
};
Expand All @@ -96,6 +98,7 @@ public static GameFeatureConfig FromGameId(GameId? gameId)
nameof(ScreenshotPage),
nameof(GachaLogPage),
nameof(GameRecordPage),
nameof(SelfQueryPage),
],
InGameNoticesWindow = true,
};
Expand All @@ -109,6 +112,7 @@ public static GameFeatureConfig FromGameId(GameId? gameId)
nameof(ScreenshotPage),
nameof(GachaLogPage),
nameof(GameRecordPage),
nameof(SelfQueryPage),
],
InGameNoticesWindow = true,
};
Expand Down
6 changes: 3 additions & 3 deletions src/Starward/Features/PlayTime/PlayTimeButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private void InitializePlayTime()
try
{
PlayTimeTotal = DatabaseService.GetValue<TimeSpan>($"playtime_total_{CurrentGameBiz}", out _);
PlayTime7Days = DatabaseService.GetValue<TimeSpan>($"playtime_7days_{CurrentGameBiz}", out _);
StartUpCount = DatabaseService.GetValue<int>($"startup_count_{CurrentGameBiz}", out _);
(var time, PlayTimeLast) = _playTimeService.GetLastPlayTime(CurrentGameBiz);
if (time > DateTimeOffset.MinValue)
Expand All @@ -93,15 +92,13 @@ private void UpdatePlayTime()
try
{
PlayTimeTotal = _playTimeService.GetPlayTimeTotal(CurrentGameBiz);
PlayTime7Days = _playTimeService.GetPlayTimeLast7Days(CurrentGameBiz);
StartUpCount = _playTimeService.GetStartUpCount(CurrentGameBiz);
(var time, PlayTimeLast) = _playTimeService.GetLastPlayTime(CurrentGameBiz);
if (time > DateTimeOffset.MinValue)
{
LastPlayTimeText = time.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss");
}
DatabaseService.SetValue($"playtime_total_{CurrentGameBiz}", PlayTimeTotal);
DatabaseService.SetValue($"playtime_7days_{CurrentGameBiz}", PlayTime7Days);
DatabaseService.SetValue($"startup_count_{CurrentGameBiz}", StartUpCount);

CalculateRecent7Days();
Expand All @@ -128,13 +125,16 @@ private void CalculateRecent7Days()
var now = DateTimeOffset.Now;
var day = now.AddHours(-now.Hour);
var list = new TimeSpan[7];
TimeSpan total = TimeSpan.Zero;
for (int i = 0; i < 7; i++)
{
var start = day.AddDays(-i);
var end = start.AddDays(1);
TimeSpan playTime = _playTimeService.CalculatePlayTime(CurrentGameBiz, start, end);
list[6 - i] = playTime;
total += playTime;
}
PlayTime7Days = total;
TimeSpan max = list.Max();
if (max == TimeSpan.Zero)
{
Expand Down
1 change: 0 additions & 1 deletion src/Starward/Features/PlayTime/PlayTimeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public async Task LogPlayTimeAsync(GameBiz biz, int pid)
}
}
DatabaseService.SetValue($"playtime_total_{biz}", GetPlayTimeTotal(biz));
DatabaseService.SetValue($"playtime_7days_{biz}", GetPlayTimeLast7Days(biz));
DatabaseService.SetValue($"startup_count_{biz}", GetStartUpCount(biz));
_logger.LogInformation("End log playtime ({biz}, {pid})", biz, pid);
}
Expand Down
266 changes: 266 additions & 0 deletions src/Starward/Features/SelfQuery/SelfQueryPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
<sf:PageBase x:Class="Starward.Features.SelfQuery.SelfQueryPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="using:Starward.Language"
xmlns:local="using:Starward.Features.SelfQuery"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sc="using:Starward.Controls"
xmlns:scs="using:Starward.Core.SelfQuery"
xmlns:sf="using:Starward.Frameworks"
x:DefaultBindMode="OneWay"
mc:Ignorable="d">

<Page.Resources>
<local:SelfQueryStatsNumberConverter x:Key="SelfQueryStatsNumberConverter" />
<local:SelfQueryStatsNumberBrushConverter x:Key="SelfQueryStatsNumberBrushConverter" />
</Page.Resources>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="44" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<TextBlock Margin="24,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="20"
FontWeight="Bold"
Text="{x:Bind lang:Lang.SelfQueryPage_AccountRecords}" />

<StackPanel Grid.ColumnSpan="2"
Margin="0,0,24,0"
HorizontalAlignment="Right"
Orientation="Horizontal"
Spacing="16">
<ComboBox Name="ComboBox_Uid"
MinWidth="140"
VerticalAlignment="Center"
ItemsSource="{x:Bind UidList}"
SelectedItem="{x:Bind SelectUid, Mode=TwoWay}" />
<Button BorderThickness="0"
Command="{x:Bind InputURLCommand}"
Content="{x:Bind lang:Lang.GachaLogPage_InputURL}"
Style="{ThemeResource AccentButtonStyle}" />
</StackPanel>


<Grid Grid.Row="1"
Margin="28,0,28,8"
Padding="8"
Background="{ThemeResource CustomOverlayAcrylicBrush}"
CornerRadius="4"
Visibility="{x:Bind QueryUserInfo, Converter={StaticResource ObjectToVisibilityConverter}}">
<sc:CachedImage Width="40"
Height="40"
Margin="4,0,0,0"
HorizontalAlignment="Left"
CornerRadius="20"
Source="{x:Bind GameIcon}" />
<StackPanel Margin="56,0,0,0"
VerticalAlignment="Center"
Spacing="2">
<TextBlock Text="{x:Bind QueryUserInfo.Nickname}" />
<TextBlock FontSize="12"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind QueryUserInfo.Uid}" />
</StackPanel>
</Grid>


<ListView Grid.Row="2"
Margin="24,0,24,0"
ItemsSource="{x:Bind TypeStatsList}"
SelectedItem="{x:Bind SelectTypeStats, Mode=TwoWay}">
<ListView.ItemContainerStyle>
<Style BasedOn="{StaticResource DefaultListViewItemStyle}" TargetType="ListViewItem">
<Setter Property="Margin" Value="0,4,0,4" />
<Setter Property="Padding" Value="4,0,4,0" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Padding="8"
Background="{ThemeResource CustomOverlayAcrylicBrush}"
ColumnSpacing="8"
CornerRadius="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" MinWidth="32" />
</Grid.ColumnDefinitions>
<sc:CachedImage Width="40"
Height="40"
Source="{Binding Icon}" />
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Left"
FontSize="14"
Foreground="{ThemeResource SystemFillColorSuccessBrush}"
Text="{Binding Add, Converter={StaticResource SelfQueryStatsNumberConverter}}" />
<TextBlock HorizontalAlignment="Left"
FontSize="14"
Foreground="{ThemeResource SystemFillColorCriticalBrush}"
Text="{Binding Sub, Converter={StaticResource SelfQueryStatsNumberConverter}}" />
</StackPanel>
<ProgressRing Grid.Column="2"
Width="24"
Height="24"
Visibility="{Binding IsUpdating, Converter={StaticResource BoolToVisibilityConverter}}" />
<TextBlock Grid.Column="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="12"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{Binding Page}"
Visibility="{Binding IsUpdating, Converter={StaticResource BoolToVisibilityConverter}}" />
<Button Name="Button_UpdateSelfQueryItems"
Grid.Column="2"
Width="32"
Height="32"
Padding="0"
Click="Button_UpdateSelfQueryItems_Click"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}"
Visibility="{Binding IsUpdating, Converter={StaticResource BoolToVisibilityReversedConverter}}">
<FontIcon FontSize="16"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Glyph="&#xE895;" />
</Button>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>


<Grid Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="1"
RowSpacing="12"
Visibility="{x:Bind SelectTypeStats, Converter={StaticResource ObjectToVisibilityConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Margin="20,0,0,0"
Orientation="Horizontal"
Spacing="24">
<TextBlock VerticalAlignment="Center"
FontSize="16"
Text="{x:Bind SelectTypeStats.Name}" />
<ComboBox Width="120"
ItemsSource="{x:Bind TypeStatsMonthList}"
SelectedItem="{x:Bind SelectTypeStatsMonth, Mode=TwoWay}" />
<TextBlock HorizontalAlignment="Left"
VerticalAlignment="Center"
Foreground="{ThemeResource SystemFillColorSuccessBrush}"
Text="{x:Bind MonthAddNum, Converter={StaticResource SelfQueryStatsNumberConverter}}" />
<TextBlock HorizontalAlignment="Left"
VerticalAlignment="Center"
Foreground="{ThemeResource SystemFillColorCriticalBrush}"
Text="{x:Bind MonthSubNum, Converter={StaticResource SelfQueryStatsNumberConverter}}" />
<Button Command="{x:Bind DeleteCurrentMonthDataCommand}" Content="{x:Bind lang:Lang.SelfQueryPage_DeleteThisMonthSData}" />
<Button Command="{x:Bind UpdateAllQueryItemsCommand}" Content="{x:Bind lang:Lang.SelfQueryPage_RetrieveAllData}" />
</StackPanel>
<ListView Name="ListView_QueryItems_Genshin"
Grid.Row="1"
Padding="0,0,0,12"
ItemsSource="{x:Bind GenshinQueryItemList}"
SelectionMode="None"
Visibility="Collapsed">
<ListView.ItemTemplate>
<DataTemplate x:DataType="scs:GenshinQueryItem">
<StackPanel Orientation="Horizontal" Spacing="16">
<TextBlock Width="160"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind DateTime.ToString('yyyy-MM-dd HH:mm:ss', x:Null)}" />
<TextBlock Width="220"
VerticalAlignment="Center"
Text="{x:Bind Reason}"
TextWrapping="Wrap" />
<TextBlock Width="220"
VerticalAlignment="Center"
Text="{x:Bind Name}"
Visibility="{x:Bind Name, Converter={StaticResource ObjectToVisibilityConverter}}" />
<TextBlock VerticalAlignment="Center"
Foreground="{x:Bind AddNum, Converter={StaticResource SelfQueryStatsNumberBrushConverter}}"
Text="{x:Bind AddNum, Converter={StaticResource SelfQueryStatsNumberConverter}}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Name="ListView_QueryItems_StarRail"
Grid.Row="1"
Padding="0,0,0,12"
ItemsSource="{x:Bind StarRailQueryItemList}"
SelectionMode="None"
Visibility="Collapsed">
<ListView.ItemTemplate>
<DataTemplate x:DataType="scs:StarRailQueryItem">
<StackPanel Orientation="Horizontal" Spacing="16">
<TextBlock Width="160"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind Time.ToString('yyyy-MM-dd HH:mm:ss', x:Null)}" />
<TextBlock Width="240"
VerticalAlignment="Center"
Text="{x:Bind Action}"
TextWrapping="Wrap" />
<TextBlock Width="220"
VerticalAlignment="Center"
Text="{x:Bind EquipmentName}"
Visibility="{x:Bind EquipmentName, Converter={StaticResource ObjectToVisibilityConverter}}" />
<TextBlock Width="220"
VerticalAlignment="Center"
Text="{x:Bind RelicName}"
Visibility="{x:Bind RelicName, Converter={StaticResource ObjectToVisibilityConverter}}" />
<TextBlock VerticalAlignment="Center"
Foreground="{x:Bind AddNum, Converter={StaticResource SelfQueryStatsNumberBrushConverter}}"
Text="{x:Bind AddNum, Converter={StaticResource SelfQueryStatsNumberConverter}}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Name="ListView_QueryItems_ZZZ"
Grid.Row="1"
Padding="0,0,0,12"
ItemsSource="{x:Bind ZZZQueryItemList}"
SelectionMode="None"
Visibility="Collapsed">
<ListView.ItemTemplate>
<DataTemplate x:DataType="scs:ZZZQueryItem">
<StackPanel Orientation="Horizontal" Spacing="16">
<TextBlock Width="160"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind DateTime.ToString('yyyy-MM-dd HH:mm:ss', x:Null)}" />
<TextBlock Width="220"
VerticalAlignment="Center"
Text="{x:Bind Reason}"
TextWrapping="Wrap" />
<TextBlock Width="220"
VerticalAlignment="Center"
Text="{x:Bind EquipName}"
Visibility="{x:Bind EquipName, Converter={StaticResource WhiteSpaceStringToVisibilityConverter}}" />
<TextBlock Width="220"
VerticalAlignment="Center"
Text="{x:Bind WeaponName}"
Visibility="{x:Bind WeaponName, Converter={StaticResource WhiteSpaceStringToVisibilityConverter}}" />
<TextBlock VerticalAlignment="Center"
Foreground="{x:Bind AddNum, Converter={StaticResource SelfQueryStatsNumberBrushConverter}}"
Text="{x:Bind AddNum, Converter={StaticResource SelfQueryStatsNumberConverter}}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

</Grid>


</Grid>
</sf:PageBase>
Loading

0 comments on commit 9a29738

Please sign in to comment.