Я нахожусь в MyArticlesBrowserViewModel, загружая данные для последних трех отображаемых статей, конечно, в зависимости от пользователя. Как только пользователь подписывается, я вызываю метод Clean () и очищаю _lastOpenedArticles, но как только другой пользователь снова входит в коллекцию, это точно соответствует его просмотренным статьям, однако я получаю изображение статьи от предыдущего пользователя. Я думаю, что мне нужно какое-то обновление или обновление sh У вас есть идея?
class MyArticlesBrowserViewModel : ObservableObject, INotifyPropertyChanged
{
public ObservableCollection<ArticleDetailData> LastThreeArticles { get; } = new ObservableCollection<ArticleDetailData>();
public MyArticlesBrowserViewModel()
: base()
{
var articlesApiResponse = await AVAT.App.ApiFactory.GetBestSellerArticlesAsync();
var allArticles = articlesApiResponse.Match(articles => articles.ToList(), _ => new List<Article>());
FillArticles(allArticles);
if (LangUpLoggedUser.LoggedIn || LangUpLoggedUser.LoggedOffline)
{
ShowLastListened();
}
}
public static void Clean()
{
_lastOpenedArticles = null;
_lastSeenArticles = null;
_allDownloadedArticles = null;
}
void ShowLastListened()
{
var lastOpenedArticle = LangUpDataSaverLoader.DeserializeLastLoadedArticle();
lastOpenedArticle.Reverse();
_lastOpenedArticles = lastOpenedArticle;
if (_lastOpenedArticles != null && _lastOpenedArticles.Count > 0)
{
foreach (var article in _lastOpenedArticles.Take(3))
{
var filename = string.Format(SharedConstants.ArticleImageUrl, SharedConstants.ApiBaseUri, article.Id);
var newCell = new ArticleDetailData()
{
Author = article.Author,
Description = article.Description,
Body = article.Description,
Section = article.Category,
BackgroundImage = filename,
Id = article.Id,
Subtitle = article.Description,
Title = article.NameCz,
WhenDay = article.DateCreate.Day.ToString() + " / ",
WhenMonth = article.DateCreate.Month.ToString() + " / ",
WhenYear = article.DateCreate.Year.ToString(),
FullDate = article.DateCreate.ToLongDateString(),
NumberOfWords = article.NumberOfWords,
AmountOfGrammarDescription = article.AmountOfGrammarDescription,
ArticleLength = article.ArticleLength,
Price = article.Price,
IsSubmitted = article.IsSubmitted,
BestSellerRating = article.BestSellerRating,
};
LastThreeArticles.Add(newCell);
}
}
}
Binding
public ArticleBrowser()
{
InitializeComponent();
BindingContext = new MyArticlesBrowserViewModel();
if (BindingContext is MyArticlesBrowserViewModel)
{
var context = new MyArticlesBrowserViewModel();
context.LoadData();
bestSellers.ItemsSource = context.ListOfBestSellers;
lastThreeArticlesCarouselView.ItemsSource = null;
lastThreeArticlesCarouselView.ItemsSource = context.LastThreeArticles;
}
}
Logging off user
public static void LogUserOff()
{
_loggedUser = null;
LoggedIn = false;
_loggedUserDetail = null;
MyArticlesBrowserViewModel.Clean();
LangUpStorage.CleanStorage();
LangUpUserCredentials.DeleteExistingCredentials();
LoggingFinished?.Invoke();
}
}
XAML
<local:ExtendedCarouselViewControl x:Name="lastThreeArticlesCarouselView"
Grid.Row ="1"
HeightRequest="250"
ShowIndicators="True"
Margin="0"
VerticalOptions="Start"
IndicatorsTintColor="{ DynamicResource TranslucidBlack }"
CurrentPageIndicatorTintColor="{ DynamicResource BaseTextColor }"
ItemsSource="{ Binding LastThreeArticles, Mode=TwoWay }">
<cv:CarouselViewControl.ItemTemplate>
<DataTemplate>
<local:AvatArticlesBrowserHeaderItemTemplate />
</DataTemplate>
</cv:CarouselViewControl.ItemTemplate>
</local:ExtendedCarouselViewControl>
Template
<ContentView.Content>
<Grid
Margin="0,0,0,40">
<!-- ARTICLE IMAGE -->
<ffimageloading:CachedImage
VerticalOptions="Fill"
Aspect="AspectFill"
Source="{ Binding BackgroundImage }" >
<ffimageloading:CachedImage.GestureRecognizers>
<TapGestureRecognizer
Tapped="ImageTapped"
NumberOfTapsRequired="1" />
</ffimageloading:CachedImage.GestureRecognizers>
</ffimageloading:CachedImage>
<!--PLAY BUTTON-->
<Button
VerticalOptions="Center"
HorizontalOptions="Center"
WidthRequest="60"
HeightRequest="60"
CornerRadius="30"
Margin="0,0,0,0"
FontSize="30"
BorderWidth="2"
BackgroundColor="#22000000"
Text="{ x:Static local:GrialIconsFont.AudioPlay }"
TextColor="{ DynamicResource OverImageTextColor }"
FontFamily="{ StaticResource IconsFontFamily }"
BorderColor="{ DynamicResource OverImageTextColor }"
Padding="5,0,0,0"
Clicked= "OnPlayButtonClicked"/>
<!-- DATA -->
<Grid
Padding="20,0,20,5"
RowSpacing="0"
VerticalOptions="End"
grial:Effects.ApplyIOSSafeAreaAsPadding="Left,Right">
<Grid.RowDefinitions>
<RowDefinition
Height="20" />
<RowDefinition
Height="Auto" />
<RowDefinition
Height="30" />
</Grid.RowDefinitions>
<!-- Date -->
<Label
Grid.Row="0"
Text="{ Binding When }"
FontSize="12"
TextColor="{ DynamicResource OverImageTextColor }" />
<!-- Title -->
<Label
Grid.Row="1"
Text="{ Binding Title }"
FontSize="26"
Style="{ StaticResource LabelBoldStyle }"
TextColor="{ DynamicResource OverImageTextColor }" />
<!-- Category -->
<Label
Grid.Row="2"
Text="{ Binding Section }"
FontSize="14"
TextColor="{ DynamicResource OverImageTextColor }" />
</Grid>
</Grid>
</ContentView.Content>