导航菜单

页面标题

页面副标题

Biko v2.0.23 - PhotoPickerView.java 源代码

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

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


package app.callpe.common.utils.custom;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import app.callpe.R;
import app.callpe.adapters.PhotoViewAdapter;
import app.callpe.common.utils.FileHandler;
import app.callpe.common.utils.FileUriUtils;
import app.callpe.common.utils.dialog.DialogHelper;
import app.callpe.common.utils.dialog.ImageProvider;
import app.callpe.common.utils.dialog.ResultListener;
import app.callpe.common.utils.file_helper.CompressFile;
import app.callpe.common.utils.file_helper.ImageConverter;
import app.callpe.ui.bottomsheet.PickerBottomSheet;
import app.callpe.ui.misc.ImageShowActivity;
import com.aemerse.dazzle.Dazzle;
import com.aemerse.dazzle.utils.DazzleOptions;
import com.crazylegend.core.dto.Config;
import com.crazylegend.core.modifiers.base.BaseSinglePickerModifier;
import com.crazylegend.imagepicker.images.ImageModel;
import com.crazylegend.imagepicker.pickers.SingleImagePicker;
import com.github.drjacky.imagepicker.ImagePicker;
import com.github.drjacky.imagepicker.listener.DismissListener;
import com.yalantis.ucrop.UCrop;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;
import timber.log.Timber;

@Metadata(d1 = {"\u0000z\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\b\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u000f\n\u0002\u0018\u0002\n\u0002\u0010\u000e\n\u0002\u0010\u0002\n\u0002\b\u000e\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010!\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\u0018\u00002\u00020\u0001B\u0011\b\u0016\u0012\b\u0010\u0002\u001a\u0004\u0018\u00010\u0003¢\u0006\u0002\u0010\u0004B\u001b\b\u0016\u0012\b\u0010\u0002\u001a\u0004\u0018\u00010\u0003\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006¢\u0006\u0002\u0010\u0007B#\b\u0016\u0012\b\u0010\u0002\u001a\u0004\u0018\u00010\u0003\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\nJ\u001e\u0010C\u001a\u00020,2\u0016\u0010D\u001a\u0012\u0012\u0004\u0012\u00020+0Ej\b\u0012\u0004\u0012\u00020+`FJ\u000e\u0010G\u001a\u00020,2\u0006\u0010H\u001a\u00020\u0010J\b\u0010I\u001a\u00020,H\u0002J\u0010\u0010J\u001a\u00020,2\u0006\u0010K\u001a\u00020LH\u0003J\b\u0010M\u001a\u00020,H\u0002J\u0010\u0010N\u001a\u00020,2\u0006\u0010O\u001a\u00020PH\u0002R\u0010\u0010\u000b\u001a\u0004\u0018\u00010\fX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\r\u001a\u0004\u0018\u00010\u000eX\u0082\u000e¢\u0006\u0002\n\u0000R\u001a\u0010\u000f\u001a\u00020\u0010X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0011\u0010\u0012\"\u0004\b\u0013\u0010\u0014R\u001a\u0010\u0015\u001a\u00020\u0010X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0016\u0010\u0012\"\u0004\b\u0017\u0010\u0014R$\u0010\u0018\u001a\b\u0012\u0004\u0012\u00020\u001a0\u00198\u0006@\u0006X\u0087\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u001b\u0010\u001c\"\u0004\b\u001d\u0010\u001eR$\u0010\u001f\u001a\b\u0012\u0004\u0012\u00020\u001a0\u00198\u0006@\u0006X\u0087\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b \u0010\u001c\"\u0004\b!\u0010\u001eR\u001a\u0010\"\u001a\u00020\u0010X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b#\u0010\u0012\"\u0004\b$\u0010\u0014R\u000e\u0010%\u001a\u00020\u0010X\u0082\u000e¢\u0006\u0002\n\u0000R\u001a\u0010&\u001a\u00020\u0010X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b'\u0010\u0012\"\u0004\b(\u0010\u0014R&\u0010)\u001a\u000e\u0012\u0004\u0012\u00020+\u0012\u0004\u0012\u00020,0*X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b-\u0010.\"\u0004\b/\u00100R&\u00101\u001a\u000e\u0012\u0004\u0012\u00020+\u0012\u0004\u0012\u00020,0*X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b2\u0010.\"\u0004\b3\u00100R$\u00104\u001a\b\u0012\u0004\u0012\u00020\u001a0\u00198\u0006@\u0006X\u0087\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b5\u0010\u001c\"\u0004\b6\u0010\u001eR\u001a\u00107\u001a\u00020\u0010X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b8\u0010\u0012\"\u0004\b9\u0010\u0014R\u0010\u0010:\u001a\u0004\u0018\u00010;X\u0082\u000e¢\u0006\u0002\n\u0000R\u0019\u0010<\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010+0=¢\u0006\b\n\u0000\u001a\u0004\b>\u0010?R\u001a\u0010@\u001a\u00020\u0010X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\bA\u0010\u0012\"\u0004\bB\u0010\u0014¨\u0006Q"}, d2 = {"Lapp/callpe/common/utils/custom/PhotoPickerView;", "Landroid/widget/RelativeLayout;", "context", "Landroid/content/Context;", "(Landroid/content/Context;)V", "attrs", "Landroid/util/AttributeSet;", "(Landroid/content/Context;Landroid/util/AttributeSet;)V", "defStyleAttr", "", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "adapter", "Lapp/callpe/adapters/PhotoViewAdapter;", "addButton", "Landroid/widget/ImageView;", "allowDelete", "", "getAllowDelete", "()Z", "setAllowDelete", "(Z)V", "approved", "getApproved", "setApproved", "cameraLauncher", "Landroidx/activity/result/ActivityResultLauncher;", "Landroid/content/Intent;", "getCameraLauncher", "()Landroidx/activity/result/ActivityResultLauncher;", "setCameraLauncher", "(Landroidx/activity/result/ActivityResultLauncher;)V", "cropLauncher", "getCropLauncher", "setCropLauncher", "customCamera", "getCustomCamera", "setCustomCamera", "hideAdd", "hideDelete", "getHideDelete", "setHideDelete", "imageDeleteCallback", "Lkotlin/Function1;", "", "", "getImageDeleteCallback", "()Lkotlin/jvm/functions/Function1;", "setImageDeleteCallback", "(Lkotlin/jvm/functions/Function1;)V", "imageUploadCallback", "getImageUploadCallback", "setImageUploadCallback", "launcher", "getLauncher", "setLauncher", "profileScreen", "getProfileScreen", "setProfileScreen", "recyclerView", "Landroidx/recyclerview/widget/RecyclerView;", "selectedPictures", "", "getSelectedPictures", "()Ljava/util/List;", "singlePic", "getSinglePic", "setSinglePic", "addItems", "pictures", "Ljava/util/ArrayList;", "Lkotlin/collections/ArrayList;", "hideAddBtn", "hide", "init", "loadImage", "imageModel", "Lcom/crazylegend/imagepicker/images/ImageModel;", "openGallery", "updateUiOnMainThread", "runnable", "Ljava/lang/Runnable;", "app_bikoRelease"}, k = 1, mv = {1, 8, 0}, xi = 48)
public final class PhotoPickerView extends RelativeLayout {
    private PhotoViewAdapter adapter;
    private ImageView addButton;
    private boolean allowDelete;
    private boolean approved;
    private ActivityResultLauncher<Intent> cameraLauncher;
    private ActivityResultLauncher<Intent> cropLauncher;
    private boolean customCamera;
    private boolean hideAdd;
    private boolean hideDelete;
    private Function1<? super String, Unit> imageDeleteCallback;
    private Function1<? super String, Unit> imageUploadCallback;
    private ActivityResultLauncher<Intent> launcher;
    private boolean profileScreen;
    private RecyclerView recyclerView;
    private final List<String> selectedPictures;
    private boolean singlePic;

    public final boolean getApproved() {
        return this.approved;
    }

    public final void setApproved(boolean z) {
        this.approved = z;
    }

    public final boolean getProfileScreen() {
        return this.profileScreen;
    }

    public final void setProfileScreen(boolean z) {
        this.profileScreen = z;
    }

    public final boolean getAllowDelete() {
        return this.allowDelete;
    }

    public final void setAllowDelete(boolean z) {
        this.allowDelete = z;
    }

    public final List<String> getSelectedPictures() {
        return this.selectedPictures;
    }

    public final boolean getCustomCamera() {
        return this.customCamera;
    }

    public final void setCustomCamera(boolean z) {
        this.customCamera = z;
    }

    public final boolean getSinglePic() {
        return this.singlePic;
    }

    public final void setSinglePic(boolean z) {
        this.singlePic = z;
    }

    public final boolean getHideDelete() {
        return this.hideDelete;
    }

    public final void setHideDelete(boolean z) {
        this.hideDelete = z;
    }

    public final Function1<String, Unit> getImageUploadCallback() {
        return this.imageUploadCallback;
    }

    public final void setImageUploadCallback(Function1<? super String, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "<set-?>");
        this.imageUploadCallback = function1;
    }

    public final Function1<String, Unit> getImageDeleteCallback() {
        return this.imageDeleteCallback;
    }

    public final void setImageDeleteCallback(Function1<? super String, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "<set-?>");
        this.imageDeleteCallback = function1;
    }

    public final ActivityResultLauncher<Intent> getLauncher() {
        return this.launcher;
    }

    public final void setLauncher(ActivityResultLauncher<Intent> activityResultLauncher) {
        Intrinsics.checkNotNullParameter(activityResultLauncher, "<set-?>");
        this.launcher = activityResultLauncher;
    }

    public static final void launcher$lambda$1(final PhotoPickerView photoPickerView, ActivityResult activityResult) {
        Intrinsics.checkNotNullParameter(photoPickerView, "this$0");
        Intrinsics.checkNotNullParameter(activityResult, "result");
        if (activityResult.getResultCode() == -1) {
            if (activityResult.getData() != null) {
                Intent data = activityResult.getData();
                Intrinsics.checkNotNull(data);
                Uri data2 = data.getData();
                Timber.e("selected %s", new Object[]{data2});
                File saveFileFromUri = FileHandler.saveFileFromUri(photoPickerView.getContext(), data2, "Pictures", "Picture_" + System.currentTimeMillis(), "jpg");
                String path = saveFileFromUri != null ? saveFileFromUri.getPath() : null;
                if (path == null) {
                    Toast.makeText(photoPickerView.getContext(), photoPickerView.getContext().getString(2131952060), 0).show();
                    return;
                } else {
                    photoPickerView.selectedPictures.add(0, path);
                    photoPickerView.updateUiOnMainThread(new Runnable() {
                        @Override
                        public final void run() {
                            PhotoPickerView.launcher$lambda$1$lambda$0(PhotoPickerView.this);
                        }
                    });
                    return;
                }
            }
            return;
        }
        activityResult.getResultCode();
    }

    public static final void launcher$lambda$1$lambda$0(PhotoPickerView photoPickerView) {
        Intrinsics.checkNotNullParameter(photoPickerView, "this$0");
        ImageView imageView = photoPickerView.addButton;
        if (imageView != null) {
            imageView.setVisibility(photoPickerView.singlePic ^ true ? 0 : 8);
        }
        PhotoViewAdapter photoViewAdapter = photoPickerView.adapter;
        if (photoViewAdapter != null) {
            photoViewAdapter.notifyDataSetChanged();
        }
    }

    public final ActivityResultLauncher<Intent> getCropLauncher() {
        return this.cropLauncher;
    }

    public final void setCropLauncher(ActivityResultLauncher<Intent> activityResultLauncher) {
        Intrinsics.checkNotNullParameter(activityResultLauncher, "<set-?>");
        this.cropLauncher = activityResultLauncher;
    }

    public static final void cropLauncher$lambda$3(final PhotoPickerView photoPickerView, ActivityResult activityResult) {
        Intrinsics.checkNotNullParameter(photoPickerView, "this$0");
        Intrinsics.checkNotNullParameter(activityResult, "result");
        if (activityResult.getResultCode() == -1) {
            Intent data = activityResult.getData();
            Intrinsics.checkNotNull(data);
            Uri output = UCrop.getOutput(data);
            if (output == null) {
                return;
            }
            Context context = photoPickerView.getContext();
            Intrinsics.checkNotNullExpressionValue(context, "context");
            String realPath = FileUriUtils.getRealPath(context, output);
            Timber.e("selectedImagePath " + realPath, new Object[0]);
            photoPickerView.selectedPictures.add(realPath);
            photoPickerView.updateUiOnMainThread(new Runnable() {
                @Override
                public final void run() {
                    PhotoPickerView.cropLauncher$lambda$3$lambda$2(PhotoPickerView.this);
                }
            });
        }
    }

    public static final void cropLauncher$lambda$3$lambda$2(PhotoPickerView photoPickerView) {
        Intrinsics.checkNotNullParameter(photoPickerView, "this$0");
        PhotoViewAdapter photoViewAdapter = photoPickerView.adapter;
        if (photoViewAdapter != null) {
            photoViewAdapter.notifyDataSetChanged();
        }
        ImageView imageView = photoPickerView.addButton;
        if (imageView == null) {
            return;
        }
        imageView.setVisibility(photoPickerView.singlePic ^ true ? 0 : 8);
    }

    public final ActivityResultLauncher<Intent> getCameraLauncher() {
        return this.cameraLauncher;
    }

    public final void setCameraLauncher(ActivityResultLauncher<Intent> activityResultLauncher) {
        Intrinsics.checkNotNullParameter(activityResultLauncher, "<set-?>");
        this.cameraLauncher = activityResultLauncher;
    }

    public static final void cameraLauncher$lambda$6(final PhotoPickerView photoPickerView, ActivityResult activityResult) {
        Intrinsics.checkNotNullParameter(photoPickerView, "this$0");
        Intrinsics.checkNotNullParameter(activityResult, "result");
        if (activityResult.getResultCode() == -1) {
            Intent data = activityResult.getData();
            ArrayList<String> stringArrayListExtra = data != null ? data.getStringArrayListExtra("PICKED_MEDIA_LIST") : null;
            Intrinsics.checkNotNull(stringArrayListExtra, "null cannot be cast to non-null type java.util.ArrayList<@[FlexibleNullability] kotlin.String?>");
            ArrayList<String> arrayList = stringArrayListExtra;
            ArrayList arrayList2 = new ArrayList(CollectionsKt.collectionSizeOrDefault(arrayList, 10));
            for (String str : arrayList) {
                Intrinsics.checkNotNullExpressionValue(str, "path");
                String compressedImageFile = CompressFile.getCompressedImageFile(Uri.parse(str), photoPickerView.getContext(), 60);
                Timber.e("selectedImagePath " + compressedImageFile, new Object[0]);
                photoPickerView.selectedPictures.add(compressedImageFile);
                photoPickerView.updateUiOnMainThread(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoPickerView.cameraLauncher$lambda$6$lambda$5$lambda$4(PhotoPickerView.this);
                    }
                });
                Function1<? super String, Unit> function1 = photoPickerView.imageUploadCallback;
                Intrinsics.checkNotNullExpressionValue(compressedImageFile, "compressedPath");
                function1.invoke(compressedImageFile);
                arrayList2.add(Unit.INSTANCE);
            }
        }
    }

    public static final void cameraLauncher$lambda$6$lambda$5$lambda$4(PhotoPickerView photoPickerView) {
        Intrinsics.checkNotNullParameter(photoPickerView, "this$0");
        PhotoViewAdapter photoViewAdapter = photoPickerView.adapter;
        if (photoViewAdapter != null) {
            photoViewAdapter.notifyDataSetChanged();
        }
        ImageView imageView = photoPickerView.addButton;
        if (imageView == null) {
            return;
        }
        imageView.setVisibility(photoPickerView.singlePic ^ true ? 0 : 8);
    }

    private final void updateUiOnMainThread(Runnable runnable) {
        Context context = getContext();
        Activity activity = context instanceof Activity ? (Activity) context : null;
        if (activity != null) {
            activity.runOnUiThread(runnable);
        }
    }

    public PhotoPickerView(Context context) {
        super(context);
        this.allowDelete = true;
        this.selectedPictures = new ArrayList();
        this.imageUploadCallback = PhotoPickerView$imageUploadCallback$1.INSTANCE;
        this.imageDeleteCallback = PhotoPickerView$imageDeleteCallback$1.INSTANCE;
        AppCompatActivity context2 = getContext();
        Intrinsics.checkNotNull(context2, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ActivityResultLauncher<Intent> registerForActivityResult = context2.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                PhotoPickerView.launcher$lambda$1(PhotoPickerView.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult, "context as AppCompatActi…r\n            }\n        }");
        this.launcher = registerForActivityResult;
        AppCompatActivity context3 = getContext();
        Intrinsics.checkNotNull(context3, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ActivityResultLauncher<Intent> registerForActivityResult2 = context3.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                PhotoPickerView.cropLauncher$lambda$3(PhotoPickerView.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult2, "context as AppCompatActi…}\n            }\n        }");
        this.cropLauncher = registerForActivityResult2;
        AppCompatActivity context4 = getContext();
        Intrinsics.checkNotNull(context4, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ActivityResultLauncher<Intent> registerForActivityResult3 = context4.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                PhotoPickerView.cameraLauncher$lambda$6(PhotoPickerView.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult3, "context as AppCompatActi…}\n            }\n        }");
        this.cameraLauncher = registerForActivityResult3;
        init();
    }

    public PhotoPickerView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.allowDelete = true;
        this.selectedPictures = new ArrayList();
        this.imageUploadCallback = PhotoPickerView$imageUploadCallback$1.INSTANCE;
        this.imageDeleteCallback = PhotoPickerView$imageDeleteCallback$1.INSTANCE;
        AppCompatActivity context2 = getContext();
        Intrinsics.checkNotNull(context2, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ActivityResultLauncher<Intent> registerForActivityResult = context2.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                PhotoPickerView.launcher$lambda$1(PhotoPickerView.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult, "context as AppCompatActi…r\n            }\n        }");
        this.launcher = registerForActivityResult;
        AppCompatActivity context3 = getContext();
        Intrinsics.checkNotNull(context3, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ActivityResultLauncher<Intent> registerForActivityResult2 = context3.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                PhotoPickerView.cropLauncher$lambda$3(PhotoPickerView.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult2, "context as AppCompatActi…}\n            }\n        }");
        this.cropLauncher = registerForActivityResult2;
        AppCompatActivity context4 = getContext();
        Intrinsics.checkNotNull(context4, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ActivityResultLauncher<Intent> registerForActivityResult3 = context4.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                PhotoPickerView.cameraLauncher$lambda$6(PhotoPickerView.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult3, "context as AppCompatActi…}\n            }\n        }");
        this.cameraLauncher = registerForActivityResult3;
        TypedArray obtainStyledAttributes = context != null ? context.obtainStyledAttributes(attributeSet, R.styleable.Picker) : null;
        this.allowDelete = obtainStyledAttributes != null ? obtainStyledAttributes.getBoolean(0, true) : true;
        if (obtainStyledAttributes != null) {
            obtainStyledAttributes.recycle();
        }
        TypedArray obtainStyledAttributes2 = context != null ? context.obtainStyledAttributes(attributeSet, R.styleable.Picker) : null;
        this.singlePic = obtainStyledAttributes2 != null ? obtainStyledAttributes2.getBoolean(2, false) : false;
        if (obtainStyledAttributes2 != null) {
            obtainStyledAttributes2.recycle();
        }
        init();
    }

    public PhotoPickerView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.allowDelete = true;
        this.selectedPictures = new ArrayList();
        this.imageUploadCallback = PhotoPickerView$imageUploadCallback$1.INSTANCE;
        this.imageDeleteCallback = PhotoPickerView$imageDeleteCallback$1.INSTANCE;
        AppCompatActivity context2 = getContext();
        Intrinsics.checkNotNull(context2, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ActivityResultLauncher<Intent> registerForActivityResult = context2.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                PhotoPickerView.launcher$lambda$1(PhotoPickerView.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult, "context as AppCompatActi…r\n            }\n        }");
        this.launcher = registerForActivityResult;
        AppCompatActivity context3 = getContext();
        Intrinsics.checkNotNull(context3, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ActivityResultLauncher<Intent> registerForActivityResult2 = context3.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                PhotoPickerView.cropLauncher$lambda$3(PhotoPickerView.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult2, "context as AppCompatActi…}\n            }\n        }");
        this.cropLauncher = registerForActivityResult2;
        AppCompatActivity context4 = getContext();
        Intrinsics.checkNotNull(context4, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ActivityResultLauncher<Intent> registerForActivityResult3 = context4.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                PhotoPickerView.cameraLauncher$lambda$6(PhotoPickerView.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult3, "context as AppCompatActi…}\n            }\n        }");
        this.cameraLauncher = registerForActivityResult3;
        TypedArray obtainStyledAttributes = context != null ? context.obtainStyledAttributes(attributeSet, R.styleable.Picker) : null;
        this.allowDelete = obtainStyledAttributes != null ? obtainStyledAttributes.getBoolean(0, true) : true;
        if (obtainStyledAttributes != null) {
            obtainStyledAttributes.recycle();
        }
        TypedArray obtainStyledAttributes2 = context != null ? context.obtainStyledAttributes(attributeSet, R.styleable.Picker) : null;
        this.singlePic = obtainStyledAttributes2 != null ? obtainStyledAttributes2.getBoolean(2, false) : false;
        if (obtainStyledAttributes2 != null) {
            obtainStyledAttributes2.recycle();
        }
        init();
    }

    private final void init() {
        RelativeLayout.inflate(getContext(), 2131558767, this);
        this.addButton = (ImageView) findViewById(2131361957);
        RecyclerView findViewById = findViewById(2131364314);
        this.recyclerView = findViewById;
        if (findViewById != null) {
            findViewById.setLayoutManager(new LinearLayoutManager(getContext(), 0, false));
        }
        ImageView imageView = this.addButton;
        if (imageView != null) {
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PhotoPickerView.init$lambda$7(PhotoPickerView.this, view);
                }
            });
        }
        PhotoViewAdapter photoViewAdapter = new PhotoViewAdapter(getContext(), this.selectedPictures, new PhotoViewAdapter.onItemClickListener() {
            @Override
            public void onItemClick(String picturePath) {
            }

            @Override
            public void onItemClick(final String picturePath, final int position) {
                Intrinsics.checkNotNullParameter(picturePath, "picturePath");
                boolean hideDelete = PhotoPickerView.this.getHideDelete();
                final PhotoPickerView photoPickerView = PhotoPickerView.this;
                Function0<Unit> function0 = new Function0<Unit>() {
                    {
                        super(0);
                    }

                    public Object invoke() {
                        m226invoke();
                        return Unit.INSTANCE;
                    }

                    public final void m226invoke() {
                        String joinToString$default = CollectionsKt.joinToString$default(PhotoPickerView.this.getSelectedPictures(), ",", (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, (Function1) null, 62, (Object) null);
                        Context context = PhotoPickerView.this.getContext();
                        Intrinsics.checkNotNull(context, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
                        Intent intent = new Intent(context, (Class<?>) ImageShowActivity.class);
                        int i = position;
                        PhotoPickerView photoPickerView2 = PhotoPickerView.this;
                        intent.putExtra("pics", joinToString$default);
                        intent.putExtra("position", i);
                        photoPickerView2.getContext().startActivity(intent);
                    }
                };
                final PhotoPickerView photoPickerView2 = PhotoPickerView.this;
                PickerBottomSheet pickerBottomSheet = new PickerBottomSheet(hideDelete, function0, new Function0<Unit>() {
                    {
                        super(0);
                    }

                    public Object invoke() {
                        m227invoke();
                        return Unit.INSTANCE;
                    }

                    public final void m227invoke() {
                        PhotoViewAdapter photoViewAdapter2;
                        ImageView imageView2;
                        PhotoPickerView.this.getSelectedPictures().remove(picturePath);
                        PhotoPickerView.this.getImageDeleteCallback().invoke(picturePath);
                        photoViewAdapter2 = PhotoPickerView.this.adapter;
                        if (photoViewAdapter2 != null) {
                            photoViewAdapter2.notifyDataSetChanged();
                        }
                        imageView2 = PhotoPickerView.this.addButton;
                        if (imageView2 == null) {
                            return;
                        }
                        imageView2.setVisibility(0);
                    }
                });
                if (pickerBottomSheet.isAdded() || pickerBottomSheet.isVisible()) {
                    return;
                }
                AppCompatActivity context = PhotoPickerView.this.getContext();
                Intrinsics.checkNotNull(context, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
                pickerBottomSheet.show(context.getSupportFragmentManager(), pickerBottomSheet.getTag());
            }

            @Override
            public void onDeleteClick(String picturePath) {
                Intrinsics.checkNotNullParameter(picturePath, "picturePath");
                PhotoPickerView.this.getSelectedPictures().remove(picturePath);
                PhotoPickerView.this.getImageDeleteCallback().invoke(picturePath);
            }
        });
        this.adapter = photoViewAdapter;
        photoViewAdapter.allowDelete = this.allowDelete;
        RecyclerView recyclerView = this.recyclerView;
        if (recyclerView == null) {
            return;
        }
        recyclerView.setAdapter(this.adapter);
    }

    public static final void init$lambda$7(final PhotoPickerView photoPickerView, View view) {
        Intrinsics.checkNotNullParameter(photoPickerView, "this$0");
        if (photoPickerView.customCamera) {
            DialogHelper dialogHelper = DialogHelper.INSTANCE;
            Context context = photoPickerView.getContext();
            Intrinsics.checkNotNullExpressionValue(context, "context");
            dialogHelper.showChooseAppDialog(context, false, new ResultListener<ImageProvider>() {

                @Metadata(k = 3, mv = {1, 8, 0}, xi = 48)
                public class WhenMappings {
                    public static final int[] $EnumSwitchMapping$0;

                    static {
                        int[] iArr = new int[ImageProvider.values().length];
                        try {
                            iArr[ImageProvider.CAMERA.ordinal()] = 1;
                        } catch (NoSuchFieldError unused) {
                        }
                        try {
                            iArr[ImageProvider.GALLERY.ordinal()] = 2;
                        } catch (NoSuchFieldError unused2) {
                        }
                        $EnumSwitchMapping$0 = iArr;
                    }
                }

                @Override
                public void onResult(ImageProvider t) {
                    if (t != null) {
                        int i = WhenMappings.$EnumSwitchMapping$0[t.ordinal()];
                        if (i != 1) {
                            if (i != 2) {
                                return;
                            }
                            SingleImagePicker singleImagePicker = SingleImagePicker.INSTANCE;
                            Context context2 = PhotoPickerView.this.getContext();
                            Intrinsics.checkNotNullExpressionValue(context2, "context");
                            singleImagePicker.showPicker(context2, new String[0], new Config(false), new Function1<BaseSinglePickerModifier, Unit>() {
                                public final void invoke(BaseSinglePickerModifier baseSinglePickerModifier) {
                                    Intrinsics.checkNotNullParameter(baseSinglePickerModifier, "$this$showPicker");
                                }

                                public Object invoke(Object obj) {
                                    invoke((BaseSinglePickerModifier) obj);
                                    return Unit.INSTANCE;
                                }
                            }, new PhotoPickerView$init$1$1$onResult$2(PhotoPickerView.this));
                            return;
                        }
                        DazzleOptions init = DazzleOptions.INSTANCE.init();
                        init.setAllowFrontCamera(true);
                        init.setExcludeVideos(true);
                        init.setCropEnabled(false);
                        init.setCameraOnly(true);
                        init.setDefaultFrontCamera(false);
                        Dazzle.Companion companion = Dazzle.INSTANCE;
                        AppCompatActivity context3 = PhotoPickerView.this.getContext();
                        Intrinsics.checkNotNull(context3, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
                        companion.startPicker((FragmentActivity) context3, init, PhotoPickerView.this.getCameraLauncher());
                    }
                }
            }, new DismissListener() {
                public void onDismiss() {
                }
            });
            return;
        }
        photoPickerView.openGallery();
    }

    private final void openGallery() {
        ImagePicker.Companion companion = ImagePicker.Companion;
        Context context = getContext();
        Intrinsics.checkNotNull(context, "null cannot be cast to non-null type android.app.Activity");
        companion.with((Activity) context).provider(com.github.drjacky.imagepicker.constant.ImageProvider.BOTH).createIntentFromDialog(new Function1<Intent, Unit>() {
            {
                super(1);
            }

            public Object invoke(Object obj) {
                invoke((Intent) obj);
                return Unit.INSTANCE;
            }

            public final void invoke(Intent intent) {
                Intrinsics.checkNotNullParameter(intent, "intent");
                PhotoPickerView.this.getLauncher().launch(intent);
            }
        });
    }

    public final void loadImage(ImageModel imageModel) {
        File saveFileFromUri = FileHandler.saveFileFromUri(getContext(), imageModel.getContentUri(), "Pictures", "Picture_" + System.currentTimeMillis(), "jpg");
        String path = saveFileFromUri != null ? saveFileFromUri.getPath() : null;
        if (path == null) {
            Toast.makeText(getContext(), getContext().getString(2131952060), 0).show();
            return;
        }
        ImageConverter imageConverter = ImageConverter.INSTANCE;
        Context context = getContext();
        Intrinsics.checkNotNullExpressionValue(context, "context");
        String convertImageToJpg = imageConverter.convertImageToJpg(context, path);
        this.selectedPictures.add(convertImageToJpg);
        PhotoViewAdapter photoViewAdapter = this.adapter;
        if (photoViewAdapter != null) {
            photoViewAdapter.notifyDataSetChanged();
        }
        ImageView imageView = this.addButton;
        if (imageView != null) {
            imageView.setVisibility(this.singlePic ^ true ? 0 : 8);
        }
        this.imageUploadCallback.invoke(convertImageToJpg);
    }

    public final void addItems(ArrayList<String> pictures) {
        Intrinsics.checkNotNullParameter(pictures, "pictures");
        PhotoViewAdapter photoViewAdapter = this.adapter;
        if (photoViewAdapter != null) {
            photoViewAdapter.addItems(pictures);
        }
    }

    public final void hideAddBtn(boolean hide) {
        ImageView imageView = this.addButton;
        if (imageView != null) {
            imageView.setVisibility(hide ^ true ? 0 : 8);
        }
        this.hideAdd = hide;
    }
}