Created
February 1, 2020 17:07
-
-
Save BobbyRuby/c6fb0125a7ececf99ca7517cab393b87 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 com.example.poleprofilingapp.project; | |
| import android.content.Context; | |
| import android.view.LayoutInflater; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import androidx.annotation.NonNull; | |
| import androidx.databinding.DataBindingUtil; | |
| import androidx.recyclerview.widget.RecyclerView; | |
| import com.example.poleprofilingapp.R; | |
| import com.example.poleprofilingapp.databinding.ProjectListItemBinding; | |
| import java.util.List; | |
| public class ProjectAdapter extends RecyclerView.Adapter<ProjectAdapter.ViewHolder> implements View.OnClickListener { | |
| private List<Project> projects; | |
| private Context context; | |
| private OnProjectListener onProjectListener; | |
| private OnEditProjectButtonListener onEditProjectButtonListener; | |
| private OnPrintProjectButtonListener onPrintProjectButtonListener; | |
| public ProjectAdapter(List<Project> projects, | |
| Context context, | |
| OnProjectListener onProjectListener, | |
| OnEditProjectButtonListener onEditProjectButtonListener, | |
| OnPrintProjectButtonListener onPrintProjectButtonListener) { | |
| this.projects = projects; | |
| this.context = context; | |
| this.onProjectListener = onProjectListener; | |
| this.onEditProjectButtonListener = onEditProjectButtonListener; | |
| this.onPrintProjectButtonListener = onPrintProjectButtonListener; | |
| } | |
| @NonNull | |
| @Override | |
| public ProjectAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | |
| ProjectListItemBinding binding = DataBindingUtil | |
| .inflate(LayoutInflater.from(parent.getContext()), | |
| R.layout.project_list_item, | |
| parent, | |
| false); | |
| return new ViewHolder(binding, onProjectListener, onEditProjectButtonListener, onPrintProjectButtonListener); | |
| } | |
| @Override | |
| public void onBindViewHolder(@NonNull ProjectAdapter.ViewHolder holder, int position) { | |
| Project project = projects.get(position); | |
| holder.projectListItemBinding.setProject(project); | |
| } | |
| @Override | |
| public int getItemCount() { | |
| return projects.size(); | |
| } | |
| @Override | |
| public void onClick(View view) { | |
| } | |
| public class ViewHolder extends RecyclerView.ViewHolder { | |
| // Binding Vars | |
| public ProjectListItemBinding projectListItemBinding; | |
| OnProjectListener onAddPoleListener; | |
| OnEditProjectButtonListener onEditProjectButtonListener; | |
| OnPrintProjectButtonListener onPrintProjectButtonListener; | |
| // Constructor to do view lookups for each subview | |
| public ViewHolder(final ProjectListItemBinding projectLayoutBinding, | |
| final OnProjectListener onAddPoleListener, | |
| final OnEditProjectButtonListener onEditProjectButtonListener, | |
| final OnPrintProjectButtonListener onPrintProjectButtonListener){ | |
| super(projectLayoutBinding.getRoot()); | |
| projectListItemBinding = projectLayoutBinding; | |
| this.onAddPoleListener = onAddPoleListener; | |
| this.onEditProjectButtonListener = onEditProjectButtonListener; | |
| this.onPrintProjectButtonListener = onPrintProjectButtonListener; | |
| // edit project | |
| projectLayoutBinding.editProjectButton.setOnClickListener(new View.OnClickListener(){ | |
| @Override | |
| public void onClick(View view){ | |
| String projectName = projectLayoutBinding.name.getText().toString(); | |
| String projectId = projectLayoutBinding.id.getText().toString(); | |
| String projectType = projectLayoutBinding.type.getText().toString(); | |
| String projectDescription = projectLayoutBinding.description.getText().toString(); | |
| String projectAddress = projectLayoutBinding.address.getText().toString(); | |
| onEditProjectButtonListener.onEditProjectButtonClick( | |
| getAdapterPosition(), | |
| projectType, | |
| projectName, | |
| projectId, | |
| projectDescription, | |
| projectAddress); | |
| } | |
| }); | |
| //add poles | |
| projectLayoutBinding.addPolesButton.setOnClickListener(new View.OnClickListener(){ | |
| @Override | |
| public void onClick(View view) { | |
| String projectName = projectLayoutBinding.name.getText().toString(); | |
| String projectId = projectLayoutBinding.id.getText().toString(); | |
| String projectType = projectLayoutBinding.type.getText().toString(); | |
| onAddPoleListener.onAddPolesButtonClick( | |
| getAdapterPosition(), | |
| projectType, | |
| projectName, | |
| projectId); | |
| } | |
| }); | |
| //print project - @TODO - Removed - functions use ITEXT - poles being printed on server | |
| /* projectLayoutBinding.printProjectButton.setOnClickListener(new View.OnClickListener(){ | |
| @Override | |
| public void onClick(View view) { | |
| String projectName = projectLayoutBinding.name.getText().toString(); | |
| String projectId = projectLayoutBinding.id.getText().toString(); | |
| String projectType = projectLayoutBinding.type.getText().toString(); | |
| onPrintProjectButtonListener.onPrintProjectButtonClick( | |
| getAdapterPosition(), | |
| projectType, | |
| projectName, | |
| projectId); | |
| } | |
| }); */ | |
| } | |
| } | |
| public interface OnProjectListener { | |
| void onAddPolesButtonClick(int position, String projectType, String projectName, String projectId); | |
| } | |
| public interface OnEditProjectButtonListener { | |
| void onEditProjectButtonClick(int position, String projectType, String projectName, String projectId, String projectDescription, String projectAddress); | |
| } | |
| public interface OnPrintProjectButtonListener { | |
| void onPrintProjectButtonClick(int position, String projectType, String projectName, String projectId); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment