package com.apibootstraper.mobile;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.apibootstraper.mobile.core.Todo;
import com.apibootstraper.mobile.core.User;
import com.apibootstraper.mobile.core.util.HTTPResponse;

public class MainActivity extends Activity
{
    private TodoApplication application;

    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        application = (TodoApplication)getApplication();

        listView = (ListView)findViewById(R.id.todoListView);

        // Create an empty list for waiting
        String[] list = {"No datas"};
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list));
        
        // Load the remote data
        refreshTodos();

        // Try to call WS
//        application.showProgressDialog(this);
//        User.userAvailability("teste", new HTTPResponse<Boolean>() {
//
//            @Override
//            public void onSuccess(Boolean isAvailable) {
//                Log.d("WS_CALL", isAvailable ? "YES" : "NO");
//            }
//
//            @Override
//            public void onFinish() {
//                MainActivity.this.application.hideProgressDialog();
//            }
//        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getItemId() == R.id.refresh) {
            refreshTodos();
        }

        return super.onOptionsItemSelected(item);
    }
    
    private void refreshTodos()
    {
        application.showProgressDialog(this);
        Todo.findAll(new HTTPResponse<ArrayList<Todo>>() {

            @Override
            public void onSuccess(ArrayList<Todo> todos) {
                
//                listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.todo_list_item, ));
            }

            @Override
            public void onFinish() {
                MainActivity.this.application.hideProgressDialog();
            }
        });
    }

}

@@ -117,33 +117,8 @@
 le;%0A
-import android.util.Log;%0A
 impo
@@ -320,20 +320,31 @@
 le.core.
-User
+util.HTTPClient
 ;%0Aimport
@@ -997,24 +997,16 @@
 list));%0A
-        
 %0A       
@@ -1013,528 +1013,167 @@
  // 
-Load the remote data%0A        refreshTodos();%0A%0A        // Try to call WS%0A//        application.showProgressDialog(this);%0A//        User.userAvailability(%22teste%22, new HTTPResponse%3CBoolean%3E() %7B%0A//%0A//            @Override%0A//            public void onSuccess(Boolean isAvailable) %7B%0A//                Log.d(%22WS_CALL%22, isAvailable ? %22YES%22 : %22NO%22);%0A//            %7D%0A//%0A//            @Override%0A//            public void onFinish() %7B%0A//                MainActivity.this.application.hideProgressDialog();%0A//            %7D%0A//        %7D
+Temporary set credentials%0A        HTTPClient.getInstance().setBasicAuth(%22user@example.com%22, %22password%22);%0A%0A        // Load the remote data%0A        refreshTodos(
 );%0A 

Update MainActivity.java