Skip to main content

Multimap at its best

private void fetchTransactions() {
        transactionViewFlipper.setDisplayedChild(0);

        StringRequest stringRequest = new StringRequest(POST, GET_ALL_MERCHANT_TRANSACTIONS, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {

                try {
                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.getString("status").equals("SUCCESS")) {
                        JSONArray jsonArray = new JSONArray(jsonObject.getString("result"));
                        final Multimap<String, ArrayList<MerchantTransactionDetails>> multimap = LinkedListMultimap.create();
                        final ArrayList<String> monthNames = new ArrayList<>();
                        for (int i = 0; i < jsonArray.length(); i++) {
                            monthTransactions = new ArrayList<>();
                            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                            MerchantTransactionDetails merchantTransactionDetails = new MerchantTransactionDetails();
                            merchantTransactionDetails.setTransactionId(jsonObject1.getString("trans_id"));

                            merchantTransactionDetails.setTransactionType(jsonObject1.getString("transaction_type"));
                            merchantTransactionDetails.setTransactionAmount(jsonObject1.getString("transaction_amount"));
                            merchantTransactionDetails.setCashBackId(jsonObject1.getString("trans_cashback_id"));
                            merchantTransactionDetails.setOfferId(jsonObject1.getString("trans_offer_redeem_id"));
                            merchantTransactionDetails.setTransactionDate(jsonObject1.getString("transaction_created_date"));
                            merchantTransactionDetails.setTransactionCustomerName(jsonObject1.getString("v_uname"));
                            merchantTransactionDetails.setTransactionText(jsonObject1.getString("v_deal_text"));
                            merchantTransactionDetails.setTransactionDealImageUrl(jsonObject1.getString("markedasfeatured"));
                            merchantTransactionDetails.setCustomerId(jsonObject1.getString("customer_id"));
                            merchantTransactionDetails.setCustomerImage(jsonObject1.getString("v_image"));
                            merchantTransactionDetails.setCustomerContactNo(jsonObject1.getString("v_contact_no"));
                            merchantTransactionDetails.setCustomerEmail(jsonObject1.getString("v_email"));
                            merchantTransactionDetails.setTransactionBillNo(jsonObject1.getString("transaction_bill_number"));
                            merchantTransactionDetails.setBillImageUrl(jsonObject1.getString("transaction_bill_image"));
                            String key = Constants.getProperFormatDate(jsonObject1.getString("transaction_created_date")).split(" ")[0];
                            if (!monthNames.contains(key))
                                monthNames.add(key);
                            monthTransactions.add(merchantTransactionDetails);
                            multimap.put(key, monthTransactions);
                        }

                        JSONArray jsonArray1 = new JSONArray(jsonObject.getString("total_redeemed_cases"));
                        for (int i = 0; i < jsonArray1.length(); i++) {
                            monthTransactions = new ArrayList<>();
                            JSONObject jsonObject1 = jsonArray1.getJSONObject(i);
                            MerchantTransactionDetails merchantTransactionDetails = new MerchantTransactionDetails();
                            merchantTransactionDetails.setTransactionId(jsonObject1.getString("trans_id"));

                            merchantTransactionDetails.setTransactionType(jsonObject1.getString("transaction_type"));
                            merchantTransactionDetails.setTransactionAmount(jsonObject1.getString("transaction_amount"));
                            merchantTransactionDetails.setCashBackId(jsonObject1.getString("trans_cashback_id"));
                            merchantTransactionDetails.setOfferId(jsonObject1.getString("trans_offer_redeem_id"));
                            merchantTransactionDetails.setTransactionDate(jsonObject1.getString("transaction_created_date"));
                            merchantTransactionDetails.setTransactionCustomerName(jsonObject1.getString("v_uname"));
                            merchantTransactionDetails.setTransactionText("Redeemed");
                            merchantTransactionDetails.setTransactionDealImageUrl("");
                            merchantTransactionDetails.setCustomerId(jsonObject1.getString("customer_id"));
                            merchantTransactionDetails.setCustomerImage(jsonObject1.getString("v_image"));
                            merchantTransactionDetails.setCustomerContactNo(jsonObject1.getString("v_contact_no"));
                            merchantTransactionDetails.setCustomerEmail(jsonObject1.getString("v_email"));
                            merchantTransactionDetails.setTransactionBillNo(jsonObject1.getString("transaction_bill_number"));
                            merchantTransactionDetails.setAmountPaidThorughWishlo(jsonObject1.getString("paid_through_wishlo_amount"));
                            merchantTransactionDetails.setBillImageUrl(jsonObject1.getString("transaction_bill_image"));
                            String key = Constants.getProperFormatDate(jsonObject1.getString("transaction_created_date")).split(" ")[0];
                            if (!monthNames.contains(key))
                                monthNames.add(key);
                            monthTransactions.add(merchantTransactionDetails);
                            multimap.put(key, monthTransactions);
                        }
                        Collections.reverse(monthTransactions);
                        transactionViewFlipper.setDisplayedChild(1);
                        if(getContext()==null){
                            final Handler handler =new Handler();
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    if(getContext() == null){
                                        handler.postDelayed(this,400);
                                    }else{
                                        transactionRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
                                        transactionRecyclerView.setAdapter(new MonthlyTransactionAdapter(getContext(), multimap, monthNames));
                                    }

                                }
                            },400);
                        }else{
                            transactionRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
                            transactionRecyclerView.setAdapter(new MonthlyTransactionAdapter(getContext(), multimap, monthNames));
                        }

                        Log.d("TAG", multimap.toString());
                    } else {
                        transactionViewFlipper.setDisplayedChild(3);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    Toast.makeText(getContext(), "Parse Exception", Toast.LENGTH_LONG).show();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                transactionViewFlipper.setDisplayedChild(2);
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> stringStringHashMap = new HashMap<>();
                stringStringHashMap.put("Content-Type", "application/x-www-form-urlencoded");
                stringStringHashMap.put("X-API-KEY", "1234");
                stringStringHashMap.put("Accept", "application/json");
                return stringStringHashMap;
            }

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> hashMap = new HashMap<>();
                hashMap.put("merchant_id", getArguments().getString(MERCHANT_ID));
                Log.d(Constants.TAG, hashMap.toString());
                return hashMap;
            }
        };
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(
                10000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        AppController.getInstance().addToRequestQueue(stringRequest);
    }





@Override
    public void onBindViewHolder(MonthlyTransactionAdapterViewHolder holder, int position) {
        Collection<ArrayList<MerchantTransactionDetails>> albumDataArrayList1 = multimap.get(monthName.get(position));

        Iterator it = albumDataArrayList1.iterator();

        ArrayList<MerchantTransactionDetails> albumDataArrayList2 = new ArrayList<>();
        while (it.hasNext()) {
            albumDataArrayList2.addAll((Collection<? extends MerchantTransactionDetails>) it.next());
        }
        holder.monthsRecyclerView.setLayoutManager(new LinearLayoutManager(context));
        IndividualMonthDetailAdapter individualMonthDetailAdapter = new IndividualMonthDetailAdapter(context, albumDataArrayList2, mFont);
        holder.monthsRecyclerView.setAdapter(individualMonthDetailAdapter);
        holder.monthName.setText(monthName.get(position));
        holder.monthName.setTypeface(mFont);
    }


Comments

Popular posts from this blog

curl http://localhost:8042/studies/333b2c11-52e9feea-5516186e-ecd61f37-69da2603  curl http://localhost:8042/patients/dc65762c-f476e8b9-898834f4-2f8a5014-2599bc94 bird@bird-Lenovo-ideapad-310-15IKB:/media/bird/2AE477A5E4777245/Meteor/OrthancMirror/build$ curl http://localhost:8042/patients [    "333b2c11-52e9feea-5516186e-ecd61f37-69da2603",    "da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709" ] bird@bird-Lenovo-ideapad-310-15IKB:/media/bird/2AE477A5E4777245/Meteor/OrthancMirror/build$ curl http://localhost:8042/studies [    "9b5629ef-c28c48db-b3593009-35fda9cb-7a0bb799",    "abae0b24-5a718d9e-1b560140-2cda3ae0-30b846cb" ] bird@bird-Lenovo-ideapad-310-15IKB:/media/bird/2AE477A5E4777245/Meteor/OrthancMirror/build$  curl http://localhost:8042/series [    "993a521c-1b11574c-92e1c71d-a048784c-36866be0",    "5f19601c-3e5fa872-e566e9f2-36aa3b31-dc719c3e" ] bird@bird-Lenovo-ideapad-310-15IKB:/med...

Android Commands

meteor run android-device --mobile-server="https://sitename.com" metero build (BUIld Path/home/bird/Downloads/Meteor/bit/uploads ) --server="https://sitename.com"