discord-jadx/app/src/main/java/com/lytefast/flexinput/fragment/FilesFragment.java

248 lines
10 KiB
Java

package com.lytefast.flexinput.fragment;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import c.b.a.a.e;
import com.lytefast.flexinput.R;
import com.lytefast.flexinput.adapters.EmptyListAdapter;
import com.lytefast.flexinput.adapters.FileListAdapter;
import com.lytefast.flexinput.model.Attachment;
import com.lytefast.flexinput.utils.SelectionAggregator;
import com.lytefast.flexinput.utils.SelectionCoordinator;
import d0.z.d.k;
import d0.z.d.m;
import d0.z.d.o;
import java.io.File;
import java.util.Objects;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: FilesFragment.kt */
public class FilesFragment extends Fragment {
public static final Companion Companion = new Companion(null);
private static final String REQUIRED_PERMISSION = "android.permission.READ_EXTERNAL_STORAGE";
private FileListAdapter adapter;
private RecyclerView recyclerView;
private SelectionCoordinator<Attachment<Object>, Attachment<File>> selectionCoordinator;
private SwipeRefreshLayout swipeRefreshLayout;
/* compiled from: FilesFragment.kt */
public static final class Companion {
public Companion() {
}
public Companion(DefaultConstructorMarker defaultConstructorMarker) {
}
}
/* compiled from: FilesFragment.kt */
public static final class a implements View.OnClickListener {
public final /* synthetic */ View i;
public final /* synthetic */ FilesFragment j;
public final /* synthetic */ c.b.a.b k;
/* compiled from: FilesFragment.kt */
/* renamed from: com.lytefast.flexinput.fragment.FilesFragment$a$a reason: collision with other inner class name */
public static final class C0189a extends o implements Function0<Unit> {
public final /* synthetic */ a this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public C0189a(a aVar) {
super(0);
this.this$0 = aVar;
}
/* Return type fixed from 'java.lang.Object' to match base method */
@Override // kotlin.jvm.functions.Function0
/* renamed from: invoke */
public Unit mo1invoke() {
ContentResolver contentResolver;
Context context = this.this$0.i.getContext();
if (!(context == null || (contentResolver = context.getContentResolver()) == null)) {
FilesFragment filesFragment = this.this$0.j;
SelectionCoordinator access$getSelectionCoordinator$p = FilesFragment.access$getSelectionCoordinator$p(filesFragment);
m.checkNotNull(access$getSelectionCoordinator$p);
FilesFragment.access$setAdapter$p(filesFragment, new FileListAdapter(contentResolver, access$getSelectionCoordinator$p));
RecyclerView recyclerView$flexinput_release = this.this$0.j.getRecyclerView$flexinput_release();
if (recyclerView$flexinput_release != null) {
recyclerView$flexinput_release.setAdapter(FilesFragment.access$getAdapter$p(this.this$0.j));
}
FilesFragment.access$loadDownloadFolder(this.this$0.j);
}
return Unit.a;
}
}
public a(View view, FilesFragment filesFragment, c.b.a.b bVar) {
this.i = view;
this.j = filesFragment;
this.k = bVar;
}
@Override // android.view.View.OnClickListener
public final void onClick(View view) {
c.b.a.b bVar = this.k;
if (bVar != null) {
bVar.requestMediaPermissions(new C0189a(this));
}
}
}
/* compiled from: FilesFragment.kt */
public static final /* synthetic */ class b extends k implements Function0<Unit> {
public b(FilesFragment filesFragment) {
super(0, filesFragment, FilesFragment.class, "loadDownloadFolder", "loadDownloadFolder()V", 0);
}
/* Return type fixed from 'java.lang.Object' to match base method */
@Override // kotlin.jvm.functions.Function0
/* renamed from: invoke */
public Unit mo1invoke() {
FilesFragment.access$loadDownloadFolder((FilesFragment) this.receiver);
return Unit.a;
}
}
public static final /* synthetic */ FileListAdapter access$getAdapter$p(FilesFragment filesFragment) {
return filesFragment.adapter;
}
public static final /* synthetic */ SelectionCoordinator access$getSelectionCoordinator$p(FilesFragment filesFragment) {
return filesFragment.selectionCoordinator;
}
public static final /* synthetic */ void access$loadDownloadFolder(FilesFragment filesFragment) {
filesFragment.loadDownloadFolder();
}
public static final /* synthetic */ void access$setAdapter$p(FilesFragment filesFragment, FileListAdapter fileListAdapter) {
filesFragment.adapter = fileListAdapter;
}
public static final /* synthetic */ void access$setSelectionCoordinator$p(FilesFragment filesFragment, SelectionCoordinator selectionCoordinator) {
filesFragment.selectionCoordinator = selectionCoordinator;
}
private final boolean hasPermissions(String... strArr) {
int length = strArr.length;
int i = 0;
while (true) {
boolean z2 = true;
if (i >= length) {
return true;
}
if (ContextCompat.checkSelfPermission(requireContext(), strArr[i]) != 0) {
z2 = false;
}
if (!z2) {
return false;
}
i++;
}
}
private final void loadDownloadFolder() {
if (this.adapter == null) {
SwipeRefreshLayout swipeRefreshLayout = this.swipeRefreshLayout;
m.checkNotNull(swipeRefreshLayout);
swipeRefreshLayout.setRefreshing(false);
return;
}
File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
FileListAdapter fileListAdapter = this.adapter;
m.checkNotNull(fileListAdapter);
m.checkNotNullExpressionValue(externalStoragePublicDirectory, "downloadFolder");
Objects.requireNonNull(fileListAdapter);
m.checkNotNullParameter(externalStoragePublicDirectory, "root");
new FileListAdapter.a(fileListAdapter).execute(externalStoragePublicDirectory);
SwipeRefreshLayout swipeRefreshLayout2 = this.swipeRefreshLayout;
m.checkNotNull(swipeRefreshLayout2);
swipeRefreshLayout2.setRefreshing(false);
}
public final RecyclerView getRecyclerView$flexinput_release() {
return this.recyclerView;
}
public EmptyListAdapter newPermissionsRequestAdapter(View.OnClickListener onClickListener) {
m.checkNotNullParameter(onClickListener, "onClickListener");
return new EmptyListAdapter(R.f.item_permission_storage, R.e.permissions_req_btn, onClickListener);
}
@Override // androidx.fragment.app.Fragment
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
m.checkNotNullParameter(layoutInflater, "inflater");
this.selectionCoordinator = new SelectionCoordinator<>(null, null, 3);
Fragment parentFragment = getParentFragment();
Fragment parentFragment2 = parentFragment != null ? parentFragment.getParentFragment() : null;
if (!(parentFragment2 instanceof c.b.a.b)) {
parentFragment2 = null;
}
c.b.a.b bVar = (c.b.a.b) parentFragment2;
if (bVar != null) {
SelectionAggregator b2 = bVar.b();
SelectionCoordinator<Attachment<Object>, Attachment<File>> selectionCoordinator = this.selectionCoordinator;
m.checkNotNull(selectionCoordinator);
b2.registerSelectionCoordinator(selectionCoordinator);
}
View inflate = layoutInflater.inflate(R.f.fragment_recycler_view, viewGroup, false);
if (inflate == null) {
return null;
}
this.recyclerView = (RecyclerView) inflate.findViewById(R.e.list);
if (hasPermissions("android.permission.READ_EXTERNAL_STORAGE")) {
Context context = inflate.getContext();
m.checkNotNullExpressionValue(context, "context");
ContentResolver contentResolver = context.getContentResolver();
m.checkNotNullExpressionValue(contentResolver, "context.contentResolver");
SelectionCoordinator<Attachment<Object>, Attachment<File>> selectionCoordinator2 = this.selectionCoordinator;
m.checkNotNull(selectionCoordinator2);
FileListAdapter fileListAdapter = new FileListAdapter(contentResolver, selectionCoordinator2);
this.adapter = fileListAdapter;
RecyclerView recyclerView = this.recyclerView;
if (recyclerView != null) {
recyclerView.setAdapter(fileListAdapter);
}
} else {
RecyclerView recyclerView2 = this.recyclerView;
if (recyclerView2 != null) {
recyclerView2.setAdapter(newPermissionsRequestAdapter(new a(inflate, this, bVar)));
}
}
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) inflate.findViewById(R.e.swipeRefreshLayout);
this.swipeRefreshLayout = swipeRefreshLayout;
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setOnRefreshListener(new e(new b(this)));
}
return inflate;
}
@Override // androidx.fragment.app.Fragment
public void onDestroyView() {
SelectionCoordinator<Attachment<Object>, Attachment<File>> selectionCoordinator = this.selectionCoordinator;
if (selectionCoordinator != null) {
selectionCoordinator.f2408c.unregister();
}
super.onDestroyView();
}
@Override // androidx.fragment.app.Fragment
public void onStart() {
super.onStart();
loadDownloadFolder();
}
public final void setRecyclerView$flexinput_release(RecyclerView recyclerView) {
this.recyclerView = recyclerView;
}
}