package org.duckdns.raven.ttscallresponder.tts;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;

public class StartAnsweringServiceReceiver extends BroadcastReceiver {
	private static final String TAG = "StartAnsweringServiceReceiver";

	@Override
	public void onReceive(Context context, Intent intent) {
		String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
		Log.i(TAG, "Phone state changed: " + state);

		if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
			Log.i(TAG, "Ringing - preparing service");
			Intent startResponderService = new Intent(context, TtsAnsweringService.class);
			context.startService(startResponderService);
			Log.i(TAG, "Service started");
		}

		if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
			Log.i(TAG, "InCall - answering");
		}
	}
}

@@ -42,16 +42,151 @@
 r.tts;%0A%0A
+import org.duckdns.raven.ttscallresponder.domain.call.Call;%0Aimport org.duckdns.raven.ttscallresponder.domain.call.PersistentCallList;%0A%0A
 import a
@@ -951,107 +951,319 @@
 %22);%0A
+%0A
 %09%09
-%7D%0A%0A%09%09if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) %7B%0A%09%09%09Log.i(TAG, %22InCall - answering%22
+%09Log.i(TAG, %22Adding to answered calls: %22 + intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER));%0A%09%09%09PersistentCallList callList = new PersistentCallList(context.getFilesDir());%0A%09%09%09callList.add(new Call(intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)));%0A%09%09%09callList.savePersistentList(
 );%0A%09

Add calls to list of answered calls.