Android Open Source - adventure.datetime Author Controller






From Project

Back to project page adventure.datetime.

License

The source code is released under:

MIT License

If you think the Android project adventure.datetime listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2013 Andrew Fontaine, James Finlay, Jesse Tucker, Jacob Viau, and
 * Evan DeGraff/*from w w  w .j a  v a  2s  .com*/
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


package ca.cmput301f13t03.adventure_datetime.controller;

import ca.cmput301f13t03.adventure_datetime.model.Interfaces.IStoryModelDirector;
import ca.cmput301f13t03.adventure_datetime.model.Story;
import ca.cmput301f13t03.adventure_datetime.model.StoryFragment;

import java.util.Collection;
import java.util.HashSet;
import java.util.UUID;

/**
 * Controller for aspects of authoring a story
 *
 * @author Evan DeGraff
 * @author Jesse Tucker
 */
public class AuthorController {
  
  private IStoryModelDirector m_storyDirector = null;

    /**
     * Constructor for the AuthorController
     *
     * @param director The director managing transactions with local and online storage
     */
  public AuthorController(IStoryModelDirector director) {
    m_storyDirector = director;
  }

    /**
     * Passes a new story created by the director to the view
     *
     * @return A new Story
     */
  public Story CreateStory()
  {
    return m_storyDirector.CreateNewStory();
  }
  
  public StoryFragment CreateFragment()
  {
    return m_storyDirector.CreateNewStoryFragment();
  }

    /**
     * Saves a story to the local storage
     * @return Whether or not the save was successful
     */
  public boolean saveStory() 
  {
    return m_storyDirector.SaveStory();
  }

    /**
     * Gets a story from the director
     *
     * @param storyId UUID of the Story to get
     *
     * @return The Story, if found. Null, otherwise.
     */
  public Story getStory(UUID storyId) {
    return m_storyDirector.getStory(storyId);
  }

    /**
     * Deletes a Story and all StoryFragments from local and online storage.
     *
     * @param storyId UUID of the story to delete
     */
  public void deleteStory(UUID storyId) {
    Story story = m_storyDirector.getStory(storyId);
    if (story == null) return;
    
    HashSet<UUID> fragments = story.getFragmentIds();

    for(UUID fragment : fragments) {
      deleteFragment(fragment);
    }

    m_storyDirector.deleteStory(storyId);
  }

    /**
     * Deletes a fragment from local or online storage
     *
     * @param fragmentId UUID of the fragment to delete
     */
  public void deleteFragment(UUID fragmentId) {
    m_storyDirector.deleteFragment(fragmentId);
  }

    public void deleteImage(UUID imageId) {
        m_storyDirector.deleteImage(imageId);
    }

    /**
     * Selects a Story from the local or online storage.
     *
     * @param storyId UUID of the story
     */
  public void selectStory(UUID storyId)
  {
    m_storyDirector.selectStory(storyId);
  }

    /**
     * Selects a StoryFragment from the local or online storage
     *
     * @param fragmentId UUID of the fragment
     */
  public void selectFragment(UUID fragmentId)
  {
    m_storyDirector.selectFragment(fragmentId);
  }
  /**
   * Uploads a story to the server
   */
  public void upload(){
    m_storyDirector.uploadCurrentStory();
  }
  
  /**
   * Changes a downloaded story to author mode
   * @param storyId
     * @param username The new author name
   */
  public void setStoryToAuthor(UUID storyId, String username) {
    m_storyDirector.setStoryToAuthor(storyId, username);
  }

  /**
   * Checks the list of stories to see if the user authored them
   * @param stories - list of stories to be checked
   * @return list of authored stories
   */
  public Collection<Story> checkIfAuthored(Collection<Story> stories) {
    Collection<Story> authoredStories = new HashSet<Story>();
    for(Story story : stories) {
      if(m_storyDirector.isAuthored(story.getId()))
        authoredStories.add(story);
    }
    return authoredStories;
  }

  /**
   * Checks the list of stories to see if the user didn't author them
   * @param stories - list of stories to be checked
   * @return list of non-authored stories
   */
  public Collection<Story> checkIfNotAuthored(Collection<Story> stories) {
    Collection<Story> authoredStories = new HashSet<Story>();
    for(Story story : stories) {
      if(!m_storyDirector.isAuthored(story.getId()))
        authoredStories.add(story);
    }
    return authoredStories;
  }

}




Java Source Code List

ca.cmput301f13t03.adventure_datetime.controller.AuthorControllerTest.java
ca.cmput301f13t03.adventure_datetime.controller.AuthorController.java
ca.cmput301f13t03.adventure_datetime.controller.UserControllerTest.java
ca.cmput301f13t03.adventure_datetime.controller.UserController.java
ca.cmput301f13t03.adventure_datetime.model.AccountServiceTests.java
ca.cmput301f13t03.adventure_datetime.model.AccountService.java
ca.cmput301f13t03.adventure_datetime.model.BookmarkTest.java
ca.cmput301f13t03.adventure_datetime.model.Bookmark.java
ca.cmput301f13t03.adventure_datetime.model.ChoiceTest.java
ca.cmput301f13t03.adventure_datetime.model.Choice.java
ca.cmput301f13t03.adventure_datetime.model.CommentTest.java
ca.cmput301f13t03.adventure_datetime.model.Comment.java
ca.cmput301f13t03.adventure_datetime.model.ES.java
ca.cmput301f13t03.adventure_datetime.model.ImageTest.java
ca.cmput301f13t03.adventure_datetime.model.Image.java
ca.cmput301f13t03.adventure_datetime.model.StoryDBTest.java
ca.cmput301f13t03.adventure_datetime.model.StoryDB.java
ca.cmput301f13t03.adventure_datetime.model.StoryFragmentTest.java
ca.cmput301f13t03.adventure_datetime.model.StoryFragment.java
ca.cmput301f13t03.adventure_datetime.model.StoryManager.java
ca.cmput301f13t03.adventure_datetime.model.StoryTest.java
ca.cmput301f13t03.adventure_datetime.model.Story.java
ca.cmput301f13t03.adventure_datetime.model.ThreadPool.java
ca.cmput301f13t03.adventure_datetime.model.WebStorageCleaner.java
ca.cmput301f13t03.adventure_datetime.model.WebStorageTest.java
ca.cmput301f13t03.adventure_datetime.model.WebStorage.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IAllFragmentsListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IBookmarkListListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ICommentsListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ICurrentFragmentListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ICurrentStoryListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ILocalStorage.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ILocalStoriesListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IOnlineStoriesListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IStoryModelDirector.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IStoryModelPresenter.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IWebStorage.java
ca.cmput301f13t03.adventure_datetime.serviceLocator.Locator.java
ca.cmput301f13t03.adventure_datetime.view.AuthorEdit_Edit.java
ca.cmput301f13t03.adventure_datetime.view.AuthorEdit_Overview.java
ca.cmput301f13t03.adventure_datetime.view.AuthorEdit.java
ca.cmput301f13t03.adventure_datetime.view.AuthorStories.java
ca.cmput301f13t03.adventure_datetime.view.AuthorStoryDescription.java
ca.cmput301f13t03.adventure_datetime.view.AuthorViewPager.java
ca.cmput301f13t03.adventure_datetime.view.BrowseFragment.java
ca.cmput301f13t03.adventure_datetime.view.BrowseView.java
ca.cmput301f13t03.adventure_datetime.view.CommentsView.java
ca.cmput301f13t03.adventure_datetime.view.ContinueView.java
ca.cmput301f13t03.adventure_datetime.view.FragmentViewActivity.java
ca.cmput301f13t03.adventure_datetime.view.FragmentView.java
ca.cmput301f13t03.adventure_datetime.view.FullScreen_Image.java
ca.cmput301f13t03.adventure_datetime.view.IFragmentSelected.java
ca.cmput301f13t03.adventure_datetime.view.MainViewTest.java
ca.cmput301f13t03.adventure_datetime.view.MainView.java
ca.cmput301f13t03.adventure_datetime.view.StoryDescription.java
ca.cmput301f13t03.adventure_datetime.view.treeView.Camera.java
ca.cmput301f13t03.adventure_datetime.view.treeView.ConnectionPlacer.java
ca.cmput301f13t03.adventure_datetime.view.treeView.FragmentConnection.java
ca.cmput301f13t03.adventure_datetime.view.treeView.FragmentNode.java
ca.cmput301f13t03.adventure_datetime.view.treeView.GridSegment.java
ca.cmput301f13t03.adventure_datetime.view.treeView.InputHandler.java
ca.cmput301f13t03.adventure_datetime.view.treeView.NodeGrid.java
ca.cmput301f13t03.adventure_datetime.view.treeView.NodePlacer.java
ca.cmput301f13t03.adventure_datetime.view.treeView.Region.java
ca.cmput301f13t03.adventure_datetime.view.treeView.TreeView.java