feature: date selector in ranking page

This commit is contained in:
2020-05-14 13:31:20 +08:00
parent ac1e7dfd02
commit 2015389cb5
6 changed files with 168 additions and 12 deletions

View File

@@ -4,6 +4,7 @@
xmlns:i="clr-namespace:Pixiview.Illust"
xmlns:u="clr-namespace:Pixiview.UI"
xmlns:r="clr-namespace:Pixiview.Resources"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
x:Class="Pixiview.Illust.RankingPage"
BackgroundColor="{DynamicResource WindowColor}"
Title="{r:Text Ranking}">
@@ -33,8 +34,15 @@
</Grid>
</Shell.TitleView>
<ContentPage.ToolbarItems>
<ToolbarItem Order="Primary" Clicked="Refresh_Clicked"
IconImageSource="{DynamicResource FontIconRefresh}"/>
<ToolbarItem Order="Primary"
Command="{Binding ToolbarCommand}" CommandParameter="prev"
IconImageSource="{DynamicResource FontIconCaretCircleLeft}"/>
<ToolbarItem Order="Primary"
Command="{Binding ToolbarCommand}" CommandParameter="select"
IconImageSource="{DynamicResource FontIconCalendarDay}"/>
<ToolbarItem Order="Primary"
Command="{Binding ToolbarCommand}" CommandParameter="next"
IconImageSource="{DynamicResource FontIconCaretCircleRight}"/>
</ContentPage.ToolbarItems>
<Grid>
<ScrollView x:Name="scrollView" Scrolled="ScrollView_Scrolled"
@@ -92,5 +100,11 @@
<ActivityIndicator IsRunning="True" IsVisible="True"
Color="{DynamicResource WindowColor}"/>
</Frame>
<DatePicker x:Name="datePicker" IsVisible="False"
ios:DatePicker.UpdateMode="WhenFinished"
Date="{Binding SelectedDate}"
MaximumDate="{Binding MaximumDate}"
DateSelected="DatePicker_DateSelected"/>
</Grid>
</i:IllustRankingDataCollectionPage>

View File

@@ -18,6 +18,10 @@ namespace Pixiview.Illust
nameof(SegmentDate), typeof(int), typeof(RankingPage), propertyChanged: OnSegmentDatePropertyChanged);
public static readonly BindableProperty SegmentTypeProperty = BindableProperty.Create(
nameof(SegmentType), typeof(int), typeof(RankingPage), propertyChanged: OnSegmentTypePropertyChanged);
public static readonly BindableProperty MaximumDateProperty = BindableProperty.Create(
nameof(MaximumDate), typeof(DateTime), typeof(RankingPage), DateTime.Now);
public static readonly BindableProperty SelectedDateProperty = BindableProperty.Create(
nameof(SelectedDate), typeof(DateTime), typeof(RankingPage), DateTime.Now);
private static void OnSegmentDatePropertyChanged(BindableObject obj, object old, object @new)
{
@@ -60,12 +64,28 @@ namespace Pixiview.Illust
get => (int)GetValue(SegmentTypeProperty);
set => SetValue(SegmentTypeProperty, value);
}
public DateTime MaximumDate
{
get => (DateTime)GetValue(MaximumDateProperty);
set => SetValue(MaximumDateProperty, value);
}
public DateTime SelectedDate
{
get => (DateTime)GetValue(SelectedDateProperty);
set => SetValue(SelectedDateProperty, value);
}
public Command<string> ToolbarCommand { get; private set; }
private double lastScrollY = double.MinValue;
public bool previousEnabled;
public bool dateEnabled;
public bool nextEnabled;
private bool isFilterVisible;
private string lastQueryKey;
private string queryDate;
private string previousDate;
private string nextDate;
private int currentPage;
private int nextPage;
@@ -74,6 +94,7 @@ namespace Pixiview.Illust
public RankingPage()
{
Resources.Add("cardView", GetCardViewTemplate());
ToolbarCommand = new Command<string>(OnDateTrigger, OnCanDateTrigger);
InitializeComponent();
gridFilter.TranslationY = -100;
panelFilter.TranslationY = -100;
@@ -81,6 +102,9 @@ namespace Pixiview.Illust
lastQueryKey = QueryKey;
queryDate = null; // $"{now.Year}{now.Month:00}{now.Day:00}";
currentPage = 1;
datePicker.MinimumDate = new DateTime(2007, 9, 13);
MaximumDate = DateTime.Now;
}
protected override void DoIllustsLoaded(IllustCollection collection)
@@ -118,13 +142,56 @@ namespace Pixiview.Illust
nextPage = next;
}
var date = data.date;
if (date.Length == 8)
DateTime now;
if (date.Length == 8 && int.TryParse(date, out _))
{
queryDate = date;
date = date.Substring(0, 4) + "-" + date.Substring(4, 2) + "-" + date.Substring(6, 2);
now = new DateTime(
int.Parse(date.Substring(0, 4)),
int.Parse(date.Substring(4, 2)),
int.Parse(date.Substring(6, 2)));
SelectedDate = now;
date = now.ToShortDateString();
}
else
{
now = default;
}
date = ResourceHelper.GetResource(data.mode, date);
MainThread.BeginInvokeOnMainThread(() => Title = date);
var prev = data.prev_date;
if (int.TryParse(prev, out _))
{
previousDate = prev;
previousEnabled = true;
}
else
{
previousDate = null;
previousEnabled = false;
}
var next_ = data.next_date;
if (int.TryParse(next_, out _))
{
nextDate = next_;
nextEnabled = true;
}
else
{
nextDate = null;
nextEnabled = false;
if (now != default)
{
MaximumDate = now;
}
}
dateEnabled = true;
MainThread.BeginInvokeOnMainThread(() =>
{
ToolbarCommand.ChangeCanExecute();
Title = date;
});
}
return data;
}
@@ -157,14 +224,74 @@ namespace Pixiview.Illust
}
}
private void Refresh_Clicked(object sender, EventArgs e)
private void OnDateTrigger(string action)
{
if (IsLoading)
{
return;
}
if (action == "select")
{
datePicker.Focus();
}
else
{
var date = action == "prev" ? previousDate : nextDate;
if (date == null)
{
return;
}
if (isFilterVisible)
{
ToggleFilterPanel(false);
}
// release
var collection = IllustCollection;
if (collection != null)
{
collection.Running = false;
IllustCollection = null;
}
previousEnabled = false;
dateEnabled = false;
nextEnabled = false;
queryDate = date;
currentPage = 1;
StartLoad(true);
}
}
private bool OnCanDateTrigger(string action)
{
switch (action)
{
case "prev":
return previousEnabled;
case "next":
return nextEnabled;
default:
return dateEnabled;
}
}
private void DatePicker_DateSelected(object sender, DateChangedEventArgs e)
{
if (IsLoading)
{
return;
}
// release
var collection = IllustCollection;
if (collection != null)
{
collection.Running = false;
IllustCollection = null;
}
previousEnabled = false;
dateEnabled = false;
nextEnabled = false;
queryDate = e.NewDate.ToString("yyyyMMdd");
currentPage = 1;
IllustCollection = null;
StartLoad(true);
}
@@ -226,10 +353,16 @@ namespace Pixiview.Illust
}
if (lastQueryKey != query)
{
// release
var collection = IllustCollection;
if (collection != null)
{
collection.Running = false;
IllustCollection = null;
}
// query changed.
currentPage = 1;
lastQueryKey = query;
IllustCollection = null;
refresh = true;
App.DebugPrint($"query changed: {query}");
}