public void loadMenu() { String url = NameConstant.BASE_API_URL_V1 + "getCategoriesByApiKey.php?APIKey=" + AppConfiguration.getInstance(context).websiteKey; MyRequestQueue.Instance(this).cancelPendingRequests("menu"); new VolleyData(this) { @Override protected void VPreExecute() { progressBar.setVisibility(View.VISIBLE); itemsRecyclerView.setVisibility(View.GONE); } @Override protected void VResponse(JSONObject response, String tag) { JSONObject json = response; progressBar.setVisibility(View.GONE); itemsRecyclerView.setVisibility(View.VISIBLE); try { if (json != null) { try { JSONArray jsonCategories = json.getJSONArray("categories"); drawer1MenuAdapter.clear(); ArrayList<Category> menuCategories = new ArrayList<Category>(); if (getPackageName().equalsIgnoreCase("com.applop.vidhrra")) { menuCategories.add(new Category("", "Pune", "home")); } else { menuCategories.add(new Category("", "Home", "home")); } if (getPackageName().equalsIgnoreCase("com.applop")) { menuCategories.add(new Category("", "Make App Now", "enquiry")); } else { if (!getPackageName().equalsIgnoreCase("com.applop.meeaagiapp")) menuCategories.add(new Category("", "enquiry", "enquiry")); } for (int i = 0; i < jsonCategories.length(); i++) { menuCategories.add(new Category(jsonCategories.getJSONObject(i))); } // for getting story on home page.........only first line loadCategory(menuCategories.get(0), 1, false, false); drawer1MenuAdapter.insertCategories(menuCategories); } catch (Exception e) { } } } catch (Exception e) { } } @Override protected void VError(VolleyError error, String tag) { progressBar.setVisibility(View.GONE); itemsRecyclerView.setVisibility(View.VISIBLE); } }.getJsonObject(url, true, "menu", this); ; }
// for loading page on click of button in navigation drawer list public void loadCategory( Category category, final int page, boolean isRefreshing, final boolean isLoadingMore) { if (category == null) { itemsRecyclerView.setVisibility(View.INVISIBLE); return; } try { String pageviews = "Category Page with Category(" + category.categoryId + ") : " + category.name; AnalyticsHelper.trackPageView(pageviews, this); } catch (Exception e) { e.printStackTrace(); } try { String categoryName = "Category"; String label = "Opened"; String action = "Category(" + category.categoryId + ") : " + category.name; AnalyticsHelper.trackEvent(categoryName, action, label, this); } catch (Exception e) { e.printStackTrace(); } myTitle.setText(category.name); currentCategory = category; current_page = page; final Context context = this; String URL = getCategoryStoryURL(category, page); // 1 MyRequestQueue.Instance(this).cancelPendingRequests("stories"); new VolleyData(this) { @Override protected void VPreExecute() { if (!isLoadingMore) { progressBar.setVisibility(View.VISIBLE); itemsRecyclerView.setVisibility(View.GONE); storyAdapter.clear(); storyAdapter.notifyDataSetChanged(); } } @Override protected void VResponse(JSONObject response, String tag) { swipeRefreshLayout.setRefreshing(false); endLoadMore(); JSONObject json = response; try { if (json != null) { try { progressBar.setVisibility(View.GONE); JSONArray jsonStories = json.getJSONArray("stories"); ArrayList<Story> stories = new ArrayList<Story>(); for (int i = 0; i < jsonStories.length(); i++) { Story story = new Story(context, jsonStories.getJSONObject(i)); // if (!IsStoryAlreadyAdded(story)){ stories.add(story); // } } itemsRecyclerView.setAdapter(storyAdapter); itemsRecyclerView.setVisibility(View.VISIBLE); storyAdapter.insertStories(stories); } catch (Exception e) { Toast.makeText(getApplicationContext(), "" + e, Toast.LENGTH_LONG).show(); } } } catch (Exception e) { Toast.makeText(getApplicationContext(), "" + e, Toast.LENGTH_LONG).show(); } } @Override protected void VError(VolleyError error, String tag) { swipeRefreshLayout.setRefreshing(false); endLoadMore(); progressBar.setVisibility(View.GONE); itemsRecyclerView.setVisibility(View.VISIBLE); } }.getJsonObject(URL, true, "stories", this); }