added functional star button on feed item

This commit is contained in:
Hauke Schade 2012-11-23 22:55:43 +01:00
parent 3d05cd7359
commit aff8932303
2 changed files with 88 additions and 1 deletions

View file

@ -21,6 +21,7 @@ Page {
property string pageTitle: ""
property string url: ""
property bool loading: false
property bool starloading: false
property bool marked: false
anchors.margins: 0
@ -61,6 +62,7 @@ Page {
itemView.html = data.content;
url = data.link
pageTitle = data.title
marked = data.marked
}
}
@ -72,6 +74,16 @@ Page {
showFeedItem();
}
function markedCallback() {
var ttrss = rootWindow.getTTRSS()
var data = ttrss.getFeedItem(feedId, articleId);
starloading = false
if (data)
marked = data.marked
}
PageHeader {
id: pageHeader
text: pageTitle
@ -81,7 +93,19 @@ Page {
id: itemTools
ToolIcon { iconId: "toolbar-back"; onClicked: { itemMenu.close(); pageStack.pop(); } }
ToolIcon { iconId: "toolbar-favorite-"+(marked?"":"un")+"mark"; onClicked: { marked = !marked } }
BusyIndicator {
visible: starloading
running: starloading
platformStyle: BusyIndicatorStyle { size: 'medium' }
}
ToolIcon {
iconId: "toolbar-favorite-"+(marked?"":"un")+"mark";
visible: !starloading
onClicked: {
starloading = true
var ttrss = rootWindow.getTTRSS()
ttrss.updateFeedStar(feedId, articleId, !marked, markedCallback)
} }
ToolIcon { iconId: "toolbar-share"; onClicked: { } }
BusyIndicator {

View file

@ -30,6 +30,7 @@ var state={
'feeditems': {},
'lastcategory': { 'id': null },
'lastfeed': { 'id': null, 'continuation': 0 },
'lastfeeditem': { 'feedId': null, 'articleId': null },
};
var requestsPending={
@ -37,6 +38,7 @@ var requestsPending={
'categories' : false,
'feeds' : false,
'feeditems' : false,
'feeditemstar': false,
};
var responsesPending={
@ -44,6 +46,7 @@ var responsesPending={
'categories' : false,
'feeds' : false,
'feeditems' : false,
'feeditemstar': false,
};
var constants={
@ -423,10 +426,70 @@ function processPendingRequests(callback) {
else
updateFeedItems(state['lastfeed']['id'], callback);
}
else if (requestsPending['feeditemstar']) {
trace(4, 'feeditemstar request pending');
foundWork = true;
if(responsesPending['feeditemstar'])
return foundWork;
if(!state['token'])
//Get the auth token
login(callback);
else
updateFeedStar(state['lastfeeditem']['feedId'],
state['lastfeeditem']['articleId'],
state['lastfeeditem']['value'],
callback);
}
return foundWork;
}
function updateFeedStar(feedId, articleId, starred, callback) {
if(responsesPending['feeditemstar'])
return;
if (state['lastfeeditem']['feedId'] !== feedId || state['lastfeeditem']['articleId'] !== articleId) {
state['lastfeeditem']['feedId'] = feedId;
state['lastfeeditem']['articleId'] = articleId;
state['lastfeeditem']['value'] = starred;
}
// needs to be logged in
if(!state['token']) {
requestsPending['feeditemstar'] = true;
processPendingRequests(callback);
return;
}
responsesPending['feeditemstar'] = true;
var params = {
'op': 'updateArticle',
'sid': state['token'],
'article_ids': articleId,
'field': 0,
'mode': (starred ? 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].marked = starred;
responsesPending['feeditemstar'] = 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'];