Some tries
This commit is contained in:
parent
aa3c6f07e7
commit
455e5666a9
@ -85,11 +85,9 @@ dependencies {
|
|||||||
implementation 'com.github.GrenderG:Toasty:1.5.2'
|
implementation 'com.github.GrenderG:Toasty:1.5.2'
|
||||||
implementation 'org.framagit.tom79:SparkButton:1.0.13'
|
implementation 'org.framagit.tom79:SparkButton:1.0.13'
|
||||||
implementation "com.github.bumptech.glide:glide:4.12.0"
|
implementation "com.github.bumptech.glide:glide:4.12.0"
|
||||||
|
implementation "com.github.bumptech.glide:okhttp3-integration:4.12.0"
|
||||||
|
|
||||||
implementation 'com.github.mergehez:ArgPlayer:v3.1'
|
implementation 'com.github.mergehez:ArgPlayer:v3.1'
|
||||||
implementation ("com.github.bumptech.glide:recyclerview-integration:4.12.0") {
|
|
||||||
// Excludes the support library because it's already included by Glide.
|
|
||||||
transitive = false
|
|
||||||
}
|
|
||||||
implementation project(path: ':mytransl')
|
implementation project(path: ':mytransl')
|
||||||
implementation project(path: ':ratethisapp')
|
implementation project(path: ':ratethisapp')
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ public class Account implements Serializable {
|
|||||||
public transient Spannable span_display_name;
|
public transient Spannable span_display_name;
|
||||||
public transient Spannable span_note;
|
public transient Spannable span_note;
|
||||||
public transient RelationShip relationShip;
|
public transient RelationShip relationShip;
|
||||||
|
public boolean emojiFetched = false;
|
||||||
|
|
||||||
public static class AccountParams implements Serializable {
|
public static class AccountParams implements Serializable {
|
||||||
@SerializedName("discoverable")
|
@SerializedName("discoverable")
|
||||||
|
@ -105,6 +105,7 @@ public class Status implements Serializable, Cloneable {
|
|||||||
public transient boolean setCursorToEnd = false;
|
public transient boolean setCursorToEnd = false;
|
||||||
public transient int cursorPosition = 0;
|
public transient int cursorPosition = 0;
|
||||||
public transient boolean submitted = false;
|
public transient boolean submitted = false;
|
||||||
|
public transient boolean emojiFetched = false;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public Object clone() throws CloneNotSupportedException {
|
public Object clone() throws CloneNotSupportedException {
|
||||||
|
@ -1,13 +1,24 @@
|
|||||||
package app.fedilab.android.helper;
|
package app.fedilab.android.helper;
|
||||||
|
/* Copyright 2022 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.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.drawable.Animatable;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.style.ReplacementSpan;
|
import android.text.style.ImageSpan;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -16,10 +27,9 @@ import androidx.preference.PreferenceManager;
|
|||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.request.target.CustomTarget;
|
import com.bumptech.glide.request.target.CustomTarget;
|
||||||
import com.bumptech.glide.request.target.Target;
|
|
||||||
import com.bumptech.glide.request.transition.Transition;
|
import com.bumptech.glide.request.transition.Transition;
|
||||||
|
import com.github.penfeizhou.animation.apng.APNGDrawable;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -27,73 +37,42 @@ import java.util.regex.Pattern;
|
|||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.client.entities.api.Emoji;
|
import app.fedilab.android.client.entities.api.Emoji;
|
||||||
|
|
||||||
public class CustomEmoji extends ReplacementSpan {
|
public class CustomEmoji {
|
||||||
|
|
||||||
|
|
||||||
private final float scale;
|
public static void displayEmoji(Context context, List<Emoji> emojis, Spannable content, View view, String id, Callback listener) {
|
||||||
private Drawable imageDrawable;
|
|
||||||
private final WeakReference<View> viewWeakReference;
|
|
||||||
|
|
||||||
|
|
||||||
CustomEmoji(WeakReference<View> viewWeakReference) {
|
|
||||||
Context mContext = viewWeakReference.get().getContext();
|
|
||||||
this.viewWeakReference = viewWeakReference;
|
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
|
||||||
scale = sharedpreferences.getFloat(mContext.getString(R.string.SET_FONT_SCALE), 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void displayEmoji(List<Emoji> emojis, Spannable spannableString, View view) {
|
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(view.getContext());
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(view.getContext());
|
||||||
boolean animate = !sharedpreferences.getBoolean(view.getContext().getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false);
|
boolean animate = !sharedpreferences.getBoolean(view.getContext().getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false);
|
||||||
|
int count = 1;
|
||||||
for (Emoji emoji : emojis) {
|
for (Emoji emoji : emojis) {
|
||||||
Matcher matcher = Pattern.compile(":" + emoji.shortcode + ":", Pattern.LITERAL)
|
int finalCount = count;
|
||||||
.matcher(spannableString);
|
|
||||||
while (matcher.find()) {
|
|
||||||
CustomEmoji customEmoji = new CustomEmoji(new WeakReference<>(view));
|
|
||||||
spannableString.setSpan(customEmoji, matcher.start(), matcher.end(), 0);
|
|
||||||
Glide.with(view.getContext())
|
Glide.with(view.getContext())
|
||||||
.asDrawable()
|
.asDrawable()
|
||||||
.load(animate ? emoji.url : emoji.static_url)
|
.load(animate ? emoji.url : emoji.static_url)
|
||||||
.into(customEmoji.getTarget(animate));
|
.into(
|
||||||
}
|
new CustomTarget<Drawable>() {
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSize(@NonNull Paint paint, CharSequence charSequence, int i, int i1, @Nullable Paint.FontMetricsInt fontMetricsInt) {
|
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
||||||
if (fontMetricsInt != null) {
|
super.onLoadFailed(errorDrawable);
|
||||||
Paint.FontMetrics fontMetrics = paint.getFontMetrics();
|
if (finalCount == emojis.size()) {
|
||||||
fontMetricsInt.top = (int) fontMetrics.top;
|
listener.allEmojisfound(id);
|
||||||
fontMetricsInt.ascent = (int) fontMetrics.ascent;
|
|
||||||
fontMetricsInt.descent = (int) fontMetrics.descent;
|
|
||||||
fontMetricsInt.bottom = (int) fontMetrics.bottom;
|
|
||||||
}
|
|
||||||
return (int) (paint.getTextSize() * scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(@NonNull Canvas canvas, CharSequence charSequence, int start, int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
|
|
||||||
|
|
||||||
if (imageDrawable != null) {
|
|
||||||
canvas.save();
|
|
||||||
int emojiSize = (int) (paint.getTextSize() * scale);
|
|
||||||
Drawable drawable = imageDrawable;
|
|
||||||
drawable.setBounds(0, 0, emojiSize, emojiSize);
|
|
||||||
int transY = bottom - drawable.getBounds().bottom;
|
|
||||||
transY -= paint.getFontMetrics().descent / 2;
|
|
||||||
canvas.translate(x, (float) transY);
|
|
||||||
drawable.draw(canvas);
|
|
||||||
canvas.restore();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Target<Drawable> getTarget(boolean animate) {
|
|
||||||
return new CustomTarget<Drawable>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||||
View view = viewWeakReference.get();
|
Matcher matcher = Pattern.compile(":" + emoji.shortcode + ":", Pattern.LITERAL)
|
||||||
if (animate && resource instanceof Animatable) {
|
.matcher(content);
|
||||||
|
while (matcher.find()) {
|
||||||
|
ImageSpan imageSpan;
|
||||||
|
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||||
|
resource.setVisible(true, true);
|
||||||
|
imageSpan = new ImageSpan(resource);
|
||||||
|
content.setSpan(
|
||||||
|
imageSpan, matcher.start(),
|
||||||
|
matcher.end(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
}
|
||||||
|
if (animate && resource instanceof APNGDrawable) {
|
||||||
Drawable.Callback callback = resource.getCallback();
|
Drawable.Callback callback = resource.getCallback();
|
||||||
resource.setCallback(new Drawable.Callback() {
|
resource.setCallback(new Drawable.Callback() {
|
||||||
@Override
|
@Override
|
||||||
@ -118,16 +97,26 @@ public class CustomEmoji extends ReplacementSpan {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
((Animatable) resource).start();
|
((APNGDrawable) resource).start();
|
||||||
|
|
||||||
|
}
|
||||||
|
if (finalCount == emojis.size()) {
|
||||||
|
listener.allEmojisfound(id);
|
||||||
}
|
}
|
||||||
imageDrawable = resource;
|
|
||||||
view.invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Callback {
|
||||||
|
void allEmojisfound(String id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -878,19 +878,18 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//--- MAIN CONTENT ---
|
//--- MAIN CONTENT ---
|
||||||
if (statusToDeal.emojis != null && statusToDeal.emojis.size() > 0) {
|
|
||||||
CustomEmoji.displayEmoji(statusToDeal.emojis, statusToDeal.span_content, holder.binding.statusContent);
|
|
||||||
holder.binding.statusContent.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
holder.binding.statusContent.setText(statusToDeal.span_content, TextView.BufferType.SPANNABLE);
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
} else {
|
|
||||||
holder.binding.statusContent.setText(statusToDeal.span_content, TextView.BufferType.SPANNABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
CustomEmoji.displayEmoji(context, statusToDeal.emojis, statusToDeal.span_content, holder.binding.statusContent, status.id, id -> {
|
||||||
|
if (!status.emojiFetched) {
|
||||||
|
status.emojiFetched = true;
|
||||||
|
if (timelineType == Timeline.TimeLineEnum.UNKNOWN) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
holder.binding.statusContent.post(() -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// CustomEmoji.displayEmoji(statusToDeal.emojis, statusToDeal.span_content, holder.binding.statusContent, null, null);
|
||||||
|
holder.binding.statusContent.setText(statusToDeal.span_content, TextView.BufferType.SPANNABLE);
|
||||||
if (truncate_toots_size > 0) {
|
if (truncate_toots_size > 0) {
|
||||||
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
||||||
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);
|
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
@ -1733,6 +1732,34 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will manage the current position of the element in the adapter. Action is async, and position might have changed
|
||||||
|
*
|
||||||
|
* @param notificationList List<Notification> - Not null when calling from notification adapter
|
||||||
|
* @param statusList ist<Status> statusList - Not null when calling from status adapter
|
||||||
|
* @param id String - Current status
|
||||||
|
* @return int - position in real time
|
||||||
|
*/
|
||||||
|
public static int getPositionAsync(List<Notification> notificationList, List<Status> statusList, String id) {
|
||||||
|
int position = 0;
|
||||||
|
if (statusList != null) {
|
||||||
|
for (Status _status : statusList) {
|
||||||
|
if (id != null && ((_status.id != null && _status.id.compareTo(id) == 0) || (_status.reblog != null && _status.reblog.id != null && _status.reblog.id.compareTo(id) == 0))) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
} else if (notificationList != null) {
|
||||||
|
for (Notification notification : notificationList) {
|
||||||
|
if (notification.status != null && notification.status.id.compareTo(id) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
if (timelineType == Timeline.TimeLineEnum.ART) {
|
if (timelineType == Timeline.TimeLineEnum.ART) {
|
||||||
|
@ -461,7 +461,9 @@ public class StatusesVM extends AndroidViewModel {
|
|||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
Accounts accountsPagination = new Accounts();
|
Accounts accountsPagination = new Accounts();
|
||||||
accountsPagination.accounts = accounts;
|
accountsPagination.accounts = accounts;
|
||||||
|
if (headers != null) {
|
||||||
accountsPagination.pagination = MastodonHelper.getPagination(headers);
|
accountsPagination.pagination = MastodonHelper.getPagination(headers);
|
||||||
|
}
|
||||||
Runnable myRunnable = () -> accountsMutableLiveData.setValue(accountsPagination);
|
Runnable myRunnable = () -> accountsMutableLiveData.setValue(accountsPagination);
|
||||||
mainHandler.post(myRunnable);
|
mainHandler.post(myRunnable);
|
||||||
}).start();
|
}).start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user