Группировка товаров Recycler по дате с разбивкой на страницы

Я хочу добиться чего-то вроде:

  17 July,2018
    - item
    - item
  16 July,2018
    - item
    - item
    - item

Я достиг этого успешно с помощью следующей ссылки:

Разделите элементы по группам в элементах RecyclerView или Grouping Recyclerview, скажем, по дате

Но теперь проблема заключается в разбиении на страницы, если такая же дата есть на следующей странице, и тогда будет создан второй заголовок с той же датой.

то есть если на первой странице у меня есть данные с датой 16 июля 2018 года, а на второй странице также, если у меня есть данные с датой 16 июля 2018 года, то создаются два заголовка для 16 июля 2018 года.

 Page -1
 17 July,2018
        - item
        - item
 16 July,2018
        - item
        - item
 Page -2
 16 July,2018
        - item
        - item
        - item
        - item
 14 July,2018
        - item
        - item

Я хочу, чтобы все элементы одной даты были под одним заголовком. Я хочу объединить две страницы данных, если они совпадают.

Мой код такой же, как указано выше по ссылке.. все же я добавляю какой-то важный код и, если требуется какой-либо другой код, пожалуйста, дайте мне знать

 private LinkedHashMap<String, List<NotificationData>> groupDataIntoHashMap(List<NotificationData> listOfPojosOfJsonArray) {

        LinkedHashMap<String, List<NotificationData>> groupedHashMap = new LinkedHashMap<>();

        for (NotificationData pojoOfJsonArray : listOfPojosOfJsonArray) {

            String hashMapKey = pojoOfJsonArray.getTicket_date();

            if (groupedHashMap.containsKey(hashMapKey)) {
                // The key is already in the HashMap; add the pojo object
                // against the existing key.
                groupedHashMap.get(hashMapKey).add(pojoOfJsonArray);


            } else {
                // The key is not there in the HashMap; create a new key-value pair
                List<NotificationData>  list = new ArrayList<>();
                list.add(pojoOfJsonArray);
                groupedHashMap.put(hashMapKey, list);

            }
        }

        return groupedHashMap;
    }

Внутренний успех сервиса:

 try {
            JSONObject object = new JSONObject(response);
            if (!Utils.isEmptyString(response)) {
                if (id == reqIdNotificationList) {

                    if (object.getInt(PARAMS.TAG_STATUS) == PARAMS.SUCCESS_STATUS) {
                        String resultArray = object.getString(PARAMS.TAG_RESULT);
                        if (!Utils.isEmptyString(resultArray)) {

                            Type listType = new TypeToken<List<NotificationData>>() {
                            }.getType();
                            ArrayList<NotificationData> tmpNotification = new Gson().fromJson(resultArray, listType);


                            if (tmpNotificationList != null)
                                tmpNotificationList = new ArrayList<>();

                            if (TextUtils.isEmpty(mtktNo)) {

                                tmpNotificationList.clear();
                                tmpNotificationList.addAll(tmpNotification);

                                LinkedHashMap<String, List<NotificationData>> groupedHashMap = groupDataIntoHashMap(tmpNotificationList);


                                for (String date : groupedHashMap.keySet()) {
                                    dateItem = new DateItem();
                                    dateItem.setTicket_date(date);
                                    consolidatedList.add(dateItem);


                                    for (NotificationData pojoOfJsonArray : groupedHashMap.get(date)) {
                                        generalItem = new GeneralItem();
                                        generalItem.setResult(pojoOfJsonArray);
                                        consolidatedList.add(generalItem);

                                    }

                                }
                                adapter = new NotificationListAdapter(this, consolidatedList, this);
                                rvNotification.setAdapter(adapter);

//                                notificationList.addAll(tmpNotificationList);
//                                adapter = new NotificationListAdapter(NotificationActivity.this, notificationList, this);
//                                rvNotification.setAdapter(adapter);

                            } else {

                                int startIndex = tmpNotification.size();
                                tmpNotificationList.addAll(tmpNotification);

                                Log.d("size",tmpNotificationList.size()+"");

                               adapter.notifyItemRangeInserted(startIndex, tmpNotificationList.size() - 1);

                                LinkedHashMap<String, List<NotificationData>> groupedHashMap = groupDataIntoHashMap(tmpNotificationList);

                                for (String date : groupedHashMap.keySet()) {
                                    DateItem dateItem = new DateItem();
                                    dateItem.setTicket_date(date);
                                    consolidatedList.add(dateItem);


                                    for (NotificationData pojoOfJsonArray : groupedHashMap.get(date)) {
                                        GeneralItem generalItem = new GeneralItem();
                                        generalItem.setResult(pojoOfJsonArray);
                                        consolidatedList.add(generalItem);
                                    }
                                }

                                if (consolidatedList.size() >= object.getInt(PARAMS.TAG_RECORD)) {
                                    rvNotification.removeMoreListener();
                                }


                            }
                            if (tmpNotificationList.isEmpty()) hideMenu();
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

Примечание: в данной ссылке это hashmap, но я использовал связанный hashmap для поддержания порядка элементов.

Также я использовал этот менеджер линейного макета.

Спасибо!

0 ответов

Другие вопросы по тегам