示例#1
0
文件: Chat.java 项目: acruche/DobleFC
  @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;
    }

    switch (id) {
      case android.R.id.home:
        onBackPressed();
        return true;

      case R.id.action_clearChat:
        // Limpando as mensagens no banco de dados
        messageDAO.limparConversa(mNumeroChatAtivo);
        // Limpando a lista
        chatAdapter.clearItemList();
        // Ativando o textview com a mensagem
        findViewById(R.id.empty).setVisibility(View.VISIBLE);
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
示例#2
0
文件: Chat.java 项目: acruche/DobleFC
  @Override
  public void updateObs() {
    Message newMessage = mMessageSubject.getLastMessage();

    // Verificando se a nova mensagem tem o mesmo numero do chat ativo
    if (newMessage.getNumber().equals(mNumeroChatAtivo)) {
      newMessage.setWasRead(1);

      // Adicionando a nova mensagem
      ((ChatAdapter) mRecyclerView.getAdapter()).addItemList(newMessage, mListMessage.size());
      mRecyclerView
          .getLayoutManager()
          .scrollToPosition(mRecyclerView.getAdapter().getItemCount() - 1);

      messageDAO.novasMensagensLidas(mNumeroChatAtivo);
    }
  }
示例#3
0
文件: Chat.java 项目: acruche/DobleFC
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);

    // Registrando CHAT no observer
    this.mMessageSubject = MessageSubject.getInstance();
    this.mMessageSubject.attach(this);

    // Instancias
    this.mBD = new BD(this);
    this.mFirebase = new Firebase(Util.FIREBASE_URL);
    this.mListMessage = new ArrayList<Message>();
    this.messageDAO = new MessageDAO(this);

    // Referências
    mNewMessage = (EditText) findViewById(R.id.et_newMessage);
    mRecyclerView = (RecyclerView) findViewById(R.id.rv_listMsg);

    // Pegando o nome
    String nomeChatAtivo = getIntent().getStringExtra("nome").toString();
    // Pegando o numero
    mNumeroChatAtivo = getIntent().getStringExtra("numero").toString();

    // Mudando o status da mensagem para lida
    messageDAO.novasMensagensLidas(mNumeroChatAtivo);
    // Buscando o log
    this.mListMessage = messageDAO.getLog(mNumeroChatAtivo);

    Toolbar toolbar = (Toolbar) findViewById(R.id.tbChat);
    // Setando como titulo e subtitulo
    toolbar.setTitle(nomeChatAtivo);
    toolbar.setSubtitle("online");
    setSupportActionBar(toolbar);

    // Ativando o botao voltar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Ativando a foto que fica ao lado do botao voltar
    getSupportActionBar().setDisplayShowHomeEnabled(false);

    // Criando um LayoutManager
    LinearLayoutManager llm = new LinearLayoutManager(this);
    llm.setReverseLayout(false);
    llm.setOrientation(LinearLayoutManager.VERTICAL);

    // Setando os atributos do RecyclerView
    // mRecyclerView.setScrollContainer(true);
    mRecyclerView.setHasFixedSize(
        true); // Informa que o tamanho do recyclerView não vai mudar, ajuda na otimização.
    mRecyclerView.setLayoutManager(llm); // Setando o layoutmanager no recyclerview

    // Criando e passando a lista de mensagens para o adapter
    chatAdapter = new ChatAdapter(mListMessage, this, this);

    // Setando o Adapter no RecyclerView
    mRecyclerView.setAdapter(chatAdapter);

    // Caso a lista de mensagem esteja vazia, esconde o textview com a frase
    if (this.mListMessage.size() > 0) {
      findViewById(R.id.empty).setVisibility(View.INVISIBLE);
      mRecyclerView.getLayoutManager().scrollToPosition(mListMessage.size() - 1);
    }
  }