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-08-23 11:38:41 +02:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.view.LayoutInflater;
|
2017-11-03 13:55:18 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-11-06 11:56:23 +01:00
|
|
|
import android.widget.BaseAdapter;
|
2017-11-03 13:55:18 +01:00
|
|
|
import android.widget.ImageView;
|
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2017-11-03 13:55:18 +01:00
|
|
|
|
2017-12-02 11:02:25 +01:00
|
|
|
import com.bumptech.glide.Glide;
|
2020-04-09 14:59:36 +02:00
|
|
|
import com.bumptech.glide.request.target.CustomTarget;
|
2019-08-23 11:38:41 +02:00
|
|
|
import com.bumptech.glide.request.transition.Transition;
|
2020-04-08 12:42:15 +02:00
|
|
|
|
2017-11-03 13:55:18 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-08-23 11:38:41 +02:00
|
|
|
import app.fedilab.android.R;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.client.Entities.Emojis;
|
2019-08-23 11:38:41 +02:00
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
|
2017-11-03 13:55:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 03/11/2017.
|
|
|
|
* Adapter to display custom emojis
|
|
|
|
*/
|
2019-11-06 11:56:23 +01:00
|
|
|
public class CustomEmojiAdapter extends BaseAdapter {
|
2017-11-03 13:55:18 +01:00
|
|
|
|
|
|
|
|
2021-01-19 17:43:51 +01:00
|
|
|
private final List<Emojis> emojis;
|
2017-11-03 13:55:18 +01:00
|
|
|
|
2019-11-06 11:56:23 +01:00
|
|
|
public CustomEmojiAdapter(List<Emojis> emojis) {
|
2017-11-03 13:55:18 +01:00
|
|
|
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) {
|
2019-11-06 11:56:23 +01:00
|
|
|
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
|
2019-08-23 11:38:41 +02:00
|
|
|
convertView = layoutInflater.inflate(R.layout.drawer_emoji_picker, parent, false);
|
|
|
|
imageView = convertView.findViewById(R.id.img_custom_emoji);
|
2017-11-03 13:55:18 +01:00
|
|
|
} else {
|
|
|
|
imageView = (ImageView) convertView;
|
|
|
|
}
|
2019-08-23 11:38:41 +02:00
|
|
|
|
|
|
|
|
2020-04-05 19:26:08 +02:00
|
|
|
SharedPreferences sharedpreferences = parent.getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
2020-03-08 10:29:06 +01:00
|
|
|
Glide.with(parent.getContext())
|
2020-04-08 12:42:15 +02:00
|
|
|
.load(!disableAnimatedEmoji ? emoji.getUrl() : emoji.getStatic_url())
|
2020-03-08 10:29:06 +01:00
|
|
|
.thumbnail(0.1f)
|
2020-04-09 14:59:36 +02:00
|
|
|
.into(new CustomTarget<Drawable>() {
|
2020-03-08 10:29:06 +01:00
|
|
|
@Override
|
2020-04-05 19:26:08 +02:00
|
|
|
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
|
|
|
emoji.setDrawable(resource);
|
2020-06-20 11:14:22 +02:00
|
|
|
if (imageView != null && emoji.getDrawable() != null) {
|
2020-07-17 17:07:15 +02:00
|
|
|
try {
|
|
|
|
imageView.setImageDrawable(emoji.getDrawable());
|
2020-07-24 19:52:36 +02:00
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2020-06-19 18:00:48 +02:00
|
|
|
}
|
2020-03-08 10:29:06 +01:00
|
|
|
}
|
2020-04-09 14:59:36 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadCleared(@Nullable Drawable placeholder) {
|
|
|
|
|
|
|
|
}
|
2020-03-08 10:29:06 +01:00
|
|
|
});
|
2019-08-23 11:38:41 +02:00
|
|
|
return convertView;
|
2017-11-03 13:55:18 +01:00
|
|
|
}
|
|
|
|
}
|