Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
修复动态及消息条目的显示问题 (#1244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy authored Jun 26, 2022
1 parent f80e2ba commit c976191
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/Adapter/Adapter.Implementation/CommunityAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public MessageInformation ConvertToMessageInformation(LikeMessageItem messageIte
messageItem.Item.Business);
}

var publishTime = DateTimeOffset.FromUnixTimeSeconds(messageItem.LikeTime).ToLocalTime().DateTime;
var publishTime = DateTimeOffset.FromUnixTimeSeconds(messageItem.LikeTime).DateTime;
var id = messageItem.Id.ToString();
var sourceContent = string.IsNullOrEmpty(messageItem.Item.Title)
? messageItem.Item.Description
Expand Down Expand Up @@ -475,7 +475,7 @@ public MessageInformation ConvertToMessageInformation(AtMessageItem messageItem)
var sourceContent = string.IsNullOrEmpty(messageItem.Item.Title)
? _resourceToolkit.GetLocaleString(Models.Enums.LanguageNames.NoSpecificData)
: messageItem.Item.Title;
var publishTime = DateTimeOffset.FromUnixTimeSeconds(messageItem.AtTime).ToLocalTime().DateTime;
var publishTime = DateTimeOffset.FromUnixTimeSeconds(messageItem.AtTime).DateTime;
var id = messageItem.Id.ToString();
var sourceId = messageItem.Item.Uri;

Expand Down Expand Up @@ -507,7 +507,7 @@ public MessageInformation ConvertToMessageInformation(ReplyMessageItem messageIt
var sourceContent = string.IsNullOrEmpty(messageItem.Item.Title)
? messageItem.Item.Description
: messageItem.Item.Title;
var publishTime = DateTimeOffset.FromUnixTimeSeconds(messageItem.ReplyTime).ToLocalTime().DateTime;
var publishTime = DateTimeOffset.FromUnixTimeSeconds(messageItem.ReplyTime).DateTime;
var id = messageItem.Id.ToString();
var sourceId = messageItem.Item.SubjectId.ToString();
var properties = new Dictionary<string, string>()
Expand Down
17 changes: 4 additions & 13 deletions src/App/Controls/User/UserSpaceView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,13 @@
Command="{x:Bind ViewModel.UserViewModel.ToggleRelationCommand}"
Content="{x:Bind ViewModel.UserViewModel.Relation, Mode=OneWay, Converter={StaticResource RelationTextConverter}}"
Visibility="{x:Bind ViewModel.IsMe, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
<!--<Grid
<Button
Grid.Row="1"
Grid.Column="1"
MinWidth="120"
Margin="8,0,0,0"
Visibility="{x:Bind ViewModel.CanFixPublisher, Mode=OneWay}">
<Button
MinWidth="120"
Click="OnFixButtonClickAsync"
Content="{loc:Locale Name=FixPublisher}"
Visibility="{x:Bind ViewModel.IsPublisherFixed, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
<Button
MinWidth="120"
Click="OnFixButtonClickAsync"
Content="{loc:Locale Name=UnfixPublisher}"
Visibility="{x:Bind ViewModel.IsPublisherFixed, Mode=OneWay}" />
</Grid>-->
Command="{x:Bind ViewModel.FixedCommand}"
Content="{x:Bind ViewModel.IsFixed, Mode=OneWay, Converter={StaticResource FixedContentConverter}}" />
</Grid>
</Grid>
<StackPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public sealed partial class UserItemViewModel
private readonly IAccountProvider _accountProvider;
private readonly IResourceToolkit _resourceToolkit;
private readonly AppViewModel _appViewModel;
private readonly AccountViewModel _accountViewModel;

private readonly ObservableAsPropertyHelper<bool> _isRelationChanging;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public UserItemViewModel(
INumberToolkit numberToolkit,
IAccountProvider accountProvider,
IResourceToolkit resourceToolkit,
AppViewModel appViewModel)
AppViewModel appViewModel,
AccountViewModel accountViewModel)
{
_numberToolkit = numberToolkit;
_accountProvider = accountProvider;
_resourceToolkit = resourceToolkit;
_appViewModel = appViewModel;
_accountViewModel = accountViewModel;

ToggleRelationCommand = ReactiveCommand.CreateFromTask(ToggleRelationAsync, outputScheduler: RxApp.MainThreadScheduler);
InitializeRelationCommand = ReactiveCommand.CreateFromTask(InitializeRelationAsync, outputScheduler: RxApp.MainThreadScheduler);
Expand Down Expand Up @@ -88,6 +90,12 @@ public void SetProfile(UserProfile profile)

private async Task ToggleRelationAsync()
{
if (_accountViewModel.State != AuthorizeState.SignedIn)
{
_appViewModel.ShowTip(_resourceToolkit.GetLocaleString(LanguageNames.NeedLoginFirst), Models.Enums.App.InfoType.Warning);
return;
}

bool? isFollow = null;
if (Relation == UserRelationStatus.Unfollow || Relation == UserRelationStatus.BeFollowed)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public sealed partial class UserSpaceViewModel
private readonly IAccountProvider _accountProvider;
private readonly IResourceToolkit _resourceToolkit;
private readonly NavigationViewModel _navigationViewModel;
private readonly AccountViewModel _accountViewModel;
private readonly AppViewModel _appViewModel;
private readonly ObservableAsPropertyHelper<bool> _isSearching;
private readonly ObservableAsPropertyHelper<bool> _canSearch;
private UserProfile _userProfile;
Expand Down Expand Up @@ -52,6 +54,11 @@ public sealed partial class UserSpaceViewModel
/// </summary>
public ReactiveCommand<Unit, Unit> GotoFollowsPageCommand { get; }

/// <summary>
/// 固定条目的命令.
/// </summary>
public ReactiveCommand<Unit, Unit> FixedCommand { get; }

/// <summary>
/// 搜索的视频结果.
/// </summary>
Expand Down Expand Up @@ -93,6 +100,12 @@ public sealed partial class UserSpaceViewModel
[Reactive]
public bool IsSearchVideoEmpty { get; set; }

/// <summary>
/// 该用户是否已经被固定在首页.
/// </summary>
[Reactive]
public bool IsFixed { get; set; }

/// <summary>
/// 是否正在搜索.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using Bili.Lib.Interfaces;
using Bili.Models.Data.Local;
using Bili.Models.Data.User;
using Bili.Models.Data.Video;
using Bili.Toolkit.Interfaces;
Expand All @@ -29,12 +30,16 @@ public UserSpaceViewModel(
IAccountProvider accountProvider,
IResourceToolkit resourceToolkit,
NavigationViewModel navigationViewModel,
AccountViewModel accountViewModel,
AppViewModel appViewModel,
CoreDispatcher dispatcher)
: base(dispatcher)
{
_accountProvider = accountProvider;
_resourceToolkit = resourceToolkit;
_navigationViewModel = navigationViewModel;
_accountViewModel = accountViewModel;
_appViewModel = appViewModel;

SearchVideos = new ObservableCollection<VideoItemViewModel>();

Expand All @@ -46,6 +51,7 @@ public UserSpaceViewModel(
SearchCommand = ReactiveCommand.CreateFromTask(SearchAsync, canSearch, RxApp.MainThreadScheduler);
GotoFollowsPageCommand = ReactiveCommand.Create(GotoFollowsPage, outputScheduler: RxApp.MainThreadScheduler);
GotoFansPageCommand = ReactiveCommand.Create(GotoFansPage, outputScheduler: RxApp.MainThreadScheduler);
FixedCommand = ReactiveCommand.Create(Fix, outputScheduler: RxApp.MainThreadScheduler);

_isSearching = SearchCommand.IsExecuting.ToProperty(this, x => x.IsSearching, scheduler: RxApp.MainThreadScheduler);
_canSearch = canSearch.ToProperty(this, x => x.CanSearch, scheduler: RxApp.MainThreadScheduler);
Expand Down Expand Up @@ -183,5 +189,29 @@ private void GotoFollowsPage()
_navigationViewModel.NavigateToSecondaryView(Models.Enums.PageIds.Follows, UserViewModel.User);
}
}

private void Fix()
{
if (_accountViewModel.State != Models.Enums.AuthorizeState.SignedIn)
{
_appViewModel.ShowTip(_resourceToolkit.GetLocaleString(Models.Enums.LanguageNames.NeedLoginFirst), Models.Enums.App.InfoType.Warning);
return;
}

if (IsFixed)
{
_accountViewModel.RemoveFixedItemCommand.Execute(UserViewModel.User.Id).Subscribe();
IsFixed = false;
}
else
{
_accountViewModel.AddFixedItemCommand.Execute(new FixedItem(
UserViewModel.User.Avatar.Uri,
UserViewModel.User.Name,
UserViewModel.User.Id,
Models.Enums.App.FixedType.Publisher)).Subscribe();
IsFixed = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class DynamicModuleViewModelBase
private readonly ICommunityProvider _communityProvider;
private readonly IResourceToolkit _resourceToolkit;
private readonly ISettingsToolkit _settingsToolkit;
private readonly IAuthorizeProvider _authorizeProvider;
private readonly bool _isOnlyVideo;
private bool _isEnd;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ internal DynamicModuleViewModelBase(
ICommunityProvider communityProvider,
IResourceToolkit resourceToolkit,
ISettingsToolkit settingsToolkit,
IAuthorizeProvider authorizeProvider,
bool isOnlyVideo,
CoreDispatcher dispatcher)
: base(dispatcher)
{
_communityProvider = communityProvider;
_resourceToolkit = resourceToolkit;
_settingsToolkit = settingsToolkit;
_authorizeProvider = authorizeProvider;
_isOnlyVideo = isOnlyVideo;
}

Expand All @@ -55,7 +57,7 @@ protected override string FormatException(string errorMsg)
/// <inheritdoc/>
protected override async Task GetDataAsync()
{
if (_isEnd)
if (_isEnd || _authorizeProvider.State != Models.Enums.AuthorizeState.SignedIn)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public CommentDetailModuleViewModel(

SendCommentCommand = ReactiveCommand.CreateFromTask(SendCommentAsync, outputScheduler: RxApp.MainThreadScheduler);
BackCommand = ReactiveCommand.Create(Back, outputScheduler: RxApp.MainThreadScheduler);
ResetSelectedCommentCommand = ReactiveCommand.Create(UnselectComment, outputScheduler: RxApp.MainThreadScheduler);

_isSending = SendCommentCommand.IsExecuting.ToProperty(this, x => x.IsSending, scheduler: RxApp.MainThreadScheduler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public DynamicAllModuleViewModel(
ICommunityProvider communityProvider,
IResourceToolkit resourceToolkit,
ISettingsToolkit settingsToolkit,
IAuthorizeProvider authorizeProvider,
CoreDispatcher dispatcher)
: base(communityProvider, resourceToolkit, settingsToolkit, false, dispatcher)
: base(communityProvider, resourceToolkit, settingsToolkit, authorizeProvider, false, dispatcher)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private void SelectHeader(DynamicHeader header)
}

private void OnAuthorizeStateChanged(object sender, AuthorizeStateChangedEventArgs e)
=> NeedSignIn = e.NewState != Models.Enums.AuthorizeState.SignedIn;
{
NeedSignIn = e.NewState != Models.Enums.AuthorizeState.SignedIn;
RefreshModuleCommand.Execute().Subscribe();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public DynamicVideoModuleViewModel(
ICommunityProvider communityProvider,
IResourceToolkit resourceToolkit,
ISettingsToolkit settingsToolkit,
IAuthorizeProvider authorizeProvider,
CoreDispatcher dispatcher)
: base(communityProvider, resourceToolkit, settingsToolkit, true, dispatcher)
: base(communityProvider, resourceToolkit, settingsToolkit, authorizeProvider, true, dispatcher)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ private void Share()

private void Fix()
{
if (_accountViewModel.State != AuthorizeState.SignedIn)
{
_appViewModel.ShowTip(_resourceToolkit.GetLocaleString(LanguageNames.NeedLoginFirst), Models.Enums.App.InfoType.Warning);
return;
}

if (IsLiveFixed)
{
_accountViewModel.RemoveFixedItemCommand.Execute(View.Information.Identifier.Id).Subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ private void ShowSeasonDetail()

private void Fix()
{
if (_accountViewModel.State != AuthorizeState.SignedIn)
{
_appViewModel.ShowTip(_resourceToolkit.GetLocaleString(LanguageNames.NeedLoginFirst), Models.Enums.App.InfoType.Warning);
return;
}

if (IsVideoFixed)
{
_accountViewModel.RemoveFixedItemCommand.Execute(View.Information.Identifier.Id).Subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.Linq;
using System.Threading.Tasks;
using Bili.Models.App.Args;
using Bili.Models.Data.Community;
using Bili.Models.Data.Local;
Expand Down Expand Up @@ -65,6 +64,12 @@ private void Share()

private void Fix()
{
if (_accountViewModel.State != AuthorizeState.SignedIn)
{
_appViewModel.ShowTip(_resourceToolkit.GetLocaleString(LanguageNames.NeedLoginFirst), Models.Enums.App.InfoType.Warning);
return;
}

if (IsVideoFixed)
{
_accountViewModel.RemoveFixedItemCommand.Execute(View.Information.Identifier.Id).Subscribe();
Expand Down

0 comments on commit c976191

Please sign in to comment.