248 lines
10 KiB
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.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.core.content.ContextCompat;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
import c.b.a.d.i;
|
|
import com.discord.utilities.display.DisplayUtils;
|
|
import com.lytefast.flexinput.R;
|
|
import com.lytefast.flexinput.adapters.EmptyListAdapter;
|
|
import com.lytefast.flexinput.model.Attachment;
|
|
import com.lytefast.flexinput.model.Media;
|
|
import com.lytefast.flexinput.utils.SelectionAggregator;
|
|
import com.lytefast.flexinput.utils.SelectionCoordinator;
|
|
import d0.z.d.m;
|
|
import d0.z.d.o;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
/* compiled from: MediaFragment.kt */
|
|
public class MediaFragment extends Fragment {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final int GRID_LAYOUT_SPAN_COUNT = 3;
|
|
private static final String REQUIRED_PERMISSION = "android.permission.READ_EXTERNAL_STORAGE";
|
|
private RecyclerView recyclerView;
|
|
private SelectionCoordinator<Attachment<Object>, Media> selectionCoordinator;
|
|
private SwipeRefreshLayout swipeRefreshLayout;
|
|
|
|
/* compiled from: MediaFragment.kt */
|
|
public static final class Companion {
|
|
public Companion() {
|
|
}
|
|
|
|
public Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
}
|
|
}
|
|
|
|
/* compiled from: MediaFragment.kt */
|
|
public static final class a implements View.OnClickListener {
|
|
public final /* synthetic */ View i;
|
|
public final /* synthetic */ i j;
|
|
public final /* synthetic */ MediaFragment k;
|
|
public final /* synthetic */ c.b.a.b l;
|
|
|
|
/* compiled from: MediaFragment.kt */
|
|
/* renamed from: com.lytefast.flexinput.fragment.MediaFragment$a$a reason: collision with other inner class name */
|
|
public static final class C0190a 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 C0190a(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() {
|
|
RecyclerView recyclerView$flexinput_release = this.this$0.k.getRecyclerView$flexinput_release();
|
|
m.checkNotNull(recyclerView$flexinput_release);
|
|
recyclerView$flexinput_release.setLayoutManager(new GridLayoutManager(this.this$0.i.getContext(), 3));
|
|
RecyclerView recyclerView$flexinput_release2 = this.this$0.k.getRecyclerView$flexinput_release();
|
|
m.checkNotNull(recyclerView$flexinput_release2);
|
|
recyclerView$flexinput_release2.setAdapter(this.this$0.j);
|
|
RecyclerView recyclerView$flexinput_release3 = this.this$0.k.getRecyclerView$flexinput_release();
|
|
m.checkNotNull(recyclerView$flexinput_release3);
|
|
recyclerView$flexinput_release3.invalidateItemDecorations();
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
public a(View view, i iVar, MediaFragment mediaFragment, c.b.a.b bVar) {
|
|
this.i = view;
|
|
this.j = iVar;
|
|
this.k = mediaFragment;
|
|
this.l = bVar;
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
c.b.a.b bVar = this.l;
|
|
if (bVar != null) {
|
|
bVar.requestMediaPermissions(new C0190a(this));
|
|
}
|
|
}
|
|
}
|
|
|
|
/* compiled from: MediaFragment.kt */
|
|
public static final class b implements SwipeRefreshLayout.OnRefreshListener {
|
|
public final /* synthetic */ View a;
|
|
public final /* synthetic */ i b;
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
|
public final /* synthetic */ MediaFragment f2403c;
|
|
public final /* synthetic */ c.b.a.b d;
|
|
|
|
public b(View view, i iVar, MediaFragment mediaFragment, c.b.a.b bVar) {
|
|
this.a = view;
|
|
this.b = iVar;
|
|
this.f2403c = mediaFragment;
|
|
this.d = bVar;
|
|
}
|
|
|
|
@Override // androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener
|
|
public final void onRefresh() {
|
|
if (MediaFragment.access$hasPermissions(this.f2403c, "android.permission.READ_EXTERNAL_STORAGE")) {
|
|
i iVar = this.b;
|
|
Context context = this.a.getContext();
|
|
m.checkNotNullExpressionValue(context, "context");
|
|
ContentResolver contentResolver = context.getContentResolver();
|
|
m.checkNotNullExpressionValue(contentResolver, "context.contentResolver");
|
|
iVar.b(contentResolver);
|
|
}
|
|
SwipeRefreshLayout access$getSwipeRefreshLayout$p = MediaFragment.access$getSwipeRefreshLayout$p(this.f2403c);
|
|
if (access$getSwipeRefreshLayout$p != null) {
|
|
access$getSwipeRefreshLayout$p.setRefreshing(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static final /* synthetic */ SwipeRefreshLayout access$getSwipeRefreshLayout$p(MediaFragment mediaFragment) {
|
|
return mediaFragment.swipeRefreshLayout;
|
|
}
|
|
|
|
public static final /* synthetic */ boolean access$hasPermissions(MediaFragment mediaFragment, String... strArr) {
|
|
return mediaFragment.hasPermissions(strArr);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setSwipeRefreshLayout$p(MediaFragment mediaFragment, SwipeRefreshLayout swipeRefreshLayout) {
|
|
mediaFragment.swipeRefreshLayout = swipeRefreshLayout;
|
|
}
|
|
|
|
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++;
|
|
}
|
|
}
|
|
|
|
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>, Media> 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);
|
|
Context context = inflate.getContext();
|
|
m.checkNotNullExpressionValue(context, "context");
|
|
int width = (int) (((float) DisplayUtils.getScreenSize(context).width()) / ((float) 3));
|
|
SelectionCoordinator<Attachment<Object>, Media> selectionCoordinator2 = this.selectionCoordinator;
|
|
m.checkNotNull(selectionCoordinator2);
|
|
i iVar = new i(selectionCoordinator2, width, width);
|
|
if (hasPermissions("android.permission.READ_EXTERNAL_STORAGE")) {
|
|
RecyclerView recyclerView = this.recyclerView;
|
|
if (recyclerView != null) {
|
|
recyclerView.setLayoutManager(new GridLayoutManager(inflate.getContext(), 3));
|
|
}
|
|
RecyclerView recyclerView2 = this.recyclerView;
|
|
if (recyclerView2 != null) {
|
|
recyclerView2.setAdapter(iVar);
|
|
}
|
|
} else {
|
|
RecyclerView recyclerView3 = this.recyclerView;
|
|
if (recyclerView3 != null) {
|
|
recyclerView3.setAdapter(newPermissionsRequestAdapter(new a(inflate, iVar, this, bVar)));
|
|
}
|
|
}
|
|
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) inflate.findViewById(R.e.swipeRefreshLayout);
|
|
this.swipeRefreshLayout = swipeRefreshLayout;
|
|
if (swipeRefreshLayout != null) {
|
|
swipeRefreshLayout.setOnRefreshListener(new b(inflate, iVar, this, bVar));
|
|
}
|
|
return inflate;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onDestroyView() {
|
|
SelectionCoordinator<Attachment<Object>, Media> selectionCoordinator = this.selectionCoordinator;
|
|
m.checkNotNull(selectionCoordinator);
|
|
selectionCoordinator.f2405c.unregister();
|
|
super.onDestroyView();
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onPause() {
|
|
super.onPause();
|
|
SwipeRefreshLayout swipeRefreshLayout = this.swipeRefreshLayout;
|
|
if (swipeRefreshLayout != null) {
|
|
swipeRefreshLayout.setEnabled(false);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onResume() {
|
|
super.onResume();
|
|
SwipeRefreshLayout swipeRefreshLayout = this.swipeRefreshLayout;
|
|
if (swipeRefreshLayout != null) {
|
|
swipeRefreshLayout.setEnabled(true);
|
|
}
|
|
}
|
|
|
|
public final void setRecyclerView$flexinput_release(RecyclerView recyclerView) {
|
|
this.recyclerView = recyclerView;
|
|
}
|
|
}
|