
package org.zarroboogs.weibo.activity;

import org.zarroboogs.weibo.R;
import org.zarroboogs.weibo.bean.UserBean;
import org.zarroboogs.weibo.fragment.DMConversationListFragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

public class DMActivity extends AbstractAppActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dm_activity_layout);
        Toolbar mToolBar = (Toolbar) findViewById(R.id.settingToolBar);
        UserBean bean = getIntent().getParcelableExtra("user");

        mToolBar.setTitle(R.string.private_message_list);
        if (savedInstanceState == null) {
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.content_frame, DMConversationListFragment.newInstance(bean),
                            DMConversationListFragment.class.getName()).commit();
        }

        disPlayHomeAsUp(mToolBar);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent intent;
        switch (item.getItemId()) {
            case android.R.id.home:
                intent = MainTimeLineActivity.newIntent();
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                return true;
        }
        return false;
    }

    @Override
    public void onBackPressed() {
        DMConversationListFragment fragment = (DMConversationListFragment) getSupportFragmentManager().findFragmentByTag(
                DMConversationListFragment.class.getName());
        if (fragment != null) {
            if (fragment.isSmileShown()) {
                fragment.removeSmile();
            } else {
                super.onBackPressed();
            }
        } else {
            super.onBackPressed();
        }
    }
}
