package com.nbusy.app.activities;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import com.nbusy.app.R;

/**
 * An activity representing a single Chat detail screen. This
 * activity is only used on handset devices. On tablet-size devices,
 * item details are presented side-by-side with a list of items
 * in a {@link ChatListActivity}.
 * <p/>
 * This activity is mostly just a 'shell' activity containing nothing
 * more than a {@link ChatDetailFragment}.
 */
public class ChatDetailActivity extends Activity {

    /* get an instance of WorkerService */
//    private WorkerService workerService;
//
//    private ServiceConnection workerServiceConnection = new ServiceConnection() {
//        public void onServiceConnected(ComponentName className, IBinder binder) {
//            WorkerService.WorkerServiceBinder workerServiceBinder = (WorkerService.WorkerServiceBinder) binder;
//            workerService = workerServiceBinder.getService();
//        }
//
//        public void onServiceDisconnected(ComponentName className) {
//            workerService = null;
//        }
//    };
//
//    @Override
//    public void onResume() {
//        super.onResume();
//        Intent intent = new Intent(this, WorkerService.class);
//        bindService(intent, workerServiceConnection, Context.BIND_AUTO_CREATE);
//    }
//
//    @Override
//    protected void onPause() {
//        super.onPause();
//        unbindService(workerServiceConnection);
//    }
    /* get an instance of WorkerService */

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat_detail);

        // Show the Up button in the action bar.
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        // savedInstanceState is non-null when there is fragment state saved from previous configurations of this activity
        // (e.g. when rotating the screen from portrait to landscape)
        // in this case, the fragment will automatically be re-added to its container so we don't need to manually add it
        if (savedInstanceState != null) {
            return;
        }

        // Set activity title
        String chatId = getIntent().getStringExtra(ChatDetailFragment.ARG_ITEM_ID);
        setTitle(chatId);

        // create the detail fragment and add it to the activity using a fragment transaction.
        Bundle arguments = new Bundle();
        arguments.putString(ChatDetailFragment.ARG_ITEM_ID, chatId);
        ChatDetailFragment fragment = new ChatDetailFragment();
        fragment.setArguments(arguments);
        getFragmentManager().beginTransaction().add(R.id.chat_detail_container, fragment).commit();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            // this ID represents the Home or Up button
            // in the case of this activity, the Up button is shown
            navigateUpTo(new Intent(this, ChatListActivity.class));
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

@@ -198,16 +198,97 @@
 y.app.R;
+%0Aimport com.nbusy.app.worker.Worker;%0Aimport com.nbusy.app.worker.WorkerSingleton;
 %0A%0A/**%0A *
@@ -699,994 +699,66 @@
     
-/* get an instance of WorkerService */%0A//    private WorkerService workerService;%0A//%0A//    private ServiceConnection workerServiceConnection = new ServiceConnection() %7B%0A//        public void onServiceConnected(ComponentName className, IBinder binder) %7B%0A//            WorkerService.WorkerServiceBinder workerServiceBind
+private final Worker work
 er = 
-(
 WorkerS
-ervice.WorkerServiceBinder) binder;%0A//            workerService = workerServiceBinder.getService();%0A//        %7D%0A//%0A//        public void onServiceDisconnected(ComponentName className) %7B%0A//            workerService = null;%0A//        %7D%0A//    %7D;%0A//%0A//    @Override%0A//    public void onResume() %7B%0A//        super.onResume();%0A//        Intent intent = new Intent(this, WorkerService.class);%0A//        bindService(intent, workerServiceConnection, Context.BIND_AUTO_CREATE);%0A//    %7D%0A//%0A//    @Override%0A//    protected void onPause() %7B%0A//        super.onPause();%0A//        unbindService(workerServiceConnection);%0A//    %7D%0A    /* get an instance of WorkerService */
+ingleton.getWorker();
 %0A%0A  
@@ -1639,22 +1639,59 @@
 etTitle(
-chatId
+worker.userProfile.getChat(chatId).peerName
 );%0A%0A    

fix chat title display