2019-06-19 14:58:57 +02: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;
|
2019-06-21 18:42:00 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
2019-06-19 14:58:57 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import app.fedilab.android.R;
|
2019-06-21 18:42:00 +02:00
|
|
|
import app.fedilab.android.activities.AccountReportActivity;
|
2019-06-19 14:58:57 +02:00
|
|
|
import app.fedilab.android.asynctasks.RetrieveAccountsAsyncTask;
|
|
|
|
import app.fedilab.android.client.Entities.Account;
|
|
|
|
import app.fedilab.android.client.Entities.Report;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
import app.fedilab.android.interfaces.OnRetrieveEmojiAccountInterface;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 19/06/2019.
|
|
|
|
* Adapter for reports
|
|
|
|
*/
|
|
|
|
public class ReportsListAdapter extends RecyclerView.Adapter implements OnRetrieveEmojiAccountInterface {
|
|
|
|
|
|
|
|
private List<Report> reports;
|
|
|
|
private LayoutInflater layoutInflater;
|
|
|
|
private RetrieveAccountsAsyncTask.Type action;
|
|
|
|
private Context context;
|
|
|
|
private ReportsListAdapter reportsListAdapter;
|
|
|
|
private String targetedId;
|
|
|
|
|
|
|
|
public ReportsListAdapter(Context context, List<Report> reports){
|
|
|
|
this.context = context;
|
|
|
|
this.reports = reports;
|
|
|
|
layoutInflater = LayoutInflater.from(context);
|
|
|
|
this.reportsListAdapter = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
|
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_report, parent, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
|
|
|
final ReportsListAdapter.ViewHolder holder = (ReportsListAdapter.ViewHolder) viewHolder;
|
|
|
|
Report report = reports.get(position);
|
2019-06-19 18:42:07 +02:00
|
|
|
Account account = report.getAccount().getAccount();
|
|
|
|
Account target_account = report.getTarget_account().getAccount();
|
2019-06-19 14:58:57 +02:00
|
|
|
|
|
|
|
|
2019-06-19 18:48:41 +02:00
|
|
|
account.makeAccountNameEmoji(context, ReportsListAdapter.this, account);
|
|
|
|
target_account.makeAccountNameEmoji(context, ReportsListAdapter.this, target_account);
|
2019-06-19 14:58:57 +02:00
|
|
|
if( account.getdisplayNameSpan() == null || account.getdisplayNameSpan().toString().trim().equals("")) {
|
|
|
|
if( account.getDisplay_name() != null && !account.getDisplay_name().trim().equals(""))
|
2019-06-19 16:05:14 +02:00
|
|
|
holder.account_dn_reporter.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true));
|
2019-06-19 14:58:57 +02:00
|
|
|
else
|
2019-06-19 16:05:14 +02:00
|
|
|
holder.account_dn_reporter.setText(account.getUsername().replace("@",""));
|
2019-06-19 14:58:57 +02:00
|
|
|
}else
|
2019-06-19 16:05:14 +02:00
|
|
|
holder.account_dn_reporter.setText( account.getdisplayNameSpan(), TextView.BufferType.SPANNABLE);
|
2019-06-19 14:58:57 +02:00
|
|
|
|
2019-06-19 16:05:14 +02:00
|
|
|
if( target_account.getdisplayNameSpan() == null || target_account.getdisplayNameSpan().toString().trim().equals("")) {
|
|
|
|
if( target_account.getDisplay_name() != null && !target_account.getDisplay_name().trim().equals(""))
|
|
|
|
holder.account_dn.setText(Helper.shortnameToUnicode(target_account.getDisplay_name(), true));
|
2019-07-24 09:39:06 +02:00
|
|
|
else {
|
|
|
|
if( target_account.getUsername() != null) {
|
|
|
|
holder.account_dn.setText(target_account.getUsername().replace("@", ""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
2019-07-25 10:33:57 +02:00
|
|
|
if( target_account.getdisplayNameSpan() != null) {
|
|
|
|
holder.account_dn.setText(target_account.getdisplayNameSpan(), TextView.BufferType.SPANNABLE);
|
|
|
|
}
|
2019-07-24 09:39:06 +02:00
|
|
|
}
|
2019-06-19 16:05:14 +02:00
|
|
|
|
|
|
|
|
2019-07-25 10:33:57 +02:00
|
|
|
if( target_account.getAvatar() != null) {
|
2019-08-02 13:41:08 +02:00
|
|
|
Helper.loadGiF(context, target_account.getAvatar(), holder.account_pp);
|
2019-07-25 10:33:57 +02:00
|
|
|
}
|
2019-08-02 13:41:08 +02:00
|
|
|
Helper.loadGiF(context, account.getAvatar(), holder.account_pp_reporter);
|
2019-07-25 10:33:57 +02:00
|
|
|
if( target_account.getAcct() != null) {
|
|
|
|
holder.account_ac.setText(target_account.getAcct());
|
|
|
|
}
|
2019-06-19 14:58:57 +02:00
|
|
|
|
2019-06-19 18:42:07 +02:00
|
|
|
holder.report_comment.setText(report.getComment());
|
2019-06-19 14:58:57 +02:00
|
|
|
|
2019-06-20 12:28:28 +02:00
|
|
|
if( report.getStatuses() != null){
|
|
|
|
holder.report_number_status.setText(String.valueOf(report.getStatuses().size()));
|
|
|
|
}else{
|
|
|
|
holder.report_number_status.setText("0");
|
|
|
|
}
|
|
|
|
|
2019-06-21 18:42:00 +02:00
|
|
|
holder.main_container.setOnClickListener(view ->{
|
|
|
|
Intent intent = new Intent(context, AccountReportActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putParcelable("report", report);
|
|
|
|
intent.putExtras(b);
|
|
|
|
context.startActivity(intent);
|
|
|
|
});
|
|
|
|
|
2019-06-19 14:58:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return reports.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Report getItemAt(int position){
|
|
|
|
if( reports.size() > position)
|
|
|
|
return reports.get(position);
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrieveEmojiAccount(Account account) {
|
|
|
|
notifyAccountChanged(account);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void notifyAccountChanged(Account account){
|
|
|
|
for (int i = 0; i < reportsListAdapter.getItemCount(); i++) {
|
|
|
|
//noinspection ConstantConditions
|
2019-06-23 14:47:23 +02:00
|
|
|
if (reportsListAdapter.getItemAt(i) != null && reportsListAdapter.getItemAt(i).getStatuses().size() > 0 && reportsListAdapter.getItemAt(i).getStatuses().get(0).getAccount().getId().equals(account.getId())) {
|
2019-06-19 14:58:57 +02:00
|
|
|
try {
|
|
|
|
reportsListAdapter.notifyItemChanged(i);
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class ViewHolder extends RecyclerView.ViewHolder{
|
2019-06-19 16:05:14 +02:00
|
|
|
ImageView account_pp, account_pp_reporter;
|
2019-06-19 14:58:57 +02:00
|
|
|
TextView account_ac;
|
2019-06-19 16:05:14 +02:00
|
|
|
TextView account_dn, account_dn_reporter;
|
2019-06-20 12:28:28 +02:00
|
|
|
TextView report_comment, report_number_status;
|
2019-06-19 14:58:57 +02:00
|
|
|
|
2019-06-21 18:42:00 +02:00
|
|
|
LinearLayout main_container;
|
2019-06-19 14:58:57 +02:00
|
|
|
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
account_pp = itemView.findViewById(R.id.account_pp);
|
2019-06-19 16:05:14 +02:00
|
|
|
account_pp_reporter = itemView.findViewById(R.id.account_pp_reporter);
|
2019-06-19 14:58:57 +02:00
|
|
|
account_dn = itemView.findViewById(R.id.account_dn);
|
2019-06-19 16:05:14 +02:00
|
|
|
account_dn_reporter = itemView.findViewById(R.id.account_dn_reporter);
|
2019-06-19 14:58:57 +02:00
|
|
|
account_ac = itemView.findViewById(R.id.account_ac);
|
2019-06-19 18:42:07 +02:00
|
|
|
report_comment = itemView.findViewById(R.id.report_comment);
|
2019-06-21 18:42:00 +02:00
|
|
|
main_container = itemView.findViewById(R.id.main_container);
|
2019-06-20 12:28:28 +02:00
|
|
|
report_number_status = itemView.findViewById(R.id.report_number_status);
|
2019-06-19 14:58:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|