fix: date selector in ranking page

feature: auto redirect to login when failed to get data
This commit is contained in:
2020-05-21 09:00:51 +08:00
parent 5b8e02a04b
commit 978085ddd3
3 changed files with 31 additions and 21 deletions

View File

@ -66,6 +66,7 @@ namespace Pixiview.Illust
protected virtual bool IsFavoriteVisible => true; protected virtual bool IsFavoriteVisible => true;
protected virtual bool IsAutoReload => true; protected virtual bool IsAutoReload => true;
protected virtual bool IsRedirectLogin => false;
protected virtual ActivityIndicator LoadingIndicator => null; protected virtual ActivityIndicator LoadingIndicator => null;
protected virtual double IndicatorMarginTop => 16; protected virtual double IndicatorMarginTop => 16;
@ -76,7 +77,6 @@ namespace Pixiview.Illust
private T illustData; private T illustData;
private ParallelTask task; private ParallelTask task;
private bool isTrying;
public IllustCollectionPage() public IllustCollectionPage()
{ {
@ -531,16 +531,30 @@ namespace Pixiview.Illust
{ {
MainThread.BeginInvokeOnMainThread(async () => MainThread.BeginInvokeOnMainThread(async () =>
{ {
if (isTrying) if (!IsRedirectLogin)
{ {
string extra;
if (lastError != null)
{
if (lastError.Length > 40)
{
extra = $"\n{lastError.Substring(0, 40)}...";
}
else
{
extra = $"\n{lastError}";
}
}
else
{
extra = string.Empty;
}
_ = DisplayAlert(ResourceHelper.Title, _ = DisplayAlert(ResourceHelper.Title,
ResourceHelper.FailedResponse + "\n" + lastError?.Substring(0, 40), ResourceHelper.FailedResponse + extra,
ResourceHelper.Ok); ResourceHelper.Ok);
isTrying = false;
} }
else else
{ {
//isTrying = true;
var result = await DisplayAlert( var result = await DisplayAlert(
ResourceHelper.Title, ResourceHelper.Title,
ResourceHelper.ConfirmLogin, ResourceHelper.ConfirmLogin,
@ -560,7 +574,6 @@ namespace Pixiview.Illust
IsBottomLoading = false; IsBottomLoading = false;
return; return;
} }
isTrying = false;
if (force && IsFavoriteVisible) if (force && IsFavoriteVisible)
{ {
var now = DateTime.Now; var now = DateTime.Now;

View File

@ -35,6 +35,7 @@ namespace Pixiview.Illust
#endif #endif
} }
protected override bool IsRedirectLogin => true;
protected override ActivityIndicator LoadingIndicator => activityLoading; protected override ActivityIndicator LoadingIndicator => activityLoading;
protected override double IndicatorMarginTop => 66; protected override double IndicatorMarginTop => 66;

View File

@ -112,7 +112,7 @@ namespace Pixiview.Illust
queryDate = Preferences.Get(Configs.QueryDateKey, null); queryDate = Preferences.Get(Configs.QueryDateKey, null);
currentPage = 1; currentPage = 1;
datePicker.MinimumDate = new DateTime(2007, 9, 13); datePicker.MinimumDate = new DateTime(2007, 9, 13);
MaximumDate = DateTime.Today; MaximumDate = DateTime.Today.AddDays(-1);
} }
protected override ActivityIndicator LoadingIndicator => activityLoading; protected override ActivityIndicator LoadingIndicator => activityLoading;
@ -184,11 +184,12 @@ namespace Pixiview.Illust
now = default; now = default;
} }
date = ResourceHelper.GetResource(data.mode, date); date = ResourceHelper.GetResource(data.mode, date);
MainThread.BeginInvokeOnMainThread(() => Title = date);
var prev = data.prev_date; var prev_date = data.prev_date;
if (int.TryParse(prev, out _)) if (int.TryParse(prev_date, out _))
{ {
previousDate = prev; previousDate = prev_date;
previousEnabled = true; previousEnabled = true;
} }
else else
@ -196,29 +197,24 @@ namespace Pixiview.Illust
previousDate = null; previousDate = null;
previousEnabled = false; previousEnabled = false;
} }
var next_ = data.next_date; var next_date = data.next_date;
if (int.TryParse(next_, out _)) if (int.TryParse(next_date, out _))
{ {
nextDate = next_; nextDate = next_date;
nextEnabled = true; nextEnabled = true;
} }
else else
{ {
nextDate = null; nextDate = null;
nextEnabled = false; nextEnabled = false;
if (now != default) if (now != default && force)
{ {
MaximumDate = now; MaximumDate = now;
} }
} }
dateEnabled = true;
MainThread.BeginInvokeOnMainThread(() =>
{
ToolbarCommand.ChangeCanExecute();
Title = date;
});
} }
dateEnabled = true;
MainThread.BeginInvokeOnMainThread(ToolbarCommand.ChangeCanExecute);
return data; return data;
} }