Search code examples
javascriptandroidiostwittertitanium

how to open up an editable dialog to post a tweet


I'm wondering if there is a way when I click on a button to open up a dialog with a predefined message which the user can (i) edit(text field) (ii) cancel out of (button) and (iii) press ok (button) thus tweeting. I'm using the codebird module and titanium with the following link https://gist.github.com/Rogichi/5905010 This enabled me to send a tweet but only with a set text and no ability to edit, press ok or cancel. Also it only works on the first time you run the app on the phone, after that, I have to uninstall and re-install before I can send again. Any help at all would be much appreciated


Solution

  • you will have to create the window with the two buttons and a textarea so the user can compose his own tweet. i managed to do this using the codebird files you mention, all you have to do is edit the setTweet function like this:(everything else stay the same, doing this enables to send as many tweets with out relaunching the app. good luck)

    function setTweet(){
        var post = Ti.UI.createButton({
            title : 'Send',
            right: 10,
            width: 80,
            height: 30,
            top: 10
        });
        var content = Ti.UI.createTextArea({
          color: '#888',
          font: {fontSize:20, fontWeight:'bold'},
          textAlign: 'left',
          value: 'compose a tweet',
          top: 60,
          width: 280, height : 140
        });
        var floatW = Ti.UI.createWindow({
            backgroundColor:'#fff',
            borderWidth:8,
            borderColor:'#999',
            height:200,width:300,
            borderRadius:10
        });
        floatW.add(post);
        floatW.add(content);
        floatW.open();
        post.addEventListener('click', function(e){
            var tweet = content.getValue();
            cb.__call(
                "statuses_update",
                    {"status": tweet },
                        function (reply) {
                        Ti.API.info("Respuesta al publicar: ");// ...
                        Ti.API.info(reply);// ...
                            ///////////INSPECT OBJECT
                        function inspeccionar(obj){
                            var msg = '';
                            for (var property in obj){
                                if (typeof obj[property] == 'function')
                                {
                                    var inicio = obj[property].toString().indexOf('function');
                                    var fin = obj[property].toString().indexOf(')')+1;
                                    var propertyValue=obj[property].toString().substring(inicio,fin);
                                    msg +=(typeof obj[property])+' '+property+' : '+propertyValue+' ;\n';
                                }
                                else if (typeof obj[property] == 'unknown')
                                {
                                    msg += 'unknown '+property+' : unknown ;\n';
                                }
                                else
                                    {
                                        msg +=(typeof obj[property])+' '+property+' : '+obj[property]+' ;\n';
                                    }
                            }
                            return msg;
                            }
    
                    //Ti.API.info(inspeccionar(reply));
                    //Ti.API.info(inspeccionar(reply.errors[0]));
                        //Ti.API.info(reply.httpstatus);
    
                    if(reply.httpstatus == 200)
                            floatW.close();
                        else
                            alert(reply.errors);
                    }
            );
        });
    }