I have a simple parsing method from firebase. How i can do it smaller?The fact is that after the data is changed I will need to update my View so that the code can be added, which also does not sound cool.

private void createMainHashMapForData() {
    reference = database.getReference().child("OBJ");
    reference.addValueEventListener(new ValueEventListener() {
        public void onDataChange(DataSnapshot dataSnapshot) {
            try {
               int iterationForMainHashmap = 0;
    mHashmapForData.clear(); // clear

    for (DataSnapshot messageSnapshot : dataSnapshot.getChildren()) {
        //main data
        int iterationForConstructor = 0;
        ArrayList<Product> temp_heshmap = new ArrayList<>();

        for (DataSnapshot messageSnapshot2 : messageSnapshot.child("ITEMS").getChildren()) {
            //progress show its news product // main data
            Product product = messageSnapshot2.getValue(Product.class);
            temp_heshmap.add(iterationForConstructor, product);
            iterationForConstructor += 1;

        //main data
        String mNumberOfProduct = messageSnapshot.child("NUMBER_OF_PRODUCTS").getValue().toString();
        String nameOfBlock = messageSnapshot.child("TITLE").getValue().toString();
        Boolean mShowCoins = Boolean.parseBoolean(messageSnapshot.child("SHOW_COINS").getValue().toString());

        //put to main hashmap
                new ContainerForData(mShowCoins, nameOfBlock, mNumberOfProduct, temp_heshmap));
        iterationForMainHashmap += 1;
            } catch (Exception e) {
                Log.d("Exception getProducts", e.getMessage());
                FirebaseCrash.report(new Exception(e.getMessage()));

        public void onCancelled(DatabaseError databaseError) {
            FirebaseCrash.report(new Exception(databaseError.getMessage()));

As I said, my question is how to make modal methods less and more productive? Do you have any ideas??


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.