private boolean internalRemove(Object object) {
    if (mMedia.remove(object)) {
      if (object instanceof TextModel) {
        mText = null;
      } else if (object instanceof ImageModel) {
        mImage = null;
        mCanAddVideo = true;
      } else if (object instanceof AudioModel) {
        mAudio = null;
        mCanAddVideo = true;
      } else if (object instanceof VideoModel) {
        mVideo = null;
        mCanAddImage = true;
        mCanAddAudio = true;
      }
      // If the media is resizable, at this point consider it to be zero length.
      // Just before we send the slideshow, we take the remaining space in the
      // slideshow and equally allocate it to all the resizeable media items and resize them.
      int decreaseSize =
          ((MediaModel) object).getMediaResizable() ? 0 : ((MediaModel) object).getMediaSize();
      decreaseSlideSize(decreaseSize);
      decreaseMessageSize(decreaseSize);

      ((Model) object).unregisterAllModelChangedObservers();

      return true;
    }

    return false;
  }
  private void internalAddOrReplace(MediaModel old, MediaModel media) {
    // If the media is resizable, at this point consider it to be zero length.
    // Just before we send the slideshow, we take the remaining space in the
    // slideshow and equally allocate it to all the resizeable media items and resize them.
    int addSize = media.getMediaResizable() ? 0 : media.getMediaSize();
    int removeSize;
    if (old == null) {
      if (null != mParent) {
        mParent.checkMessageSize(addSize);
      }
      mMedia.add(media);
      increaseSlideSize(addSize);
      increaseMessageSize(addSize);
    } else {
      removeSize = old.getMediaResizable() ? 0 : old.getMediaSize();
      if (addSize > removeSize) {
        if (null != mParent) {
          mParent.checkMessageSize(addSize - removeSize);
        }
        increaseSlideSize(addSize - removeSize);
        increaseMessageSize(addSize - removeSize);
      } else {
        decreaseSlideSize(removeSize - addSize);
        decreaseMessageSize(removeSize - addSize);
      }
      mMedia.set(mMedia.indexOf(old), media);
      old.unregisterAllModelChangedObservers();
    }

    for (IModelChangedObserver observer : mModelChangedObservers) {
      media.registerModelChangedObserver(observer);
    }
  }
  public void clear() {
    if (mMedia.size() > 0) {
      for (MediaModel media : mMedia) {
        media.unregisterAllModelChangedObservers();
        int decreaseSize = media.getMediaSize();
        decreaseSlideSize(decreaseSize);
        decreaseMessageSize(decreaseSize);
      }
      mMedia.clear();

      mText = null;
      mImage = null;
      mAudio = null;
      mVideo = null;

      mCanAddImage = true;
      mCanAddAudio = true;
      mCanAddVideo = true;

      notifyModelChanged(true);
    }
  }