Android firebase with zxing barcode scan

0

Oops galley blz ?, I'm having problems with the zxing class next to a firebase search ... As soon as I retrieve the value from the barcode I perform a search using the barcode as a parameter, what I need is which during the search is slow because of the volume of data in the firebase, it takes time ... I tried to put a Progress bar, but the class ignores and still does. Could someone help me with some solution.

Zxing class

public class ScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
private AlertDialog.Builder b;

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    mScannerView = new ZXingScannerView(this); 
    setContentView(mScannerView);
}

@Override
public void onResume() {
    super.onResume();
    mScannerView.setResultHandler(this);
    mScannerView.startCamera();        
}

@Override
public void onPause() {
    super.onPause();
    mScannerView.stopCamera();        
}

@Override
public void handleResult(Result rawResult) {


    //CadastroProdutoActivity.nome_produto.setText(rawResult.getText());
    DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();

    // a variavel m vai ser a variavel que vai receber os dados do usuario--------------
    String m = rawResult.getText();

    Query last = databaseReference.child("Produtos").orderByChild("codigo_barras").equalTo(m);

    //REcuperando o valor do codigo de barras
    last.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
final ProgressDialog dialog2 = new ProgressDialog(ScanActivity.this, R.style.Theme_AppCompat_Light_Dialog_Alert);
    dialog2.setTitle("Buscando dados... Aguarde!");
      dialog2.create();
    dialog2.show();


            for(DataSnapshot dados: dataSnapshot.getChildren()) {

                //Chamando a class do codigo de barras e criando obj----------------------------
                CodigoBarras m = dados.getValue(CodigoBarras.class);

                //Colocando o item do obj na
                CadastroProdutoActivity.nome_produto.setText(m.getNome_completo());

                CadastroProdutoActivity.categoria.setText(m.getCategoria());

                CadastroProdutoActivity.peso.setText(m.getUnidade());

            }

 dialog2.dismiss();

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

                    onBackPressed();
 }
}
    
asked by anonymous 22.01.2018 / 05:15

0 answers