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;
|
2019-08-23 11:38:41 +02:00
|
|
|
import com.bumptech.glide.request.target.SimpleTarget;
|
|
|
|
import com.bumptech.glide.request.transition.Transition;
|
|
|
|
import com.github.penfeizhou.animation.apng.APNGDrawable;
|
2019-08-23 15:31:22 +02:00
|
|
|
import com.github.penfeizhou.animation.apng.decode.APNGParser;
|
2019-08-23 11:38:41 +02:00
|
|
|
import com.github.penfeizhou.animation.gif.GifDrawable;
|
2019-08-23 11:46:50 +02:00
|
|
|
import com.github.penfeizhou.animation.gif.decode.GifParser;
|
2017-12-02 11:02:25 +01:00
|
|
|
|
2019-08-23 11:38:41 +02:00
|
|
|
import java.io.File;
|
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
|
|
|
|
|
|
|
|
|
|
|
private List<Emojis> emojis;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2019-11-16 18:36:08 +01:00
|
|
|
//if (!emoji.isDrawableFound()) {
|
2019-08-23 15:31:22 +02:00
|
|
|
emoji.setDrawableFound(true);
|
2019-11-06 11:56:23 +01:00
|
|
|
Glide.with(parent.getContext())
|
2019-08-23 15:31:22 +02:00
|
|
|
.asFile()
|
|
|
|
.load(emoji.getUrl())
|
|
|
|
.thumbnail(0.1f)
|
|
|
|
.into(new SimpleTarget<File>() {
|
|
|
|
@Override
|
|
|
|
public void onResourceReady(@NonNull File resourceFile, @Nullable Transition<? super File> transition) {
|
2019-08-23 19:08:52 +02:00
|
|
|
Drawable resource;
|
2019-11-06 11:56:23 +01:00
|
|
|
SharedPreferences sharedpreferences = parent.getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
2019-08-23 19:08:52 +02:00
|
|
|
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!disableAnimatedEmoji) {
|
2019-08-23 19:08:52 +02:00
|
|
|
if (GifParser.isGif(resourceFile.getAbsolutePath())) {
|
|
|
|
resource = GifDrawable.fromFile(resourceFile.getAbsolutePath());
|
|
|
|
emoji.setDrawable(resource);
|
|
|
|
} else if (APNGParser.isAPNG(resourceFile.getAbsolutePath())) {
|
|
|
|
resource = APNGDrawable.fromFile(resourceFile.getAbsolutePath());
|
|
|
|
emoji.setDrawable(resource);
|
|
|
|
} else {
|
|
|
|
resource = Drawable.createFromPath(resourceFile.getAbsolutePath());
|
|
|
|
emoji.setDrawable(resource);
|
|
|
|
|
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
} else {
|
2019-08-23 19:08:52 +02:00
|
|
|
resource = Drawable.createFromPath(resourceFile.getAbsolutePath());
|
|
|
|
emoji.setDrawable(resource);
|
|
|
|
}
|
2019-11-06 11:56:23 +01:00
|
|
|
imageView.setImageDrawable(emoji.getDrawable());
|
2019-08-23 11:38:41 +02:00
|
|
|
}
|
2019-08-23 15:31:22 +02:00
|
|
|
});
|
2019-11-16 18:36:08 +01:00
|
|
|
// }
|
2019-08-23 11:38:41 +02:00
|
|
|
return convertView;
|
2017-11-03 13:55:18 +01:00
|
|
|
}
|
|
|
|
}
|