mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-01-07 00:20:08 +02:00
Fix issue #263 - Custom emoji for Friendica
This commit is contained in:
parent
b060dcb38d
commit
c033064d13
3 changed files with 70 additions and 31 deletions
|
@ -17,6 +17,7 @@ package app.fedilab.android.activities;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -25,10 +26,14 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
|
||||
import app.fedilab.android.BaseMainActivity;
|
||||
import app.fedilab.android.R;
|
||||
|
@ -89,6 +94,7 @@ public class InstanceActivity extends BaseActivity {
|
|||
if (instanceInfo == null || instanceInfo.info == null || instanceInfo.info.description == null) {
|
||||
binding.maxCharContainer.setVisibility(View.VISIBLE);
|
||||
binding.instanceContainer.setVisibility(View.GONE);
|
||||
binding.instanceContact.setVisibility(View.GONE);
|
||||
int val = sharedpreferences.getInt(getString(R.string.SET_MAX_INSTANCE_CHAR) + MainActivity.currentInstance, -1);
|
||||
if (val != -1) {
|
||||
binding.maxChar.setText(String.valueOf(val));
|
||||
|
@ -110,9 +116,20 @@ public class InstanceActivity extends BaseActivity {
|
|||
binding.instanceContact.hide();
|
||||
}
|
||||
Glide.with(InstanceActivity.this)
|
||||
.asBitmap()
|
||||
.asDrawable()
|
||||
.load(instance.thumbnail)
|
||||
.into(binding.backGroundImage);
|
||||
.into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
binding.background.setAlpha(0.2f);
|
||||
binding.background.setBackground(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
binding.instanceContact.setOnClickListener(v -> {
|
||||
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", instance.email, null));
|
||||
|
|
|
@ -54,6 +54,7 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -89,6 +90,17 @@ public class SpannableHelper {
|
|||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
Pattern imgPattern = Pattern.compile("<img [^>]*src=\"([^\"]+)\"[^>]*>");
|
||||
Matcher matcherImg = imgPattern.matcher(text);
|
||||
HashMap<String, String> imagesToReplace = new LinkedHashMap<>();
|
||||
int inc = 0;
|
||||
while (matcherImg.find()) {
|
||||
String replacement = "[FEDI_IMG_" + inc + "]";
|
||||
imagesToReplace.put(replacement, matcherImg.group(1));
|
||||
inc++;
|
||||
text = text.replaceAll(Pattern.quote(matcherImg.group()), replacement);
|
||||
}
|
||||
|
||||
SpannableStringBuilder content;
|
||||
View view = viewWeakReference.get();
|
||||
List<Mention> mentionList = null;
|
||||
|
@ -148,6 +160,24 @@ public class SpannableHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (imagesToReplace.size() > 0) {
|
||||
for (Map.Entry<String, String> entry : imagesToReplace.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String url = entry.getValue();
|
||||
Matcher matcher = Pattern.compile(key, Pattern.LITERAL)
|
||||
.matcher(content);
|
||||
while (matcher.find()) {
|
||||
CustomEmoji customEmoji = new CustomEmoji(new WeakReference<>(view));
|
||||
content.setSpan(customEmoji, matcher.start(), matcher.end(), 0);
|
||||
Glide.with(view)
|
||||
.asDrawable()
|
||||
.load(url)
|
||||
.into(customEmoji.getTarget(true));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return trimSpannable(new SpannableStringBuilder(content));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,31 +22,19 @@
|
|||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/main_container"
|
||||
android:layout_height="420dp"
|
||||
android:padding="@dimen/fab_margin"
|
||||
android:paddingLeft="@dimen/drawer_padding"
|
||||
android:paddingRight="@dimen/drawer_padding">
|
||||
|
||||
<RelativeLayout
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:id="@+id/background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:alpha="0.2">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_ground_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:contentDescription="@string/logo_of_the_instance"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@tools:sample/backgrounds/scenic" />
|
||||
</RelativeLayout>
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="300dp"
|
||||
android:id="@+id/instance_container"
|
||||
android:layout_width="match_parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
@ -97,15 +85,7 @@
|
|||
android:textStyle="italic" />
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/instance_contact"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:contentDescription="@string/contact_instance_admin"
|
||||
android:src="@drawable/ic_baseline_mail_outline_24"
|
||||
app:backgroundTint="@color/cyanea_accent_dark_reference" />
|
||||
|
||||
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
@ -142,7 +122,7 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="420dp"
|
||||
android:gravity="center"
|
||||
tools:visibility="visible"
|
||||
android:visibility="gone">
|
||||
|
@ -153,6 +133,18 @@
|
|||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/instance_contact"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:contentDescription="@string/contact_instance_admin"
|
||||
android:src="@drawable/ic_baseline_mail_outline_24"
|
||||
app:backgroundTint="@color/cyanea_accent_dark_reference"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -165,10 +157,10 @@
|
|||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/close"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
Loading…
Reference in a new issue