use of chatty.util.api.StreamInfo in project chatty by chatty.
the class StreamHighlightHelper method addHighlight.
/**
* Adds a highlight for the given channel with the given comment.
*
* Thread-saftey: It should be safe to call this from several threads.
* Instance variables and writing to the file is synchronized on this.
*
* @param channel The channel to add the highlight for
* @param comment The comment to add (can be null or empty for no comment)
* @return A textual response to adding the highlight
*/
public String addHighlight(String channel, String comment) {
if (channel == null || channel.isEmpty() || !Helper.isRegularChannel(channel)) {
return "Failed adding stream highlight (no channel).";
}
// Get StreamInfo
StreamInfo streamInfo = api.getStreamInfo(Helper.toStream(channel), null);
String streamTime = "Stream Time N/A";
if (streamInfo.isValid() && streamInfo.getOnline()) {
streamTime = DateTime.ago(streamInfo.getTimeStarted());
}
if (comment == null) {
comment = "";
}
// Make the line to add to the file
String line = String.format("%s %s [%s] %s", DateTime.fullDateTime(), channel, streamTime, comment);
synchronized (this) {
// Add seperator if probably new stream
if (streamInfo.getTimeStarted() != lastStreamStartWritten) {
addToFile("-");
}
// Add to file and make textual response
boolean success = addToFile(line);
if (success) {
lastStreamStartWritten = streamInfo.getTimeStarted();
String shortComment = "";
if (!comment.isEmpty()) {
shortComment = "(" + StringUtil.shortenTo(comment, 30) + ")";
}
return "Added stream highlight for " + channel + " [" + streamTime + "] " + shortComment;
}
return "Failed adding stream highlight (write error).";
}
}
use of chatty.util.api.StreamInfo in project chatty by chatty.
the class LiveStreamsList method checkStreams.
/**
* Checks all added streams and removes invalid ones.
*/
private void checkStreams() {
if ((System.currentTimeMillis() - lastChecked) / 1000 < CHECK_DELAY) {
return;
}
lastChecked = System.currentTimeMillis();
Set<StreamInfo> toRemove = new HashSet<>();
for (StreamInfo info : data) {
if (!info.isValidEnough() || !info.getOnline()) {
toRemove.add(info);
}
}
// Remove invalid items
for (StreamInfo info : toRemove) {
data.remove(info);
itemRemoved(info);
}
// Update and inform only if items were actually removed
if (!toRemove.isEmpty()) {
listDataChanged();
}
}
Aggregations