package co.cutely.asim.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smackx.nick.packet.Nick;

import java.io.IOException;

/**
 * Created by nicole on 11/4/14.
 */
public class XmppService extends Service {
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
	}

	@Override
	public int onStartCommand(final Intent intent, final int flags, final int startId) {
		Log.i("XmppService", "Started with start id " + startId + ": " + intent);
		connect();

		// continue running until stopped
		return START_STICKY;

		//return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	private void connect() {
		AbstractXMPPConnection conn = new XMPPTCPConnection("0xxon.net");

		Log.i("XmppService", "trying to connect...");
		try {
			conn.connect();
			Log.i("XmppService", "trying to login...");
			//conn.login("smacktest", "thisIsThePasswordForSmacktest");
		} catch (SmackException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XMPPException e) {
			e.printStackTrace();
		}

	}
}

@@ -85,16 +85,45 @@
 Intent;%0A
+import android.os.AsyncTask;%0A
 import a
@@ -1148,16 +1148,162 @@
 ect() %7B%0A
+%09%09new AsyncTask%3CVoid, Void, AbstractXMPPConnection%3E() %7B%0A%09%09%09@Override%0A%09%09%09protected AbstractXMPPConnection doInBackground(final Void... params) %7B%0A%09%09
 %09%09Abstra
@@ -1363,16 +1363,18 @@
 net%22);%0A%0A
+%09%09
 %09%09Log.i(
@@ -1419,14 +1419,18 @@
 ;%0A%09%09
+%09
+%09
 try %7B%0A
+%09%09
 %09%09%09c
@@ -1444,16 +1444,18 @@
 nect();%0A
+%09%09
 %09%09%09Log.i
@@ -1496,18 +1496,18 @@
 .%22);%0A%09%09%09
+%09%09
-//
 conn.log
@@ -1556,16 +1556,36 @@
 test%22);%0A
+%09%09%09%09%09return conn;%0A%09%09
 %09%09%7D catc
@@ -1599,32 +1599,34 @@
 kException e) %7B%0A
+%09%09
 %09%09%09e.printStackT
@@ -1625,32 +1625,34 @@
 ntStackTrace();%0A
+%09%09
 %09%09%7D catch (IOExc
@@ -1658,32 +1658,34 @@
 ception e) %7B%0A%09%09%09
+%09
+%09
 e.printStackTrac
@@ -1689,16 +1689,18 @@
 race();%0A
+%09%09
 %09%09%7D catc
@@ -1724,16 +1724,18 @@
 e) %7B%0A%09%09%09
+%09%09
 e.printS
@@ -1749,16 +1749,258 @@
 ce();%0A%09%09
+%09
-%7D
+%09%7D%0A%0A%09%09%09%09return null;%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09protected void onPostExecute(final AbstractXMPPConnection connection) %7B%0A%09%09%09%09onConnected(connection);%0A%09%09%09%7D%0A%09%09%7D.execute((Void) null);%0A%0A%09%7D%0A%0A%09private void onConnected(AbstractXMPPConnection connection) %7B
 %0A%0A%09%7D%0A%7D%0A

Add an example of an AsyncTask for the connection call =)