2019-07-20 15:15:47 +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;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-07-20 15:15:47 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-07-20 15:15:47 +02:00
|
|
|
import java.util.List;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-07-20 15:15:47 +02:00
|
|
|
import app.fedilab.android.R;
|
|
|
|
import app.fedilab.android.client.Entities.Suggestion;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 19/07/2019.
|
|
|
|
* Adapter for suggestions results
|
|
|
|
*/
|
2020-06-16 18:23:13 +02:00
|
|
|
public class SuggestionsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
2019-07-20 15:15:47 +02:00
|
|
|
|
|
|
|
private Context context;
|
|
|
|
private List<Suggestion> suggestions;
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
public SuggestionsAdapter(List<Suggestion> suggestions) {
|
2019-07-20 15:15:47 +02:00
|
|
|
this.suggestions = suggestions;
|
2019-08-19 09:18:30 +02:00
|
|
|
|
2019-07-20 15:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Suggestion getItem(int position) {
|
2019-09-06 17:55:14 +02:00
|
|
|
return suggestions.get(position);
|
2019-07-20 15:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
|
2019-08-19 09:18:30 +02:00
|
|
|
context = parent.getContext();
|
|
|
|
LayoutInflater layoutInflater = LayoutInflater.from(context);
|
2019-07-20 15:15:47 +02:00
|
|
|
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_suggestions, parent, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
|
|
|
final ViewHolder holder = (ViewHolder) viewHolder;
|
|
|
|
final Suggestion suggestion = getItem(i);
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
if (suggestion.getType() == Suggestion.suggestionType.TAG) {
|
2019-07-20 15:15:47 +02:00
|
|
|
holder.suggestion_content.setText(String.format("#%s", suggestion.getContent()));
|
|
|
|
holder.suggestion_image.setVisibility(View.GONE);
|
2019-09-06 17:55:14 +02:00
|
|
|
} else {
|
2019-07-20 15:15:47 +02:00
|
|
|
holder.suggestion_content.setText(suggestion.getContent());
|
2019-08-02 13:41:08 +02:00
|
|
|
Helper.loadGiF(context, suggestion.getImageUrl(), holder.suggestion_image);
|
2019-07-20 15:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return suggestions.size();
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:16:28 +01:00
|
|
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
2019-11-15 16:32:25 +01:00
|
|
|
private TextView suggestion_content;
|
|
|
|
private ImageView suggestion_image;
|
|
|
|
|
|
|
|
public ViewHolder(@NonNull View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
suggestion_content = itemView.findViewById(R.id.suggestion_content);
|
|
|
|
suggestion_image = itemView.findViewById(R.id.suggestion_image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-20 15:15:47 +02:00
|
|
|
|
|
|
|
}
|