/**
*	NotificationManager.java
*
*	@author Johan
*/

package se.chalmers.watchme.notifications;

import java.util.Calendar;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;

public class NotificationClient {
	
	private Context ctx;
	private NotificationService service;
	private boolean isBound;
	
	private ServiceConnection connection;
	
	public NotificationClient(Context context) {
		this.ctx = context;
		this.isBound = false;
		this.connection = new ServiceConnection() {

			public void onServiceConnected(ComponentName name, IBinder s) {
				service = ((NotificationService.ServiceBinder) s).getService();
				
			}

			public void onServiceDisconnected(ComponentName name) {
				service = null;
			}
			
		};
	}
	
	public void connectToService() {
		this.ctx.bindService(new Intent(this.ctx, NotificationService.class), null, Context.BIND_AUTO_CREATE);
		this.isBound = true;
	}
	
	
	public void setDateForNotification(Calendar date) {
		if(this.service != null){
			this.service.setAlarm(date);
		}
	}
	
	public void disconnectService() {
		if(this.isBound) {
			this.ctx.unbindService(connection);
			this.isBound = false;
		}
	}
	
}

@@ -943,20 +943,31 @@
 class), 
-null
+this.connection
 , Contex
@@ -1019,132 +1019,8 @@
 %7D%0A%09%0A
-%09%0A%09public void setDateForNotification(Calendar date) %7B%0A%09%09if(this.service != null)%7B%0A%09%09%09this.service.setAlarm(date);%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09pub
@@ -1144,10 +1144,130 @@
 %09%7D%0A%09%7D%0A%09%0A
+%09public void setDateForNotification(Calendar date) %7B%0A%09%09if(this.service != null)%7B%0A%09%09%09this.service.setAlarm(date);%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

Fix null pointer bug in NotificationClient