mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Make links and media clickable when composing
This commit is contained in:
parent
0861becc56
commit
4711d5fd23
4 changed files with 84 additions and 0 deletions
|
@ -48,6 +48,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
|
@ -59,6 +60,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.widget.AppCompatEditText;
|
import androidx.appcompat.widget.AppCompatEditText;
|
||||||
import androidx.appcompat.widget.LinearLayoutCompat;
|
import androidx.appcompat.widget.LinearLayoutCompat;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.core.app.ActivityOptionsCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
@ -101,9 +103,11 @@ import app.fedilab.android.activities.MainActivity;
|
||||||
import app.fedilab.android.databinding.ComposeAttachmentItemBinding;
|
import app.fedilab.android.databinding.ComposeAttachmentItemBinding;
|
||||||
import app.fedilab.android.databinding.ComposePollBinding;
|
import app.fedilab.android.databinding.ComposePollBinding;
|
||||||
import app.fedilab.android.databinding.ComposePollItemBinding;
|
import app.fedilab.android.databinding.ComposePollItemBinding;
|
||||||
|
import app.fedilab.android.databinding.DrawerMediaListBinding;
|
||||||
import app.fedilab.android.databinding.DrawerStatusComposeBinding;
|
import app.fedilab.android.databinding.DrawerStatusComposeBinding;
|
||||||
import app.fedilab.android.databinding.DrawerStatusSimpleBinding;
|
import app.fedilab.android.databinding.DrawerStatusSimpleBinding;
|
||||||
import app.fedilab.android.mastodon.activities.ComposeActivity;
|
import app.fedilab.android.mastodon.activities.ComposeActivity;
|
||||||
|
import app.fedilab.android.mastodon.activities.MediaActivity;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.Account;
|
import app.fedilab.android.mastodon.client.entities.api.Account;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.Attachment;
|
import app.fedilab.android.mastodon.client.entities.api.Attachment;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.Emoji;
|
import app.fedilab.android.mastodon.client.entities.api.Emoji;
|
||||||
|
@ -1343,6 +1347,38 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||||
if (getItemViewType(position) == TYPE_NORMAL) {
|
if (getItemViewType(position) == TYPE_NORMAL) {
|
||||||
Status status = statusList.get(position);
|
Status status = statusList.get(position);
|
||||||
StatusSimpleViewHolder holder = (StatusSimpleViewHolder) viewHolder;
|
StatusSimpleViewHolder holder = (StatusSimpleViewHolder) viewHolder;
|
||||||
|
if(status.media_attachments != null && status.media_attachments.size() > 0 ) {
|
||||||
|
holder.binding.simpleMedia.removeAllViews();
|
||||||
|
List<Attachment> attachmentList = statusList.get(position).media_attachments;
|
||||||
|
for(Attachment attachment: attachmentList) {
|
||||||
|
DrawerMediaListBinding drawerMediaListBinding = DrawerMediaListBinding.inflate(LayoutInflater.from(context), holder.binding.simpleMedia, false);
|
||||||
|
Glide.with(drawerMediaListBinding.media.getContext())
|
||||||
|
.load(attachment.preview_url)
|
||||||
|
.into(drawerMediaListBinding.media);
|
||||||
|
|
||||||
|
if(attachment.filename != null) {
|
||||||
|
drawerMediaListBinding.mediaName.setText(attachment.filename);
|
||||||
|
} else if (attachment.preview_url != null){
|
||||||
|
drawerMediaListBinding.mediaName.setText(URLUtil.guessFileName(attachment.preview_url, null, null));
|
||||||
|
}
|
||||||
|
drawerMediaListBinding.getRoot().setOnClickListener(v->{
|
||||||
|
Intent mediaIntent = new Intent(context, MediaActivity.class);
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
ArrayList<Attachment> attachments = new ArrayList<>();
|
||||||
|
attachments.add(attachment);
|
||||||
|
b.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
|
||||||
|
mediaIntent.putExtras(b);
|
||||||
|
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||||
|
.makeSceneTransitionAnimation((Activity) context, drawerMediaListBinding.media, attachment.url);
|
||||||
|
context.startActivity(mediaIntent, options.toBundle());
|
||||||
|
});
|
||||||
|
holder.binding.simpleMedia.addView(drawerMediaListBinding.getRoot());
|
||||||
|
|
||||||
|
}
|
||||||
|
holder.binding.simpleMediaContainer.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
holder.binding.simpleMediaContainer.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
holder.binding.statusContent.setText(
|
holder.binding.statusContent.setText(
|
||||||
status.getSpanContent(context,
|
status.getSpanContent(context,
|
||||||
new WeakReference<>(holder.binding.statusContent), () -> notifyItemChanged(position)),
|
new WeakReference<>(holder.binding.statusContent), () -> notifyItemChanged(position)),
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/media"
|
||||||
|
android:contentDescription="@string/thumbnail"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
tools:src="@tools:sample/avatars"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:scaleType="centerCrop" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/media_name"
|
||||||
|
android:contentDescription="@string/thumbnail"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
tools:text="@tools:sample/lorem/random"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
|
@ -101,6 +101,25 @@
|
||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
tools:maxLines="10"
|
tools:maxLines="10"
|
||||||
tools:text="@tools:sample/lorem/random" />
|
tools:text="@tools:sample/lorem/random" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.LinearLayoutCompat
|
||||||
|
android:id="@+id/simple_media_container"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="6dp"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="?colorPrimary" />
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/simple_media"/>
|
||||||
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
</com.google.android.material.card.MaterialCardView>
|
|
@ -2035,4 +2035,5 @@
|
||||||
<string name="set_custom_accent_value_light_description">Color that will be applied to the light theme</string>
|
<string name="set_custom_accent_value_light_description">Color that will be applied to the light theme</string>
|
||||||
<string name="set_custom_accent_value_dark_description">Color that will be applied to the dark theme</string>
|
<string name="set_custom_accent_value_dark_description">Color that will be applied to the dark theme</string>
|
||||||
|
|
||||||
|
<string name="thumbnail">Thumbnail</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in a new issue