Esempio n. 1
0
 @Test
 public void testAddOtherStaffMember() throws Exception {
   Responsible toAdd = RESPONSIBLE_FACTORY.getNext();
   otherStaffMembers.add(toAdd);
   entity.addOtherStaffMember(toAdd);
   assertEquals(otherStaffMembers, entity.getOtherStaffMembers());
 }
Esempio n. 2
0
 @Test
 public void testAddScenarist() throws Exception {
   Responsible toAdd = RESPONSIBLE_FACTORY.getNext();
   scenarists.add(toAdd);
   entity.addScenarist(toAdd);
   assertEquals(scenarists, entity.getScenarists());
 }
Esempio n. 3
0
  public boolean modifierVideo(
      String oldTitre,
      String titre,
      int annee,
      int eval,
      boolean type,
      String comments,
      String categories) {
    ArrayList<String> arrayCategories = liste.obtenirCles();
    Video video;
    try {
      video = new Video(titre, annee, eval, type);
    } catch (Exception ex) {
      this.messageErreur(ex.getMessage());
      return false;
    }

    video.setCommentaires(comments);

    Video oldVideo = obtenirVideo(oldTitre);

    int indexOfVideo;

    boolean confirmation = false;

    for (String categorie : arrayCategories) {
      indexOfVideo = liste.obtenirIndex(categorie, oldVideo);
      if (indexOfVideo >= 0) {
        confirmation = liste.modifier(categorie, video, indexOfVideo);
      }
    }
    modeModification();
    return confirmation;
  }
Esempio n. 4
0
 @Test
 public void testAddDirector() throws Exception {
   Responsible toAdd = RESPONSIBLE_FACTORY.getNext();
   directors.add(toAdd);
   entity.addDirector(toAdd);
   assertEquals(directors, entity.getDirectors());
 }
Esempio n. 5
0
  // Mode modification
  public void modeModification() {
    resetCollection();
    loadCollection();
    resetCategorie();
    loadCategorie();
    comboCollection.setEnabled(true);

    textTitre.setVisible(true);
    textTitre.setEnabled(true);
    textTitre.setEditable(true);

    textAnnee.setVisible(true);
    textAnnee.setEnabled(true);
    textAnnee.setEditable(true);

    comboType.setVisible(true);
    comboType.setEnabled(true);

    comboEval.setVisible(true);
    comboEval.setEnabled(true);

    scrollCom.setEnabled(true);
    scrollCat.setEnabled(true);

    textCommentaires.setEnabled(true);
    textCommentaires.setEditable(true);
    textCommentaires.setBackground(Color.WHITE);
    textCommentaires.setText("");

    textCategories.setEnabled(true);
    textCategories.setEditable(false);
    textCategories.setBackground(GRIS);
    textCategories.setText("");

    for (int i = 0; i < infos_film.length; i++) {
      infos_film[i].setVisible(false);
    }

    for (int k = 0; k < modeButton.length; k++) {
      modeButton[k].setEnabled(false);
      modeButton[k].setVisible(false);
    }

    modeButton[3].setVisible(true); // Boutton Modifier
    modeButton[4].setVisible(true); // Boutton Supprimer
    boolean enabled = true;
    if (listeEstVide()) {
      enabled = false;
    }
    modeButton[3].setEnabled(enabled);
    modeButton[4].setEnabled(enabled);

    optionCategories[0].setEnabled(true); // Boutton ajouter categorie
    optionCategories[1].setEnabled(true);

    // Place the first element of combobox in the grid
    comboCollection.setSelectedIndex(0);
    Video video = this.obtenirVideo(comboCollection.getSelectedItem().toString());
    afficherFilmChoisis(video.getTitre());
  }
Esempio n. 6
0
 @Test
 public void testAddActor() throws Exception {
   Role toAdd = ROLE_FACTORY.getNext();
   actors.add(toAdd);
   entity.addActor(toAdd);
   assertEquals(actors, entity.getActors());
 }
Esempio n. 7
0
  // Big bunch of AJOUTS
  public boolean ajouterVideo(
      String titre, int annee, boolean type, int eval, String comments, String categories) {
    try {
      // Creer un objet video avec TITRE ANNEE TYPE EVAL COMMENTS
      Video video = new Video(titre, annee, eval, type);
      video.setCommentaires(comments);

      String[] arrayCategories = categories.split(System.getProperty("line.separator"));

      boolean confirmation = false;

      // Ajouter cette video dans toutes les categories
      for (String categorie : arrayCategories) {
        confirmation = liste.ajouter(categorie, video);
      }
      if (confirmation) {
        JOptionPane.showMessageDialog(fenetre, video.getTitre() + " ajouté à la liste!");
        return true;
      } else {
        JOptionPane.showMessageDialog(
            fenetre, video.getTitre() + " n'a pas été ajouté à la liste!");
        return false;
      }
    } catch (Exception ex) {
      this.messageErreur(ex.getMessage());
      return false;
    }
  }
Esempio n. 8
0
 @Test
 public void testAddProducer() throws Exception {
   Responsible toAdd = RESPONSIBLE_FACTORY.getNext();
   producers.add(toAdd);
   entity.addProducer(toAdd);
   assertEquals(producers, entity.getProducers());
 }
Esempio n. 9
0
  // Mode consultation
  public void modeConsultation() {
    resetCollection();
    loadCollection();
    comboCollection.setEnabled(true);

    textTitre.setVisible(false);
    textTitre.setEditable(false);
    textAnnee.setVisible(false);
    textAnnee.setEditable(false);
    comboType.setVisible(false);
    comboType.setEnabled(false);
    comboEval.setVisible(false);
    comboEval.setEnabled(false);

    // Juste au cas que ca foire
    scrollCom.setEnabled(true);
    scrollCat.setEnabled(true);

    textCommentaires.setEnabled(true);
    textCommentaires.setEditable(false);
    textCategories.setEnabled(true);
    textCategories.setEditable(false);

    textCommentaires.setBackground(GRIS);
    textCategories.setBackground(GRIS);

    for (int k = 0; k < infos_film.length; k++) {
      infos_film[k].setVisible(true);
    }

    // Place the first element of combobox in the grid DEPRECATED by Enoncé
    comboCollection.setSelectedIndex(comboCollection.getSelectedIndex());

    for (int l = 0; l < modeButton.length; l++) {
      if (l < 2) {
        modeButton[0].setEnabled(false);
        modeButton[0].setVisible(true);
        if (comboCollection.getItemCount() > 1) {
          modeButton[l].setEnabled(true);
          modeButton[l].setVisible(true);
        } else {
          modeButton[l].setEnabled(false);
          modeButton[l].setVisible(true);
        }
        // modeButton[l].setEnabled(true);
        // modeButton[l].setVisible(true);
      } else {
        modeButton[l].setEnabled(false);
        modeButton[l].setVisible(false);
      }
    }
    optionCategories[0].setEnabled(false);
    optionCategories[1].setEnabled(false);

    // Get the collection and place in combobox

    Video video = this.obtenirVideo(comboCollection.getSelectedItem().toString());
    afficherFilmChoisis(video.getTitre());
  }
Esempio n. 10
0
  @Test
  public void testRemoveComposer() throws Exception {
    Responsible toRemove = entity.getComposers().iterator().next();
    composers.remove(toRemove);
    entity.removeComposer(toRemove);

    assertEquals(composers, entity.getComposers());
  }
Esempio n. 11
0
  @Test
  public void testRemoveDirector() throws Exception {
    Responsible toRemove = entity.getDirectors().iterator().next();
    directors.remove(toRemove);
    entity.removeDirector(toRemove);

    assertEquals(directors, entity.getDirectors());
  }
Esempio n. 12
0
  @Test
  public void testRemoveOtherStaffMember() throws Exception {
    Responsible toRemove = entity.getOtherStaffMembers().iterator().next();
    otherStaffMembers.remove(toRemove);
    entity.removeOtherStaffMember(toRemove);

    assertEquals(otherStaffMembers, entity.getOtherStaffMembers());
  }
Esempio n. 13
0
  @Test
  public void testRemoveRole() throws Exception {
    Role toRemove = entity.getActors().iterator().next();
    actors.remove(toRemove);
    entity.removeRole(toRemove.getRole());

    assertEquals(actors, entity.getActors());
  }
Esempio n. 14
0
  @Test
  public void testRemoveScenarist() throws Exception {
    Responsible toRemove = entity.getScenarists().iterator().next();
    scenarists.remove(toRemove);
    entity.removeScenarist(toRemove);

    assertEquals(scenarists, entity.getScenarists());
  }
Esempio n. 15
0
 public static Video wrap(VideoElement e) {
   assert Document.get().getBody().isOrHasChild(e);
   Video v = new Video(e);
   v.maybeInitMediaEvents();
   // The two lines below seems to be good practice to avoid memory leaks...
   v.onAttach();
   RootPanel.detachOnWindowClose(v);
   return v;
 }
Esempio n. 16
0
 /** Mark videos as viewed if they are listed in {@code mViewedVideosIds}. */
 private void markVideosAsViewed() {
   if (mVideos == null || mViewedVideosIds == null) {
     return;
   }
   for (Video video : mVideos) {
     if (mViewedVideosIds.contains(video.getId())) {
       video.setAlreadyPlayed(true);
     }
   }
 }
Esempio n. 17
0
  @Test
  public void testAddAllProducers() throws Exception {
    Collection<Responsible> toAdd = new HashSet<>();
    toAdd.add(RESPONSIBLE_FACTORY.getNext());
    toAdd.add(RESPONSIBLE_FACTORY.getNext());
    toAdd.add(RESPONSIBLE_FACTORY.getNext());

    producers.addAll(toAdd);
    entity.addAllProducers(toAdd);
    assertEquals(producers, entity.getProducers());
  }
Esempio n. 18
0
  @Test
  public void testAddAllActors() throws Exception {
    Collection<Role> toAdd = new HashSet<>();
    toAdd.add(ROLE_FACTORY.getNext());
    toAdd.add(ROLE_FACTORY.getNext());
    toAdd.add(ROLE_FACTORY.getNext());

    actors.addAll(toAdd);
    entity.addAllActors(toAdd);
    assertEquals(actors, entity.getActors());
  }
Esempio n. 19
0
  @Test
  public void testAddAllScenarists() throws Exception {
    Collection<Responsible> toAdd = new HashSet<>();
    toAdd.add(RESPONSIBLE_FACTORY.getNext());
    toAdd.add(RESPONSIBLE_FACTORY.getNext());
    toAdd.add(RESPONSIBLE_FACTORY.getNext());

    scenarists.addAll(toAdd);
    entity.addAllScenarists(toAdd);
    assertEquals(scenarists, entity.getScenarists());
  }
Esempio n. 20
0
  public void charger() throws Exception {
    String PATH = "./videos.txt";

    ArrayList<String> stringVideos = new ArrayList();

    // Regex
    String pattern = "\\[(.*?)\\]";
    String backupPattern = "/\\\\[(.*?)\\\\]/";

    Pattern r = Pattern.compile(pattern);

    String line = null;

    try {
      BufferedReader bufferedReader = new BufferedReader(new FileReader(PATH));

      while ((line = bufferedReader.readLine()) != null) {
        line = line.replace("[*]", "\n");
        stringVideos.add(line);
      }
      bufferedReader.close();
    } catch (FileNotFoundException ex) {
      this.messageErreurFatale(ex.getMessage());
    } catch (IOException ex) {
      this.messageErreurFatale(ex.getMessage());
    }

    for (String stringer : stringVideos) {
      String[] elements = stringer.split("::");
      String titre = elements[0];
      int annee = Integer.parseInt(elements[1]);
      boolean type = false;

      if (elements[2] /*.toString()*/.equals("FILM")) {
        type = true;
      } else if (elements[2] /*.toString()*/.equals("SÉRIE TV")) {
        type = false;
      } else {
        this.messageErreur("ERREUR TYPE");
      }
      int eval = Integer.parseInt(elements[3]);
      String commentaires = elements[4];
      Video video = new Video(titre, annee, eval, type);
      video.setCommentaires(commentaires);
      for (int i = 5; i < elements.length; i++) {
        liste.ajouter(elements[i], video);
      }
    }
  }
  /**
   * Get a the appropriate Token for a given URL
   *
   * @param text the anchor text
   * @param url the url
   */
  public static Token tokenForUrl(String url, String text) {
    if (url == null) {
      return null;
    }

    // Look for video links
    Video video = Video.matchURL(url, text);
    if (video != null) {
      return video;
    }

    // Look for video links.
    YouTubeVideo ytVideo = YouTubeVideo.matchURL(url, text);
    if (ytVideo != null) {
      return ytVideo;
    }

    // Look for photo links.
    Photo photo = Photo.matchURL(url, text);
    if (photo != null) {
      return photo;
    }

    // Look for photo links.
    FlickrPhoto flickrPhoto = FlickrPhoto.matchURL(url, text);
    if (flickrPhoto != null) {
      return flickrPhoto;
    }

    // Not media, so must be a regular URL
    return new Link(url, text);
  }
Esempio n. 22
0
  // Obtenir une video
  public Video obtenirVideo(String titre) {
    // Obtenir la video en naviguant dans les categories
    Video video = null;
    ArrayList categories = liste.obtenirCles();

    for (Object categorie : categories) {
      ArrayList<Video> videosOfCategorie = liste.obtenirElements((String) categorie);

      for (Video vid : videosOfCategorie) {
        Video temp = (Video) vid;
        if (temp.getTitre().equals(titre)) {
          video = temp;
        }
      }
    }

    // Return
    return video;
  }
Esempio n. 23
0
  @Test
  public void testRemoveAllProducers() throws Exception {
    Responsible base = RESPONSIBLE_FACTORY.getNext();
    Responsible second = RESPONSIBLE_FACTORY.getNext();
    Responsible third = RESPONSIBLE_FACTORY.getNext();

    Collection<Responsible> toAdd = new HashSet<>();
    toAdd.add(base);
    toAdd.add(second);
    toAdd.add(third);

    Collection<Responsible> toRemove = new HashSet<>();
    toRemove.add(second);
    toRemove.add(third);

    producers.addAll(toAdd);
    entity.addAllProducers(toAdd);

    producers.removeAll(toRemove);
    entity.removeAllProducers(toRemove);

    assertEquals(producers, entity.getProducers());
  }
Esempio n. 24
0
  @Test
  public void testRemoveAllActors() throws Exception {
    Role base = ROLE_FACTORY.getNext();
    Role second = ROLE_FACTORY.getNext();
    Role third = ROLE_FACTORY.getNext();

    Collection<Role> toAdd = new HashSet<>();
    toAdd.add(base);
    toAdd.add(second);
    toAdd.add(third);

    Collection<Role> toRemove = new HashSet<>();
    toRemove.add(second);
    toRemove.add(third);

    actors.addAll(toAdd);
    entity.addAllActors(toAdd);

    actors.removeAll(toRemove);
    entity.removeAllActors(toRemove);

    assertEquals(actors, entity.getActors());
  }
 @Override
 public void onBackPressed() {
   try {
     //			AppMap.DownloadBannerData.bannerEnabled="false";
   } catch (Exception e) {
     // TODO: handle exception
   }
   try {
     Video.setClickableVideo(true);
     Video.backgroungLayout.setVisibility(View.VISIBLE);
   } catch (Exception e) {
     // TODO: handle exception
   }
   finish();
 }
Esempio n. 26
0
 @Before
 public void setUp() throws Exception {
   entity = FACTORY.getNext();
   actors = entity.getActors();
   producers = entity.getProducers();
   directors = entity.getDirectors();
   composers = entity.getComposers();
   scenarists = entity.getScenarists();
   otherStaffMembers = entity.getOtherStaffMembers();
 }
Esempio n. 27
0
  public void sauvegarder() {
    final String PATH = "./videos.txt";
    File fichier = new File(PATH);
    String formatDeSortie = "";

    for (Video video : this.obtenirCollection()) {
      String catos = this.obtenirCategoriesEnString(video.getTitre());
      catos = catos.replace("\n", "::");
      String comments = video.getCommentaires();
      comments = comments.replace("\n", "[*]");

      formatDeSortie += video.getTitre() + "::";
      formatDeSortie += video.getAnnee() + "::";
      if (video.isFilm()) {
        formatDeSortie += "FILM" + "::";
      } else {
        formatDeSortie += "SÉRIE TV" + "::";
      }
      formatDeSortie += video.getEval() + "::";

      formatDeSortie += comments; // Comments

      formatDeSortie += "::";

      formatDeSortie += catos; // Catos
      formatDeSortie += "\r\n"; // Petit fix pour que les new lines append au fichier txt
    }

    formatDeSortie = formatDeSortie.substring(0, formatDeSortie.length() - 1);

    try {
      FileWriter ecrivain = new FileWriter(fichier);
      ecrivain.write(formatDeSortie);
      ecrivain.close();
    } catch (IOException io) {
      io.getMessage();
    }
  }
Esempio n. 28
0
  private static Video parseVideo(JSONObject jVideo) throws JSONException {
    Video video = new Video();

    try {
      JSONArray jEncodings = jVideo.getJSONArray("encodings");

      int numEncodings = jEncodings.length();
      for (int i = 0; i < numEncodings; i++) {
        video.addEncoding(parseVideoEncoding(jEncodings.getJSONObject(i)));
      }

      video.setHeight(jVideo.getInt("width"));
      video.setWidth(jVideo.getInt("height"));
      video.setDuration(jVideo.getInt("duration"));
      video.setFilename(jVideo.getString("filename"));
      video.setThumbnail(parseVideoThumbnail(jVideo.getJSONObject("image")));

    } catch (JSONException e) {
      e.printStackTrace();
      Log.e("JSONHelper parseVideo", "Error parsing video API response");
    }

    return video;
  }
Esempio n. 29
0
 public static Notification parse(JSONObject o) {
   Notification n = null;
   try {
     n = new Notification();
     n.type = o.getString("type");
     n.date = o.optLong("date");
     if (n.type.equals(FOLLOW)) {
       JSONObject jfeedback = o.optJSONObject("feedback"); // profiles
       n.parent = null; // empty
       if (jfeedback != null) n.feedback = getProfiles(jfeedback);
     } else if (n.type.equals(FRIEND_ACCEPTED)) {
       JSONObject jfeedback = o.optJSONObject("feedback"); // profiles
       n.parent = null; // empty
       if (jfeedback != null) n.feedback = getProfiles(jfeedback);
     } else if (n.type.equals(MENTION)) {
       JSONObject jfeedback = o.optJSONObject("feedback"); // post
       n.parent = null; // empty
       if (jfeedback != null) n.feedback = WallMessage.parseForNotifications(jfeedback);
     } else if (n.type.equals(MENTION_COMMENTS)) {
       JSONObject jparent = o.optJSONObject("parent"); // post
       JSONObject jfeedback = o.optJSONObject("feedback"); // comment
       if (jparent != null) n.parent = WallMessage.parse(jparent);
       if (jfeedback != null) n.feedback = Comment.parseNotificationComment(jfeedback, false);
     } else if (n.type.equals(WALL)) {
       JSONObject jfeedback = o.optJSONObject("feedback"); // post
       if (jfeedback != null) n.feedback = WallMessage.parseForNotifications(jfeedback);
     } else if (n.type.equals(COMMENT_POST)) {
       JSONObject jparent = o.optJSONObject("parent"); // post
       JSONObject jfeedback = o.optJSONObject("feedback"); // comment
       if (jparent != null) n.parent = WallMessage.parse(jparent);
       if (jfeedback != null) n.feedback = Comment.parseNotificationComment(jfeedback, false);
     } else if (n.type.equals(COMMENT_PHOTO)) {
       JSONObject jparent = o.optJSONObject("parent"); // photo
       JSONObject jfeedback = o.optJSONObject("feedback"); // comment
       if (jparent != null) n.parent = Photo.parse(jparent);
       if (jfeedback != null) n.feedback = Comment.parseNotificationComment(jfeedback, false);
     } else if (n.type.equals(COMMENT_VIDEO)) {
       JSONObject jparent = o.optJSONObject("parent"); // video
       JSONObject jfeedback = o.optJSONObject("feedback"); // comment
       if (jparent != null) n.parent = Video.parse(jparent);
       if (jfeedback != null) n.feedback = Comment.parseNotificationComment(jfeedback, false);
     } else if (n.type.equals(REPLY_COMMENT)) {
       JSONObject jparent = o.optJSONObject("parent"); // comment
       JSONObject jfeedback = o.optJSONObject("feedback"); // comment
       if (jparent != null) n.parent = Comment.parseNotificationComment(jparent, true);
       if (jfeedback != null) n.feedback = Comment.parseNotificationComment(jfeedback, false);
     } else if (n.type.equals(REPLY_COMMENT_PHOTO)) {
       JSONObject jparent = o.optJSONObject("parent"); // comment
       JSONObject jfeedback = o.optJSONObject("feedback"); // comment
       if (jparent != null) {
         n.parent = Comment.parseNotificationComment(jparent, false);
         if (jparent.has("photo")) n.photo = Photo.parse(jparent.optJSONObject("photo"));
       }
       if (jfeedback != null) n.feedback = Comment.parseNotificationComment(jfeedback, false);
     } else if (n.type.equals(REPLY_COMMENT_VIDEO)) {
       JSONObject jparent = o.optJSONObject("parent"); // comment
       JSONObject jfeedback = o.optJSONObject("feedback"); // comment
       if (jparent != null) {
         n.parent = Comment.parseNotificationComment(jparent, false);
         if (jparent.has("video")) n.video = Video.parse(jparent.optJSONObject("video"));
       }
       if (jfeedback != null) n.feedback = Comment.parseNotificationComment(jfeedback, false);
     } else if (n.type.equals(REPLY_TOPIC)) {
       JSONObject jparent = o.optJSONObject("parent"); // topic
       JSONObject jfeedback = o.optJSONObject("feedback"); // comment
       if (jparent != null) n.parent = GroupTopic.parseForNotifications(jparent);
       if (jfeedback != null) n.feedback = Comment.parseNotificationComment(jfeedback, false);
     } else if (n.type.equals(LIKE_POST)) {
       JSONObject jparent = o.optJSONObject("parent"); // post
       JSONObject jfeedback = o.optJSONObject("feedback"); // profiles
       if (jparent != null) n.parent = WallMessage.parse(jparent);
       if (jfeedback != null) n.feedback = getProfiles(jfeedback);
     } else if (n.type.equals(LIKE_COMMENT)) {
       JSONObject jparent = o.optJSONObject("parent"); // comment
       JSONObject jfeedback = o.optJSONObject("feedback"); // profiles
       if (jparent != null) n.parent = Comment.parseNotificationComment(jparent, true);
       if (jfeedback != null) n.feedback = getProfiles(jfeedback);
     } else if (n.type.equals(LIKE_COMMENT_PHOTO)) {
       JSONObject jparent = o.optJSONObject("parent"); // comment
       JSONObject jfeedback = o.optJSONObject("feedback"); // profiles
       if (jparent != null) {
         n.parent = Comment.parseNotificationComment(jparent, false);
         if (jparent.has("photo")) n.photo = Photo.parse(jparent.optJSONObject("photo"));
       }
       if (jfeedback != null) n.feedback = getProfiles(jfeedback);
     } else if (n.type.equals(LIKE_COMMENT_VIDEO)) {
       JSONObject jparent = o.optJSONObject("parent"); // comment
       JSONObject jfeedback = o.optJSONObject("feedback"); // profiles
       if (jparent != null) {
         n.parent = Comment.parseNotificationComment(jparent, false);
         if (jparent.has("video")) n.video = Video.parse(jparent.optJSONObject("video"));
       }
       if (jfeedback != null) n.feedback = getProfiles(jfeedback);
     } else if (n.type.equals(LIKE_COMMENT_TOPIC)) {
       JSONObject jparent = o.optJSONObject("parent"); // comment
       JSONObject jfeedback = o.optJSONObject("feedback"); // profiles
       if (jparent != null) {
         n.parent = Comment.parseNotificationComment(jparent, false);
         // TODO
         // if(jparent.has("topic"))
         //    n.xxx=Xxx.parse(jparent.optJSONObject("topic"));
       }
       if (jfeedback != null) n.feedback = getProfiles(jfeedback);
     } else if (n.type.equals(LIKE_PHOTO)) {
       JSONObject jparent = o.optJSONObject("parent"); // photo
       JSONObject jfeedback = o.optJSONObject("feedback"); // profiles
       if (jparent != null) n.parent = Photo.parse(jparent);
       if (jfeedback != null) n.feedback = getProfiles(jfeedback);
     } else if (n.type.equals(LIKE_VIDEO)) {
       JSONObject jparent = o.optJSONObject("parent"); // video
       JSONObject jfeedback = o.optJSONObject("feedback"); // profiles
       if (jparent != null) n.parent = Video.parse(jparent);
       if (jfeedback != null) n.feedback = getProfiles(jfeedback);
     } else if (n.type.equals(COPY_POST)) {
       JSONObject jparent = o.optJSONObject("parent"); // wall
       JSONObject jfeedback = o.optJSONObject("feedback"); // copy
       if (jparent != null) n.parent = WallMessage.parse(jparent);
       if (jfeedback != null) n.feedback = getCopies(jfeedback);
     } else if (n.type.equals(COPY_PHOTO)) {
       JSONObject jparent = o.optJSONObject("parent"); // photo
       JSONObject jfeedback = o.optJSONObject("feedback"); // copy
       if (jparent != null) n.parent = Photo.parse(jparent);
       if (jfeedback != null) n.feedback = getCopies(jfeedback);
     } else if (n.type.equals(COPY_VIDEO)) {
       JSONObject jparent = o.optJSONObject("parent"); // video
       JSONObject jfeedback = o.optJSONObject("feedback"); // copy
       if (jparent != null) n.parent = Video.parse(jparent);
       if (jfeedback != null) n.feedback = getCopies(jfeedback);
     }
     JSONObject jreply = o.optJSONObject("reply");
     if (jreply != null) n.reply = Reply.parse(jreply);
   } catch (JSONException ex) {
     ex.printStackTrace();
     return null;
   }
   return n;
 }
Esempio n. 30
0
  public static Post getPostFromJsonObject(JSONObject jsonObject) {
    Post post = null;
    try {
      Post tmpPost = new Post();

      tmpPost.setId(jsonObject.getString(InstagramAPI.RESPONSE_KEYWORD_POST_ID));

      JSONObject imagesJsonObject =
          jsonObject.optJSONObject(InstagramAPI.RESPONSE_KEYWORD_POST_IMAGES);

      JSONObject lowResolutionImageJsonObject =
          imagesJsonObject.optJSONObject(InstagramAPI.RESPONSE_KEYWORD_POST_IMAGES_LOW_RESOLUTION);
      if (lowResolutionImageJsonObject != null) {
        Image lowResolutionImage = Image.getImageFromJsonObject(lowResolutionImageJsonObject);

        if (lowResolutionImage != null) {
          tmpPost.setLowResolutionImage(lowResolutionImage);
        }
      }

      JSONObject thumbnailImageJsonObject =
          imagesJsonObject.optJSONObject(InstagramAPI.RESPONSE_KEYWORD_POST_IMAGES_THUMBNAIL);
      if (thumbnailImageJsonObject != null) {
        Image thumbnailImage = Image.getImageFromJsonObject(thumbnailImageJsonObject);

        if (thumbnailImage != null) {
          tmpPost.setThumbnailImage(thumbnailImage);
        }
      }

      JSONObject standardResolutionImageJsonObject =
          imagesJsonObject.optJSONObject(
              InstagramAPI.RESPONSE_KEYWORD_POST_IMAGES_STANDARD_RESOLUTION);
      if (standardResolutionImageJsonObject != null) {
        Image standardResolution = Image.getImageFromJsonObject(standardResolutionImageJsonObject);

        if (standardResolution != null) {
          tmpPost.setStandardResolutionImage(standardResolution);
        }
      }

      tmpPost.setCaption(
          Caption.getCaptionFromJSONObject(
              jsonObject.optJSONObject(InstagramAPI.RESPONSE_KEYWORD_POST_CAPTION)));

      User user =
          User.getUserFromJsonObject(
              jsonObject.getJSONObject(InstagramAPI.RESPONSE_KEYWORD_POST_USER));
      if (user != null) {
        tmpPost.setUser(user);
      }

      String createdTimeString =
          jsonObject.optString(InstagramAPI.RESPONSE_KEYWORD_POST_CREATED_TIME, "0");
      if (createdTimeString.length() <= 10) {
        createdTimeString = createdTimeString + "000";
      }
      long createdTime = Long.parseLong(createdTimeString);
      if (createdTime != 0) {
        tmpPost.setCreatedTime(createdTime);
      }

      String type = jsonObject.getString(InstagramAPI.RESPONSE_KEYWORD_POST_TYPE);
      if (type.equalsIgnoreCase(InstagramAPI.RESPONSE_KEYWORD_POST_TYPE_VALUE_IMAGE)) {
        tmpPost.setType(Type.IMAGE);
      } else if (type.equalsIgnoreCase(InstagramAPI.RESPONSE_KEYWORD_POST_TYPE_VALUE_VIDEO)) {
        tmpPost.setType(Type.VIDEO);
      }

      JSONObject videosJsonObject =
          jsonObject.optJSONObject(InstagramAPI.RESPONSE_KEYWORD_POST_VIDEOS);

      if (videosJsonObject != null) {

        JSONObject lowBandwidthVideoJsonObject =
            videosJsonObject.optJSONObject(InstagramAPI.RESPONSE_KEYWORD_POST_VIDEOS_LOW_BANDWIDTH);
        if (lowBandwidthVideoJsonObject != null) {
          Video lowBandwidthVideo = Video.getVideoFromJsonObject(lowBandwidthVideoJsonObject);

          if (lowBandwidthVideo != null) {
            tmpPost.setLowBandwidthVideo(lowBandwidthVideo);
          }
        }

        JSONObject lowResolutionVideoJsonObject =
            videosJsonObject.optJSONObject(
                InstagramAPI.RESPONSE_KEYWORD_POST_VIDEOS_LOW_RESOLUTION);
        if (lowResolutionVideoJsonObject != null) {
          Video lowResolutionVideo = Video.getVideoFromJsonObject(lowResolutionVideoJsonObject);

          if (lowResolutionVideo != null) {
            tmpPost.setLowResolutionVideo(lowResolutionVideo);
          }
        }

        JSONObject standardResolutionVideoJsonObject =
            videosJsonObject.optJSONObject(
                InstagramAPI.RESPONSE_KEYWORD_POST_VIDEOS_STANDARD_RESOLUTION);
        if (standardResolutionVideoJsonObject != null) {
          Video standardResolutionVideo =
              Video.getVideoFromJsonObject(standardResolutionVideoJsonObject);

          if (standardResolutionVideo != null) {
            tmpPost.setStandardResolutionVideo(standardResolutionVideo);
          }
        }
      }

      post = tmpPost;
    } catch (JSONException e) {
      e.printStackTrace();
    }

    return post;
  }