Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createCommentForCommentsV2(wall_post, wallType, endpoint, table) {
- var that = {};
- var windowOpen = Ti.UI.createAnimation({
- duration : 150,
- left : 0
- });
- var containerViewWidth = 300;
- var viewHeight = 30;
- if (Ti.Platform.osname === 'ipad') {
- if (wallType != null) {
- if (wallType === "iPadCommentsViewer") {
- containerViewWidth = Ti.Platform.displayCaps.platformWidth - 320;
- viewHeight = 50;
- } else
- containerViewWidth = Ti.Platform.displayCaps.platformWidth - 20;
- } else
- containerViewWidth = Ti.Platform.displayCaps.platformWidth - 20;
- }
- var containerView = Ti.UI.createView({
- width : containerViewWidth,
- // top : 5,
- height : 100,
- backgroundColor : "white"
- });
- var profilePicImageViewHolder = Titanium.UI.createView({
- width : 30,
- height : 30,
- zIndex : 1000,
- left : 2,
- top : 2,
- borderColor : "#dedede",
- borderWidth : 1
- });
- var profilePicImageView = Titanium.UI.createImageView({
- // width:50,
- // height:50
- });
- profilePicImageViewHolder.add(profilePicImageView);
- cachedImageView('cachedImages_CommentsViewer', wall_post.user.avatar.thumb, profilePicImageView);
- containerView.add(profilePicImageViewHolder);
- profilePicImageView.addEventListener('singletap', function(e) {
- var userProfileWindow = new UserProfileWindow(wall_post.user.veramiko_id);
- userProfileWindow.left = Titanium.Platform.displayCaps.platformWidth;
- userProfileWindow.open(windowOpen);
- });
- var usernameLabel = Titanium.UI.createLabel({
- text : wall_post.user.name,
- font : {
- fontSize : 15,
- fontWeight : 'bold'
- },
- height : 14,
- left : 35,
- right : 65,
- top : 9,
- });
- usernameLabel.addEventListener('singletap', function(e) {
- var userProfileWindow = new UserProfileWindow(wall_post.user.veramiko_id);
- userProfileWindow.left = Titanium.Platform.displayCaps.platformWidth;
- userProfileWindow.open(windowOpen);
- });
- containerView.add(usernameLabel);
- if (wall_post.created_at != null)
- var created_at = dateFormatter(wall_post.created_at);
- var dateLabel = Titanium.UI.createLabel({
- text : created_at,
- color : "#888888",
- font : {
- fontSize : 10
- },
- top : 2,
- right : 5,
- });
- containerView.add(dateLabel);
- var extraSpace = 31;
- if(Ti.Platform.osname === 'ipad')
- {
- extraSpace = 62;
- }
- var wallPostCommentTrimmed;
- if(typeof wall_post.comment !== 'undefined')
- {
- wallPostCommentTrimmed = wall_post.comment.replace(/[\n\r]/g, ' ');
- // Ti.API.info('wallpost ' + wallPostCommentTrimmed);
- }
- else if(typeof wall_post.secondary_target.comment !== 'undefined')
- {
- wallPostCommentTrimmed = wall_post.secondary_target.comment.replace(/[\n\r]/g, ' ');
- // Ti.API.info('ex wallpost ' + wallPostCommentTrimmed);
- // extraSpace = 60;
- }
- else if(typeof wall_post.secondary_target.description !== 'undefined')
- {
- wallPostCommentTrimmed = wall_post.secondary_target.description.replace(/[\n\r]/g, ' ');
- }
- // Ti.API.info('length ' + wallPostCommentTrimmed.length);
- // if(wallPostCommentTrimmed > )
- containerView.applyProperties({
- height : extraSpace + calculateCommentContentViewHeight(wallPostCommentTrimmed)
- });
- var postContent = Titanium.UI.createLabel({
- text : wallPostCommentTrimmed,
- font : {
- fontSize : 12
- },
- height : "auto",
- color : "#3f3f3f",
- top : 35,
- left : 10,
- bottom : 22
- });
- containerView.add(postContent);
- //***************************
- // LIKE, NO LIKE Layout
- var likesLabel = Ti.UI.createLabel({
- text : wall_post.like_counter_cache + ' ' + L('like_string'),
- font : {
- fontSize : 10
- },
- color : '#333333',
- width : (containerViewWidth - 170) / 2,
- height : '100%',
- textAlign : 'left',
- right : 25
- });
- var likeness = wall_post.likeness;
- var dislikesLabel = Ti.UI.createLabel({
- text : wall_post.dislike_counter_cache + ' ' + L('dislike_string'),
- font : {
- fontSize : 10
- },
- color : '#333333',
- width : (containerViewWidth - 170) / 2,
- height : '100%',
- textAlign : 'right',
- left : 25
- });
- var separatorLabel = Ti.UI.createLabel({
- text : ' · ',
- font : {
- fontSize : 20,
- fontWieght : 'bold'
- },
- color : '#333333',
- height : '100%',
- width : 20,
- textAlign : 'center'
- // left : 10,
- // right : 10
- });
- var like_msg_str = '';
- var dislike_msg_str = '';
- if(wall_post.like_counter_cache > 0)
- {
- like_msg_str = String.format(L('you_like_string'), wall_post.like_counter_cache);
- }
- else
- {
- like_msg_str = L('i_like_string');
- }
- if(wall_post.dislike_counter_cache > 0)
- {
- dislike_msg_str = String.format(L('you_dislike_string'), wall_post.dislike_counter_cache);
- }
- else
- {
- dislike_msg_str = L('i_dislike_string');
- }
- var viewOptionsLayout_Comment = Titanium.UI.createView({
- width : containerViewWidth,
- height : viewHeight,
- backgroundColor : "#FAFAFA",
- borderWidth : 1,
- borderColor : "#F0F0F0",
- bottom : 0,
- left : 0,
- right : 0,
- opacity : 1,
- zIndex : 1002
- });
- var buttonOptions01_Comment = Titanium.UI.createView({
- width : containerViewWidth - 50,
- height : "100%",
- left : -(containerViewWidth - 100),
- backgroundColor : "#EB7F06",
- zIndex : 1050
- });
- var frontView01 = Ti.UI.createView({
- width : containerViewWidth - 50,
- height : '100%',
- left : -(containerViewWidth - 100),
- optionView : buttonOptions01_Comment,
- zIndex : 1052
- });
- var dislikeHeartView = Titanium.UI.createImageView({
- width : 20,
- height : 20,
- right : 25,
- image : imagesPath + 'heart.png'
- });
- var dislikesMessage = Ti.UI.createLabel({
- text : dislike_msg_str,
- color : '#fff',
- font : {
- fontSize : 10,
- fontWeight : 'bold'
- },
- right : 50,
- height : "auto",
- width : "auto",
- textAlign : 'center',
- visible : false
- });
- // Create a Label.
- var buttonOptions01label_Comment = Ti.UI.createLabel({
- text : '>',
- color : '#ddd',
- font : {
- fontSize : 15,
- fontWeight : 'bold'
- },
- right : 5,
- height : "auto",
- width : "auto",
- textAlign : 'center',
- });
- var buttonOptions02_Comment = Titanium.UI.createView({
- // width : containerViewWidth - 100,
- height : "100%",
- left : 50,
- right : 50,
- backgroundColor : "transparent",
- // layout : 'horizontal',
- zIndex : 1045
- });
- var buttonOptions03_Comment = Titanium.UI.createView({
- width : containerViewWidth - 50,
- height : "100%",
- right : -(containerViewWidth - 100),
- backgroundColor : "#9ACA40",
- zIndex : 1050
- });
- var frontView03 = Ti.UI.createView({
- width : containerViewWidth - 50,
- height : '100%',
- right : -(containerViewWidth - 100),
- optionView : buttonOptions01_Comment,
- zIndex : 1052
- });
- var likeHeartView = Titanium.UI.createImageView({
- width : 20,
- height : 20,
- left : 25,
- image : imagesPath + 'heart.png'
- });
- var likesMessage = Ti.UI.createLabel({
- text : like_msg_str,
- color : '#fff',
- font : {
- fontSize : 10,
- fontWeight : 'bold'
- },
- left : 50,
- height : "auto",
- width : "auto",
- textAlign : 'center',
- visible : false
- });
- var buttonOptions03label_Comment = Ti.UI.createLabel({
- text : '<',
- color : '#ddd',
- font : {
- fontSize : 15,
- fontWeight : 'bold'
- },
- left : 5,
- height : "auto",
- width : "auto",
- textAlign : 'center',
- });
- if (likeness == true) {
- Ti.API.info('liked');
- // buttonOptions01label_Comment.applyProperties({
- // color : '#007D0A'
- // });
- // buttonOptions03label_Comment.applyProperties({
- // color : '#333333'
- // });
- }
- if (likeness == false) {
- Ti.API.info('unliked');
- // buttonOptions01label_Comment.applyProperties({
- // color : '#333333'
- // });
- // buttonOptions03label_Comment.applyProperties({
- // color : '#7D0032'
- // });
- }
- var dislike_touched = false;
- var like_touched = false;
- var moved = false;
- var initialViewX = 0;
- var curX = 0;
- var deltaX = 0;
- var currentPosition = 0;
- var prevPosition;
- var rowWidth = containerViewWidth - 100;
- var threshold = 0.5;
- function changeLikeness(side)
- {
- var likeness = 'like';
- if(side > 0)
- {
- likeness = 'dislike';
- }
- var networkArrayIndex = parseInt(getGenericConfig("activeNetworkArrayIndex"), 10);
- var token = JSON.parse(Ti.App.Properties.getString('loggedUser', 'No existe')).networks[networkArrayIndex].token;
- Ti.API.info('token ' + token);
- var url = endpoint;
- url = String.format(url, wall_post.veramiko_id, likeness);
- Ti.API.info('url ' + url);
- var client = Ti.Network.createHTTPClient({
- onload : function(e){
- Ti.API.info('Se recibio del likeness: ' + this.responseText);
- },
- onerror : function(e){
- Ti.API.error('Error changing likeness: ' + this.responseText);
- },
- timeout : 10000
- });
- client.open('POST', url);
- client.setRequestHeader('Authorization', 'Bearer ' + token);
- // client.send();
- }
- function touchStart(e) {
- table.setScrollingEnabled(false);
- prevPosition = containerViewWidth*2;
- Ti.API.info('e ' + JSON.stringify(e));
- Ti.API.info('source ' + JSON.stringify(e.source));
- // Ti.API.info('parent ' + JSON.stringify(e.source.optionView));
- // Ti.API.info(' containerViewWidth ' + containerViewWidth + ' rowWidth ' + rowWidth);
- initialViewX = rowWidth;
- curX = e.x;
- // Ti.API.info('initialViewX ' + initialViewX + ' curX ' + curX);
- }
- function touchMove(e, side) {
- likesMessage.visible = false;
- dislikesMessage.visible = false;
- // Ti.API.info('e ' + JSON.stringify(e));
- deltaX = (side) * (e.x - curX);
- currentPosition = rowWidth - deltaX;
- // Ti.API.info(' e.x ' + e.x + ' curX ' + curX + ' deltaX ' + deltaX + ' currentPosition ' + currentPosition + ' prevPosition ' + prevPosition);
- var percentageDiscovered = (deltaX / rowWidth);
- // Ti.API.info('percentageDiscovered ' + percentageDiscovered);
- // Ti.API.info('');
- if ((-currentPosition) > (-prevPosition)) {
- if((-currentPosition) > 0)
- {
- currentPosition = 0;
- }
- if (side == 1) {
- // Ti.API.info('dislike is moving');
- buttonOptions01_Comment.applyProperties({
- left : -currentPosition
- });
- if (like_touched) {
- // Ti.API.info('like has been touched, move it too');
- var otherRight = buttonOptions03_Comment.right;
- var newRight = -deltaX;
- if(newRight < -(containerViewWidth - 100))
- {
- newRight = -(containerViewWidth - 100);
- }
- // Ti.API.info('other right ' + otherRight + ' newRight ' + newRight);
- buttonOptions03_Comment.applyProperties({
- right : newRight
- });
- }
- } else {
- // Ti.API.info('like is moving');
- buttonOptions03_Comment.applyProperties({
- right : -currentPosition
- });
- if (dislike_touched) {
- // Ti.API.info('dislike has been touched, move it too');
- var otherLeft = buttonOptions01_Comment.left;
- var newLeft = -deltaX;
- if(newLeft < -(containerViewWidth - 100))
- {
- newLeft = -(containerViewWidth - 100);
- }
- // Ti.API.info('other left ' + otherLeft + ' newleft ' + newLeft);
- buttonOptions01_Comment.applyProperties({
- left : newLeft
- });
- }
- }
- if (percentageDiscovered >= threshold) {
- moved = true;
- } else {
- moved = false;
- }
- prevPosition = currentPosition;
- }
- }
- function touchEnd(e, side) {
- table.setScrollingEnabled(true);
- if (moved) {
- if (side == 1) {
- // Ti.API.info('dislike did reach the end');
- buttonOptions01_Comment.applyProperties({
- left : 0
- });
- frontView01.applyProperties({
- left : 0
- });
- dislikesMessage.visible = true;
- dislike_touched = true;
- if(like_touched)
- {
- // Ti.API.info('like has been touched before, moving it to the back');
- buttonOptions03_Comment.applyProperties({right : -(containerViewWidth - 100)});
- frontView03.applyProperties({right : -(containerViewWidth - 100)});
- like_touched = false;
- }
- changeLikeness(side);
- } else {
- // Ti.API.info('like did reach the end');
- buttonOptions03_Comment.applyProperties({
- right : 0
- });
- frontView03.applyProperties({right : 0});
- likesMessage.visible = true;
- like_touched = true;
- if(dislike_touched)
- {
- // Ti.API.info('dislike has been touched before, moving it to the back');
- buttonOptions01_Comment.applyProperties({left : -(containerViewWidth - 100)});
- frontView01.applyProperties({ left : -(containerViewWidth - 100)});
- dislike_touched = false;
- }
- changeLikeness(side);
- }
- } else {
- if (side == 1) {
- // Ti.API.info('dislike did not reach the end');
- buttonOptions01_Comment.applyProperties({
- left : -(containerViewWidth - 100)
- });
- frontView01.applyProperties({left : -(containerViewWidth - 100)});
- dislikesMessage.visible = false;
- dislike_touched = false;
- if(like_touched)
- {
- // Ti.API.info('like has been touched before, moving it to the end');
- likesMessage.visible = true;
- buttonOptions03_Comment.applyProperties({right : 0});
- frontView03.applyProperties({right : 0});
- }
- } else {
- // Ti.API.info('like did not reach the end');
- buttonOptions03_Comment.applyProperties({
- right : -(containerViewWidth - 100)
- });
- frontView03.applyProperties({right : -(containerViewWidth - 100)});
- likesMessage.visible = false;
- like_touched = false;
- if(dislike_touched)
- {
- // Ti.API.info('dislike has been touched before, moving it to the end');
- dislikesMessage.visible = true;
- buttonOptions01_Comment.applyProperties({left : 0});
- frontView01.applyProperties({left : 0});
- }
- }
- }
- moved = false;
- }
- function touchCancel(e, side)
- {
- Ti.API.info('cancelado');
- touchEnd(e, side);
- }
- frontView01.addEventListener('touchstart', function(e) {
- touchStart(e);
- });
- frontView01.addEventListener('touchmove', function(e) {
- touchMove(e, 1);
- });
- frontView01.addEventListener('touchend', function(e) {
- touchEnd(e, 1);
- });
- frontView01.addEventListener('touchcancel', function(e){
- touchCancel(e, 1);
- });
- frontView03.addEventListener('touchstart', function(e) {
- touchStart(e);
- });
- frontView03.addEventListener('touchmove', function(e) {
- touchMove(e, -1);
- });
- frontView03.addEventListener('touchend', function(e) {
- touchEnd(e, -1);
- });
- frontView03.addEventListener('touchcancel', function(e){
- touchCancel(e, -1);
- });
- buttonOptions01_Comment.add(buttonOptions01label_Comment);
- buttonOptions01_Comment.add(dislikeHeartView);
- buttonOptions01_Comment.add(dislikesMessage);
- buttonOptions02_Comment.add(dislikesLabel);
- buttonOptions02_Comment.add(separatorLabel);
- buttonOptions02_Comment.add(likesLabel);
- buttonOptions03_Comment.add(buttonOptions03label_Comment);
- buttonOptions03_Comment.add(likeHeartView);
- buttonOptions03_Comment.add(likesMessage);
- viewOptionsLayout_Comment.add(buttonOptions01_Comment);
- viewOptionsLayout_Comment.add(frontView01);
- viewOptionsLayout_Comment.add(buttonOptions02_Comment);
- viewOptionsLayout_Comment.add(buttonOptions03_Comment);
- viewOptionsLayout_Comment.add(frontView03);
- //*******************
- containerView.add(viewOptionsLayout_Comment);
- that.comment = containerView;
- return that;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement