Created
February 26, 2018 13:49
-
-
Save wiredprairie/dde9e1dde91fc35de9f1d42e37903cf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<File> _getCacheFile() async { | |
final dir = (await getApplicationDocumentsDirectory()).path; | |
return new File('$dir/hotlist.xml'); | |
} | |
Future<XmlDocument> _getHotListCache() async { | |
try { | |
final file = await _getCacheFile(); | |
return parse(await file.readAsString()); | |
} | |
on FileSystemException { | |
return _getDefaultHotGameInfo(); | |
} | |
} | |
Future<bool> _hotListCacheFileExists() async => | |
await (await _getCacheFile()).exists(); | |
Future<Null> _saveHotListToCache(XmlDocument doc) async { | |
try { | |
final file = await _getCacheFile(); | |
final sink = await file.openWrite(); | |
await sink.write(doc.toXmlString(pretty: true)); | |
await sink.close(); | |
final prefs = await SharedPreferences.getInstance(); | |
final later = new DateTime.now().add(new Duration(hours: 8)); | |
prefs.setInt(NEXT_CACHE_UPDATE_EPOCH_KEY, later.millisecondsSinceEpoch); | |
setState(() { | |
_nextUpdate = new DateTime.fromMicrosecondsSinceEpoch( | |
later.millisecondsSinceEpoch * 1000); | |
_lastUpdate = new DateTime.now(); | |
}); | |
await prefs.commit(); | |
} | |
catch (exception) { | |
debugPrint(exception); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment