limit publications Parse

0

Next staff to making an app where the person publishes photos

I would like to limit the publication to 10 posts per person and when the person tries to post more pictures give an error message

Someone knows how I could do this

Here is the action of publishing and saving in parse

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    //testar o processo de retorno dos dados
    if (requestCode == 1 && resultCode == RESULT_OK && data != null) {


        //Recuperar local do recurso
        Uri localImagemSelecionada = data.getData();



        //Recupera a imagem do local que foi selecionada
        try {
            Bitmap imagem = MediaStore.Images.Media.getBitmap(getContentResolver(), localImagemSelecionada);

            /*
            Comprimir imagem no formato PNG
             */
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            imagem.compress(Bitmap.CompressFormat.PNG, 75, stream);



            /*Cria  Arrays de Bytes da imagem formato PNG 
            */
            byte[] byteArray = stream.toByteArray();


            /*Cria arquivos com formato proprio do Parse para PNG              */
            SimpleDateFormat dateFormat = new SimpleDateFormat("ddmmaaaahhmmss");
            String nomeImagem = dateFormat.format(new Date());
            ParseFile arquivoParse = new ParseFile(nomeImagem + "imagem.png", byteArray);

            /*Monta um objeto para salvar no Parse
             */
            final ParseObject parseObject = new ParseObject("Imagem");
            parseObject.put("username", ParseUser.getCurrentUser().getUsername());

            /*Atribui 2 entradas de dados no objeto "imagem", para PNG */

            parseObject.put("imagem", arquivoParse);




            //Salvar os dados
            parseObject.saveInBackground(new SaveCallback() {
                @Override
                public void done(ParseException e) {

                    if (e == null) {//Sucesso



                        String idObjeto = parseObject.getObjectId();

                        Intent intent = new Intent(PublicarImagemActivity.this, descricaoActivity.class);
                        intent.putExtra("idObjeto", idObjeto);
                        startActivity(intent);
                        finish();
                        Toast.makeText(getApplicationContext(), "Sua imagem foi publicada!", Toast.LENGTH_LONG).show();


                    } else {//Erro
                        Toast.makeText(getApplicationContext(), "Erro ao postar sua imagem, tente novamente!",
                                Toast.LENGTH_LONG).show();
                    }


                }
    
asked by anonymous 20.02.2017 / 00:56

1 answer

0

Do both sides on both Android and your Server . If you have a relatively small collection of keys to save, which is an option for this situation, use SharedPreferences .

SharedPreferences are used in situations where there is no need to create a database, or even when there is little number of data to be stored. Broadly speaking, this storage can consist of several types of data, including integers.

SharedPreferences consists of an interface that allows you to access and modify user preference data. The stored value is presented in key-value or key-value format, that is, each stored preference has an ID or key and associated with it is a value. It allows you to store various types of values, such as int , float , Strings , booleans and sets of Strings . Here is an example of how it is used:

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("qndFotosEnviadas", 0);
editor.commit();

When you add a photo, you change the value of the key qndFotosEnviadas by increasing +1 .

To redeem the value before incrementing, you can do this:

int qndFotos = sharedPref.getInt("qndFotosEnviadas", 0);
if(qndFotos<=10){

    qndFotos++;
    editor.putInt("qndFotosEnviadas", qndFotos);
    editor.commit();
    // chama função para tirar foto

} else {
    // exibe mensagem você não pode enviar mais que 10
}

Note : Never under any circumstances, save user passwords in SharedPreferences , even it is recommended that no personal user data, such as credit card , phone, and passwords are stored in the device in some way.

    
20.02.2017 / 01:57