added a toolbar button to mark a feed as (un)read

This commit is contained in:
Hauke Schade 2012-11-24 16:30:33 +01:00
parent aff8932303
commit 2b25f21dc8
2 changed files with 86 additions and 4 deletions

View file

@ -22,7 +22,9 @@ Page {
property string url: ""
property bool loading: false
property bool starloading: false
property bool unreadloading: false
property bool marked: false
property bool unread: true
anchors.margins: 0
@ -63,6 +65,7 @@ Page {
url = data.link
pageTitle = data.title
marked = data.marked
unread = data.unread
}
}
@ -84,6 +87,16 @@ Page {
marked = data.marked
}
function unreadCallback() {
var ttrss = rootWindow.getTTRSS()
var data = ttrss.getFeedItem(feedId, articleId);
unreadloading = false
if (data)
unread = data.unread
}
PageHeader {
id: pageHeader
text: pageTitle
@ -106,13 +119,19 @@ Page {
var ttrss = rootWindow.getTTRSS()
ttrss.updateFeedStar(feedId, articleId, !marked, markedCallback)
} }
ToolIcon { iconId: "toolbar-share"; onClicked: { } }
BusyIndicator {
visible: loading
running: loading
visible: unreadloading
running: unreadloading
platformStyle: BusyIndicatorStyle { size: 'medium' }
}
ToolIcon {
iconId: "toolbar-"+(unread?"share":"add");
visible: !unreadloading
onClicked: {
unreadloading = true
var ttrss = rootWindow.getTTRSS()
ttrss.updateFeedUnread(feedId, articleId, !unread, unreadCallback)
} }
ToolIcon { iconId: "toolbar-view-menu" ; onClicked: (itemMenu.status === DialogStatus.Closed) ? itemMenu.open() : itemMenu.close() }
}

View file

@ -31,6 +31,7 @@ var state={
'lastcategory': { 'id': null },
'lastfeed': { 'id': null, 'continuation': 0 },
'lastfeeditem': { 'feedId': null, 'articleId': null },
'lastfeeditemunread':{ 'feedId': null, 'articleId': null },
};
var requestsPending={
@ -39,6 +40,7 @@ var requestsPending={
'feeds' : false,
'feeditems' : false,
'feeditemstar': false,
'feeditemunread': false,
};
var responsesPending={
@ -47,6 +49,7 @@ var responsesPending={
'feeds' : false,
'feeditems' : false,
'feeditemstar': false,
'feeditemunread': false,
};
var constants={
@ -440,6 +443,20 @@ function processPendingRequests(callback) {
state['lastfeeditem']['value'],
callback);
}
else if (requestsPending['feeditemunread']) {
trace(4, 'feeditemunread request pending');
foundWork = true;
if(responsesPending['feeditemunread'])
return foundWork;
if(!state['token'])
//Get the auth token
login(callback);
else
updateFeedUnrad(state['lastfeeditemunread']['feedId'],
state['lastfeeditemunread']['articleId'],
state['lastfeeditemunread']['value'],
callback);
}
return foundWork;
}
@ -490,6 +507,52 @@ function updateFeedStar(feedId, articleId, starred, callback) {
http.send(JSON.stringify(params));
}
function updateFeedUnread(feedId, articleId, unread, callback) {
if(responsesPending['feeditemunread'])
return;
if (state['lastfeeditemunread']['feedId'] !== feedId || state['lastfeeditemunread']['articleId'] !== articleId) {
state['lastfeeditemunread']['feedId'] = feedId;
state['lastfeeditemunread']['articleId'] = articleId;
state['lastfeeditemunread']['value'] = unread;
}
// needs to be logged in
if(!state['token']) {
requestsPending['feeditemunread'] = true;
processPendingRequests(callback);
return;
}
responsesPending['feeditemunread'] = true;
var params = {
'op': 'updateArticle',
'sid': state['token'],
'article_ids': articleId,
'field': 2,
'mode': (unread ? 1 : 0)
}
var http = new XMLHttpRequest();
http.open("POST", state['url'], true);
http.setRequestHeader('Content-type','application/json; charset=utf-8');
http.onreadystatechange = function() {
if (http.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
trace(3, "Response Headers -->");
trace(3, http.getAllResponseHeaders());
}
else if (http.readyState === XMLHttpRequest.DONE) {
state['feeditems'][feedId][articleId].unread = unread;
responsesPending['feeditemunread'] = false;
if(!processPendingRequests(callback))
if(callback)
callback(0);
}
}
http.send(JSON.stringify(params));
}
//Indicates whether only unread items should be shown
function getShowAll() {
return state['showall'];