features:
- launcher logo - tab bar tint color - favorites logic udpated
This commit is contained in:
@@ -8,8 +8,8 @@
|
||||
xmlns:util="clr-namespace:Pixiview.Utils"
|
||||
x:Class="Pixiview.AppShell"
|
||||
BackgroundColor="{DynamicResource NavColor}"
|
||||
ForegroundColor="{DynamicResource MainTextColor}"
|
||||
TitleColor="{DynamicResource MainTextColor}"
|
||||
ForegroundColor="{DynamicResource TintColor}"
|
||||
TitleColor="{DynamicResource TextColor}"
|
||||
UnselectedColor="{DynamicResource SubTextColor}">
|
||||
<Shell.FlyoutHeaderTemplate>
|
||||
<DataTemplate>
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Pixiview.UI.Theme
|
||||
{
|
||||
public partial class DarkTheme : ThemeBase
|
||||
public class DarkTheme : ThemeBase
|
||||
{
|
||||
private static DarkTheme _instance;
|
||||
|
||||
@@ -29,11 +29,10 @@ namespace Pixiview.UI.Theme
|
||||
{
|
||||
Add(StatusBarStyle, StatusBarStyles.WhiteText);
|
||||
Add(WindowColor, Color.Black);
|
||||
Add(TintColor, Color.FromRgb(0x00, 0x96, 0xfa));
|
||||
Add(TextColor, Color.White);
|
||||
Add(SubTextColor, Color.LightGray);
|
||||
Add(MainColor, Color.FromRgb(0x11, 0x11, 0x11));
|
||||
Add(MainTextColor, Color.White);
|
||||
Add(SubColor, Color.FromRgb(0x33, 0x33, 0x33));
|
||||
Add(CardBackgroundColor, Color.FromRgb(0x33, 0x33, 0x33));
|
||||
Add(MaskColor, Color.FromRgba(0xff, 0xff, 0xff, 0x50));
|
||||
Add(NavColor, Color.Black);
|
||||
Add(NavSelectedColor, Color.FromRgb(0x22, 0x22, 0x22));
|
||||
|
@@ -3,7 +3,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Pixiview.UI.Theme
|
||||
{
|
||||
public partial class LightTheme : ThemeBase
|
||||
public class LightTheme : ThemeBase
|
||||
{
|
||||
private static LightTheme _instance;
|
||||
|
||||
@@ -29,13 +29,12 @@ namespace Pixiview.UI.Theme
|
||||
{
|
||||
Add(StatusBarStyle, StatusBarStyles.DarkText);
|
||||
Add(WindowColor, Color.White);
|
||||
Add(TintColor, Color.FromRgb(0x00, 0x96, 0xfa)); // 0x7f, 0x99, 0xc6
|
||||
Add(TextColor, Color.Black);
|
||||
Add(SubTextColor, Color.DimGray);
|
||||
Add(MainColor, Color.FromRgb(0xf0, 0xf0, 0xf0)); // Color.FromRgb(0x7f, 0x99, 0xc6)
|
||||
Add(MainTextColor, Color.Black);
|
||||
Add(SubColor, Color.FromRgb(0xf0, 0xf0, 0xf0)); // Color.FromRgb(0xfa, 0xfa, 0xf0)
|
||||
Add(CardBackgroundColor, Color.FromRgb(0xfa, 0xfa, 0xf0));
|
||||
Add(MaskColor, Color.FromRgba(0, 0, 0, 0x50));
|
||||
Add(NavColor, Color.FromRgb(0xee, 0xee, 0xee));
|
||||
Add(NavColor, Color.FromRgb(0xf0, 0xf0, 0xf0));
|
||||
Add(NavSelectedColor, Color.LightGray);
|
||||
}
|
||||
}
|
||||
|
@@ -4,8 +4,6 @@ namespace Pixiview.UI.Theme
|
||||
{
|
||||
public class ThemeBase : ResourceDictionary
|
||||
{
|
||||
public const string TitleButton = nameof(TitleButton);
|
||||
public const string TitleLabel = nameof(TitleLabel);
|
||||
public const string FontIconUser = nameof(FontIconUser);
|
||||
public const string FontIconSparkles = nameof(FontIconSparkles);
|
||||
public const string FontIconOrder = nameof(FontIconOrder);
|
||||
@@ -18,11 +16,10 @@ namespace Pixiview.UI.Theme
|
||||
|
||||
public const string StatusBarStyle = nameof(StatusBarStyle);
|
||||
public const string WindowColor = nameof(WindowColor);
|
||||
public const string TintColor = nameof(TintColor);
|
||||
public const string TextColor = nameof(TextColor);
|
||||
public const string SubTextColor = nameof(SubTextColor);
|
||||
public const string MainColor = nameof(MainColor);
|
||||
public const string MainTextColor = nameof(MainTextColor);
|
||||
public const string SubColor = nameof(SubColor);
|
||||
public const string CardBackgroundColor = nameof(CardBackgroundColor);
|
||||
public const string MaskColor = nameof(MaskColor);
|
||||
public const string NavColor = nameof(NavColor);
|
||||
public const string NavSelectedColor = nameof(NavSelectedColor);
|
||||
@@ -58,43 +55,19 @@ namespace Pixiview.UI.Theme
|
||||
}
|
||||
}
|
||||
|
||||
var mainColor = (Color)this[MainTextColor];
|
||||
var tintColor = (Color)this[TextColor];
|
||||
var regularFontFamily = (string)this[IconRegularFontFamily];
|
||||
var solidFontFamily = (string)this[IconSolidFontFamily];
|
||||
|
||||
Add(TitleLabel, new Style(typeof(Label))
|
||||
{
|
||||
Setters =
|
||||
{
|
||||
new Setter { Property = View.VerticalOptionsProperty, Value = LayoutOptions.Center },
|
||||
new Setter { Property = View.HorizontalOptionsProperty, Value = LayoutOptions.Fill },
|
||||
new Setter { Property = Label.HorizontalTextAlignmentProperty, Value = TextAlignment.Center },
|
||||
new Setter { Property = Label.FontSizeProperty, Value = StyleDefinition.FontSizeTitle },
|
||||
new Setter { Property = Label.TextColorProperty, Value = mainColor }
|
||||
}
|
||||
});
|
||||
|
||||
Add(TitleButton, new Style(typeof(Button))
|
||||
{
|
||||
Setters =
|
||||
{
|
||||
new Setter { Property = Button.BorderWidthProperty, Value = 0.0 },
|
||||
new Setter { Property = VisualElement.BackgroundColorProperty, Value = Color.Transparent },
|
||||
new Setter { Property = Button.FontFamilyProperty, Value = solidFontFamily },
|
||||
new Setter { Property = Button.FontSizeProperty, Value = StyleDefinition.FontSizeTitleIcon },
|
||||
new Setter { Property = Button.TextColorProperty, Value = mainColor }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Add(FontIconUser, GetSolidIcon(StyleDefinition.IconUser, solidFontFamily, mainColor));
|
||||
Add(FontIconSparkles, GetSolidIcon(StyleDefinition.IconSparkles, solidFontFamily, mainColor));
|
||||
Add(FontIconOrder, GetSolidIcon(StyleDefinition.IconOrder, solidFontFamily, mainColor));
|
||||
Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, solidFontFamily, mainColor));
|
||||
Add(FontIconUser, GetSolidIcon(StyleDefinition.IconUser, solidFontFamily, tintColor));
|
||||
Add(FontIconSparkles, GetSolidIcon(StyleDefinition.IconSparkles, solidFontFamily, tintColor));
|
||||
Add(FontIconOrder, GetSolidIcon(StyleDefinition.IconOrder, solidFontFamily, tintColor));
|
||||
Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, solidFontFamily, tintColor));
|
||||
Add(FontIconLove, GetSolidIcon(StyleDefinition.IconLove, solidFontFamily, StyleDefinition.ColorRedBackground));
|
||||
Add(FontIconNotLove, GetSolidIcon(StyleDefinition.IconLove, (string)this[IconRegularFontFamily], mainColor));
|
||||
Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily, mainColor));
|
||||
Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily, mainColor));
|
||||
Add(FontIconFavorite, GetSolidIcon(StyleDefinition.IconFavorite, solidFontFamily, mainColor));
|
||||
Add(FontIconNotLove, GetSolidIcon(StyleDefinition.IconLove, regularFontFamily, tintColor));
|
||||
Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily, tintColor));
|
||||
Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily, tintColor));
|
||||
Add(FontIconFavorite, GetSolidIcon(StyleDefinition.IconFavorite, solidFontFamily, tintColor));
|
||||
}
|
||||
|
||||
private FontImageSource GetSolidIcon(string icon, string family, Color color)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
@@ -11,7 +12,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Pixiview.Utils
|
||||
{
|
||||
public class Stores
|
||||
public static class Stores
|
||||
{
|
||||
public static readonly string PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
||||
public static readonly string CacheFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
|
||||
@@ -43,6 +44,48 @@ namespace Pixiview.Utils
|
||||
}
|
||||
}
|
||||
|
||||
private static IllustFavorite favoriteObject;
|
||||
public static IllustFavorite FavoriteObject
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
if (favoriteObject == null)
|
||||
{
|
||||
var favorites = LoadFavoritesIllusts();
|
||||
if (favorites != null)
|
||||
{
|
||||
favoriteObject = favorites;
|
||||
}
|
||||
}
|
||||
return favoriteObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<IllustItem> Favorites => FavoriteObject.Illusts;
|
||||
|
||||
private static IllustFavorite LoadFavoritesIllusts()
|
||||
{
|
||||
var file = Path.Combine(PersonalFolder, favoriteFile);
|
||||
lock (sync)
|
||||
{
|
||||
return ReadObject<IllustFavorite>(file);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveFavoritesIllusts()
|
||||
{
|
||||
var file = Path.Combine(PersonalFolder, favoriteFile);
|
||||
lock (sync)
|
||||
{
|
||||
var data = FavoriteObject;
|
||||
data.LastFavoriteUtc = DateTime.UtcNow;
|
||||
WriteObject(file, data);
|
||||
}
|
||||
}
|
||||
|
||||
private static T LoadObject<T>(string file, string url, string referer = null, bool force = false)
|
||||
{
|
||||
string content = null;
|
||||
@@ -179,24 +222,6 @@ namespace Pixiview.Utils
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IllustFavorite LoadFavoritesIllusts()
|
||||
{
|
||||
var file = Path.Combine(PersonalFolder, favoriteFile);
|
||||
lock (sync)
|
||||
{
|
||||
return ReadObject<IllustFavorite>(file);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveFavoritesIllusts(IllustFavorite data)
|
||||
{
|
||||
var file = Path.Combine(PersonalFolder, favoriteFile);
|
||||
lock (sync)
|
||||
{
|
||||
WriteObject(file, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageSource LoadIllustImage(string url)
|
||||
{
|
||||
return LoadImage(url, PersonalFolder, imageFolder);
|
||||
|
Reference in New Issue
Block a user