/*   
 * Copyright 2013 karsten
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.muckebox.android.net;

import java.io.IOException;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.muckebox.android.utils.Preferences;

import android.os.AsyncTask;

public class PreannounceTask extends AsyncTask<Integer, Void, Void> {
    @Override
    protected Void doInBackground(Integer... trackIds) {
        for (int i = 0; i < trackIds.length; ++i)
        {
            int trackId = trackIds[i];
            
            try {
                String url = ApiHelper.getApiUrl(
                    "hint",
                    Integer.toString(trackId),
                    new String[] { "format", "quality" },
                    new String[] {
                        Preferences.getTranscodingType(),
                        Preferences.getTranscodingQuality()
                        });
                
                HttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                
                httpClient.execute(httpPost);
                
                httpPost.abort();
            } catch (IOException e) {
            }
        }
        
        return null;
    }
}

@@ -744,62 +744,8 @@
 st;%0A
-import org.apache.http.impl.client.DefaultHttpClient;%0A
 impo
@@ -787,16 +787,16 @@
 rences;%0A
+
 %0Aimport 
@@ -1058,16 +1058,58 @@
 Ids%5Bi%5D;%0A
+            HttpClient httpClient = null;%0A
         
@@ -1524,35 +1524,24 @@
             
-HttpClient 
 httpClient =
@@ -1545,18 +1545,21 @@
 t = 
-new Defaul
+HttpHelper.ge
 tHtt
@@ -1703,84 +1703,175 @@
     
-    %0A                httpPost.abort();%0A            %7D catch (IOException e) %7B
+%7D catch (IOException e) %7B%0A            %7D finally%0A            %7B%0A                if (httpClient != null)%0A                    httpClient.getConnectionManager().shutdown();
 %0A   

Fix unauthorized preannounce.