2019-05-18 11:10:30 +02:00
|
|
|
package app.fedilab.android.drawers;
|
2017-11-03 13:55:18 +01:00
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* This file is a part of Fedilab
|
2017-11-03 13:55:18 +01: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
|
2017-11-03 13:55:18 +01: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,
|
2017-11-03 13:55:18 +01:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
2019-06-11 19:38:26 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2017-11-03 13:55:18 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.GridView;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
|
|
|
|
2017-12-02 11:02:25 +01:00
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
|
2017-11-03 13:55:18 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.client.Entities.Emojis;
|
2017-11-03 13:55:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 03/11/2017.
|
|
|
|
* Adapter to display custom emojis
|
|
|
|
*/
|
|
|
|
public class CustomEmojiAdapter extends ArrayAdapter {
|
|
|
|
|
|
|
|
|
|
|
|
private Context context;
|
|
|
|
private List<Emojis> emojis;
|
|
|
|
|
|
|
|
public CustomEmojiAdapter(@NonNull Context context, int resource, List<Emojis> emojis) {
|
|
|
|
super(context, resource, resource);
|
|
|
|
this.context = context;
|
|
|
|
this.emojis = emojis;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return emojis.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Emojis getItem(int position) {
|
|
|
|
return emojis.get(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
|
|
|
|
final ImageView imageView;
|
|
|
|
Emojis emoji = emojis.get(position);
|
|
|
|
if (convertView == null) {
|
|
|
|
imageView = new ImageView(context);
|
|
|
|
float density = context.getResources().getDisplayMetrics().density;
|
2019-07-26 16:36:37 +02:00
|
|
|
imageView.setLayoutParams(new GridView.LayoutParams((int)(40*density), (int)(40*density)));
|
|
|
|
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
2017-11-03 13:55:18 +01:00
|
|
|
imageView.setPadding((int)(2*density), (int)(5*density), (int)(2*density), (int)(5*density));
|
|
|
|
} else {
|
|
|
|
imageView = (ImageView) convertView;
|
|
|
|
}
|
2017-12-02 11:02:25 +01:00
|
|
|
Glide.with(context)
|
|
|
|
.load(emoji.getUrl())
|
2019-07-26 16:36:37 +02:00
|
|
|
.into(imageView);
|
2017-11-03 13:55:18 +01:00
|
|
|
return imageView;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|