1

I am making a chat app and I want to add a feature like telegram to copy links ,phone numbers and etc.. from long clicking on an auto link.I used this library to add long click listeners on a auto link.I implemented it successfully.But when I do this, i want to show a Lottie animation in the start like this but on long click of a link. I tried many answer but I get an exception.I already made the layout for custom snakbar.It is given below

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="56dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="@dimen/_3sdp"
android:backgroundTint="@color/snakbar_background"
app:cardCornerRadius="@dimen/_4sdp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical">

    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/lottieSnakbar"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:layout_marginStart="@dimen/_5sdp"
        android:layout_marginEnd="@dimen/_10sdp"
        app:lottie_rawRes="@drawable/copy"
        app:lottie_autoPlay="true"
        app:lottie_loop="false"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="Text copied to clipboard"
        android:gravity="center_vertical"
        android:theme="?snackbarTextViewStyle"
        tools:ignore="HardcodedText" />

</LinearLayout>

</androidx.cardview.widget.CardView>

Now how can I achieve this?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Sambhav Khandelwal
  • 3,585
  • 2
  • 7
  • 38
  • Perhaps you add other codes for us to try what you have currently, but i suppose [medium](https://medium.com/@fabionegri/make-snackbar-great-again-51edf7c940d4) would help out with the animation you want to achieve – Ric17101 Nov 23 '21 at 11:53
  • it indeed is helpful, but it is for Kotlin, but I want for java – Sambhav Khandelwal Nov 23 '21 at 13:34

2 Answers2

1

You can use an interface in the adapter. And receive and show snakbar from activity

0

You could use localBroadcast and broadcast a local signal from the adapter and let the other Activity(probably receiver) handle snakbar.

AdapterClass{
   LocalBroadcastManager localBroadcastManager = null;
   
   void sendB(parms){
      if(localBroadcastManager != null){
            localBroadcastManager.sendBroadcast(Intent("NOTIFICATION_RECEIVER"))
      }

   onCreateViewHolder(){
       localBroadcastManager = LocalBroadcastManager.getInstance(applicationContext)
      }

  onBindViewHolder(){
      if(someCondition){
           sendB(parms);
    }
}

then receive it from an activity then call snakBar