package com.giul.profissionaisdeobracivil.adapter;
import android.app.Application; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView;
import com.bumptech.glide.Glide; import com.giul.profissionaisdeobracivil.R; import com.giul.profissionaisdeobracivil.activity.ActivityPedreiro; import com.giul.profissionaisdeobracivil.activity.LoginActivityPedreiro; import com.giul.profissionaisdeobracivil.model.Pedreiro;
import java.util.IllegalFormatCodePointException; import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
public class AdapterPermission extends RecyclerView.Adapter {
private List<Pedreiro> pedreiros;
private Context context;
public AdapterPedreiro(List<Pedreiro> listaPedreiros, Context context){
this.pedreiros = listaPedreiros;
this.context = context;
setHasStableIds(true);
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemLista = LayoutInflater.from(parent.getContext())
.inflate(R.layout.adapter_profissionais,parent, false);
return new MyViewHolder(itemLista);
}
@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, int position) {
final Pedreiro pedreiro = pedreiros.get(position);
holder.nome.setText(pedreiro.getNome());
holder.profissao.setText(pedreiro.getProfissao());
holder.telefoneContato.setImageResource(R.drawable.telefone);
holder.telefoneContato.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.telefone.setText(pedreiro.getTelefone());
String number = pedreiro.getTelefone();
Uri call = Uri.parse("tel:" + number);
Intent surf = new Intent(Intent.ACTION_DIAL, call);
surf.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(surf);
}
});
holder.telefone.setText(pedreiro.getTelefone());
if (pedreiro.getFoto() != null){
Uri uri = Uri.parse(pedreiro.getFoto());
Glide.with( context).load(uri).into(holder.fotoUsuario);
}else{
holder.fotoUsuario.setImageResource(R.drawable.padrao);
}
/*
holder.nome.setText("Giuliano");
holder.profissao.setText("Pedreiro");
holder.telefone.setText("03195430219");
holder.telefoneContato.setImageResource(R.drawable.telefone);
holder.fotoUsuario.setImageResource(R.drawable.padrao);
holder.telefoneContato.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:995430219"));
view.getContext().startActivity(callIntent);
}
});
*/
}
@Override
public int getItemCount() {
return pedreiros.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
TextView nome;
TextView profissao;
TextView telefone;
CircleImageView fotoUsuario;
ImageView telefoneContato;
public MyViewHolder(View itemView) {
super(itemView);
nome = itemView.findViewById(R.id.textoNomeContato);
profissao = itemView.findViewById(R.id.textNomeProfissaos);
telefone = itemView.findViewById(R.id.textNumeroTelefones);
telefoneContato = itemView.findViewById(R.id.imagemTelefoneContatos);
fotoUsuario =itemView.findViewById(R.id.imageViewFotoContatos);
}
}
}
package com.giul.profissionaisdeobracivil.activity;
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.Button;
import com.giul.professionalsdeobracivil.R; import com.giul.profissionaisdeobracivil.activity.ActivityProfissoes; import com.giul.profissionaisdeobracivil.adapter.AdapterPedreiro; import com.giul.professionalsofobracivil.config.FirebaseConfiguration; import com.giul.profissionaisdeobracivil.model.Pedreiro; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class ActivityPedreiro extends AppCompatActivity { private RecyclerView recyclerViewProfissoes; private Button button; private AdapterPedreiro adapterPedreiro; private ArrayList listPersonals = new ArrayList ; private DatabaseReference pedreirosRef; private ValueEventListener valueEventListenerPeders;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pedreiro);
// Button button = findViewById(R.id.chamar);
// button.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Intent intent = new Intent(getApplicationContext(),ActivityProfissoes.class);
// startActivity(intent);
// }
// });
RecyclerView recyclerViewProfissoes = (RecyclerView) findViewById(R.id.recyclerviewProfissoes);
pedreirosRef = ConfiguraçaoFirebase.getFirebaseDatabase().child("pedreiros");
//Configurar Adapter
adapterPedreiro = new AdapterPedreiro(listaPedreiros, getApplication());
// AdapterPedreiro adapterProfissionais = new AdapterPedreiro();
//Configurar Recyclerview
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerViewProfissoes.setLayoutManager(layoutManager);
recyclerViewProfissoes.setHasFixedSize(true);
recyclerViewProfissoes.setAdapter(adapterPedreiro);
}
public void onStart(){
super.onStart();
recuperarPedreiros();
}public void onPause() {
super.onPause();
pedreirosRef.removeEventListener(valueEventListenerPedreiros);
}
public void onStop(){
super.onStop();
pedreirosRef.removeEventListener(valueEventListenerPedreiros);
}
public void recuperarPedreiros(){
valueEventListenerPedreiros = pedreirosRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot dados:dataSnapshot.getChildren()){
Pedreiro pedreiro = dados.getValue(Pedreiro.class);
listaPedreiros.add(pedreiro);
}
adapterPedreiro.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}