Created
February 24, 2016 12:46
-
-
Save fioalpha/007eb0f11d6cc39760e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.redeife.Adpater; | |
import android.content.Context; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v7.widget.CardView; | |
import android.support.v7.widget.RecyclerView; | |
import android.util.Log; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.LinearLayout; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
import java.util.List; | |
import br.com.redeife.Dao.Contract; | |
import br.com.redeife.Model.QueroEscutarChat; | |
import br.com.redeife.R; | |
import br.com.redeife.Repository.QueroEscutarChatRepository; | |
import br.com.redeife.Ui.Login.QueroEscutar.QueroEscutarChatActivity; | |
/** | |
* Created by IFE-01 on 10/12/2015. | |
*/ | |
public class QueroEscutarNovaConversaChatAdapter extends RecyclerView.Adapter<QueroEscutarNovaConversaChatAdapter.ViewHolder>{ | |
private List<QueroEscutarChat> mData; | |
private long idUsuario ; | |
private Context context; | |
public QueroEscutarNovaConversaChatAdapter(Context context,List<QueroEscutarChat> list, long idUsuario){ | |
this.context = context; | |
this.mData = list; | |
this.idUsuario = idUsuario; | |
} | |
@Override | |
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View view = LayoutInflater.from(parent.getContext()) | |
.inflate( | |
R.layout.quero_escutar_chat_adapter, | |
parent, | |
false | |
); | |
ViewHolder holder = new ViewHolder(view); | |
return holder; | |
} | |
@Override | |
public void onBindViewHolder(ViewHolder holder, int position) { | |
int lida = (this.mData.get(position).isCht_Visualizado()) ? | |
R.drawable.check_message_active : R.drawable.check_message; | |
if(this.mData.get(position).isUser() || (this.idUsuario == this.mData.get(position).getAcs_Id())){ | |
holder.mImgCheckRight.setImageResource(lida); | |
holder.mTxtMessageRight.setText( | |
this.mData.get(position).getCht_Mensagem() | |
); | |
holder.mTxtDataRight.setText( | |
this.mData.get(position).getCht_Data() | |
); | |
holder.mBoxCardRight.setVisibility(View.VISIBLE); | |
holder.mBoxCardLeft.setVisibility(View.GONE); | |
} else { | |
//holder.mImgCheckLeft.setImageResource(lida); | |
holder.mTxtMessageLeft.setText( | |
this.mData.get(position).getCht_Mensagem() | |
); | |
holder.mTxtDataLeft.setText( | |
this.mData.get(position).getCht_Data() | |
); | |
holder.mBoxCardLeft.setVisibility(View.VISIBLE); | |
holder.mBoxCardRight.setVisibility(View.GONE); | |
} | |
} | |
@Override | |
public int getItemCount() { | |
return this.mData == null ? 0 : this.mData.size(); | |
} | |
public static class ViewHolder extends RecyclerView.ViewHolder{ | |
CardView mBoxCardLeft; | |
TextView mTxtMessageLeft; | |
TextView mTxtDataLeft; | |
ImageView mImgCheckLeft; | |
CardView mBoxCardRight; | |
TextView mTxtMessageRight; | |
TextView mTxtDataRight; | |
ImageView mImgCheckRight; | |
public ViewHolder(View itemView) { | |
super(itemView); | |
mBoxCardLeft = (CardView) itemView.findViewById(R.id.chat_left); | |
mTxtDataLeft = (TextView) itemView.findViewById(R.id.txt_data_left); | |
mTxtMessageLeft = (TextView) itemView.findViewById(R.id.txt_message_left); | |
mBoxCardRight = (CardView) itemView.findViewById(R.id.chat_right); | |
mTxtDataRight = (TextView) itemView.findViewById(R.id.txt_data_right); | |
mTxtMessageRight = (TextView) itemView.findViewById(R.id.txt_message_right); | |
mImgCheckRight = (ImageView) itemView.findViewById(R.id.img_check_right); | |
} | |
} | |
public void addItem(QueroEscutarChat item){ | |
if(this.mData == null){ | |
this.mData = new ArrayList<>(); | |
} | |
this.mData.add(item); | |
} | |
public long getLastItem(){ | |
return (this.mData != null) ? this.mData.get(this.mData.size()-1).getCht_Id() : 0; | |
} | |
/** | |
* Alterar o icone quando foi lido a message | |
*/ | |
public void checkImageCheck(){ | |
int a = (this.getItemCount() == 0) ? 0 : this.mData.size()-1; | |
Log.d(QueroEscutarChatActivity.class.getSimpleName(), a+""); | |
boolean continua = true; | |
while(continua){ | |
if(this.getItemCount() > 0) { | |
Log.d("id usuario", this.idUsuario+""); | |
//Log.d("size", this.) | |
if (this.idUsuario == this.mData.get(a).getAcs_Id()) { | |
this.mData.get(a).setCht_Visualizado(true); | |
QueroEscutarChatRepository repository = new QueroEscutarChatRepository(this.context); | |
repository.setUpdateReadMessage(this.mData.get(a).getCht_Id()); | |
} | |
a--; | |
continua = (a < 0) ? false : true; | |
}else { | |
continua = false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment