GitNex/app/src/main/java/org/mian/gitnex/adapters/TeamRepositoriesAdapter.java
qwerty287 6a84e4d897 Extend CI workflows (#1155)
Extend CI workflows (-> https://codeberg.org/gitnex/GitNex/issues/1099)
	1. pull translations and push them again on every pull
       @mmarif this needs the secrets and `BOT_TOKEN`
       the code for this comes from tea4j-autodeploy
    2. add a **template** for a check workflow which only does some static checks right now. It is disabled because it requires some investigation and discussion on how we should deal with these issues. The checks are currently (if we would enable it):
    	1. check code style and formatting according to the project file in `.idea/`
        2. make sure every Java file has an `@author` annotation

I would wait until you reviewed with enabling them because we have to reformat all the files which results in changes with a few thousand changed lines (tried this once).

Closes https://codeberg.org/gitnex/GitNex/issues/141

Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1155
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-07-29 14:08:44 +02:00

158 lines
5.1 KiB
Java

package org.mian.gitnex.adapters;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import org.gitnex.tea4j.v2.models.Repository;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.RoundedTransformation;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* @author M M Arif
*/
public class TeamRepositoriesAdapter extends RecyclerView.Adapter<TeamRepositoriesAdapter.TeamReposViewHolder> {
private final List<Repository> reposList;
private final Context context;
private final int teamId;
private final String orgName;
private final String teamName;
private final List<Repository> reposArr;
public TeamRepositoriesAdapter(List<Repository> dataList, Context ctx, int teamId, String orgName, String teamName) {
this.context = ctx;
this.reposList = dataList;
this.teamId = teamId;
this.orgName = orgName;
this.teamName = teamName;
reposArr = new ArrayList<>();
}
class TeamReposViewHolder extends RecyclerView.ViewHolder {
private Repository repoInfo;
private final ImageView repoAvatar;
private final TextView name;
private final ImageView addRepoButtonAdd;
private TeamReposViewHolder(View itemView) {
super(itemView);
repoAvatar = itemView.findViewById(R.id.userAvatar);
name = itemView.findViewById(R.id.userFullName);
itemView.findViewById(R.id.userName).setVisibility(View.GONE);
addRepoButtonAdd = itemView.findViewById(R.id.addCollaboratorButtonAdd);
ImageView addRepoButtonRemove = itemView.findViewById(R.id.addCollaboratorButtonRemove);
//addRepoButtonAdd.setVisibility(View.VISIBLE);
//addRepoButtonRemove.setVisibility(View.GONE);
new Handler(Looper.getMainLooper()).postDelayed(TeamRepositoriesAdapter.this::getTeamRepos, 200);
new Handler(Looper.getMainLooper()).postDelayed(() -> {
if(reposArr.size() > 0) {
for(int i = 0; i < reposArr.size(); i++) {
if(!reposArr.get(i).getName().equals(repoInfo.getName())) {
addRepoButtonAdd.setVisibility(View.VISIBLE);
}
else {
addRepoButtonAdd.setVisibility(View.GONE);
}
}
}
else {
addRepoButtonAdd.setVisibility(View.VISIBLE);
}
}, 500);
addRepoButtonAdd.setOnClickListener(v -> AlertDialogs.addRepoDialog(context, orgName, repoInfo.getName(), Integer.parseInt(String.valueOf(teamId)), teamName));
addRepoButtonRemove.setOnClickListener(v ->
AlertDialogs.removeRepoDialog(context, orgName, repoInfo.getName(), Integer.parseInt(String.valueOf(teamId)), teamName));
}
}
@NonNull
@Override
public TeamRepositoriesAdapter.TeamReposViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_collaborators_search, parent, false);
return new TeamRepositoriesAdapter.TeamReposViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull final TeamRepositoriesAdapter.TeamReposViewHolder holder, int position) {
Repository currentItem = reposList.get(position);
holder.repoInfo = currentItem;
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
holder.name.setText(currentItem.getName());
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28)
.endConfig().buildRoundRect(String.valueOf(currentItem.getFullName().charAt(0)), ColorGenerator.Companion.getMATERIAL().getColor(currentItem.getName()), 3);
if(currentItem.getAvatarUrl() != null && !currentItem.getAvatarUrl().equals("")) {
PicassoService.getInstance(context).get().load(currentItem.getAvatarUrl()).placeholder(R.drawable.loader_animated)
.transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(holder.repoAvatar);
}
else {
holder.repoAvatar.setImageDrawable(drawable);
}
}
@Override
public int getItemCount() {
return reposList.size();
}
private void getTeamRepos() {
if(getItemCount() > 0) {
Call<List<Repository>> call = RetrofitClient
.getApiInterface(context)
.orgListTeamRepos((long) teamId, 1, 50);
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<List<Repository>> call, @NonNull Response<List<Repository>> response) {
if(response.code() == 200) {
for(int i = 0; i < Objects.requireNonNull(response.body()).size(); i++) {
reposArr.addAll(response.body());
}
}
}
@Override
public void onFailure(@NonNull Call<List<Repository>> call, @NonNull Throwable t) {
}
});
}
}
}