fedilab-Android-App/app/src/main/java/app/fedilab/android/drawers/IdentityProofsAdapter.java

93 lines
3.4 KiB
Java
Raw Normal View History

2019-12-18 09:08:22 +01:00
package app.fedilab.android.drawers;
/* Copyright 2019 Thomas Schneider
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
2020-03-08 10:29:06 +01:00
2019-12-18 09:08:22 +01:00
import androidx.annotation.NonNull;
2020-03-08 10:29:06 +01:00
import androidx.constraintlayout.widget.ConstraintLayout;
2019-12-18 09:08:22 +01:00
import androidx.recyclerview.widget.RecyclerView;
2020-03-08 10:29:06 +01:00
2019-12-18 09:08:22 +01:00
import java.util.List;
2020-03-08 10:29:06 +01:00
2019-12-18 09:08:22 +01:00
import app.fedilab.android.R;
2019-12-18 09:26:21 +01:00
import app.fedilab.android.client.Entities.IdentityProof;
import app.fedilab.android.helper.Helper;
2019-12-18 09:08:22 +01:00
/**
2019-12-18 09:26:21 +01:00
* Created by Thomas on 19/12/2019.
* Adapter for identity proofs
2019-12-18 09:08:22 +01:00
*/
2019-12-18 09:26:21 +01:00
public class IdentityProofsAdapter extends RecyclerView.Adapter {
2019-12-18 09:08:22 +01:00
private Context context;
2019-12-18 09:26:21 +01:00
private List<IdentityProof> identityProofs;
2019-12-18 09:08:22 +01:00
2019-12-18 09:26:21 +01:00
public IdentityProofsAdapter(List<IdentityProof> identityProofs) {
this.identityProofs = identityProofs;
2019-12-18 09:08:22 +01:00
}
2019-12-18 09:26:21 +01:00
public IdentityProof getItem(int position) {
return identityProofs.get(position);
2019-12-18 09:08:22 +01:00
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
context = parent.getContext();
LayoutInflater layoutInflater = LayoutInflater.from(context);
2019-12-18 09:26:21 +01:00
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_identity_proofs, parent, false));
2019-12-18 09:08:22 +01:00
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
final ViewHolder holder = (ViewHolder) viewHolder;
2019-12-18 09:26:21 +01:00
final IdentityProof identityProof = getItem(i);
holder.proof_name.setText(String.format("@%s", identityProof.getProvider_username()));
2020-03-07 14:16:28 +01:00
holder.proof_name.setOnClickListener(v -> Helper.openBrowser(context, identityProof.getProfile_url()));
2020-03-08 10:29:06 +01:00
holder.proof_name_network.setText(context.getString(R.string.verified_by, identityProof.getProvider(), Helper.shortDateToString(identityProof.getUpdated_at())));
2020-03-07 14:16:28 +01:00
holder.proof_container.setOnClickListener(v -> Helper.openBrowser(context, identityProof.getProfile_url()));
holder.proof_name_network.setOnClickListener(v -> Helper.openBrowser(context, identityProof.getProof_url()));
2019-12-18 09:08:22 +01:00
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
2019-12-18 09:26:21 +01:00
return identityProofs.size();
2019-12-18 09:08:22 +01:00
}
2020-03-07 14:16:28 +01:00
static class ViewHolder extends RecyclerView.ViewHolder {
2019-12-18 13:49:39 +01:00
private TextView proof_name, proof_name_network;
private ConstraintLayout proof_container;
2019-12-18 09:08:22 +01:00
public ViewHolder(@NonNull View itemView) {
super(itemView);
2019-12-18 09:26:21 +01:00
proof_name = itemView.findViewById(R.id.proof_name);
proof_name_network = itemView.findViewById(R.id.proof_name_network);
proof_container = itemView.findViewById(R.id.proof_container);
2019-12-18 09:08:22 +01:00
}
}
}