package com.whinc.easemobdemo.easemob.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Menu;
import android.view.MenuItem;

import com.easemob.easeui.EaseConstant;
import com.whinc.easemobdemo.BaseActivity;
import com.whinc.easemobdemo.R;
import com.whinc.easemobdemo.easemob.widget.TitleBar;
import com.whinc.easemobdemo.easemob.fragment.ChatFragment;

public class ChatActivity extends BaseActivity{
    private static final String TAG = "ChatActivity";
    private static final String TAG_CHAT_FRAGMENT = "ChatFragment";
    private static final String EXTRA_CHAT_TYPE = "com.whinc.easemobdemo.easemob.activity.ChatActivity.EXTRA_CHAT_TYPE";
    private static final String EXTRA_USER_ID = "com.whinc.easemobdemo.easemob.activity.ChatActivity.EXTRA_USER_ID";

    public static void start(@NonNull Context context, int chatType, String userId) {
        Intent starter = new Intent(context, ChatActivity.class);
        starter.putExtra(EXTRA_CHAT_TYPE, chatType);
        starter.putExtra(EXTRA_USER_ID, userId);
        context.startActivity(starter);
    }

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

        if (getIntent() == null) {
            throw new IllegalArgumentException();
        }
        String userId = getIntent().getStringExtra(EXTRA_USER_ID);
        int chatType = getIntent().getIntExtra(EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_SINGLE);

        TitleBar titleBar = (TitleBar) findViewById(R.id.chat_toolbar);
        titleBar.setCenterTitle(userId);
        titleBar.setTitle(R.string.title_message);
        titleBar.showBackIcon(true);

        initChatFragment(chatType, userId);
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void initChatFragment(int chatType, String userId) {
        ChatFragment fragment = findFragmentByTag(TAG_CHAT_FRAGMENT);
        if (fragment == null) {
            fragment = ChatFragment.newInstance(chatType, userId);
            addFragment(fragment, R.id.fragment_container, TAG_CHAT_FRAGMENT);
        }
    }
}

@@ -267,24 +267,69 @@
 seConstant;%0A
+import com.easemob.easeui.controller.EaseUI;%0A
 import com.w
@@ -432,23 +432,29 @@
 mob.
-widget.TitleBar
+fragment.ChatFragment
 ;%0Aim
@@ -488,37 +488,31 @@
 easemob.
-fragment.ChatFragment
+widget.TitleBar
 ;%0A%0Apubli
@@ -1634,24 +1634,142 @@
 E_SINGLE);%0A%0A
+        // %E6%A0%B9%E6%8D%AE%E7%94%A8%E6%88%B7%E6%98%B5%E7%A7%B0%0A        String nickName = EaseUI.getInstance().getUserProfileProvider().getUser(userId).getNick();%0A%0A
         Titl
@@ -1860,22 +1860,24 @@
 erTitle(
-userId
+nickName
 );%0A     

更新 - 聊天界面标题显示用户昵称