package de.fmaul.android.cmis.asynctask;

import android.app.Application;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import de.fmaul.android.cmis.CmisApp;
import de.fmaul.android.cmis.ListCmisFeedActivity;
import de.fmaul.android.cmis.R;
import de.fmaul.android.cmis.model.Server;
import de.fmaul.android.cmis.repo.CmisRepository;
import de.fmaul.android.cmis.utils.FeedLoadException;

public class ServerInitTask extends AsyncTask<String, Void, CmisRepository> {

	private final ListCmisFeedActivity activity;
	private ProgressDialog pg;
	private Server server;
	private Application app;

	public ServerInitTask(ListCmisFeedActivity activity, Application app, final Server server) {
		super();
		this.activity = activity;
		this.app = app;
		this.server = server;
		
	}

	@Override
	protected void onPreExecute() {
		pg = ProgressDialog.show(activity, "", activity.getText(R.string.loading), true);
	}

	@Override
	protected CmisRepository doInBackground(String... params) {
		try {
			return CmisRepository.create(app, server);
		} catch (FeedLoadException fle) {
			return null;
		}
	}

	@Override
	protected void onPostExecute(CmisRepository repo) {
		repo.generateParams(activity);
		((CmisApp) activity.getApplication()).setRepository(repo);
		((CmisApp) activity.getApplication()).getRepository().clearCache(repo.getServer().getWorkspace());
		activity.processSearchOrDisplayIntent();
		pg.dismiss();
	}

	@Override
	protected void onCancelled() {
		pg.dismiss();
	}
}
@@ -106,16 +106,115 @@
 ialog;%0D%0A
+import android.content.DialogInterface;%0D%0Aimport android.content.DialogInterface.OnCancelListener;%0D%0A
 import a
@@ -235,16 +235,16 @@
 cTask;%0D%0A
-
 import d
@@ -1039,16 +1039,171 @@
 g), true
+, true, new OnCancelListener() %7B%0D%0A%09%09%09@Override%0D%0A%09%09%09public void onCancel(DialogInterface dialog) %7B%0D%0A%09%09%09%09activity.finish();%0D%0A%09%09%09%09dialog.dismiss();%0D%0A%09%09%09%7D%0D%0A%09%09%7D
 );%0D%0A%09%7D%0D%0A
@@ -1734,32 +1734,32 @@
 %0D%0A%0D%0A%09@Override%0D%0A
-
 %09protected void 
@@ -1771,24 +1771,46 @@
 celled() %7B%0D%0A
+%09%09activity.finish();%0D%0A
 %09%09pg.dismiss

Fix : Cancel loading server.