Transfer a Url from an image to another activity and retrieve it in an image view for later comment

0

Hello, I'm trying to create an option in my application, that when I click the photo I'll be redirected to another screen, with the photo selected in a imageview and a texview to comment!

What is the biggest problem I'm doing with a adapter , that is, I have the photos posted and I use a dialog alert to go to another activity ! I can not turn it into a array , I'm simply passing your URL to another screen as String , but I can not retrieve it, and move to Image view , could someone help me:

follow my code:

My adapter , first activity:

package com.parse.starter.adapter;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.starter.R;
import com.parse.starter.activity.ComentarActivity;
import com.parse.starter.activity.DescricaoActivity;
import com.parse.starter.activity.LoginActivity;
import com.parse.starter.activity.MainActivity;
import com.parse.starter.activity.TrocarActivity;
import com.parse.starter.activity.ComprasActivity;
import com.squareup.picasso.Picasso;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import static android.app.Activity.RESULT_OK;


public class TimeLineAdapter extends ArrayAdapter<ParseObject> {

    private Context context;
    private ArrayList<ParseObject> postagens;
    private AlertDialog.Builder dialog;
    private Bitmap bitmap;
    //private ImageButton botao;


    public TimeLineAdapter(Context c, ArrayList<ParseObject> objects) {
        super(c, 0, objects);

        this.context = c;
        this.postagens = objects;


    }


    @NonNull
    @Override
    public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        View view = convertView;

        if (view == null) {


            //INICIAliza oOBJETO PARA MONTAGEM DO LAYOUT
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);

            // MONTA VIEW A PARTIR DO XML
            view = inflater.inflate(R.layout.lista_timeline, parent, false);
            //  botao =(ImageButton) view.findViewById(R.id.button);


        }


        // verifica postagem

        if (postagens.size() > 0) {

            //RECUPERA COMPONENTE DA TELA
            final ImageView imagemPostagem = (ImageView) view.findViewById(R.id.image_lista_dicas);

            final ParseObject parseObject = postagens.get(position);


            //mostra o usuario encima da foto

            TextView texto = (TextView) view.findViewById(R.id.text_lista_usuarios);
            texto.setText(parseObject.get("username").toString());

            // mostra descrição abaixo da foto

            TextView textoo = (TextView) view.findViewById(R.id.text_descricaoo);
            textoo.setText(parseObject.get("descricao").toString());


            // mostra comentario abaixo da foto

            //  TextView textooo = (TextView) view.findViewById(R.id.text_comentarioss);
            //textooo.setText( parseObject.get("comentario").toString() );


            parseObject.getParseFile("imagem");
            Picasso.with(context)
                    .load(parseObject.getParseFile("imagem").getUrl())
                    .fit()
                    .into(imagemPostagem);


                imagemPostagem.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        AlertDialog.Builder dialog = new AlertDialog.Builder(context);
                        dialog.setTitle("COMENTAR");
                        dialog.setMessage("Deseja comentar está foto?");

                        dialog.setCancelable(false);

                        dialog.setNegativeButton("Não",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int which) {
                                        Toast.makeText(getContext(), "Foto não comentada", Toast.LENGTH_SHORT).show();
                                    }
                                });

                        dialog.setPositiveButton("Sim",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {


                                        traferirImagem();

                                        Toast.makeText(getContext(), "Deixe seu comentário", Toast.LENGTH_SHORT).show();


                                    }
                                });
                        dialog.create();
                        dialog.show();
                    }
                });


                //  ir para Comprar ou trocar usando um dialog

                imagemPostagem.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {

                        AlertDialog.Builder dialog = new AlertDialog.Builder(context);
                        dialog.setTitle("O que deseja fazer:");
                        dialog.setMessage("Comprar ou trocar? Faça a sua escolha!");

                        dialog.setCancelable(false);

                        dialog.setNegativeButton("Comprar",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int which) {

                                        // enviando para a tela de compras
                                        context.startActivity(new Intent(context, ComprasActivity.class));
                                        Toast.makeText(getContext(), "Preencha seus dados corretamente!", Toast.LENGTH_SHORT).show();
                                    }
                                });
                        dialog.setNeutralButton("Voltar",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int which) {

                                    }
                                });

                        dialog.setPositiveButton("Trocar",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        // enviando para a tela de trocas
                                        context.startActivity(new Intent(context, TrocarActivity.class));
                                        Toast.makeText(getContext(), "Preencha seus dados corretamente!", Toast.LENGTH_SHORT).show();
                                    }
                                });


                        dialog.create();
                        dialog.show();
                        return false;
                    }
                });
            }

            return view;


        }

        public void traferirImagem(){


            //armazena a URL em uma String
            String url = "imagem";



//Cria uma intent apontando a activity que voce deseja navegar
            Intent it = new Intent(context, ComentarActivity.class);

//Através do método putExtra você irá enviar a url passando o identificador, e a variável com a url armazenada
            it.putExtra("imagem", url);

//Agora basta iniciar a activity
            context.startActivity(it);

        }

}

My second activity :

package com.parse.starter.activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.parse.GetDataCallback;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseRelation;
import com.parse.ParseUser;
import com.parse.SaveCallback;
import com.parse.starter.R;
import com.squareup.picasso.Picasso;

import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ComentarActivity extends AppCompatActivity {

    private EditText comentario;
    private Button botaoSalvar;
    private ImageView fotoSelecionada;
    private String obID;
    private ViewPager viewPager;
    private TextView texto;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comentar);

        comentario = (EditText) findViewById(R.id.text_comentario);
        botaoSalvar = (Button) findViewById(R.id.button_salvar);
        fotoSelecionada = (ImageView) findViewById(R.id.imageView2);
        texto = (TextView) findViewById(R.id.textoId);


        //passando uma foto da galeria para a imageviewe




        botaoSalvar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                addTheComment();
            }
        });

    }


    // salvando no banco de dados dados do campo comentario

    private void cadastrarComentario() {


        //criar objeto usuario


        ParseObject post = new ParseObject("Comentario");
        post.put("comentario", comentario.getText().toString());


        ParseObject postObject = new ParseObject("Imagem");
        post.put("parentPost", postObject);




        post.saveInBackground(new SaveCallback() {

            @Override
            public void done(ParseException e) {
                if (e == null) { //Sucesso ao salvar
                    Toast.makeText(ComentarActivity.this, " Comentário feito com sucesso! ", Toast.LENGTH_SHORT).show();


                    Intent intent = new Intent(ComentarActivity.this, MainActivity.class);
                    startActivity(intent);

                } else {//error ao salvar
                    Toast.makeText(getApplicationContext(), "Erro ao comentar - Tente novamente!",
                            Toast.LENGTH_LONG).show();
                }
            }
        });

    }

    public void addTheComment() {


// Create the comment
        ParseObject myComment = new ParseObject("Comentario");
        myComment.put("comentario", comentario.getText().toString());

// Add a relation between the Post with objectId "1zEcyElZ80" and the comment
        myComment.put("parent", ParseObject.createWithoutData("Imagem", "aE2cj1PDjz")); // preciso colocar id aqui

// This will save both myPost and myComment
        myComment.saveInBackground();

    }




}
    
asked by anonymous 25.04.2018 / 01:47

0 answers