forked from lubuwest/Friendiqa
Version 0.003
This commit is contained in:
parent
9f9a9f618c
commit
10dccdcdbb
572 changed files with 3711 additions and 13631 deletions
362
source-android/qml/newsqml/NewsTab.qml
Normal file
362
source-android/qml/newsqml/NewsTab.qml
Normal file
|
@ -0,0 +1,362 @@
|
|||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.2
|
||||
import "qrc:/qml/genericqml"
|
||||
import "qrc:/js/news.js" as Newsjs
|
||||
import "qrc:/js/helper.js" as Helperjs
|
||||
import "qrc:/js/service.js" as Service
|
||||
|
||||
Item {
|
||||
Connections{
|
||||
target:newstab
|
||||
onNewstabstatusChanged:{
|
||||
newstabstatusButton.text= qsTr(newstab.newstabstatus)
|
||||
}
|
||||
}
|
||||
|
||||
Connections{
|
||||
target:newstab
|
||||
onConversationChanged:{
|
||||
newsBusy.running=false;
|
||||
newstab.newstabstatus="Conversation";
|
||||
//newsStack.push({item:"qrc:/qml/newsqml/Conversation.qml",properties:{"news": conversation}})
|
||||
showNews(conversation);
|
||||
}
|
||||
}
|
||||
|
||||
Connections{
|
||||
target:root
|
||||
onCurrentContactChanged:{
|
||||
if (root.newContacts.length>0){
|
||||
if(root.currentContact<root.newContacts.length){
|
||||
downloadNotice.text= qsTr("Download profile image for ")+ root.newContacts[root.currentContact].name;
|
||||
print(root.newContacts[root.currentContact].name)
|
||||
}
|
||||
}else{downloadNotice.text=""}
|
||||
}
|
||||
}
|
||||
|
||||
Connections{
|
||||
target:xhr
|
||||
onError:{if (data=="contact"){downloadNotice.text=root.newContacts[root.currentContact].name+"... Error!"}}
|
||||
onSuccess:{replytimer.start() //wait 1 second to load new timeline
|
||||
}
|
||||
}
|
||||
|
||||
Timer {id:replytimer; interval: 1000; running: false; repeat: false
|
||||
onTriggered: {if(newstab.newstabstatus=="Conversation"){
|
||||
showConversation(newsStack.timelineIndex-1,newsModel.get(0).newsitemobject)} else{
|
||||
var onlynew=true;
|
||||
Newsjs.getFriendsTimeline(login,db,contactlist,onlynew,newstab,function(rns,rnc){
|
||||
root.contactLoadType="news";
|
||||
root.news=rns;root.newContacts=rnc;root.currentContact=0})
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
function showNews(newsToShow){
|
||||
try{if (newsStack.depth>1){newsStack.pop()}}catch(e){}
|
||||
newsBusy.running=false;
|
||||
var currentTime= new Date();
|
||||
downloadNotice.text="";
|
||||
var msg = {'currentTime': currentTime, 'model': newsModel,'news':newsToShow};
|
||||
newsWorker.sendMessage(msg);
|
||||
}
|
||||
|
||||
function showConversation(timelineIndex,newsitemobject){
|
||||
|
||||
newsBusy.running=true;
|
||||
root.contactLoadType="conversation";
|
||||
newsStack.timelineIndex= timelineIndex;
|
||||
if(newsitemobject.messagetype==0){
|
||||
Newsjs.requestConversation(root.login,db,newsitemobject.status_id,root.contactlist,root,function(ns,nc){
|
||||
root.news=ns;root.newContacts=nc;root.currentContact=0;
|
||||
})}
|
||||
else{Newsjs.conversationfromdb(root.db,root.login.username,newsitemobject.statusnet_conversation_id, function(newsarray){
|
||||
root.news=newsarray;root.newContacts=[];root.currentContact=1;
|
||||
})}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function onFriendsMessages(friend){
|
||||
newstab.newstabstatus="Contact"
|
||||
Newsjs.newsfromdb(db,root.login.username, function(dbnews){showNews(dbnews)},friend)
|
||||
}
|
||||
|
||||
function onDirectMessage(friend){
|
||||
newstab.newstabstatus="SendMessage"
|
||||
newsStack.push({item:"qrc:/qml/newsqml/MessageSend.qml",properties:{"reply_to_user": friend,"directmessage":1,"login":root.login}});
|
||||
}
|
||||
|
||||
StackView{
|
||||
id: newsStack
|
||||
anchors.fill:parent
|
||||
property int timelineIndex: 0
|
||||
onTimelineIndexChanged:print("timelineindex:"+ timelineIndex)
|
||||
|
||||
initialItem:Rectangle {
|
||||
y:1
|
||||
color: "white"
|
||||
width:root.width-2*mm
|
||||
height:root.height-8*mm
|
||||
|
||||
BlueButton{
|
||||
id:newstabstatusButton
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 0.5*mm
|
||||
text: qsTr(newstab.newstabstatus)
|
||||
onClicked: {newstabmenu.popup()}
|
||||
}
|
||||
|
||||
Row{
|
||||
spacing: mm
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 0.5*mm
|
||||
anchors.right: parent.right
|
||||
|
||||
BlueButton {
|
||||
id: newMessageButton
|
||||
width:10*mm
|
||||
text: "\uf040"
|
||||
onClicked: {
|
||||
var groups=[];
|
||||
Helperjs.readData(root.db,"groups",root.login.username,function(groupobject){
|
||||
groups=groupobject});
|
||||
newstab.newstabstatus="SendMessage";
|
||||
Helperjs.readData(root.db,"contacts",root.login.username,function(friends){
|
||||
newsStack.push({item:"qrc:/qml/newsqml/MessageSend.qml",properties:{"contacts": friends,"login":root.login}})
|
||||
},"isFriend",1);
|
||||
}
|
||||
}
|
||||
BlueButton {
|
||||
id: quitButton
|
||||
width:10*mm
|
||||
text: "\uf08b"
|
||||
onClicked: {Service.cleanNews(root.db,function(){Qt.quit() })}
|
||||
}
|
||||
BlueButton {
|
||||
id: update
|
||||
text: "\uf021"
|
||||
onClicked: {
|
||||
newsBusy.running=true;
|
||||
newstab.newstabstatus=login.newsViewType;
|
||||
root.contactLoadType="news";
|
||||
var onlynew=true;
|
||||
Newsjs.getFriendsTimeline(login,db,contactlist,onlynew,newstab,function(ns,nc){
|
||||
root.news=ns;root.newContacts=nc;root.currentContact=0;
|
||||
if (ns.length==0){// update last 20 existing news for changes and likes
|
||||
onlynew=false;
|
||||
Newsjs.getFriendsTimeline(login,db,contactlist,onlynew,newstab,function(rns,rnc){
|
||||
root.contactLoadType="news";
|
||||
root.news=rns;root.newContacts=rnc;root.currentContact=0})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Component { id:footerComponent
|
||||
Rectangle{
|
||||
border.color: "#EEEEEE"
|
||||
border.width: 1
|
||||
width:newsView.width
|
||||
height:6*mm
|
||||
Text{
|
||||
font.pixelSize: 1.5*mm
|
||||
anchors.centerIn: parent
|
||||
text:qsTr("More")
|
||||
}
|
||||
MouseArea{anchors.fill:parent
|
||||
onClicked:{
|
||||
var currentTime= new Date();
|
||||
if(newstab.newstabstatus=="Timeline"){
|
||||
var lastnews_id=newsModel.get(newsModel.count-1).newsitemobject.created_at;
|
||||
Newsjs.newsfromdb(root.db,root.login.username, function(news){
|
||||
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true};
|
||||
newsWorker.sendMessage(msg);
|
||||
},false,lastnews_id)}
|
||||
if(newstab.newstabstatus=="Tree"){
|
||||
var lastnews_id=newsModel.get(newsModel.count-1).newsitemobject.created_at;
|
||||
Newsjs.chatsfromdb(root.db,root.login.username, function(news){
|
||||
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true};
|
||||
newsWorker.sendMessage(msg);
|
||||
},lastnews_id)}
|
||||
else if(newstab.newstabstatus=="Contact"){
|
||||
Newsjs.newsfromdb(root.db,root.login.username, function(news){
|
||||
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true};
|
||||
newsWorker.sendMessage(msg);
|
||||
},newsModel.get(newsModel.count-1).newsitemobject.uid,newsModel.get(newsModel.count-1).newsitemobject.created_at)}
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
Component { id:footerReply
|
||||
Rectangle{
|
||||
border.color: "#EEEEEE"
|
||||
border.width: 1
|
||||
color:"lightgrey"
|
||||
width:newsView.width
|
||||
height:Math.max(replyText.contentHeight+2*mm,6*mm)
|
||||
Rectangle{
|
||||
color: "white"
|
||||
radius:0.5*mm
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin:mm
|
||||
anchors.top:parent.top
|
||||
anchors.topMargin: 0.5*mm
|
||||
width:parent.width-12*mm
|
||||
height:Math.max( replyText.contentHeight,5*mm)
|
||||
|
||||
TextInput {
|
||||
id: replyText
|
||||
font.pixelSize: 3*mm
|
||||
wrapMode: Text.Wrap
|
||||
//width: parent.width
|
||||
anchors.fill: parent
|
||||
selectByMouse: true
|
||||
}
|
||||
}
|
||||
|
||||
BlueButton {
|
||||
id: sendButton
|
||||
text: "\uf1d9"
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin:mm
|
||||
anchors.top:parent.top
|
||||
anchors.topMargin: 0.5*mm
|
||||
color:"white"
|
||||
onClicked: { try{
|
||||
var body=replyText.getText(0,replyText.length);
|
||||
newsBusy.running=true;
|
||||
replyText.text=""
|
||||
xhr.clearParams();
|
||||
xhr.setLogin(login.username+":"+Qt.atob(login.password));
|
||||
if (newsModel.get(0).newsitemobject.messagetype==0){
|
||||
xhr.setParam("source", "Friendiqa");
|
||||
xhr.url= login.server + "/api/statuses/update.json";
|
||||
xhr.setParam("status", body);
|
||||
xhr.setParam("in_reply_to_status_id", newsModel.get(newsModel.count-1).newsitemobject.status_id)}
|
||||
else {xhr.url= login.server + "/api/direct_messages/new.json";
|
||||
xhr.setParam("text", body);
|
||||
xhr.setParam("screen_name",newsModel.get(newsModel.count-1).newsitemobject.screen_name);
|
||||
xhr.setParam("replyto", newsModel.get(newsModel.count-1).newsitemobject.status_id)
|
||||
}
|
||||
xhr.post();
|
||||
//replyText.text=""
|
||||
} catch(e){Helperjs.showMessage("Error",e.toString(),root)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: newsView
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: 8*root.mm
|
||||
anchors.leftMargin: 3*root.mm; anchors.rightMargin: root.mm
|
||||
anchors.bottomMargin: 1*root.mm
|
||||
clip: true
|
||||
spacing: 0
|
||||
footer: (newstab.newstabstatus=="Conversation")?footerReply:footerComponent
|
||||
model: newsModel
|
||||
delegate: Newsitem{}
|
||||
Component.onCompleted: {//print(newstab.newstabstatus);
|
||||
if(newstab.newstabstatus!="Conversation"){
|
||||
positionViewAtIndex(newsStack.timelineIndex-1, ListView.Beginning)}
|
||||
else {positionViewAtBeginning();
|
||||
newsStack.timelineIndex=0
|
||||
}}
|
||||
}
|
||||
|
||||
ListModel{id: newsModel}
|
||||
|
||||
WorkerScript {
|
||||
id: newsWorker
|
||||
source: "qrc:/js/newsworker.js"
|
||||
}
|
||||
|
||||
BusyIndicator{
|
||||
id: newsBusy
|
||||
anchors.horizontalCenter: newsView.horizontalCenter
|
||||
anchors.top:newsView.top
|
||||
anchors.topMargin: 2*mm
|
||||
width:10*mm
|
||||
height: 10*mm
|
||||
}
|
||||
Rectangle{
|
||||
id:downloadNotice
|
||||
property alias text: noticeText.text
|
||||
color:"white"
|
||||
border.color:"grey"
|
||||
z:1
|
||||
anchors.horizontalCenter: newsView.horizontalCenter
|
||||
anchors.bottom:newsView.bottom
|
||||
anchors.bottomMargin: 2*mm
|
||||
width: noticeText.width+2*mm
|
||||
height: noticeText.height+2*mm
|
||||
visible: (downloadNotice.text!="")
|
||||
|
||||
Text{
|
||||
id:noticeText
|
||||
color: "grey"
|
||||
anchors.centerIn: parent
|
||||
width: contentWidth
|
||||
height: contentHeight
|
||||
font.pixelSize: 2*mm
|
||||
text:""
|
||||
}
|
||||
}
|
||||
Menu {
|
||||
id:newstabmenu
|
||||
MenuItem {
|
||||
text: qsTr("Timeline")
|
||||
onTriggered: {
|
||||
newstab.newstabstatus="Timeline";
|
||||
newsModel.clear();
|
||||
try{ Newsjs.newsfromdb(root.db,root.login.username, function(dbnews){
|
||||
showNews(dbnews)
|
||||
})}catch(e){Helperjs.showMessage("Error",e,root)}}
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Favorites")
|
||||
onTriggered:{
|
||||
newstab.newstabstatus="Favorites";
|
||||
root.contactLoadType="favorites";
|
||||
newsBusy.running=true;
|
||||
Newsjs.requestFavorites(root.login,db,root.contactlist,root,function(ns,nc){
|
||||
root.news=ns; root.newContacts=nc;root.currentContact=0;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
text: qsTr("Tree")
|
||||
onTriggered:{
|
||||
newsModel.clear();
|
||||
newstab.newstabstatus="Tree";
|
||||
Newsjs.chatsfromdb(db,root.login.username,function(news){showNews(news)})
|
||||
}
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Notifications")
|
||||
onTriggered:{
|
||||
newstab.newstabstatus="Notifications";
|
||||
newsBusy.running=true;
|
||||
Newsjs.getNotifications(root.login,db,root,function(news){
|
||||
showNews(news)}
|
||||
)}
|
||||
}
|
||||
}
|
||||
Component.onCompleted: {
|
||||
root.messageSignal.connect(onFriendsMessages);
|
||||
root.directmessageSignal.connect(onDirectMessage);
|
||||
root.newsSignal.connect(showNews);
|
||||
try{newsModel.clear()} catch(e){}
|
||||
newstab.newstabstatus=login.newsViewType;
|
||||
if(login.newsViewType=="Timeline"){Newsjs.newsfromdb(db,login.username,function(dbnews){showNews(dbnews)})}
|
||||
else{Newsjs.chatsfromdb(db,login.username,function(dbnews){showNews(dbnews)})}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue