Created
September 2, 2015 01:40
-
-
Save moizest89/0b3695b1e69c80ef1338 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Data methods | |
private void getValuesUrl(){ | |
Log.e("fragment", URL_CONNECTION); | |
JsonObjectRequest request = new JsonObjectRequest(this.URL_CONNECTION, null, | |
new Response.Listener<JSONObject>() { | |
@Override | |
public void onResponse(JSONObject response) { | |
//System.out.print("response: "+response); | |
setValuesUrl(response); | |
} | |
},new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
Log.e(TAG, "Error Volley"); | |
} | |
}); | |
TopChef.getInstance().addToRequestQueue(request); | |
} | |
private void setValuesUrl(JSONObject response){ | |
try { | |
this.mData.clear(); | |
JSONArray jsonArrayArticles = response.getJSONArray(ArticlesModel.CN_ARTICLES); | |
for (int articles = 0; articles < jsonArrayArticles.length(); articles++) { | |
JSONObject jsonObjectArticle = ((JSONObject)jsonArrayArticles.get(articles)).getJSONObject(ArticlesModel.CN_ARTICLE); | |
ArticlesModel articlesModel = new ArticlesModel(); | |
articlesModel.setContent(jsonObjectArticle.getString(articlesModel.CN_CONTENT)); | |
articlesModel.setTitle(jsonObjectArticle.getString(articlesModel.CN_TITLE)); | |
articlesModel.setExcerpt(jsonObjectArticle.getString(articlesModel.CN_EXCERPT)); | |
articlesModel.setShare_url(jsonObjectArticle.getString(articlesModel.CN_SHARE_URL)); | |
articlesModel.setPublished_at(jsonObjectArticle.getString(articlesModel.CN_PUBLISHED)); | |
articlesModel.setSlug(jsonObjectArticle.getString(articlesModel.CN_SLUG)); | |
/** Photos **/ | |
JSONArray jsonArrayPhotos = jsonObjectArticle.getJSONArray(articlesModel.CN_PHOTOS); | |
for (int photos = 0; photos < jsonArrayPhotos.length(); photos++) { | |
JSONObject jsonObjectPhotos = (JSONObject) jsonArrayPhotos.get(photos); | |
ArticlesPhotosModel articlesPhotosModel = new ArticlesPhotosModel(); | |
articlesPhotosModel.setDetail(jsonObjectPhotos.getString(articlesPhotosModel.CN_DETAIL)); | |
articlesPhotosModel.setNormal(jsonObjectPhotos.getString(articlesPhotosModel.CN_NORMAL)); | |
articlesPhotosModel.setPinterest(jsonObjectPhotos.getString(articlesPhotosModel.CN_PINTEREST)); | |
articlesPhotosModel.setPinterest_retina(jsonObjectPhotos.getString(articlesPhotosModel.CN_PINTEREST_RETINA)); | |
articlesPhotosModel.setRetina2x(jsonObjectPhotos.getString(articlesPhotosModel.CN_RETINA2X)); | |
articlesPhotosModel.setRetina3x(jsonObjectPhotos.getString(articlesPhotosModel.CN_RETINA3X)); | |
articlesModel.setArticle_photos(articlesPhotosModel); | |
} | |
/** Videos **/ | |
JSONArray jsonArrayVideos = jsonObjectArticle.getJSONArray(articlesModel.CN_ARTICLE_VIDEOS); | |
for (int videos = 0; videos < jsonArrayVideos.length(); videos++) { | |
JSONObject jsonObjectVideo = jsonArrayVideos.getJSONObject(videos); | |
ArticlesVideosModel articlesVideosModel = new ArticlesVideosModel(); | |
articlesVideosModel.setHls_url(jsonObjectVideo.getString(articlesVideosModel.CN_HLS_URL)); | |
articlesVideosModel.setUrl(jsonObjectVideo.getString(articlesVideosModel.CN_URL)); | |
articlesVideosModel.setRetina3x(jsonObjectVideo.getString(articlesVideosModel.CN_RETINA3X)); | |
articlesVideosModel.setRetina2x(jsonObjectVideo.getString(articlesVideosModel.CN_RETINA3X)); | |
articlesVideosModel.setNormal(jsonObjectVideo.getString(articlesVideosModel.CN_NORMAL)); | |
articlesVideosModel.setCover(jsonObjectVideo.getString(articlesVideosModel.CN_COVER)); | |
articlesVideosModel.setCover_retina(jsonObjectVideo.getString(articlesVideosModel.CN_COVER_RETINA)); | |
articlesVideosModel.setCover_width(jsonObjectVideo.getInt(articlesVideosModel.CN_COVER_WIDTH)); | |
articlesVideosModel.setCover_height(jsonObjectVideo.getInt(articlesVideosModel.CN_COVER_HEIGHT)); | |
articlesModel.setArticle_videos(articlesVideosModel); | |
} | |
this.mData.add(articlesModel); | |
} | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
this.mAdapter.notifyDataSetChanged(); | |
this.PBLoadData.setVisibility(View.INVISIBLE); | |
this.mGridView.setVisibility(View.VISIBLE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment