import static ro.ieval.fonbot.R.string.logging_in;
import static ro.ieval.fonbot.Utils.toNonNull;
-import java.util.Collections;
-
+import java.io.InputStream;
import org.eclipse.jdt.annotation.Nullable;
import ro.ieval.fonbot.FonBotMainService.Binder;
+import ro.ieval.fonbot.HttpCallExecutableRunnable.ResultCallback;
import ro.ieval.fonbot.Utils.OngoingEvent;
import android.app.ListActivity;
import android.content.BroadcastReceiver;
public void onReceive(@Nullable final Context context, @Nullable final Intent intent) {
if(intent==null)
return;
- resultTextView.setText(intent.getStringExtra(SendHttpMessageAsyncTask.EXTRA_RESPONSE_MESSAGE));
- final int responseCode=intent.getIntExtra(SendHttpMessageAsyncTask.EXTRA_RESPONSE_CODE, 0);
+ resultTextView.setText(intent.getStringExtra(BroadcastResultCallback.EXTRA_RESPONSE_MESSAGE));
+ final int responseCode=intent.getIntExtra(BroadcastResultCallback.EXTRA_RESPONSE_CODE, 0);
if(responseCode>=200&&responseCode<300)
resultTextView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tick, 0, 0);
else
}
}
+ /**
+ * Implementation of <code>ResultCallback</code> that broadcasts a {@link #LOGIN_BROADCAST}
+ *
+ * @author Marius Gavrilescu
+ */
+ public final class BroadcastResultCallback implements ResultCallback{
+ /**
+ * Extra: the response message
+ */
+ public static final String EXTRA_RESPONSE_MESSAGE="response_message";
+ /**
+ * Extra: the response code
+ */
+ public static final String EXTRA_RESPONSE_CODE="response_code";
+
+ @Override
+ public void onResult(final int responseCode, final String responseMessage, final InputStream inputStream) {
+ final Intent intent=new Intent(LOGIN_BROADCAST);
+ intent.putExtra(EXTRA_RESPONSE_MESSAGE, responseMessage);
+ intent.putExtra(EXTRA_RESPONSE_CODE, responseCode);
+ sendBroadcast(intent);
+ }
+
+ @Override
+ public void onError(final String error) {
+ final Intent intent=new Intent(LOGIN_BROADCAST);
+ intent.putExtra(EXTRA_RESPONSE_MESSAGE, error);
+ sendBroadcast(intent);
+ }
+ }
+
/**
* The one instance of {@link OngoingUpdateReceiver}
*/
*/
private final BroadcastReceiver loginReceiver=new LoginReceiver();
/**
- * The broadcast sent by {@link SendHttpMessageAsyncTask} when logging in.
+ * The broadcast sent by {@link HttpCallExecutableRunnable} when logging in.
*/
private static final String LOGIN_BROADCAST="ro.ieval.fonbot.LOGIN_RESULT";
/**
* IntentFilter for {@link #loginReceiver}
*/
private static final IntentFilter LOGIN_FILTER=new IntentFilter(LOGIN_BROADCAST);
+ /**
+ * The one instance of {@link BroadcastResultCallback}
+ */
+ private final BroadcastResultCallback broadcastResultCallback=new BroadcastResultCallback();
/**
* The one instance of {@link ServiceConnection}
*/
protected void onStart() {
super.onStart();
resultTextView.setText(logging_in);
- new SendHttpMessageAsyncTask("/ok", toNonNull(Collections.<Header>emptySet()),
- LOGIN_BROADCAST,this).execute();
+ new HttpCallExecutableRunnable("/ok", null,
+ toNonNull(getApplicationContext()), toNonNull(broadcastResultCallback)).execute();
connection.refreshAdapter();
}