97 lines
3.0 KiB
Java
97 lines
3.0 KiB
Java
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.os.Build;
|
|
import android.text.Html;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.List;
|
|
|
|
import app.fedilab.android.R;
|
|
|
|
public class StatusReportAdapter extends RecyclerView.Adapter<StatusReportAdapter.ViewHolder> {
|
|
|
|
private final List<String> mData;
|
|
private ItemClickListener mClickListener;
|
|
|
|
|
|
public StatusReportAdapter(List<String> data) {
|
|
this.mData = data;
|
|
}
|
|
|
|
|
|
@NotNull
|
|
@Override
|
|
public ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
|
|
Context context = parent.getContext();
|
|
LayoutInflater mInflater = LayoutInflater.from(context);
|
|
View view = mInflater.inflate(R.layout.drawer_status_report, parent, false);
|
|
return new ViewHolder(view);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NotNull ViewHolder holder, int position) {
|
|
String content;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
|
content = Html.fromHtml(mData.get(position), Html.FROM_HTML_MODE_LEGACY).toString();
|
|
else
|
|
content = Html.fromHtml(mData.get(position)).toString();
|
|
holder.report_content.setText(content);
|
|
}
|
|
|
|
// total number of rows
|
|
@Override
|
|
public int getItemCount() {
|
|
return mData.size();
|
|
}
|
|
|
|
String getItem(int id) {
|
|
return mData.get(id);
|
|
}
|
|
|
|
void setClickListener(ItemClickListener itemClickListener) {
|
|
this.mClickListener = itemClickListener;
|
|
}
|
|
|
|
public interface ItemClickListener {
|
|
void onItemClick(View view, int position);
|
|
}
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
TextView report_content;
|
|
|
|
ViewHolder(View itemView) {
|
|
super(itemView);
|
|
report_content = itemView.findViewById(R.id.report_content);
|
|
itemView.setOnClickListener(this);
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View view) {
|
|
if (mClickListener != null) mClickListener.onItemClick(view, getAdapterPosition());
|
|
}
|
|
}
|
|
} |