Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.0 kB
3
Indexable
Never
 private void setTimings() {
        try {
            String timingObject = mRestaurantCart.getRestaurant().getDeliveryTime();
            if (!TextUtils.isEmpty(timingObject) && !timingObject.equals("null")) {
                timingObject = timingObject.replace("\\\"", "\"");
                JSONObject timingsJson = new JSONObject(timingObject);

                List<RestaurantTiming> timingList = new ArrayList<>();

                Iterator<String> keys = timingsJson.keys();
                while (keys.hasNext()) {
                    String day = keys.next();
                    ArrayList<String> openTimeList = new ArrayList<>();
                    ArrayList<String> closeTimeList = new ArrayList<>();

                    JSONObject dayObject = timingsJson.getJSONObject(day);
                    JSONArray openArray = dayObject.optJSONArray("open");
                    if (openArray != null && openArray.length() > 0) {
                        for (int i = 0; i < openArray.length(); i++) {
                            openTimeList.add(openArray.getString(i));
                        }
                    }

                    JSONArray closeArray = dayObject.optJSONArray("close");
                    if (closeArray != null && closeArray.length() > 0) {
                        for (int i = 0; i < closeArray.length(); i++) {
                            closeTimeList.add(closeArray.getString(i));
                        }
                    }

                    RestaurantTiming timing = new RestaurantTiming();
                    timing.dayName = day;
                    timing.openTime = openTimeList;
                    timing.closeTime = closeTimeList;
                    timingList.add(timing);
                }
                mRestaurantCart.getRestaurant().setRestaurantTimings(timingList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
Leave a Comment