导航菜单

页面标题

页面副标题

Biko v2.0.23 - DazzleGallery.java 源代码

正在查看: Biko v2.0.23 应用的 DazzleGallery.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.aemerse.dazzle;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.WindowInsets;
import android.webkit.MimeTypeMap;
import android.widget.TextView;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.aemerse.cropper.CropImageContract;
import com.aemerse.cropper.CropImageContractOptions;
import com.aemerse.cropper.CropImageContractOptionsKt;
import com.aemerse.cropper.CropImageView;
import com.aemerse.dazzle.databinding.ActivityDazzleGalleryBinding;
import com.aemerse.dazzle.gallery.BottomSheetMediaRecyclerAdapter;
import com.aemerse.dazzle.gallery.MediaModel;
import com.aemerse.dazzle.interfaces.MediaClickInterface;
import com.aemerse.dazzle.interfaces.PermissionCallback;
import com.aemerse.dazzle.utils.DazzleOptions;
import com.aemerse.dazzle.utils.HeaderItemDecoration;
import com.aemerse.dazzle.utils.MediaConstants;
import com.aemerse.dazzle.utils.PermissionUtils;
import com.facebook.internal.NativeProtocol;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.collections.ArraysKt;
import kotlin.collections.CollectionsKt;
import kotlin.coroutines.CoroutineContext;
import kotlin.io.FilesKt;
import kotlin.jvm.JvmStatic;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.StringCompanionObject;
import kotlinx.coroutines.BuildersKt;
import kotlinx.coroutines.CoroutineScopeKt;
import kotlinx.coroutines.CoroutineStart;
import kotlinx.coroutines.Dispatchers;

@Metadata(d1 = {"\u0000m\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0006*\u0001\u0014\u0018\u0000 +2\u00020\u0001:\u0001+B\u0005¢\u0006\u0002\u0010\u0002J\b\u0010\u001c\u001a\u00020\u001dH\u0002J\b\u0010\u001e\u001a\u00020\u001fH\u0002J\b\u0010 \u001a\u00020\u001bH\u0002J\b\u0010!\u001a\u00020\u001fH\u0002J\b\u0010\"\u001a\u00020\u001fH\u0002J\b\u0010#\u001a\u00020\u001fH\u0016J\u0012\u0010$\u001a\u00020\u001f2\b\u0010%\u001a\u0004\u0018\u00010&H\u0014J\b\u0010'\u001a\u00020\u001fH\u0014J\b\u0010(\u001a\u00020\u001fH\u0002J\b\u0010)\u001a\u00020\u001fH\u0002J\b\u0010*\u001a\u00020\u001fH\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082.¢\u0006\u0002\n\u0000R\u001c\u0010\u0005\u001a\u0010\u0012\f\u0012\n \b*\u0004\u0018\u00010\u00070\u00070\u0006X\u0082\u0004¢\u0006\u0002\n\u0000R\u001e\u0010\t\u001a\u0012\u0012\u0004\u0012\u00020\u000b0\nj\b\u0012\u0004\u0012\u00020\u000b`\fX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\r\u001a\u00020\u000eX\u0082.¢\u0006\u0002\n\u0000R\u0010\u0010\u000f\u001a\u0004\u0018\u00010\u0010X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\u0012X\u0082.¢\u0006\u0002\n\u0000R\u0010\u0010\u0013\u001a\u00020\u0014X\u0082\u0004¢\u0006\u0004\n\u0002\u0010\u0015R\u001e\u0010\u0016\u001a\u0012\u0012\u0004\u0012\u00020\u00170\nj\b\u0012\u0004\u0012\u00020\u0017`\fX\u0082\u0004¢\u0006\u0002\n\u0000R\u001e\u0010\u0018\u001a\u0012\u0012\u0004\u0012\u00020\u00190\nj\b\u0012\u0004\u0012\u00020\u0019`\fX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u001a\u001a\u00020\u001bX\u0082.¢\u0006\u0002\n\u0000¨\u0006,"}, d2 = {"Lcom/aemerse/dazzle/DazzleGallery;", "Landroidx/appcompat/app/AppCompatActivity;", "()V", "cameraExecutor", "Ljava/util/concurrent/ExecutorService;", "cropImage", "Landroidx/activity/result/ActivityResultLauncher;", "Lcom/aemerse/cropper/CropImageContractOptions;", "kotlin.jvm.PlatformType", "galleryImageList", "Ljava/util/ArrayList;", "Lcom/aemerse/dazzle/gallery/MediaModel;", "Lkotlin/collections/ArrayList;", "mBinding", "Lcom/aemerse/dazzle/databinding/ActivityDazzleGalleryBinding;", "mBottomMediaAdapter", "Lcom/aemerse/dazzle/gallery/BottomSheetMediaRecyclerAdapter;", "mDazzleOptions", "Lcom/aemerse/dazzle/utils/DazzleOptions;", "mMediaClickListener", "com/aemerse/dazzle/DazzleGallery$mMediaClickListener$1", "Lcom/aemerse/dazzle/DazzleGallery$mMediaClickListener$1;", "mPath", "Landroid/net/Uri;", "mPathList", "", "outputDirectory", "Ljava/io/File;", "allPermissionsGranted", "", "getMedia", "", "getOutputDirectory", "handleBottomSheet", "hideTopViews", "onBackPressed", "onCreate", "savedInstanceState", "Landroid/os/Bundle;", "onDestroy", "pickImages", "removeSelection", "showTopViews", "Companion", "picker_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
public final class DazzleGallery extends AppCompatActivity {
    public static final String PICKED_MEDIA_LIST = "PICKED_MEDIA_LIST";
    public static final String PICKER_OPTIONS = "PICKER_OPTIONS";
    public static final int REQUEST_CODE_PICKER = 10;
    private static final String TAG = "Picker";
    private ExecutorService cameraExecutor;
    private final ActivityResultLauncher<CropImageContractOptions> cropImage;
    private final ArrayList<MediaModel> galleryImageList;
    private ActivityDazzleGalleryBinding mBinding;
    private BottomSheetMediaRecyclerAdapter mBottomMediaAdapter;
    private DazzleOptions mDazzleOptions;
    private final DazzleGallery$mMediaClickListener$1 mMediaClickListener;
    private File outputDirectory;

    public static final Companion INSTANCE = new Companion(null);
    private static final String[] REQUIRED_PERMISSIONS = {"android.permission.CAMERA"};
    private final ArrayList<String> mPathList = new ArrayList<>();
    private final ArrayList<Uri> mPath = new ArrayList<>();

    public static final WindowInsets onCreate$lambda$0(View view, WindowInsets windowInsets) {
        Intrinsics.checkNotNullParameter(view, "<anonymous parameter 0>");
        Intrinsics.checkNotNullParameter(windowInsets, "insets");
        return windowInsets;
    }

    @JvmStatic
    public static final void startPicker(Fragment fragment, DazzleOptions dazzleOptions) {
        INSTANCE.startPicker(fragment, dazzleOptions);
    }

    @JvmStatic
    public static final void startPicker(FragmentActivity fragmentActivity, DazzleOptions dazzleOptions) {
        INSTANCE.startPicker(fragmentActivity, dazzleOptions);
    }

    public DazzleGallery() {
        ActivityResultLauncher<CropImageContractOptions> registerForActivityResult = registerForActivityResult(new CropImageContract(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                DazzleGallery.cropImage$lambda$3(DazzleGallery.this, (CropImageView.CropResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult, "registerForActivityResul…        }\n        }\n    }");
        this.cropImage = registerForActivityResult;
        this.galleryImageList = new ArrayList<>();
        this.mMediaClickListener = new MediaClickInterface() {
            @Override
            public void onMediaClick(MediaModel media) {
                Intrinsics.checkNotNullParameter(media, "media");
                DazzleGallery.this.pickImages();
            }

            @Override
            public void onMediaLongClick(MediaModel media, String intentFrom) {
                BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter;
                ActivityDazzleGalleryBinding activityDazzleGalleryBinding;
                BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter2;
                ActivityDazzleGalleryBinding activityDazzleGalleryBinding2;
                BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter3;
                Intrinsics.checkNotNullParameter(media, "media");
                Intrinsics.checkNotNullParameter(intentFrom, "intentFrom");
                if (Intrinsics.areEqual(intentFrom, "BottomSheetMediaRecyclerAdapter")) {
                    bottomSheetMediaRecyclerAdapter = DazzleGallery.this.mBottomMediaAdapter;
                    Integer valueOf = bottomSheetMediaRecyclerAdapter != null ? Integer.valueOf(bottomSheetMediaRecyclerAdapter.getImageCount()) : null;
                    Intrinsics.checkNotNull(valueOf);
                    if (valueOf.intValue() > 0) {
                        activityDazzleGalleryBinding = DazzleGallery.this.mBinding;
                        if (activityDazzleGalleryBinding == null) {
                            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
                            activityDazzleGalleryBinding = null;
                        }
                        TextView textView = activityDazzleGalleryBinding.textViewImageCount;
                        bottomSheetMediaRecyclerAdapter2 = DazzleGallery.this.mBottomMediaAdapter;
                        textView.setText(bottomSheetMediaRecyclerAdapter2 != null ? Integer.valueOf(bottomSheetMediaRecyclerAdapter2.getImageCount()).toString() : null);
                        activityDazzleGalleryBinding2 = DazzleGallery.this.mBinding;
                        if (activityDazzleGalleryBinding2 == null) {
                            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
                            activityDazzleGalleryBinding2 = null;
                        }
                        TextView textView2 = activityDazzleGalleryBinding2.textViewTopSelect;
                        StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
                        String string = DazzleGallery.this.getString(R.string.images_selected);
                        Intrinsics.checkNotNullExpressionValue(string, "getString(R.string.images_selected)");
                        Object[] objArr = new Object[1];
                        bottomSheetMediaRecyclerAdapter3 = DazzleGallery.this.mBottomMediaAdapter;
                        objArr[0] = bottomSheetMediaRecyclerAdapter3 != null ? Integer.valueOf(bottomSheetMediaRecyclerAdapter3.getImageCount()).toString() : null;
                        String format = String.format(string, Arrays.copyOf(objArr, 1));
                        Intrinsics.checkNotNullExpressionValue(format, "format(format, *args)");
                        textView2.setText(format);
                        DazzleGallery.this.showTopViews();
                        return;
                    }
                    DazzleGallery.this.hideTopViews();
                }
            }
        };
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityDazzleGalleryBinding inflate = ActivityDazzleGalleryBinding.inflate(getLayoutInflater());
        Intrinsics.checkNotNullExpressionValue(inflate, "inflate(layoutInflater)");
        this.mBinding = inflate;
        if (inflate == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            inflate = null;
        }
        setContentView((View) inflate.getRoot());
        Intent intent = getIntent();
        Serializable serializableExtra = intent != null ? intent.getSerializableExtra("PICKER_OPTIONS") : null;
        Intrinsics.checkNotNull(serializableExtra, "null cannot be cast to non-null type com.aemerse.dazzle.utils.DazzleOptions");
        this.mDazzleOptions = (DazzleOptions) serializableExtra;
        this.outputDirectory = getOutputDirectory();
        ExecutorService newSingleThreadExecutor = Executors.newSingleThreadExecutor();
        Intrinsics.checkNotNullExpressionValue(newSingleThreadExecutor, "newSingleThreadExecutor()");
        this.cameraExecutor = newSingleThreadExecutor;
        getWindow().getDecorView().setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @Override
            public final WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
                WindowInsets onCreate$lambda$0;
                onCreate$lambda$0 = DazzleGallery.onCreate$lambda$0(view, windowInsets);
                return onCreate$lambda$0;
            }
        });
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public final void run() {
                DazzleGallery.onCreate$lambda$1(DazzleGallery.this);
            }
        }, 500L);
    }

    public static final void onCreate$lambda$1(DazzleGallery dazzleGallery) {
        Intrinsics.checkNotNullParameter(dazzleGallery, "this$0");
        dazzleGallery.getMedia();
    }

    public static final void cropImage$lambda$3(DazzleGallery dazzleGallery, CropImageView.CropResult cropResult) {
        Intrinsics.checkNotNullParameter(dazzleGallery, "this$0");
        if (cropResult.isSuccessful()) {
            Intrinsics.checkNotNullExpressionValue(cropResult, "result");
            Context context = (Context) dazzleGallery;
            String uriFilePath$default = CropImageView.CropResult.getUriFilePath$default(cropResult, context, false, 2, null);
            MimeTypeMap singleton = MimeTypeMap.getSingleton();
            Intrinsics.checkNotNull(uriFilePath$default);
            MediaScannerConnection.scanFile(context, new String[]{uriFilePath$default}, new String[]{singleton.getMimeTypeFromExtension(FilesKt.getExtension(new File(uriFilePath$default)))}, new MediaScannerConnection.OnScanCompletedListener() {
                @Override
                public final void onScanCompleted(String str, Uri uri) {
                    DazzleGallery.cropImage$lambda$3$lambda$2(str, uri);
                }
            });
            dazzleGallery.mPathList.add(uriFilePath$default.toString());
            Intent intent = new Intent();
            intent.putExtra("PICKED_MEDIA_LIST", dazzleGallery.mPathList);
            dazzleGallery.setResult(-1, intent);
            dazzleGallery.finish();
            return;
        }
        dazzleGallery.setResult(0, dazzleGallery.getIntent());
        dazzleGallery.finish();
    }

    public static final void cropImage$lambda$3$lambda$2(String str, Uri uri) {
        Log.d(TAG, "Image capture scanned into media store: " + uri);
    }

    protected void onDestroy() {
        super.onDestroy();
        ExecutorService executorService = this.cameraExecutor;
        if (executorService == null) {
            Intrinsics.throwUninitializedPropertyAccessException("cameraExecutor");
            executorService = null;
        }
        executorService.shutdown();
    }

    private final void getMedia() {
        BuildersKt.launch$default(CoroutineScopeKt.CoroutineScope(Dispatchers.getMain()), (CoroutineContext) null, (CoroutineStart) null, new DazzleGallery$getMedia$1(this, null), 3, (Object) null);
    }

    public final void showTopViews() {
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding = this.mBinding;
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding2 = null;
        if (activityDazzleGalleryBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding = null;
        }
        activityDazzleGalleryBinding.constraintCheck.setVisibility(0);
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding3 = this.mBinding;
        if (activityDazzleGalleryBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding3 = null;
        }
        activityDazzleGalleryBinding3.textViewOk.setVisibility(0);
        if (Build.VERSION.SDK_INT >= 23) {
            ActivityDazzleGalleryBinding activityDazzleGalleryBinding4 = this.mBinding;
            if (activityDazzleGalleryBinding4 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBinding");
                activityDazzleGalleryBinding4 = null;
            }
            activityDazzleGalleryBinding4.constraintBottomSheetTop.setBackgroundColor(getResources().getColor(R.color.colorPrimary, null));
            ActivityDazzleGalleryBinding activityDazzleGalleryBinding5 = this.mBinding;
            if (activityDazzleGalleryBinding5 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBinding");
                activityDazzleGalleryBinding5 = null;
            }
            DrawableCompat.setTint(activityDazzleGalleryBinding5.imageViewBack.getDrawable(), getResources().getColor(R.color.colorWhite, null));
            return;
        }
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding6 = this.mBinding;
        if (activityDazzleGalleryBinding6 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding6 = null;
        }
        activityDazzleGalleryBinding6.constraintBottomSheetTop.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary));
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding7 = this.mBinding;
        if (activityDazzleGalleryBinding7 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
        } else {
            activityDazzleGalleryBinding2 = activityDazzleGalleryBinding7;
        }
        DrawableCompat.setTint(activityDazzleGalleryBinding2.imageViewBack.getDrawable(), ContextCompat.getColor(getApplicationContext(), R.color.colorWhite));
    }

    public final void hideTopViews() {
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding = this.mBinding;
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding2 = null;
        if (activityDazzleGalleryBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding = null;
        }
        activityDazzleGalleryBinding.constraintCheck.setVisibility(8);
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding3 = this.mBinding;
        if (activityDazzleGalleryBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding3 = null;
        }
        activityDazzleGalleryBinding3.textViewOk.setVisibility(8);
        if (Build.VERSION.SDK_INT >= 23) {
            ActivityDazzleGalleryBinding activityDazzleGalleryBinding4 = this.mBinding;
            if (activityDazzleGalleryBinding4 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBinding");
                activityDazzleGalleryBinding4 = null;
            }
            activityDazzleGalleryBinding4.constraintBottomSheetTop.setBackgroundColor(getResources().getColor(R.color.colorWhite, null));
            ActivityDazzleGalleryBinding activityDazzleGalleryBinding5 = this.mBinding;
            if (activityDazzleGalleryBinding5 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBinding");
                activityDazzleGalleryBinding5 = null;
            }
            DrawableCompat.setTint(activityDazzleGalleryBinding5.imageViewBack.getDrawable(), getResources().getColor(R.color.colorBlack, null));
            return;
        }
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding6 = this.mBinding;
        if (activityDazzleGalleryBinding6 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding6 = null;
        }
        activityDazzleGalleryBinding6.constraintBottomSheetTop.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorWhite));
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding7 = this.mBinding;
        if (activityDazzleGalleryBinding7 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
        } else {
            activityDazzleGalleryBinding2 = activityDazzleGalleryBinding7;
        }
        DrawableCompat.setTint(activityDazzleGalleryBinding2.imageViewBack.getDrawable(), ContextCompat.getColor(getApplicationContext(), R.color.colorBlack));
    }

    public final void handleBottomSheet() {
        Context context = (Context) this;
        BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter = new BottomSheetMediaRecyclerAdapter(this.galleryImageList, this.mMediaClickListener, context);
        this.mBottomMediaAdapter = bottomSheetMediaRecyclerAdapter;
        DazzleOptions dazzleOptions = this.mDazzleOptions;
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding = null;
        if (dazzleOptions == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mDazzleOptions");
            dazzleOptions = null;
        }
        bottomSheetMediaRecyclerAdapter.setMaxCount(dazzleOptions.getMaxCount());
        RecyclerView.LayoutManager gridLayoutManager = new GridLayoutManager(context, 4);
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding2 = this.mBinding;
        if (activityDazzleGalleryBinding2 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding2 = null;
        }
        activityDazzleGalleryBinding2.recyclerViewBottomSheetMedia.setLayoutManager(gridLayoutManager);
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            public int getSpanSize(int position) {
                BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter2;
                bottomSheetMediaRecyclerAdapter2 = DazzleGallery.this.mBottomMediaAdapter;
                boolean z = false;
                if (bottomSheetMediaRecyclerAdapter2 != null && bottomSheetMediaRecyclerAdapter2.getItemViewType(position) == 1) {
                    z = true;
                }
                return z ? 4 : 1;
            }
        });
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding3 = this.mBinding;
        if (activityDazzleGalleryBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding3 = null;
        }
        activityDazzleGalleryBinding3.recyclerViewBottomSheetMedia.setAdapter(this.mBottomMediaAdapter);
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding4 = this.mBinding;
        if (activityDazzleGalleryBinding4 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding4 = null;
        }
        RecyclerView recyclerView = activityDazzleGalleryBinding4.recyclerViewBottomSheetMedia;
        BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter2 = this.mBottomMediaAdapter;
        Intrinsics.checkNotNull(bottomSheetMediaRecyclerAdapter2);
        recyclerView.addItemDecoration(new HeaderItemDecoration(bottomSheetMediaRecyclerAdapter2, context));
        int i = 0;
        ArrayList<MediaModel> arrayList = this.galleryImageList;
        ArrayList arrayList2 = new ArrayList(CollectionsKt.collectionSizeOrDefault(arrayList, 10));
        Iterator<T> it = arrayList.iterator();
        while (it.hasNext()) {
            if (((MediaModel) it.next()).getIsSelected()) {
                i++;
            }
            arrayList2.add(Unit.INSTANCE);
        }
        BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter3 = this.mBottomMediaAdapter;
        if (bottomSheetMediaRecyclerAdapter3 != null) {
            bottomSheetMediaRecyclerAdapter3.setImageCount(i);
        }
        BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter4 = this.mBottomMediaAdapter;
        if (bottomSheetMediaRecyclerAdapter4 != null) {
            bottomSheetMediaRecyclerAdapter4.notifyDataSetChanged();
        }
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding5 = this.mBinding;
        if (activityDazzleGalleryBinding5 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding5 = null;
        }
        activityDazzleGalleryBinding5.constraintCheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                DazzleGallery.handleBottomSheet$lambda$5(DazzleGallery.this, view);
            }
        });
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding6 = this.mBinding;
        if (activityDazzleGalleryBinding6 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding6 = null;
        }
        activityDazzleGalleryBinding6.textViewOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                DazzleGallery.handleBottomSheet$lambda$6(DazzleGallery.this, view);
            }
        });
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding7 = this.mBinding;
        if (activityDazzleGalleryBinding7 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
        } else {
            activityDazzleGalleryBinding = activityDazzleGalleryBinding7;
        }
        activityDazzleGalleryBinding.imageViewBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                DazzleGallery.handleBottomSheet$lambda$7(DazzleGallery.this, view);
            }
        });
    }

    public static final void handleBottomSheet$lambda$5(DazzleGallery dazzleGallery, View view) {
        Intrinsics.checkNotNullParameter(dazzleGallery, "this$0");
        dazzleGallery.pickImages();
    }

    public static final void handleBottomSheet$lambda$6(DazzleGallery dazzleGallery, View view) {
        Intrinsics.checkNotNullParameter(dazzleGallery, "this$0");
        dazzleGallery.pickImages();
    }

    public static final void handleBottomSheet$lambda$7(DazzleGallery dazzleGallery, View view) {
        Intrinsics.checkNotNullParameter(dazzleGallery, "this$0");
        dazzleGallery.onBackPressed();
    }

    public final void pickImages() {
        ArrayList<MediaModel> arrayList = this.galleryImageList;
        ArrayList arrayList2 = new ArrayList(CollectionsKt.collectionSizeOrDefault(arrayList, 10));
        for (MediaModel mediaModel : arrayList) {
            if (mediaModel.getIsSelected()) {
                ArrayList<String> arrayList3 = this.mPathList;
                MediaConstants mediaConstants = MediaConstants.INSTANCE;
                ContentResolver contentResolver = getContentResolver();
                Intrinsics.checkNotNullExpressionValue(contentResolver, "contentResolver");
                Uri mMediaUri = mediaModel.getMMediaUri();
                Intrinsics.checkNotNull(mMediaUri);
                File cacheDir = getCacheDir();
                Intrinsics.checkNotNullExpressionValue(cacheDir, "cacheDir");
                arrayList3.add(mediaConstants.getFileFromUri(contentResolver, mMediaUri, cacheDir).getPath());
                if (mediaModel.getMMediaType() == 1) {
                    ArrayList<Uri> arrayList4 = this.mPath;
                    Uri mMediaUri2 = mediaModel.getMMediaUri();
                    Intrinsics.checkNotNull(mMediaUri2);
                    arrayList4.add(mMediaUri2);
                }
            }
            arrayList2.add(Unit.INSTANCE);
        }
        DazzleOptions dazzleOptions = this.mDazzleOptions;
        if (dazzleOptions == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mDazzleOptions");
            dazzleOptions = null;
        }
        if (dazzleOptions.getCropEnabled() && this.mPath.size() == 1) {
            this.cropImage.launch(CropImageContractOptionsKt.options(this.mPath.get(0), new Function1<CropImageContractOptions, Unit>() {
                public Object invoke(Object obj) {
                    invoke((CropImageContractOptions) obj);
                    return Unit.INSTANCE;
                }

                public final void invoke(CropImageContractOptions cropImageContractOptions) {
                    Intrinsics.checkNotNullParameter(cropImageContractOptions, "$this$options");
                    cropImageContractOptions.setGuidelines(CropImageView.Guidelines.ON);
                    cropImageContractOptions.setOutputCompressFormat(Bitmap.CompressFormat.PNG);
                }
            }));
            return;
        }
        Intent intent = new Intent();
        intent.putExtra("PICKED_MEDIA_LIST", this.mPathList);
        setResult(-1, intent);
        finish();
    }

    public void onBackPressed() {
        BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter = this.mBottomMediaAdapter;
        if ((bottomSheetMediaRecyclerAdapter != null ? Integer.valueOf(bottomSheetMediaRecyclerAdapter.getImageCount()) : null) != null) {
            BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter2 = this.mBottomMediaAdapter;
            Integer valueOf = bottomSheetMediaRecyclerAdapter2 != null ? Integer.valueOf(bottomSheetMediaRecyclerAdapter2.getImageCount()) : null;
            Intrinsics.checkNotNull(valueOf);
            if (valueOf.intValue() > 0) {
                removeSelection();
                return;
            }
        }
        super.onBackPressed();
    }

    private final void removeSelection() {
        BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter = this.mBottomMediaAdapter;
        if (bottomSheetMediaRecyclerAdapter != null) {
            bottomSheetMediaRecyclerAdapter.setImageCount(0);
        }
        int size = this.galleryImageList.size();
        for (int i = 0; i < size; i++) {
            this.galleryImageList.get(i).setSelected(false);
        }
        BottomSheetMediaRecyclerAdapter bottomSheetMediaRecyclerAdapter2 = this.mBottomMediaAdapter;
        if (bottomSheetMediaRecyclerAdapter2 != null) {
            bottomSheetMediaRecyclerAdapter2.notifyDataSetChanged();
        }
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding = this.mBinding;
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding2 = null;
        if (activityDazzleGalleryBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding = null;
        }
        activityDazzleGalleryBinding.constraintCheck.setVisibility(8);
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding3 = this.mBinding;
        if (activityDazzleGalleryBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding3 = null;
        }
        activityDazzleGalleryBinding3.textViewOk.setVisibility(8);
        if (Build.VERSION.SDK_INT >= 23) {
            ActivityDazzleGalleryBinding activityDazzleGalleryBinding4 = this.mBinding;
            if (activityDazzleGalleryBinding4 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBinding");
                activityDazzleGalleryBinding4 = null;
            }
            activityDazzleGalleryBinding4.constraintBottomSheetTop.setBackgroundColor(getResources().getColor(R.color.colorWhite, null));
            ActivityDazzleGalleryBinding activityDazzleGalleryBinding5 = this.mBinding;
            if (activityDazzleGalleryBinding5 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBinding");
                activityDazzleGalleryBinding5 = null;
            }
            DrawableCompat.setTint(activityDazzleGalleryBinding5.imageViewBack.getDrawable(), getResources().getColor(R.color.colorBlack, null));
            return;
        }
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding6 = this.mBinding;
        if (activityDazzleGalleryBinding6 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
            activityDazzleGalleryBinding6 = null;
        }
        activityDazzleGalleryBinding6.constraintBottomSheetTop.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorWhite));
        ActivityDazzleGalleryBinding activityDazzleGalleryBinding7 = this.mBinding;
        if (activityDazzleGalleryBinding7 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBinding");
        } else {
            activityDazzleGalleryBinding2 = activityDazzleGalleryBinding7;
        }
        DrawableCompat.setTint(activityDazzleGalleryBinding2.imageViewBack.getDrawable(), ContextCompat.getColor(getApplicationContext(), R.color.colorBlack));
    }

    private final boolean allPermissionsGranted() {
        String[] strArr = REQUIRED_PERMISSIONS;
        int length = strArr.length;
        int i = 0;
        while (true) {
            if (i >= length) {
                return true;
            }
            if (!(ContextCompat.checkSelfPermission(getBaseContext(), strArr[i]) == 0)) {
                return false;
            }
            i++;
        }
    }

    private final File getOutputDirectory() {
        File file;
        File[] externalMediaDirs = getExternalMediaDirs();
        Intrinsics.checkNotNullExpressionValue(externalMediaDirs, "externalMediaDirs");
        File file2 = (File) ArraysKt.firstOrNull(externalMediaDirs);
        if (file2 != null) {
            file = new File(file2, getResources().getString(R.string.app_name));
            file.mkdirs();
        } else {
            file = null;
        }
        if (file != null && file.exists()) {
            return file;
        }
        File filesDir = getFilesDir();
        Intrinsics.checkNotNullExpressionValue(filesDir, "filesDir");
        return filesDir;
    }

    @Metadata(d1 = {"\u0000:\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u0011\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0018\u0010\f\u001a\u00020\r2\u0006\u0010\u000e\u001a\u00020\u000f2\u0006\u0010\u0010\u001a\u00020\u0011H\u0007J\u0018\u0010\f\u001a\u00020\r2\u0006\u0010\u0012\u001a\u00020\u00132\u0006\u0010\u0010\u001a\u00020\u0011H\u0007R\u000e\u0010\u0003\u001a\u00020\u0004X\u0086T¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004X\u0086T¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0086T¢\u0006\u0002\n\u0000R\u0016\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00040\tX\u0082\u0004¢\u0006\u0004\n\u0002\u0010\nR\u000e\u0010\u000b\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000¨\u0006\u0014"}, d2 = {"Lcom/aemerse/dazzle/DazzleGallery$Companion;", "", "()V", "PICKED_MEDIA_LIST", "", "PICKER_OPTIONS", "REQUEST_CODE_PICKER", "", "REQUIRED_PERMISSIONS", "", "[Ljava/lang/String;", "TAG", "startPicker", "", "fragment", "Landroidx/fragment/app/Fragment;", "mDazzleOptions", "Lcom/aemerse/dazzle/utils/DazzleOptions;", "activity", "Landroidx/fragment/app/FragmentActivity;", "picker_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
    public static final class Companion {
        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private Companion() {
        }

        @JvmStatic
        public final void startPicker(final Fragment fragment, final DazzleOptions mDazzleOptions) {
            Intrinsics.checkNotNullParameter(fragment, "fragment");
            Intrinsics.checkNotNullParameter(mDazzleOptions, "mDazzleOptions");
            PermissionUtils.INSTANCE.checkForCameraWritePermissions(fragment, new PermissionCallback() {
                @Override
                public void onPermission(boolean approved) {
                    Intent intent = new Intent(fragment.getActivity(), (Class<?>) DazzleGallery.class);
                    intent.putExtra("PICKER_OPTIONS", mDazzleOptions);
                    intent.addFlags(NativeProtocol.MESSAGE_GET_ACCESS_TOKEN_REQUEST);
                    fragment.startActivityForResult(intent, 10);
                }
            });
        }

        @JvmStatic
        public final void startPicker(final FragmentActivity activity, final DazzleOptions mDazzleOptions) {
            Intrinsics.checkNotNullParameter(activity, "activity");
            Intrinsics.checkNotNullParameter(mDazzleOptions, "mDazzleOptions");
            PermissionUtils.INSTANCE.checkForCameraWritePermissions(activity, new PermissionCallback() {
                @Override
                public void onPermission(boolean approved) {
                    Intent intent = new Intent(activity, (Class<?>) DazzleGallery.class);
                    intent.putExtra("PICKER_OPTIONS", mDazzleOptions);
                    intent.addFlags(NativeProtocol.MESSAGE_GET_ACCESS_TOKEN_REQUEST);
                    activity.startActivityForResult(intent, 10);
                }
            });
        }
    }
}