Friendiqa/source-android/qml/newsqml/Newsitem.qml

471 righe
18 KiB
QML

2018-02-19 22:36:00 +01:00
// This file is part of Friendiqa
2018-11-09 22:06:13 +01:00
// https://git.friendi.ca/lubuwest/Friendiqa
2018-02-19 22:36:00 +01:00
// Copyright (C) 2017 Marco R. <thomasschmidt45@gmx.net>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations including
// the two.
//
// You must obey the GNU General Public License in all respects for all
// of the code used other than OpenSSL. If you modify file(s) with this
// exception, you may extend this exception to your version of the
// file(s), but you are not obligated to do so. If you do not wish to do
// so, delete this exception statement from your version. If you delete
// this exception statement from all source files in the program, then
// also delete it here.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-01-26 21:55:31 +01:00
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import "qrc:/js/news.js" as Newsjs
2017-03-25 23:36:14 +01:00
import "qrc:/js/helper.js" as Helperjs
2018-04-11 21:50:43 +02:00
import "qrc:/qml/genericqml"
2017-01-26 21:55:31 +01:00
Item {
id: newsitem
2017-05-11 22:15:34 +02:00
width: parent.width
height:toprow.height+friendicaActivities.height+controlrow.height+1//Math.max((itemMessage.height+topFlow.height+friendicaActivities.height+4*mm),profileImage.height+user_name.height+mm)
2018-04-11 21:50:43 +02:00
property int itemindex: index
2017-05-11 22:15:34 +02:00
2017-01-26 21:55:31 +01:00
property string attending: ""
onAttendingChanged: {attendLabel.visible=true;
attendLabel.text= qsTr("attending: ")+ qsTr(attending)}
2017-01-26 21:55:31 +01:00
signal replyto(string parent_id)
2017-03-25 23:36:14 +01:00
function showActivityContacts(contacts){
var component = Qt.createComponent("qrc:/qml/newsqml/FriendicaActivities.qml");
var imagedialog = component.createObject(friendicaActivities,{"activitymembers": contacts});
}
2018-07-01 15:09:21 +02:00
function findTags(fulltext){
return fulltext.match(/\s+[#]+[A-Za-z0-9-_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]+/g)
}
2017-01-26 21:55:31 +01:00
Rectangle{width:newsitem.width; height: 1; anchors.bottom: newsitem.bottom; color:"light grey"}
2017-01-26 21:55:31 +01:00
Rectangle{
width:newsitem.width
height:newsitem.height-1
color: (newsitemobject.messagetype==1)?"#ffe6e6" : "white"
2017-05-11 22:15:34 +02:00
Row{id:toprow
Column {
2017-01-26 21:55:31 +01:00
id: authorcolumn
width: 8*mm
Image {
id:profileImage
2018-02-19 22:36:00 +01:00
source: ((newsitemobject.user.profile_image!="") && (typeof(newsitemobject.user.profile_image)=="string"))? "file://"+newsitemobject.user.profile_image : newsitemobject.user.profile_image_url
2017-01-26 21:55:31 +01:00
x:1
width: 7*mm
height: 7*mm
MouseArea{
anchors.fill: parent
2018-07-01 15:09:21 +02:00
onClicked:{
showContact(newsitemobject.user)}
2017-01-26 21:55:31 +01:00
}
onStatusChanged: if (profileImage.status == Image.Error) {source="qrc:/images/defaultcontact.jpg"}
2017-01-26 21:55:31 +01:00
}
Label {
id:user_name
color: "grey"
width:parent.width
font.pixelSize: 1.5*mm
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
2018-07-01 15:09:21 +02:00
text: newsitemobject.user.name+forumname
2017-01-26 21:55:31 +01:00
}
}
Column {
id:newscolumn
width: newsitem.width-8*mm
Flow{
id:topFlow
spacing: mm
width:parent.width
Label {
id:messageTypeLabel
color: "grey"
text: if (newsitemobject.messagetype==0){qsTr("Source: ")+newsitemobject.source
} else if (newsitemobject.messagetype==1){ qsTr("Direct Message")} else {" Notification"}
font.pixelSize: 1.5*mm
}
Label {
id:createdAtLabel
color: "grey"
font.pixelSize: 1.5*mm
horizontalAlignment: Label.AlignRight
text: dateDiff
}
Label {
id:replytoLabel
color: "grey"
font.pixelSize: 1.5*mm
horizontalAlignment: Label.AlignRight
text: try {qsTr("In reply to ")+newsitemobject.reply_user.screen_name
}catch(e){" "}
}
Label {
id:newscountLabel
2017-05-11 22:15:34 +02:00
visible:((newstabstatus=="Conversations")&&(newsitemobject.newscount>1))?true:false
2017-01-26 21:55:31 +01:00
color: "grey"
height:3.5*mm
font.pixelSize: 1.5*mm
font.bold: true
horizontalAlignment: Label.AlignRight
text: try {(newsitemobject.newscount-1)+qsTr(" comments") }catch(e){" "}
MouseArea{
anchors.fill:parent
2017-11-07 21:57:40 +01:00
onClicked: {
2018-11-09 22:06:13 +01:00
newsStack.push("qrc:/qml/newsqml/Conversation.qml");
showConversation(index,newsitemobject)
2017-11-07 21:57:40 +01:00
}
2017-01-26 21:55:31 +01:00
}
}
}
2018-07-20 21:15:54 +02:00
Column{ id: messageColumn
//anchors.top:topFlow.bottom
width:parent.width
spacing:mm
clip:true
height: Math.min(implicitHeight,3/4*root.height)
MouseArea{
width: newsitem.width-8*mm-2
height: itemMessage.height
onPressAndHold: {
newsStack.push("qrc:/qml/newsqml/Conversation.qml");
showConversation(index,newsitemobject)
}
Text {
2017-01-26 21:55:31 +01:00
color: "#404040"
linkColor: "light green"
id: itemMessage
textFormat: Text.RichText
2018-08-25 16:17:09 +02:00
text: newsitemobject.statusnet_html//newsitemobject.attachmentList.length>0?newsitemobject.text : newsitemobject.statusnet_html
2017-01-26 21:55:31 +01:00
width: newsitem.width-8*mm-2
2018-07-20 21:15:54 +02:00
height: implicitHeight
2017-01-26 21:55:31 +01:00
wrapMode: Text.Wrap
2018-04-11 21:50:43 +02:00
clip:true
2018-07-20 21:15:54 +02:00
//MouseArea{anchors.fill:parent;onClicked: print("Test")}
2017-01-26 21:55:31 +01:00
onLinkActivated:{
Qt.openUrlExternally(link)}
2017-05-11 22:15:34 +02:00
Component.onCompleted:{
2018-07-01 15:09:21 +02:00
if (newsitemobject.messagetype==0){
var hashtags=[];
hashtags=findTags(newsitemobject.text);
var component = Qt.createComponent("qrc:/qml/newsqml/Hashtag.qml");
for (var tags in hashtags){
var hashtagQml = component.createObject(friendicaActivities,{"text":hashtags[tags].trim()});
}}
2017-05-11 22:15:34 +02:00
if (newsitemobject.attachmentList.length>0){
2018-08-25 16:17:09 +02:00
2017-05-11 22:15:34 +02:00
for(var attachments in newsitemobject.attachmentList){// (newsitemobject.attachmentList[attachments].url);
2018-08-25 16:17:09 +02:00
if(newsitemobject.attachmentList[attachments].mimetype.substring(0,5)=="image"){
var component = Qt.createComponent("qrc:/qml/newsqml/NewsImage.qml");
var imageQml = component.createObject(messageColumn,{"source":newsitemobject.attachmentList[attachments].url,"mimetype":newsitemobject.attachmentList[attachments].mimetype});
2018-11-09 22:06:13 +01:00
}
2019-01-09 22:03:16 +01:00
else if(newsitemobject.attachmentList[attachments].mimetype=="text/html"){
var component = Qt.createComponent("qrc:/qml/newsqml/NewsLink.qml");
var linkQml = component.createObject(messageColumn,{"url":newsitemobject.attachmentList[attachments].url});
}
2018-11-09 22:06:13 +01:00
else {//print(newsitemobject.attachmentList[attachments].url+" Type: "+newsitemobject.attachmentList[attachments].mimetype)
2018-08-25 16:17:09 +02:00
var component = Qt.createComponent("qrc:/qml/newsqml/NewsVideo.qml");
var videoQml = component.createObject(messageColumn,{"source":newsitemobject.attachmentList[attachments].url,"mimetype":newsitemobject.attachmentList[attachments].mimetype});
}
}
2017-05-11 22:15:34 +02:00
}
}
2018-07-20 21:15:54 +02:00
}}
}
BlueButton{
width: newsitem.width-8*mm-2
height:5*mm
//anchors.bottom: messageColumn.bottom//itemMessage.bottom
visible: messageColumn.implicitHeight>3/4*root.height//itemMessage.implicitHeight>3/4*root.height
text:"\uf078"
fontColor:"grey"
border.color: "transparent"
color:"white"
// gradient: Gradient {
// GradientStop { position: 0.0; color: "transparent" }
// GradientStop { position: 0.5; color: "white" }
// }
radius:0
onClicked: {
if (text=="\uf078"){
messageColumn.height=messageColumn.implicitHeight+10*mm;text="\uf077"
} else {
messageColumn.height=Math.min(messageColumn.implicitHeight,3/4*root.height);
text="\uf078";
newsView.positionViewAtIndex(index,ListView.Beginning);
}
}
}
2017-05-11 22:15:34 +02:00
}
}
Flow{
id:friendicaActivities
2017-05-11 22:15:34 +02:00
anchors.top:toprow.bottom
2017-03-25 23:36:14 +01:00
width:parent.width
2017-01-26 21:55:31 +01:00
spacing:mm
2017-05-11 22:15:34 +02:00
2017-01-26 21:55:31 +01:00
Label{color: "grey"
2017-11-07 21:57:40 +01:00
height:3.5*mm
2017-01-26 21:55:31 +01:00
font.pixelSize: 1.5*mm
text: friendica_activities.likeText
2017-03-25 23:36:14 +01:00
MouseArea{
anchors.fill: parent
2018-07-01 15:09:21 +02:00
onClicked: { showActivityContacts(newsitemobject.friendica_activities.like)}
2017-03-25 23:36:14 +01:00
}
}
2017-01-26 21:55:31 +01:00
Label{color: "grey"
2017-11-07 21:57:40 +01:00
height:3.5*mm
2017-01-26 21:55:31 +01:00
font.pixelSize: 1.5*mm
text: friendica_activities.dislikeText
2017-03-25 23:36:14 +01:00
MouseArea{
anchors.fill: parent
2018-07-01 15:09:21 +02:00
onClicked: { showActivityContacts(newsitemobject.friendica_activities.dislike)}
2017-03-25 23:36:14 +01:00
}
}
2017-01-26 21:55:31 +01:00
Label{color: "grey"
2017-11-07 21:57:40 +01:00
height:3.5*mm
2017-01-26 21:55:31 +01:00
font.pixelSize: 1.5*mm
text: friendica_activities.attendyesText
2017-03-25 23:36:14 +01:00
MouseArea{
anchors.fill: parent
2018-07-01 15:09:21 +02:00
onClicked: { showActivityContacts(newsitemobject.friendica_activities.attendyes)}
2017-03-25 23:36:14 +01:00
}}
2017-01-26 21:55:31 +01:00
Label{color: "grey"
2017-11-07 21:57:40 +01:00
height:3.5*mm
2017-01-26 21:55:31 +01:00
font.pixelSize: 1.5*mm
text: friendica_activities.attendnoText
2017-03-25 23:36:14 +01:00
MouseArea{
anchors.fill: parent
2018-07-01 15:09:21 +02:00
onClicked: { showActivityContacts(newsitemobject.friendica_activities.attendno)}
2017-03-25 23:36:14 +01:00
}
}
2017-01-26 21:55:31 +01:00
Label{color: "grey"
2017-11-07 21:57:40 +01:00
height:3.5*mm
2017-01-26 21:55:31 +01:00
font.pixelSize: 1.5*mm
text: friendica_activities.attendmaybeText
2017-03-25 23:36:14 +01:00
MouseArea{
anchors.fill: parent
2018-07-01 15:09:21 +02:00
onClicked: { showActivityContacts(newsitemobject.friendica_activities.attendmaybe)}
2017-03-25 23:36:14 +01:00
}
2017-01-26 21:55:31 +01:00
}
2017-05-11 22:15:34 +02:00
Label{
id:attendLabel
color: "grey"
height:3.5*mm
font.pixelSize: 1.5*mm
horizontalAlignment: Label.AlignRight
text: (friendica_activities.self.attending)?(qsTr("Attending: ")+ qsTr(friendica_activities.self.attending)):""
}
2017-03-25 23:36:14 +01:00
}
2017-05-11 22:15:34 +02:00
Row{id:controlrow
anchors.top:friendicaActivities.bottom
CheckBox{
id:likeCheckbox
2017-11-07 21:57:40 +01:00
width:10*mm
visible: (newsitemobject.messagetype==0)? true:false
checked:(friendica_activities.self.liked==1)?true:false
style: CheckBoxStyle {
2017-11-07 21:57:40 +01:00
indicator: Rectangle{
implicitWidth: 10*mm
implicitHeight:3*mm
Text{
anchors.centerIn: parent
font.pixelSize: 2.5*mm
font.family:fontAwesome.name
color:control.checked?"black": "grey"
2018-10-01 21:17:54 +02:00
text:control.checked?"\uf118"+"!":"\uf118"
2017-11-07 21:57:40 +01:00
}
}
}
onClicked: {
2018-07-01 15:09:21 +02:00
if(likeCheckbox.checked==true){Newsjs.like(root.login,root.db,1,"like",newsitemobject.id,root);dislikeCheckbox.checked=false; model.friendica_activities.self.liked=0 }
else{Newsjs.like(root.login,root.db,0,"like",newsitemobject.id,root); model.friendica_activities.self.liked=1}}
}
CheckBox{
id: dislikeCheckbox
2017-11-07 21:57:40 +01:00
width:10*mm
visible: (newsitemobject.messagetype==0)? true:false
checked: (friendica_activities.self.disliked==1)?true:false
style: CheckBoxStyle {
indicator: Rectangle{
2017-11-07 21:57:40 +01:00
implicitWidth: 10*mm
implicitHeight:3*mm
Text{
2017-01-29 17:57:55 +01:00
anchors.centerIn: parent
2017-03-25 23:36:14 +01:00
font.pixelSize: 2.5*mm
font.family:fontAwesome.name
color:control.checked?"black": "grey"
2018-10-01 21:17:54 +02:00
text: control.checked?"\uf119"+"!":"\uf119"
2017-11-07 21:57:40 +01:00
}
2017-01-26 21:55:31 +01:00
}
2017-11-07 21:57:40 +01:00
}
onClicked: {
2018-07-01 15:09:21 +02:00
if (dislikeCheckbox.checked==true){Newsjs.like(root.login,root.db,1,"dislike",newsitemobject.id,root);likeCheckbox.checked=false; model.friendica_activities.self.disliked=0}
else {Newsjs.like(root.login,root.db,0,"dislike",newsitemobject.id,root); model.friendica_activities.self.disliked=1}}
}
2017-05-11 22:15:34 +02:00
CheckBox {
id:favoritedCheckbox
visible:(newsitemobject.messagetype==0)
2017-11-07 21:57:40 +01:00
width: 10*mm
style: CheckBoxStyle {
2017-11-07 21:57:40 +01:00
indicator:Rectangle{
x:4*mm
width: 3*mm
implicitHeight:4*mm
Text{
color: control.checked?"black":"grey"
font.pixelSize: 2.5*mm
text:"\uf005"
}
}
2017-11-07 21:57:40 +01:00
}
checked:(newsitemobject.favorited>0)
onClicked:{
if(favoritedCheckbox.checkedState==Qt.Checked){
2018-07-01 15:09:21 +02:00
Newsjs.favorite(login,true,newsitemobject.id,root); model.newsitemobject.favorited=1}
else if(favoritedCheckbox.checkedState==Qt.Unchecked){
2018-07-01 15:09:21 +02:00
Newsjs.favorite(login,false,newsitemobject.id,root);model.newsitemobject.favorited=0}
}
}
Rectangle{
2017-11-07 21:57:40 +01:00
width: 10*mm
height: 4*mm
2018-07-01 15:09:21 +02:00
visible:(newsitemobject.messagetype!==2)
color:"transparent"
Text{
id:newsmenusymbol
color: "grey"
anchors.centerIn: parent
2018-07-01 15:09:21 +02:00
font.pixelSize: 2.5*mm
font.family:fontAwesome.name
text: "\uf142"
2017-01-26 21:55:31 +01:00
}
MouseArea{
2017-01-26 21:55:31 +01:00
anchors.fill:parent
onClicked: {newsmenu.popup()}}
}
Rectangle{
2017-11-07 21:57:40 +01:00
width: 10*mm
height: 4*mm
2018-07-01 15:09:21 +02:00
visible:(newsitemobject.messagetype!==2)&&(newstab.newstabstatus!="Conversation")
color:"transparent"
Text{
id:conversationsymbol
color: "grey"
anchors.centerIn: parent
2017-03-25 23:36:14 +01:00
font.pixelSize: 2.5*mm
font.family: fontAwesome.name
text: "\uf086"
}
MouseArea{
2017-01-26 21:55:31 +01:00
anchors.fill:parent
2017-05-11 22:15:34 +02:00
onClicked:{
2018-07-20 21:15:54 +02:00
//conversationsymbol.color="black";
// var component = Qt.createComponent("qrc:/qml/newsqml/Conversation.qml");
// var conversationItem = component.createObject(friendicaActivities);
newsStack.push("qrc:/qml/newsqml/Conversation.qml")
showConversation(index,newsitemobject)
2017-05-11 22:15:34 +02:00
}
2017-01-26 21:55:31 +01:00
}
}
2017-05-11 22:15:34 +02:00
2017-01-26 21:55:31 +01:00
}
2017-05-11 22:15:34 +02:00
2017-01-26 21:55:31 +01:00
Menu {
id:newsmenu
MenuItem {
text: qsTr("Reply")
onTriggered: {
var directmessage=0;
if (newsitemobject.messagetype==1){ directmessage=1}
2018-07-20 21:15:54 +02:00
newsStack.push("qrc:/qml/newsqml/MessageSend.qml",{"reply_to_user": newsitemobject.user.screen_name,"parentId":newsitemobject.id,"login":root.login,"directmessage":directmessage});
}
2017-01-26 21:55:31 +01:00
}
MenuItem {
text: qsTr("DM")
onTriggered: {
root.directmessageSignal(newsitemobject.user.screen_name);
}
2017-01-26 21:55:31 +01:00
}
MenuItem {
text: qsTr("Repost")
onTriggered: {
2018-07-01 15:09:21 +02:00
Newsjs.retweetNews(root.login,db,newsitemobject.id,root,function(reply){
2017-11-07 21:57:40 +01:00
Helperjs.showMessage("Repost",qsTr("Success!"),root)
})
}
}
MenuItem {
text: qsTr("Conversation")
2017-11-07 21:57:40 +01:00
onTriggered: {
conversationsymbol.color="black";
var component = Qt.createComponent("qrc:/qml/newsqml/Conversation.qml");
var conversationItem = component.createObject(friendicaActivities,{"news":newsitemobject.chatArray});
showConversation(index,newsitemobject)
}
2017-01-26 21:55:31 +01:00
}
Menu{
title: qsTr("Attending")
MenuItem{
text:qsTr("yes")
2018-07-01 15:09:21 +02:00
onTriggered: {Newsjs.attend(root.login,db,"yes",newsitemobject.id,root,function(){
model.friendica_activities.self.attending="yes";attending="yes"})
2017-01-26 21:55:31 +01:00
}
}
MenuItem{text:qsTr("maybe")
2018-07-01 15:09:21 +02:00
onTriggered: {Newsjs.attend(root.login,db,"maybe",newsitemobject.id,root,function(){
model.friendica_activities.self.attending="maybe";attending="maybe"})
}
}
MenuItem{text:qsTr("no")
2018-07-01 15:09:21 +02:00
onTriggered: {Newsjs.attend(root.login,db,"no",newsitemobject.id,root,function(){
model.friendica_activities.self.attending="no";attending="no"})}
2017-01-26 21:55:31 +01:00
}
}
MenuItem {
text: qsTr("Delete")
onTriggered: {
2018-07-01 15:09:21 +02:00
Newsjs.deleteNews(root.login,root.db,newsitemobject.id,newsitemobject.messagetype,root,function(reply){
2017-11-07 21:57:40 +01:00
var msg = {'deleteId': index, 'model': newsModel};
newsWorker.sendMessage(msg);
})
}
2017-01-26 21:55:31 +01:00
}
2018-11-09 22:06:13 +01:00
2017-11-07 21:57:40 +01:00
//MenuItem{
// text:qsTr("Show on website")
// onTriggered:Qt.openUrlExternally(login.server+"/display/"+newsitemobject
//}
2017-01-26 21:55:31 +01:00
}
2017-05-11 22:15:34 +02:00
}}