mirror of https://codeberg.org/gitnex/GitNex.git
91 lines
2.9 KiB
Java
91 lines
2.9 KiB
Java
package org.mian.gitnex.adapters;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
import android.widget.TextView;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import org.mian.gitnex.R;
|
|
import org.mian.gitnex.activities.CommitsActivity;
|
|
import org.mian.gitnex.helpers.TinyDB;
|
|
import org.mian.gitnex.models.Branches;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* Author M M Arif
|
|
*/
|
|
|
|
public class BranchesAdapter extends RecyclerView.Adapter<BranchesAdapter.BranchesViewHolder> {
|
|
|
|
private List<Branches> branchesList;
|
|
private Context mCtx;
|
|
|
|
static class BranchesViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
private TextView branchNameTv;
|
|
private TextView branchCommitAuthor;
|
|
|
|
private BranchesViewHolder(View itemView) {
|
|
super(itemView);
|
|
|
|
branchNameTv = itemView.findViewById(R.id.branchName);
|
|
branchCommitAuthor = itemView.findViewById(R.id.branchCommitAuthor);
|
|
Button branchCommitHash = itemView.findViewById(R.id.branchCommitHash);
|
|
|
|
branchCommitHash.setOnClickListener(new View.OnClickListener() {
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(v.getContext(), CommitsActivity.class);
|
|
intent.putExtra("branchName", String.valueOf(branchNameTv.getText()));
|
|
Objects.requireNonNull(v.getContext()).startActivity(intent);
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
public BranchesAdapter(Context mCtx, List<Branches> branchesMain) {
|
|
this.mCtx = mCtx;
|
|
this.branchesList = branchesMain;
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public BranchesAdapter.BranchesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_branches, parent, false);
|
|
return new BranchesAdapter.BranchesViewHolder(v);
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NonNull BranchesAdapter.BranchesViewHolder holder, int position) {
|
|
|
|
final TinyDB tinyDb = new TinyDB(mCtx);
|
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
|
|
Branches currentItem = branchesList.get(position);
|
|
holder.branchNameTv.setText(currentItem.getName());
|
|
|
|
if(currentItem.getCommit().getAuthor().getName() != null || !currentItem.getCommit().getAuthor().getName().equals("")) {
|
|
holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getName()));
|
|
}
|
|
else {
|
|
holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getUsername()));
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return branchesList.size();
|
|
}
|
|
|
|
}
|
|
|
|
|