private void getDataFromJson(String MovieJsonStr) throws JSONException { JSONObject MoviesJson = new JSONObject(MovieJsonStr); JSONArray ResultArray = MoviesJson.getJSONArray("results"); for (int i = 0; i < ResultArray.length(); i++) { JSONObject movieTemp = ResultArray.getJSONObject(i); String poster_attr = movieTemp.getString("poster_path"); if (!poster_attr.equals("null")) { String original_title = movieTemp.getString("original_title"); String overview = movieTemp.getString("overview"); Double vote_average = movieTemp.getDouble("vote_average"); String release_date = movieTemp.getString("release_date"); Double movie_id = movieTemp.getDouble("id"); ContentValues MovieValue = new ContentValues(); MovieValue.put(MoviesContract.MoviesEntry.COLUMN_TITLE, original_title); MovieValue.put(MoviesContract.MoviesEntry.COLUMN_POSTER_ATTR, poster_attr); MovieValue.put(MoviesContract.MoviesEntry.COLUMN_OVERVIEW, overview); MovieValue.put(MoviesContract.MoviesEntry.COLUMN_VOTE_AVERAGE, vote_average); MovieValue.put(MoviesContract.MoviesEntry.COLUMN_RELEASE_DATE, release_date); MovieValue.put(MoviesContract.MoviesEntry.COLUMN_MOVIE_ID, movie_id); MovieValue.put(MoviesContract.MoviesEntry.COLUMN_SORT_INDEX, i + 1); Cursor Check = this.getContentResolver() .query( MoviesContract.MoviesEntry.buildMovieUri(movie_id.longValue()), null, null, null, null); Check.moveToFirst(); if (Check != null && Check.getCount() > 0) { this.getContentResolver() .update( MoviesContract.MoviesEntry.buildMovieUri(movie_id.longValue()), MovieValue, null, null); } else { MovieValue.put(MoviesContract.MoviesEntry.COLUMN_FAVOURITE, 0); this.getContentResolver().insert(MoviesContract.MoviesEntry.CONTENT_URI, MovieValue); } } } }
@Override protected void onPostExecute(int[] runTime) { if (runTime != null && runTime.length > 0) { RunTime.setText(runTime[0] + "min"); ContentValues MovieValue = new ContentValues(); MovieValue.put(MoviesContract.MoviesEntry.COLUMN_RUN_TIME, runTime[0]); MovieValue.put(MoviesContract.MoviesEntry.COLUMN_RUN_TIME, runTime[0]); int updated = getActivity() .getContentResolver() .update( MoviesContract.MoviesEntry.buildMovieUri(Long.valueOf(ID)), MovieValue, null, null); Log.v("updateeee", " " + updated); } }