buypeeb-cs/Settings.cs
Lynne b26326baf5
code cleanup: name conventions, redundant code...
- use var instead of specific type names where applicable
- get user's home directory from Environment.SpecialFolder.UserProfile instead of reading the HOME environment variable, which isn't always set
- use object initialisers where possible
- remove redundant identifiers (e.g. "Gtk.Application.Invoke" becomes "Application.Invoke"), of which there were MANY
- remove unused local variables
- replace "variable as Class" with "(Class) variable"
- many other miscellaneous improvements

thanks rider 0u0
2021-06-15 10:20:46 +10:00

45 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
namespace Buypeeb {
internal class Settings {
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;
public bool showSecondsInListView { get; set; } = true;
public bool autosave { get; set; } = true;
public bool showFavouritesAtTopOfList { get; set; } = true;
public Dictionary<string, YahooAuctionsItem> watchlist {
get; set;
}
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>();
}
public YahooAuctionsItem Watch(string url, string name) {
var id = BuypeebApp.IDFromURL(url);
Console.WriteLine(id);
watchlist[id] = new YahooAuctionsItem(id, name);
return watchlist[id];
}
// 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) {
int seconds;
if (item.favourite) {
seconds = item.endingSoon ? favouriteUpdateIntervalCritical : favouriteUpdateInterval;
}
else {
seconds = item.endingSoon ? updateIntervalCritical : updateInterval;
}
var later = item.LastUpdated.AddSeconds(seconds);
return DateTime.Compare(later, DateTime.UtcNow) < 0;
}
}
}