Changeset 61

Show
Ignore:
Timestamp:
05/19/07 22:23:58 (2 years ago)
Author:
chris
Message:

r7740@flan: chris
progress bar is now updated once the handshake is successful

Files:

Legend:

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

    r58 r61  
    139139            List activeRecentPlayed = onlyActiveTrackItems(recentplayed); 
    140140            List inactiveRecentPlayed = onlyInactiveTrackItems(recentplayed); 
    141             LastPod.scrobbler.handshake(activeRecentPlayed); 
    142             LastPod.scrobbler.submitTracks(activeRecentPlayed, LastPod.UI); 
     141 
     142            LastPod.scrobbler.setChunkProgress(LastPod.UI); 
     143            LastPod.scrobbler.setTracksToSubmit(activeRecentPlayed); 
     144            LastPod.scrobbler.handshake(); 
     145            LastPod.scrobbler.submitTracks(); 
    143146            LastPod.scrobbler.addHistories(activeRecentPlayed, inactiveRecentPlayed); 
    144147 
  • trunk/src/main/org/lastpod/Scrobbler.java

    r60 r61  
    7878 
    7979    /** 
     80     * Stores the chunks of tracks to be submitted. 
     81     */ 
     82    private List trackChunks; 
     83 
     84    /** 
     85     * Displays the submission progress as this class updates it. 
     86     */ 
     87    private ChunkProgress chunkProgress; 
     88 
     89    /** 
    8090     * The number of seconds to pause between submissions. Only if the server 
    8191     * asks to do so. 
     
    91101    } 
    92102 
    93     public void handshake(List recentPlayed) 
     103    /** 
     104     * Sets the object that displays submission progress.  This object updates 
     105     * the progress as it is processing. 
     106     * @param chunkProgress  The object that displays submission progress. 
     107     */ 
     108    public void setChunkProgress(ChunkProgress chunkProgress) { 
     109        this.chunkProgress = chunkProgress; 
     110    } 
     111 
     112    /** 
     113     * Sets the tracks that are submitted. 
     114     * @param recentPlayed  A list of tracks to submit. 
     115     */ 
     116    public void setTracksToSubmit(final List recentPlayed) { 
     117        if (recentPlayed.size() == 0) { 
     118            throw new RuntimeException("No tracks to submit"); 
     119        } 
     120 
     121        /* Converts the recentPlayed List into a List of Chunk objects.  Each 
     122         * chunk stores at most 10 tracks.  Each chunk will be submitted to 
     123         * Last.fm individually, per their guidelines. 
     124         */ 
     125        trackChunks = ChunkUtil.createChunks(recentPlayed, MAX_TRACKS_PER_CHUNK); 
     126 
     127        /* Add 1 because the handshake will also be included in the progress. */ 
     128        chunkProgress.setNumberOfChunks(trackChunks.size() + 1); 
     129    } 
     130 
     131    public void handshake() 
    94132            throws UnsupportedEncodingException, MalformedURLException, IOException, 
    95133                FailedLoginException { 
    96         if (recentPlayed.size() == 0) { 
     134        if (trackChunks.size() == 0) { 
    97135            throw new RuntimeException("No tracks to submit"); 
    98136        } 
     
    171209        challenge = lines[1]; 
    172210 
     211        /* Displays some progress update once the handshake is completed. */ 
     212        chunkProgress.updateCurrentChunk(1); 
     213 
    173214        logger.log(Level.INFO, "Handshake completed"); 
    174215    } 
    175216 
    176     public void submitTracks(final List recentPlayed, ChunkProgress chunkProgress
     217    public void submitTracks(
    177218            throws UnsupportedEncodingException, NoSuchAlgorithmException, MalformedURLException, 
    178219                IOException, FailedLoginException { 
    179220        logger.log(Level.INFO, "Submitting tracks..."); 
    180221 
    181         if (recentPlayed.size() == 0) { 
     222        if (trackChunks.size() == 0) { 
    182223            throw new RuntimeException("No tracks to submit"); 
    183224        } 
     
    189230        String urlEncodedChallange = URLEncoder.encode(md5chal, "UTF-8"); 
    190231 
    191         /* Converts the recentPlayed List into a List of Chunk objects.  Each 
    192          * chunk stores at most 10 tracks.  Each chunk will be submitted to 
    193          * Last.fm individually, per their guidelines. 
    194          */ 
    195         List chunks = ChunkUtil.createChunks(recentPlayed, MAX_TRACKS_PER_CHUNK); 
    196  
    197         chunkProgress.setNumberOfChunks(chunks.size()); 
    198  
    199232        Chunk chunk = null; 
    200233 
    201         for (int i = 0; i < chunks.size(); i++) { 
     234        for (int i = 0; i < trackChunks.size(); i++) { 
    202235            pauseIfRequired(); 
    203236 
    204             chunk = (Chunk) chunks.get(i); 
     237            chunk = (Chunk) trackChunks.get(i); 
    205238 
    206239            String queryString = "u=" + urlEncodedUsername + "&" + "s=" + urlEncodedChallange; 
     
    258291            } 
    259292 
    260             chunkProgress.updateCurrentChunk(i + 1); 
     293            /* Add 2 to progress.  1 because chunk progress starts at 1, whereas 
     294             * this for-loop is zero indexed.  1 because the handshake is also 
     295             * part of the progress. 
     296             */ 
     297            chunkProgress.updateCurrentChunk(i + 2); 
    261298        } 
    262299