Changeset 85

Show
Ignore:
Timestamp:
12/23/07 00:02:28 (3 years ago)
Author:
chris
Message:

Completes #20: Saves the history file and clears submitted chunks
properly. These actions are now taking place after each chunk is
submitted.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/org/lastpod/ModelImpl.java

    r82 r85  
    158158            scrobbler.setChunkProgress(userInterface); 
    159159            scrobbler.setTracksToSubmit(activeRecentPlayed); 
     160            scrobbler.addInactiveToHistories(inactiveRecentPlayed); 
    160161            scrobbler.handshake(); 
    161162            scrobbler.submitTracks(); 
    162             scrobbler.addHistories(activeRecentPlayed, inactiveRecentPlayed); 
    163163 
    164164            /* Refresh track list. */ 
  • trunk/src/main/org/lastpod/Scrobbler.java

    r77 r85  
    272272                queryString += buildTrackQueryString(track, tracknum); 
    273273 
    274                 /* Unselect the submitted track. */ 
    275                 track.setActive(Boolean.FALSE); 
    276274                tracknum++; 
    277275            } 
     
    309307                throw new RuntimeException("Unknown error submitting tracks"); 
    310308            } 
     309 
     310            /* The chunk is successfully written to last.fm. Makes sure the 
     311             * tracks are marked as inactive.  Writes the history file. 
     312             * This is done after each chunk because if the next chunk fails 
     313             * the history file should reflect where the failure occurred. 
     314             */ 
     315            for (int j = 0; j < chunk.getChunkSize(); j++) { 
     316                TrackItem track = (TrackItem) chunk.getContent().get(j); 
     317                track.setActive(Boolean.FALSE); 
     318            } 
     319 
     320            addHistories(chunk.getContent()); 
    311321 
    312322            /* Add 2 to progress.  1 because chunk progress starts at 1, whereas 
     
    381391     * Creates the histories and writes them to a file. 
    382392     * @param activeRecentPlayed  The list of active recently played tracks. 
    383      * @param inactiveRecentPlayed  The list of inactive recently played tracks. 
    384      */ 
    385     public void addHistories(List activeRecentPlayed, List inactiveRecentPlayed) { 
     393     */ 
     394    public void addHistories(List activeRecentPlayed) { 
    386395        for (int i = 0; i < activeRecentPlayed.size(); i++) { 
    387396            TrackItem track = (TrackItem) activeRecentPlayed.get(i); 
     
    389398        } 
    390399 
     400        History.getInstance(null).write(); 
     401    } 
     402 
     403    /** 
     404     * Adds inactive recent played tracks to the histories file.  This is done 
     405     * so they will be preserved in the histories. 
     406     * @param inactiveRecentPlayed  The list of inactive recently played tracks. 
     407     */ 
     408    public void addInactiveToHistories(List inactiveRecentPlayed) { 
    391409        for (int i = 0; i < inactiveRecentPlayed.size(); i++) { 
    392410            TrackItem track = (TrackItem) inactiveRecentPlayed.get(i); 
     
    396414            } 
    397415        } 
    398  
    399         History.getInstance(null).write(); 
    400416    } 
    401417 
  • trunk/src/test/org/lastpod/MockModel.java

    r82 r85  
    213213 
    214214        Scrobbler scrobbler = new Scrobbler(null, null, null); 
    215         scrobbler.addHistories(activeRecentPlayed, inactiveRecentPlayed); 
     215        scrobbler.addInactiveToHistories(inactiveRecentPlayed); 
     216        scrobbler.addHistories(activeRecentPlayed); 
    216217        userInterface.setCompletionStatus(true); 
    217218