package com.ccr.achenglibrary.photopicker.util;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
import com.ccr.achenglibrary.photopicker.util.CCRAsyncTask;
import java.io.File;
import java.lang.ref.SoftReference;

/* loaded from: classes.dex */
public class CCRSavePhotoTask extends CCRAsyncTask<Void, Void> {
    private SoftReference<Bitmap> mBitmap;
    private Context mContext;
    private File mNewFile;

    public CCRSavePhotoTask(CCRAsyncTask.Callback<Void> callback, Context context, File file) {
        super(callback);
        this.mContext = context.getApplicationContext();
        this.mNewFile = file;
    }

    public void setBitmapAndPerform(Bitmap bitmap) {
        this.mBitmap = new SoftReference<>(bitmap);
        executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0059 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Type inference failed for: r0v0, types: [int] */
    /* JADX WARN: Type inference failed for: r0v1, types: [java.io.FileOutputStream] */
    /* JADX WARN: Type inference failed for: r0v10, types: [java.io.OutputStream, java.io.FileOutputStream] */
    /* JADX WARN: Type inference failed for: r0v11 */
    /* JADX WARN: Type inference failed for: r0v12 */
    /* JADX WARN: Type inference failed for: r0v4 */
    /* JADX WARN: Type inference failed for: r0v6 */
    /* JADX WARN: Type inference failed for: r0v7 */
    /* JADX WARN: Type inference failed for: r0v8, types: [java.io.FileOutputStream] */
    /* JADX WARN: Type inference failed for: r0v9 */
    /* JADX WARN: Type inference failed for: r1v4, types: [android.graphics.Bitmap] */
    @Override // android.os.AsyncTask
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public java.lang.Void doInBackground(java.lang.Void... r6) {
        /*
            r5 = this;
            r6 = 0
            java.io.FileOutputStream r0 = new java.io.FileOutputStream     // Catch: java.lang.Throwable -> L3c java.lang.Exception -> L41
            java.io.File r1 = r5.mNewFile     // Catch: java.lang.Throwable -> L3c java.lang.Exception -> L41
            r0.<init>(r1)     // Catch: java.lang.Throwable -> L3c java.lang.Exception -> L41
            java.lang.ref.SoftReference<android.graphics.Bitmap> r1 = r5.mBitmap     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            java.lang.Object r1 = r1.get()     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            android.graphics.Bitmap r1 = (android.graphics.Bitmap) r1     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            android.graphics.Bitmap$CompressFormat r2 = android.graphics.Bitmap.CompressFormat.PNG     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            r3 = 100
            r1.compress(r2, r3, r0)     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            r0.flush()     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            android.content.Context r1 = r5.mContext     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            int r2 = com.ccr.achenglibrary.R.string.bga_pp_save_img_success_folder     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            java.io.File r3 = r5.mNewFile     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            java.io.File r3 = r3.getParentFile()     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            java.lang.String r3 = r3.getAbsolutePath()     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            java.lang.Object[] r3 = new java.lang.Object[]{r3}     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            java.lang.String r1 = r1.getString(r2, r3)     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            com.ccr.achenglibrary.photopicker.util.CCRPhotoPickerUtil.showSafe(r1)     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            java.io.File r1 = r5.mNewFile     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            r5.updateImg(r1)     // Catch: java.lang.Exception -> L42 java.lang.Throwable -> L56
            r0.close()     // Catch: java.io.IOException -> L4d
            goto L52
        L3c:
            r0 = move-exception
            r4 = r0
            r0 = r6
            r6 = r4
            goto L57
        L41:
            r0 = r6
        L42:
            int r1 = com.ccr.achenglibrary.R.string.bga_pp_save_img_failure     // Catch: java.lang.Throwable -> L56
            com.ccr.achenglibrary.photopicker.util.CCRPhotoPickerUtil.showSafe(r1)     // Catch: java.lang.Throwable -> L56
            if (r0 == 0) goto L52
            r0.close()     // Catch: java.io.IOException -> L4d
            goto L52
        L4d:
            int r0 = com.ccr.achenglibrary.R.string.bga_pp_save_img_failure
            com.ccr.achenglibrary.photopicker.util.CCRPhotoPickerUtil.showSafe(r0)
        L52:
            r5.recycleBitmap()
            return r6
        L56:
            r6 = move-exception
        L57:
            if (r0 == 0) goto L62
            r0.close()     // Catch: java.io.IOException -> L5d
            goto L62
        L5d:
            int r0 = com.ccr.achenglibrary.R.string.bga_pp_save_img_failure
            com.ccr.achenglibrary.photopicker.util.CCRPhotoPickerUtil.showSafe(r0)
        L62:
            r5.recycleBitmap()
            throw r6
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ccr.achenglibrary.photopicker.util.CCRSavePhotoTask.doInBackground(java.lang.Void[]):java.lang.Void");
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.ccr.achenglibrary.photopicker.util.CCRAsyncTask, android.os.AsyncTask
    public void onCancelled() {
        super.onCancelled();
        recycleBitmap();
    }

    private void recycleBitmap() {
        SoftReference<Bitmap> softReference = this.mBitmap;
        if (softReference == null || softReference.get() == null || this.mBitmap.get().isRecycled()) {
            return;
        }
        this.mBitmap.get().recycle();
        this.mBitmap = null;
    }

    private void updateImg(File file) {
        Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
        intent.setData(Uri.fromFile(file));
        this.mContext.sendBroadcast(intent);
        Toast.makeText(this.mContext, "更新啦", 0).show();
        Log.d("Acheng", "更新啦");
    }
}
