features:
- launcher logo - tab bar tint color - favorites logic udpated
This commit is contained in:
@@ -17,9 +17,9 @@ namespace Pixiview.Illust
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
StartLoad(true);
|
||||
//base.OnAppearing();
|
||||
loaded = false;
|
||||
StartLoad();
|
||||
}
|
||||
|
||||
protected override IEnumerable<IllustItem> DoGetIllustList(IllustItem[] data, ICommand command)
|
||||
@@ -33,12 +33,12 @@ namespace Pixiview.Illust
|
||||
|
||||
protected override IllustItem[] DoLoadIllustData(bool force)
|
||||
{
|
||||
var favorites = Stores.LoadFavoritesIllusts();
|
||||
var favorites = Stores.FavoriteObject;
|
||||
if (favorites == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return favorites.Illusts;
|
||||
return favorites.Illusts.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ namespace Pixiview.Illust
|
||||
{
|
||||
public interface IIllustCollectionPage
|
||||
{
|
||||
List<IllustItem> Favorites { get; }
|
||||
IllustCollection IllustCollection { get; set; }
|
||||
}
|
||||
|
||||
@@ -60,13 +59,13 @@ namespace Pixiview.Illust
|
||||
set => SetValue(LoadingProperty, value);
|
||||
}
|
||||
|
||||
public List<IllustItem> Favorites { get; } = new List<IllustItem>();
|
||||
#endregion
|
||||
|
||||
protected static bool IsUpdated { get; private set; } = true;
|
||||
|
||||
public IllustCollection IllustCollection { get; set; }
|
||||
|
||||
protected virtual bool IsFavoriteVisible => true;
|
||||
|
||||
#endregion
|
||||
|
||||
protected Thickness totalBarOffset;
|
||||
protected Thickness navigationBarOffset;
|
||||
protected bool loaded;
|
||||
@@ -79,12 +78,6 @@ namespace Pixiview.Illust
|
||||
{
|
||||
BindingContext = this;
|
||||
commandIllustImageTapped = new Command<IllustItem>(IllustImageTapped);
|
||||
|
||||
var favorites = Stores.LoadFavoritesIllusts();
|
||||
if (favorites != null)
|
||||
{
|
||||
Favorites.AddRange(favorites.Illusts);
|
||||
}
|
||||
}
|
||||
|
||||
private void IllustImageTapped(IllustItem illust)
|
||||
@@ -97,22 +90,38 @@ namespace Pixiview.Illust
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged;
|
||||
|
||||
if (IsUpdated || !loaded)
|
||||
{
|
||||
IsUpdated = false;
|
||||
loaded = false;
|
||||
StartLoad();
|
||||
}
|
||||
else if (IsFavoriteVisible)
|
||||
{
|
||||
var favorites = Stores.Favorites;
|
||||
foreach (var item in IllustCollection)
|
||||
{
|
||||
item.IsFavorite = favorites.Any(i => i.Id == item.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
|
||||
Connectivity.ConnectivityChanged -= Connectivity_ConnectivityChanged;
|
||||
base.OnDisappearing();
|
||||
}
|
||||
|
||||
private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
|
||||
{
|
||||
if (e.NetworkAccess == NetworkAccess.Internet || e.NetworkAccess == NetworkAccess.ConstrainedInternet)
|
||||
{
|
||||
StartLoad();
|
||||
if (!loaded)
|
||||
{
|
||||
StartLoad(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +302,7 @@ namespace Pixiview.Illust
|
||||
}
|
||||
}
|
||||
}
|
||||
.DynamicResource(BackgroundColorProperty, ThemeBase.SubColor);
|
||||
.DynamicResource(BackgroundColorProperty, ThemeBase.CardBackgroundColor);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -308,15 +317,20 @@ namespace Pixiview.Illust
|
||||
Loading = false;
|
||||
return;
|
||||
}
|
||||
if (force)
|
||||
{
|
||||
IsUpdated = true;
|
||||
}
|
||||
|
||||
var data = DoGetIllustList(illustData, commandIllustImageTapped).Where(i => i != null);
|
||||
|
||||
var collection = new IllustCollection(data);
|
||||
if (IsFavoriteVisible)
|
||||
{
|
||||
var favorites = Stores.Favorites;
|
||||
foreach (var item in collection)
|
||||
{
|
||||
item.IsFavorite = Favorites.Any(i => i.Id == item.Id);
|
||||
item.IsFavorite = favorites.Any(i => i.Id == item.Id);
|
||||
}
|
||||
}
|
||||
IllustCollection = collection;
|
||||
@@ -404,7 +418,7 @@ namespace Pixiview.Illust
|
||||
public class IllustFavorite
|
||||
{
|
||||
public DateTime LastFavoriteUtc { get; set; }
|
||||
public IllustItem[] Illusts { get; set; }
|
||||
public List<IllustItem> Illusts { get; set; }
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
|
@@ -14,11 +14,6 @@ namespace Pixiview.Illust
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public override void OnLoad()
|
||||
{
|
||||
StartLoad();
|
||||
}
|
||||
|
||||
public override void OnUnload()
|
||||
{
|
||||
Illusts = IllustCollection.Empty;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
<SearchBar Placeholder="{r:Text Search}" VerticalOptions="Start"
|
||||
Margin="0, -46, 0, 0" HeightRequest="50"
|
||||
BackgroundColor="{DynamicResource WindowColor}"
|
||||
CancelButtonColor="{DynamicResource SubTextColor}"
|
||||
CancelButtonColor="{DynamicResource TintColor}"
|
||||
Text="{Binding Keywords, Mode=TwoWay}"
|
||||
SearchButtonPressed="SearchBar_SearchButtonPressed"
|
||||
Unfocused="SearchBar_Unfocused"/>
|
||||
|
@@ -28,11 +28,6 @@ namespace Pixiview.Illust
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public override void OnLoad()
|
||||
{
|
||||
StartLoad();
|
||||
}
|
||||
|
||||
public override void OnUnload()
|
||||
{
|
||||
Illusts = IllustCollection.Empty;
|
||||
|
@@ -36,11 +36,6 @@ namespace Pixiview.Illust
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public override void OnLoad()
|
||||
{
|
||||
StartLoad();
|
||||
}
|
||||
|
||||
public override void OnUnload()
|
||||
{
|
||||
Illusts = IllustCollection.Empty;
|
||||
|
@@ -68,9 +68,10 @@ namespace Pixiview.Illust
|
||||
|
||||
fontIconLove = (ImageSource)Application.Current.Resources[ThemeBase.FontIconLove];
|
||||
fontIconNotLove = (ImageSource)Application.Current.Resources[ThemeBase.FontIconNotLove];
|
||||
if (page.Favorites != null)
|
||||
var favorites = Stores.Favorites;
|
||||
if (favorites != null)
|
||||
{
|
||||
FavoriteIcon = page.Favorites.Any(i => i.Id == illust.Id)
|
||||
FavoriteIcon = favorites.Any(i => i.Id == illust.Id)
|
||||
? fontIconLove
|
||||
: fontIconNotLove;
|
||||
}
|
||||
@@ -100,12 +101,7 @@ namespace Pixiview.Illust
|
||||
|
||||
if (collectionPage is IllustDataCollectionPage)
|
||||
{
|
||||
var favorite = new IllustFavorite
|
||||
{
|
||||
LastFavoriteUtc = DateTime.UtcNow,
|
||||
Illusts = collectionPage.Favorites.ToArray()
|
||||
};
|
||||
Stores.SaveFavoritesIllusts(favorite);
|
||||
Stores.SaveFavoritesIllusts();
|
||||
}
|
||||
Screen.SetHomeIndicatorAutoHidden(Shell.Current, false);
|
||||
}
|
||||
@@ -236,21 +232,23 @@ namespace Pixiview.Illust
|
||||
|
||||
private void Favorite_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
if (collectionPage.Favorites == null)
|
||||
var favorites = Stores.Favorites;
|
||||
if (favorites == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var index = collectionPage.Favorites.FindIndex(i => i.Id == IllustItem.Id);
|
||||
var illust = IllustItem;
|
||||
var index = favorites.FindIndex(i => i.Id == illust.Id);
|
||||
if (index < 0)
|
||||
{
|
||||
collectionPage.Favorites.Insert(0, IllustItem);
|
||||
IllustItem.IsFavorite = true;
|
||||
illust.IsFavorite = true;
|
||||
favorites.Insert(0, illust);
|
||||
FavoriteIcon = fontIconLove;
|
||||
}
|
||||
else
|
||||
{
|
||||
collectionPage.Favorites.RemoveAt(index);
|
||||
IllustItem.IsFavorite = false;
|
||||
illust.IsFavorite = false;
|
||||
favorites.RemoveAt(index);
|
||||
FavoriteIcon = fontIconNotLove;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user