2021-06-27 20:44:35 +00:00
package com.lytefast.flexinput.adapters ;
import android.animation.Animator ;
import android.animation.AnimatorInflater ;
import android.animation.AnimatorSet ;
import android.content.ContentResolver ;
import android.database.Cursor ;
import android.graphics.Bitmap ;
import android.net.Uri ;
import android.os.AsyncTask ;
import android.provider.MediaStore ;
import android.text.TextUtils ;
import android.view.LayoutInflater ;
import android.view.View ;
import android.view.ViewGroup ;
import android.webkit.MimeTypeMap ;
import android.widget.ImageView ;
import android.widget.TextView ;
import androidx.recyclerview.widget.RecyclerView ;
import c.b.a.d.f ;
import c.b.a.d.g ;
import c.b.a.d.h ;
import c.f.g.a.a.d ;
import com.discord.utilities.drawable.DrawableCompat ;
import com.facebook.drawee.view.SimpleDraweeView ;
import com.lytefast.flexinput.R ;
import com.lytefast.flexinput.model.Attachment ;
import com.lytefast.flexinput.utils.SelectionCoordinator ;
import d0.g0.t ;
import d0.g0.w ;
import d0.t.n ;
import d0.t.q ;
import d0.t.r ;
import d0.z.d.m ;
import d0.z.d.o ;
import java.io.File ;
import java.util.ArrayList ;
import java.util.Iterator ;
import java.util.LinkedList ;
import java.util.List ;
import java.util.Objects ;
import kotlin.Unit ;
import kotlin.jvm.functions.Function1 ;
/* compiled from: FileListAdapter.kt */
public final class FileListAdapter extends RecyclerView . Adapter < b > {
public final SelectionCoordinator < ? , ? super Attachment < ? extends File > > a ;
public List < ? extends Attachment < ? extends File > > b = n . emptyList ( ) ;
/* renamed from: c reason: collision with root package name */
2021-07-13 20:23:20 +00:00
public final ContentResolver f2396c ;
2021-06-27 20:44:35 +00:00
/* compiled from: FileListAdapter.kt */
public static final class a extends AsyncTask < File , Boolean , List < ? extends Attachment < ? extends File > > > {
public final FileListAdapter a ;
public a ( FileListAdapter fileListAdapter ) {
m . checkNotNullParameter ( fileListAdapter , " adapter " ) ;
this . a = fileListAdapter ;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object[]] */
@Override // android.os.AsyncTask
public List < ? extends Attachment < ? extends File > > doInBackground ( File [ ] fileArr ) {
File [ ] fileArr2 = fileArr ;
m . checkNotNullParameter ( fileArr2 , " rootFiles " ) ;
File file = fileArr2 [ 0 ] ;
h hVar = h . i ;
ArrayList arrayList = new ArrayList ( ) ;
LinkedList linkedList = new LinkedList ( ) ;
r . addAll ( linkedList , hVar . invoke ( file ) ) ;
while ( ! linkedList . isEmpty ( ) ) {
File file2 = ( File ) linkedList . remove ( ) ;
m . checkNotNullExpressionValue ( file2 , " file " ) ;
if ( ! file2 . isHidden ( ) ) {
if ( file2 . isDirectory ( ) ) {
r . addAll ( linkedList , hVar . invoke ( file2 ) ) ;
} else {
arrayList . add ( c . b . a . g . a . a ( file2 ) ) ;
}
}
}
q . sortWith ( arrayList , d0 . u . a . then ( new g ( this ) , new f ( ) ) ) ;
return arrayList ;
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // android.os.AsyncTask
public void onPostExecute ( List < ? extends Attachment < ? extends File > > list ) {
List < ? extends Attachment < ? extends File > > list2 = list ;
m . checkNotNullParameter ( list2 , " files " ) ;
FileListAdapter fileListAdapter = this . a ;
fileListAdapter . b = list2 ;
fileListAdapter . notifyDataSetChanged ( ) ;
}
}
/* compiled from: FileListAdapter.kt */
public class b extends RecyclerView . ViewHolder {
public final AnimatorSet a ;
public final AnimatorSet b ;
/* renamed from: c reason: collision with root package name */
2021-07-13 20:23:20 +00:00
public SimpleDraweeView f2397c ;
2021-06-27 20:44:35 +00:00
public ImageView d ;
public TextView e ;
public TextView f ;
public Attachment < ? extends File > g ;
public final /* synthetic */ FileListAdapter h ;
/* compiled from: FileListAdapter.kt */
public static final class a implements View . OnClickListener {
public final /* synthetic */ b i ;
public a ( b bVar ) {
this . i = bVar ;
}
@Override // android.view.View.OnClickListener
public final void onClick ( View view ) {
boolean z2 ;
b bVar = this . i ;
SelectionCoordinator < ? , ? super Attachment < ? extends File > > selectionCoordinator = bVar . h . a ;
Attachment < ? extends File > attachment = bVar . g ;
int adapterPosition = bVar . getAdapterPosition ( ) ;
Objects . requireNonNull ( selectionCoordinator ) ;
if ( attachment ! = null & & ! selectionCoordinator . d ( attachment ) ) {
selectionCoordinator . c ( attachment , adapterPosition ) ;
z2 = true ;
} else {
z2 = false ;
}
bVar . b ( z2 , true ) ;
}
}
/* compiled from: FileListAdapter.kt */
/* renamed from: com.lytefast.flexinput.adapters.FileListAdapter$b$b reason: collision with other inner class name */
2021-07-13 20:23:20 +00:00
public static final class C0188b extends o implements Function1 < AnimatorSet , Unit > {
2021-06-27 20:44:35 +00:00
public final /* synthetic */ boolean $isAnimationRequested ;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
2021-07-13 20:23:20 +00:00
public C0188b ( boolean z2 ) {
2021-06-27 20:44:35 +00:00
super ( 1 ) ;
this . $isAnimationRequested = z2 ;
}
public final void a ( AnimatorSet animatorSet ) {
m . checkNotNullParameter ( animatorSet , " animation " ) ;
animatorSet . start ( ) ;
if ( ! this . $isAnimationRequested ) {
animatorSet . end ( ) ;
}
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke ( AnimatorSet animatorSet ) {
a ( animatorSet ) ;
return Unit . a ;
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public b ( FileListAdapter fileListAdapter , View view ) {
super ( view ) ;
m . checkNotNullParameter ( view , " itemView " ) ;
this . h = fileListAdapter ;
View findViewById = view . findViewById ( R . e . thumb_iv ) ;
m . checkNotNullExpressionValue ( findViewById , " itemView.findViewById(R.id.thumb_iv) " ) ;
2021-07-13 20:23:20 +00:00
this . f2397c = ( SimpleDraweeView ) findViewById ;
2021-06-27 20:44:35 +00:00
View findViewById2 = view . findViewById ( R . e . type_iv ) ;
m . checkNotNullExpressionValue ( findViewById2 , " itemView.findViewById(R.id.type_iv) " ) ;
this . d = ( ImageView ) findViewById2 ;
View findViewById3 = view . findViewById ( R . e . file_name_tv ) ;
m . checkNotNullExpressionValue ( findViewById3 , " itemView.findViewById(R.id.file_name_tv) " ) ;
this . e = ( TextView ) findViewById3 ;
View findViewById4 = view . findViewById ( R . e . file_subtitle_tv ) ;
m . checkNotNullExpressionValue ( findViewById4 , " itemView.findViewById(R.id.file_subtitle_tv) " ) ;
this . f = ( TextView ) findViewById4 ;
View view2 = this . itemView ;
m . checkNotNullExpressionValue ( view2 , " this.itemView " ) ;
view2 . setClickable ( true ) ;
this . itemView . setOnClickListener ( new a ( this ) ) ;
Animator loadAnimator = AnimatorInflater . loadAnimator ( view . getContext ( ) , R . a . selection_shrink ) ;
Objects . requireNonNull ( loadAnimator , " null cannot be cast to non-null type android.animation.AnimatorSet " ) ;
AnimatorSet animatorSet = ( AnimatorSet ) loadAnimator ;
this . a = animatorSet ;
2021-07-13 20:23:20 +00:00
animatorSet . setTarget ( this . f2397c ) ;
2021-06-27 20:44:35 +00:00
Animator loadAnimator2 = AnimatorInflater . loadAnimator ( view . getContext ( ) , R . a . selection_grow ) ;
Objects . requireNonNull ( loadAnimator2 , " null cannot be cast to non-null type android.animation.AnimatorSet " ) ;
AnimatorSet animatorSet2 = ( AnimatorSet ) loadAnimator2 ;
this . b = animatorSet2 ;
2021-07-13 20:23:20 +00:00
animatorSet2 . setTarget ( this . f2397c ) ;
2021-06-27 20:44:35 +00:00
}
/ * JADX WARNING : Code restructure failed : missing block : B : 25 : 0x009d , code lost :
r0 = move - exception ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 26 : 0x009e , code lost :
d0 . y . b . closeFinally ( r3 , r0 ) ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 27 : 0x00a2 , code lost :
throw r0 ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 33 : 0x00aa , code lost :
r0 = move - exception ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 34 : 0x00ab , code lost :
d0 . y . b . closeFinally ( r2 , r0 ) ;
* /
/ * JADX WARNING : Code restructure failed : missing block : B : 35 : 0x00af , code lost :
throw r0 ;
* /
public final void a ( File file ) {
Bitmap thumbnail ;
2021-07-13 20:23:20 +00:00
Cursor query = this . h . f2396c . query ( MediaStore . Images . Media . EXTERNAL_CONTENT_URI , new String [ ] { " _id " , " mini_thumb_magic " } , " _data=? " , new String [ ] { file . getPath ( ) } , null ) ;
2021-06-27 20:44:35 +00:00
if ( query = = null ) {
return ;
}
if ( ! query . moveToFirst ( ) ) {
d0 . y . b . closeFinally ( query , null ) ;
return ;
}
long j = query . getLong ( 0 ) ;
2021-07-13 20:23:20 +00:00
if ( query . getLong ( 1 ) = = 0 & & ( thumbnail = MediaStore . Images . Thumbnails . getThumbnail ( this . h . f2396c , j , 1 , null ) ) ! = null ) {
2021-06-27 20:44:35 +00:00
thumbnail . recycle ( ) ;
}
2021-07-13 20:23:20 +00:00
Cursor query2 = this . h . f2396c . query ( MediaStore . Images . Thumbnails . EXTERNAL_CONTENT_URI , new String [ ] { " _id " } , " image_id=? " , new String [ ] { String . valueOf ( j ) } , null ) ;
2021-06-27 20:44:35 +00:00
if ( query2 ! = null ) {
if ( ! query2 . moveToFirst ( ) ) {
d0 . y . b . closeFinally ( query2 , null ) ;
d0 . y . b . closeFinally ( query , null ) ;
return ;
}
String string = query2 . getString ( 0 ) ;
2021-07-13 20:23:20 +00:00
SimpleDraweeView simpleDraweeView = this . f2397c ;
2021-06-27 20:44:35 +00:00
d a2 = c . f . g . a . a . b . a ( ) ;
2021-07-13 20:23:20 +00:00
a2 . n = this . f2397c . getController ( ) ;
2021-06-27 20:44:35 +00:00
d f = a2 . f ( Uri . withAppendedPath ( MediaStore . Images . Thumbnails . EXTERNAL_CONTENT_URI , string ) ) ;
f . l = true ;
simpleDraweeView . setController ( f . a ( ) ) ;
d0 . y . b . closeFinally ( query2 , null ) ;
}
d0 . y . b . closeFinally ( query , null ) ;
}
public final void b ( boolean z2 , boolean z3 ) {
View view = this . itemView ;
m . checkNotNullExpressionValue ( view , " itemView " ) ;
view . setSelected ( z2 ) ;
2021-07-13 20:23:20 +00:00
C0188b bVar = new C0188b ( z3 ) ;
2021-06-27 20:44:35 +00:00
if ( z2 ) {
2021-07-13 20:23:20 +00:00
if ( this . f2397c . getScaleX ( ) = = 1 . 0f ) {
2021-06-27 20:44:35 +00:00
bVar . a ( this . a ) ;
}
2021-07-13 20:23:20 +00:00
} else if ( this . f2397c . getScaleX ( ) ! = 1 . 0f ) {
2021-06-27 20:44:35 +00:00
bVar . a ( this . b ) ;
}
}
}
public FileListAdapter ( ContentResolver contentResolver , SelectionCoordinator < ? , Attachment < File > > selectionCoordinator ) {
m . checkNotNullParameter ( contentResolver , " contentResolver " ) ;
m . checkNotNullParameter ( selectionCoordinator , " selectionCoordinator " ) ;
2021-07-13 20:23:20 +00:00
this . f2396c = contentResolver ;
2021-06-27 20:44:35 +00:00
Objects . requireNonNull ( selectionCoordinator ) ;
m . checkNotNullParameter ( this , " adapter " ) ;
selectionCoordinator . a = this ;
this . a = selectionCoordinator ;
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public int getItemCount ( ) {
return this . b . size ( ) ;
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [androidx.recyclerview.widget.RecyclerView$ViewHolder, int] */
/* JADX WARNING: Removed duplicated region for block: B:22:0x00ef */
/* JADX WARNING: Removed duplicated region for block: B:35:? A[RETURN, SYNTHETIC] */
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public void onBindViewHolder ( b bVar , int i ) {
String str ;
String str2 ;
b bVar2 = bVar ;
m . checkNotNullParameter ( bVar2 , " holder " ) ;
Attachment < ? extends File > attachment = ( Attachment ) this . b . get ( i ) ;
Objects . requireNonNull ( bVar2 ) ;
m . checkNotNullParameter ( attachment , " fileAttachment " ) ;
bVar2 . g = attachment ;
bVar2 . b ( bVar2 . h . a . a ( attachment , bVar2 . getAdapterPosition ( ) ) , false ) ;
File file = ( File ) attachment . getData ( ) ;
if ( file ! = null ) {
bVar2 . e . setText ( file . getName ( ) ) ;
TextView textView = bVar2 . f ;
m . checkNotNullParameter ( file , " $this$getFileSize " ) ;
long j = ( long ) 1024 ;
long length = file . length ( ) / j ;
if ( length < j ) {
str2 = length + " KB " ;
} else {
long j2 = length / j ;
if ( j2 < j ) {
str2 = j2 + " MB " ;
} else {
str2 = ( j2 / j ) + " GB " ;
}
}
textView . setText ( str2 ) ;
} else {
bVar2 . e . setText ( ( CharSequence ) null ) ;
bVar2 . f . setText ( ( CharSequence ) null ) ;
}
2021-07-13 20:23:20 +00:00
SimpleDraweeView simpleDraweeView = bVar2 . f2397c ;
2021-06-27 20:44:35 +00:00
simpleDraweeView . setImageURI ( ( Uri ) null , simpleDraweeView . getContext ( ) ) ;
bVar2 . d . setVisibility ( 8 ) ;
boolean z2 = true ;
if ( file ! = null ) {
Objects . requireNonNull ( bVar2 . h ) ;
String name = file . getName ( ) ;
m . checkNotNullExpressionValue ( name , " fileName " ) ;
Objects . requireNonNull ( name , " null cannot be cast to non-null type java.lang.String " ) ;
String substring = name . substring ( w . lastIndexOf$default ( ( CharSequence ) name , '.' , 0 , false , 6 , ( Object ) null ) + 1 ) ;
m . checkNotNullExpressionValue ( substring , " (this as java.lang.String).substring(startIndex) " ) ;
if ( ! TextUtils . isEmpty ( substring ) ) {
str = MimeTypeMap . getSingleton ( ) . getMimeTypeFromExtension ( substring ) ;
if ( ! ( str = = null | | str . length ( ) = = 0 ) ) {
z2 = false ;
}
if ( z2 ) {
2021-07-13 20:23:20 +00:00
bVar2 . f2397c . setImageURI ( Uri . fromFile ( file ) , bVar2 . f2397c . getContext ( ) ) ;
2021-06-27 20:44:35 +00:00
if ( t . startsWith$default ( str , " image " , false , 2 , null ) ) {
ImageView imageView = bVar2 . d ;
imageView . setImageResource ( DrawableCompat . getThemedDrawableRes$default ( imageView , R . b . ic_flex_input_image , 0 , 2 , ( Object ) null ) ) ;
bVar2 . d . setVisibility ( 0 ) ;
bVar2 . a ( file ) ;
return ;
} else if ( t . startsWith$default ( str , " video " , false , 2 , null ) ) {
ImageView imageView2 = bVar2 . d ;
imageView2 . setImageResource ( DrawableCompat . getThemedDrawableRes$default ( imageView2 , R . b . ic_flex_input_movie , 0 , 2 , ( Object ) null ) ) ;
bVar2 . d . setVisibility ( 0 ) ;
bVar2 . a ( file ) ;
return ;
} else if ( t . startsWith$default ( str , " audio " , false , 2 , null ) ) {
ImageView imageView3 = bVar2 . d ;
imageView3 . setImageResource ( DrawableCompat . getThemedDrawableRes$default ( imageView3 , R . b . ic_flex_input_audio , 0 , 2 , ( Object ) null ) ) ;
bVar2 . d . setVisibility ( 0 ) ;
bVar2 . a ( file ) ;
return ;
} else {
return ;
}
} else {
return ;
}
}
}
str = null ;
z2 = false ;
if ( z2 ) {
}
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [androidx.recyclerview.widget.RecyclerView$ViewHolder, int, java.util.List] */
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public void onBindViewHolder ( b bVar , int i , List list ) {
SelectionCoordinator . a aVar ;
Object obj ;
b bVar2 = bVar ;
m . checkNotNullParameter ( bVar2 , " holder " ) ;
m . checkNotNullParameter ( list , " payloads " ) ;
Iterator it = list . iterator ( ) ;
while ( true ) {
aVar = null ;
if ( ! it . hasNext ( ) ) {
obj = null ;
break ;
}
obj = it . next ( ) ;
if ( obj instanceof SelectionCoordinator . a ) {
break ;
}
}
if ( obj ! = null ) {
if ( obj instanceof SelectionCoordinator . a ) {
aVar = obj ;
}
SelectionCoordinator . a aVar2 = aVar ;
if ( aVar2 ! = null ) {
bVar2 . b ( aVar2 . b , true ) ;
return ;
}
}
super . onBindViewHolder ( bVar2 , i , list ) ;
}
/* Return type fixed from 'androidx.recyclerview.widget.RecyclerView$ViewHolder' to match base method */
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public b onCreateViewHolder ( ViewGroup viewGroup , int i ) {
m . checkNotNullParameter ( viewGroup , " parent " ) ;
View inflate = LayoutInflater . from ( viewGroup . getContext ( ) ) . inflate ( R . f . view_file_item , viewGroup , false ) ;
m . checkNotNullExpressionValue ( inflate , " view " ) ;
return new b ( this , inflate ) ;
}
}