2020-09-02 03:21:32 +00:00
|
|
|
using System;
|
2020-09-01 10:41:29 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Buypeeb {
|
2021-06-15 00:20:46 +00:00
|
|
|
internal class Settings {
|
2021-10-23 17:07:24 +00:00
|
|
|
public Settings() {
|
|
|
|
// create a new watchlist from an empty dictionary if it's null, which should only happen if either this is the
|
|
|
|
// first time the program has been run, or there's something wrong with userdata.json
|
|
|
|
watchlist ??= new Dictionary<string, YahooAuctionsItem>();
|
|
|
|
}
|
|
|
|
|
2020-09-02 04:12:56 +00:00
|
|
|
public int updateInterval { get; set; } = 10 * 60;
|
|
|
|
public int favouriteUpdateInterval { get; set; } = 5 * 60;
|
|
|
|
public int updateIntervalCritical { get; set; } = 60;
|
|
|
|
public int favouriteUpdateIntervalCritical { get; set; } = 30;
|
2020-09-06 16:39:56 +00:00
|
|
|
public bool showSecondsInListView { get; set; } = true;
|
|
|
|
public bool autosave { get; set; } = true;
|
|
|
|
public bool showFavouritesAtTopOfList { get; set; } = true;
|
2020-09-02 04:12:56 +00:00
|
|
|
|
2021-06-15 00:34:11 +00:00
|
|
|
public Dictionary<string, YahooAuctionsItem> watchlist { get; set; }
|
2020-09-01 10:41:29 +00:00
|
|
|
|
2020-09-04 09:13:16 +00:00
|
|
|
public YahooAuctionsItem Watch(string url, string name) {
|
2021-06-15 00:20:46 +00:00
|
|
|
var id = BuypeebApp.IDFromURL(url);
|
2020-09-02 03:21:32 +00:00
|
|
|
Console.WriteLine(id);
|
2021-06-15 00:20:46 +00:00
|
|
|
watchlist[id] = new YahooAuctionsItem(id, name);
|
|
|
|
return watchlist[id];
|
2020-09-01 10:41:29 +00:00
|
|
|
}
|
2020-09-05 18:36:17 +00:00
|
|
|
|
|
|
|
// TRUE if the item hasn't been updated for at least interval seconds
|
|
|
|
// for example, if the interval is 10, and the item hasn't been updated since 20 seconds ago, this will be TRUE
|
|
|
|
public bool ItemNotUpdatedSinceInterval(YahooAuctionsItem item) {
|
2021-06-15 00:20:46 +00:00
|
|
|
int seconds;
|
2020-09-05 18:36:17 +00:00
|
|
|
if (item.favourite) {
|
2021-06-15 00:20:46 +00:00
|
|
|
seconds = item.endingSoon ? favouriteUpdateIntervalCritical : favouriteUpdateInterval;
|
2021-06-15 00:34:11 +00:00
|
|
|
} else {
|
2021-06-15 00:20:46 +00:00
|
|
|
seconds = item.endingSoon ? updateIntervalCritical : updateInterval;
|
2020-09-05 18:36:17 +00:00
|
|
|
}
|
2021-06-15 00:34:11 +00:00
|
|
|
|
2021-06-15 00:20:46 +00:00
|
|
|
var later = item.LastUpdated.AddSeconds(seconds);
|
2020-09-05 18:36:17 +00:00
|
|
|
return DateTime.Compare(later, DateTime.UtcNow) < 0;
|
|
|
|
}
|
2020-09-01 10:41:29 +00:00
|
|
|
}
|
|
|
|
}
|