// 根据用户的id,获得用户的所有电影
 public ArrayList<MovieInfo> getMovieByUserId(long userID) {
   ArrayList<MovieInfo> movieList = new ArrayList<MovieInfo>();
   try {
     String sql =
         "select m.name,m.published_year,m.type,mp.preference from movie_preferences mp,movies m where mp.movieID=m.id and mp.userID="
             + userID
             + " order by preference desc";
     conn = ConnectToMySQL.getConnection();
     ps = conn.prepareStatement(sql);
     rs = ps.executeQuery();
     while (rs.next()) {
       MovieInfo movieInfo = new MovieInfo();
       movieInfo.setName(rs.getString(1));
       movieInfo.setPublishedYear(rs.getString(2));
       movieInfo.setType(rs.getString(3));
       movieInfo.setPreference(rs.getInt(4));
       movieList.add(movieInfo);
     }
   } catch (Exception e) {
     // TODO: handle exception
     e.printStackTrace();
   } finally {
     closeAll();
   }
   return movieList;
 }
 // 根据推荐的movie的ID,获得movie的详细信息
 public ArrayList<MovieInfo> getMovieByMovieId(List<RecommendedItem> recommendations) {
   ArrayList<MovieInfo> movieList = new ArrayList<MovieInfo>();
   try {
     String sql = "";
     conn = ConnectToMySQL.getConnection();
     for (int i = 0; i < recommendations.size(); i++) {
       sql =
           "select m.name,m.published_year,m.type from movies m where m.id="
               + recommendations.get(i).getItemID()
               + "";
       ps = conn.prepareStatement(sql);
       rs = ps.executeQuery();
       while (rs.next()) {
         MovieInfo movieInfo = new MovieInfo();
         movieInfo.setName(rs.getString(1));
         movieInfo.setPublishedYear(rs.getString(2));
         movieInfo.setType(rs.getString(3));
         movieInfo.setPreference(recommendations.get(i).getValue());
         movieList.add(movieInfo);
       }
     }
   } catch (Exception e) {
     // TODO: handle exception
     e.printStackTrace();
   } finally {
     closeAll();
   }
   return movieList;
 }
예제 #3
0
 @Override
 public void synchronizeMovie(String movieId, List<MovieInfo> movieInfoList) {
   Movie movie = this.entityManager.find(MovieImpl.class, movieId);
   if (movie != null) {
     List<? extends MovieInfo> existMovieInfoList = movie.getInfo();
     loop:
     for (MovieInfo movieInfo : movieInfoList) {
       if (existMovieInfoList != null && !existMovieInfoList.isEmpty()) {
         for (MovieInfo existMovieInfo : existMovieInfoList) {
           if (existMovieInfo.getProviderName().equalsIgnoreCase(movieInfo.getProviderName())) {
             continue loop;
           }
         }
       }
       // Not exist in databased
       movie.addInfo(movieInfo);
     }
     this.entityManager.merge(movie);
   }
 }
  // 根据推荐的movie的ID,获得movie的详细信息
  public ArrayList<MovieInfo> getMovieByMovieId(int id) {
    ArrayList<MovieInfo> movieList = new ArrayList<MovieInfo>();
    try {
      conn = ConnectToMySQL.getConnection();
      String sql = "select m.name,m.published_year,m.type from movies m where m.id=" + id + "";
      ps = conn.prepareStatement(sql);
      rs = ps.executeQuery();
      while (rs.next()) {
        MovieInfo movieInfo = new MovieInfo();
        movieInfo.setName(rs.getString(1));
        movieInfo.setPublishedYear(rs.getString(2));
        movieInfo.setType(rs.getString(3));
        movieInfo.setPreference(5.0);
        movieList.add(movieInfo);
      }

    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
    } finally {
      closeAll();
    }
    return movieList;
  }
  @Override
  protected List<MovieInfo> doInBackground(String... params) {
    // Decode sorting preference from param[0]
    String sortby =
        (params[0].equals(associatedAdapter.getContext().getString(R.string.pref_sort_popular))
            ? "popularity.desc"
            : params[0].equals(associatedAdapter.getContext().getString(R.string.pref_sort_rating))
                ? "vote_average.desc"
                : "");

    List<MovieInfo> movieInfos = null;
    try {
      // Build URI for querying TheMovieDB
      Uri builtUri =
          Uri.parse(TMDB_BASE_URL)
              .buildUpon()
              .appendPath(TMDB_DISCOVER_PARAM1)
              .appendPath(TMDB_DISCOVER_PARAM2)
              .appendQueryParameter(TMDB_SORT, sortby)
              .appendQueryParameter(TMDB_KEY, MY_KEY)
              .build();
      URL url = new URL(builtUri.toString());
      // Log.v(LOG_TAG, "TMDB movie info url: " + url.toString());

      // Call TMDB
      String jsonString = doCallJson(url);

      // Loop through result and populate movie info
      movieInfos = new ArrayList<MovieInfo>();
      JSONObject json = new JSONObject(jsonString);
      JSONArray jArray = json.getJSONArray("results");
      for (int i = 0; i < jArray.length(); i++) {
        JSONObject oneMovie = jArray.getJSONObject(i);

        MovieInfo movieInfo = new MovieInfo();
        movieInfo.imageUrl = TMDB_IMAGE_URL + oneMovie.getString("poster_path");
        movieInfo.originalTitle = ensureGoodString(oneMovie.getString("original_title"));
        movieInfo.plotSynopsis = ensureGoodString(oneMovie.getString("overview"));
        movieInfo.rating = ensureGoodString(oneMovie.getString("vote_average"));
        movieInfo.releaseDate = ensureGoodString(oneMovie.getString("release_date"));

        movieInfos.add(movieInfo);

        // Log.v(LOG_TAG, "Added movie: " + movieInfo.originalTitle);
      }
    } catch (Exception e) {
      Log.e(LOG_TAG, "Error", e);
    }
    return movieInfos;
  }
예제 #6
0
 @Override
 public int compareTo(final MovieInfo otherMovieInfo) {
   return getTitle().compareTo(otherMovieInfo.getTitle());
 }