2019-05-18 11:10:30 +02:00
|
|
|
package app.fedilab.android.drawers;
|
2018-09-05 15:02:48 +02:00
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* This file is a part of Fedilab
|
2018-09-05 15:02:48 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2018-09-05 15:02:48 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
2018-09-05 15:02:48 +02:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
2019-06-11 19:38:26 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2018-09-05 15:02:48 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.client.Entities.Attachment;
|
|
|
|
import app.fedilab.android.client.Entities.Status;
|
|
|
|
import app.fedilab.android.R;
|
|
|
|
import app.fedilab.android.activities.MediaActivity;
|
|
|
|
import app.fedilab.android.activities.ShowAccountActivity;
|
|
|
|
import app.fedilab.android.activities.ShowConversationActivity;
|
2018-09-05 15:02:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 05/09/2018.
|
|
|
|
* Adapter to display media related to status
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class ImageAdapter extends RecyclerView.Adapter {
|
|
|
|
private Context context;
|
2019-01-22 18:07:06 +01:00
|
|
|
private List<Status> statuses;
|
2018-09-05 15:02:48 +02:00
|
|
|
private LayoutInflater layoutInflater;
|
|
|
|
|
2019-01-22 18:07:06 +01:00
|
|
|
public ImageAdapter(Context context, List<Status> statuses) {
|
2018-09-05 15:02:48 +02:00
|
|
|
this.context = context;
|
2019-01-22 18:07:06 +01:00
|
|
|
this.statuses = statuses;
|
2018-09-05 15:02:48 +02:00
|
|
|
this.layoutInflater = LayoutInflater.from(this.context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getCount() {
|
2019-01-22 18:07:06 +01:00
|
|
|
return statuses.size();
|
2018-09-05 15:02:48 +02:00
|
|
|
}
|
|
|
|
|
2019-01-22 18:07:06 +01:00
|
|
|
public Status getItem(int position) {
|
|
|
|
return statuses.get(position);
|
2018-09-05 15:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
|
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_media, parent, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
2019-01-22 18:07:06 +01:00
|
|
|
Status status = statuses.get(position);
|
2018-09-05 15:02:48 +02:00
|
|
|
|
|
|
|
final ImageAdapter.ViewHolder holder = (ImageAdapter.ViewHolder) viewHolder;
|
|
|
|
|
|
|
|
if( !((ShowAccountActivity)context).isFinishing())
|
2019-01-22 18:07:06 +01:00
|
|
|
Glide.with(context).load(status.getArt_attachment().getPreview_url()).into(holder.imageView);
|
2018-09-05 15:02:48 +02:00
|
|
|
holder.imageView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(context, MediaActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
ArrayList<Attachment> attachmentsTmp = new ArrayList<>();
|
2019-01-22 18:07:06 +01:00
|
|
|
for(Status status1: statuses){
|
|
|
|
attachmentsTmp.add(status1.getArt_attachment());
|
|
|
|
}
|
2018-09-05 15:02:48 +02:00
|
|
|
intent.putParcelableArrayListExtra("mediaArray", attachmentsTmp);
|
2019-01-23 15:38:02 +01:00
|
|
|
b.putInt("position", (viewHolder.getAdapterPosition()+1));
|
2018-09-05 15:02:48 +02:00
|
|
|
intent.putExtras(b);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
2019-01-22 18:07:06 +01:00
|
|
|
holder.imageView.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
Intent intent = new Intent(context, ShowConversationActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putParcelable("status", status);
|
|
|
|
intent.putExtras(b);
|
|
|
|
context.startActivity(intent);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2018-09-05 15:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2019-01-22 18:07:06 +01:00
|
|
|
return statuses.size();
|
2018-09-05 15:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ViewHolder extends RecyclerView.ViewHolder{
|
|
|
|
ImageView imageView;
|
|
|
|
|
|
|
|
public ViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
imageView = itemView.findViewById(R.id.media);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|