TikTok.apk(点击下载) / C35659DzU.java


package X;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Base64;
import androidx.fragment.app.Fragment;
import com.bytedance.android.livesdk.utils.crop.CropFragment;
import com.bytedance.covode.number.Covode;
import com.swift.sandhook.utils.FileUtils;
import com.zhiliaoapp.musically.R;
import java.io.File;
import org.json.JSONException;
import org.json.JSONObject;

/* renamed from: X.DzU  reason: case insensitive filesystem */
public final class C35659DzU extends E67<C35672Dzh, C35677Dzm> {
    public Fragment LIZ;
    public final String LIZIZ = "upload_photo";
    public String LIZJ;
    public C35672Dzh LIZLLL;

    static {
        Covode.recordClassIndex(10148);
    }

    public C35659DzU(Fragment fragment) {
        this.LIZ = fragment;
    }

    public static Context LIZ(Context context) {
        Context applicationContext = context.getApplicationContext();
        return (C16360kz.LIZJ && applicationContext == null) ? C16360kz.LIZ : applicationContext;
    }

    private void LIZ(Uri uri) {
        CropFragment LIZ2 = CropFragment.LIZIZ.LIZ(uri);
        LIZ2.LIZ(new C35682Dzr(this));
        LIZ2.show(this.LIZ.getChildFragmentManager(), "upload_photo");
    }

    private boolean LIZIZ(String str) {
        Context context = this.callContext.LIZ;
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(str, options);
            if (this.LIZLLL.LIZ > options.outWidth || this.LIZLLL.LIZIZ > options.outHeight) {
                C33201D2g.LIZ(LIZ(context), (int) R.string.iap);
                return false;
            }
            if (options.outWidth > this.LIZLLL.LIZJ || options.outHeight > this.LIZLLL.LIZLLL || options.outWidth * options.outHeight > this.LIZLLL.LJ) {
                C33201D2g.LIZ(LIZ(context), (int) R.string.iao);
                return false;
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public final /* synthetic */ C23860x5 LIZ(String str) {
        ActivityC31021Kp activity = this.LIZ.getActivity();
        if (activity == null) {
            finishWithFailure();
            return null;
        } else if (!LIZIZ(str)) {
            C35629Dz0.LIZ(activity, this.LIZ);
            return null;
        } else {
            Context context = this.callContext.LIZ;
            if (context != null) {
                File file = new File(str);
                if (!file.exists()) {
                    finishWithFailure();
                } else {
                    byte[] LIZ2 = AnonymousClass2DQ.LIZ(file);
                    if (!(LIZ2 == null || LIZ2.length == 0)) {
                        if (LIZ2.length >= this.LIZLLL.LJ) {
                            C33201D2g.LIZ(LIZ(context), C33241D3u.LIZ((int) R.string.i6q, Integer.valueOf((this.LIZLLL.LJ / FileUtils.FileMode.MODE_ISGID) / FileUtils.FileMode.MODE_ISGID)), 0);
                        } else {
                            JSONObject jSONObject = new JSONObject();
                            try {
                                jSONObject.put("uri", str);
                                jSONObject.put("file_name", "upload_photo_" + this.LIZJ + "crop");
                                finishWithResult(new C35677Dzm(new C35681Dzq[]{new C35681Dzq(jSONObject.toString(), LIZ2.length, "data:image/jpg;base64," + Base64.encodeToString(LIZ2, 2))}, (byte) 0));
                            } catch (JSONException e) {
                                e.printStackTrace();
                                finishWithFailure();
                            }
                        }
                    }
                }
            }
            return null;
        }
    }

    public final void LIZ(int i2, int i3, Intent intent) {
        if (i2 == 40003) {
            if (i3 != -1 || intent == null || intent.getData() == null) {
                finishWithFailure();
                return;
            }
            ActivityC31021Kp activity = this.LIZ.getActivity();
            if (activity == null) {
                finishWithFailure();
                return;
            }
            Uri data = intent.getData();
            Bitmap bitmap = null;
            try {
                bitmap = BitmapFactory.decodeStream(activity.getContentResolver().openInputStream(data));
            } catch (Exception unused) {
            }
            if (bitmap == null) {
                AnonymousClass0NQ.LIZ(activity, (int) R.drawable.bz8, (int) R.string.ial);
                finishWithFailure();
                return;
            }
            LIZ(data);
        }
    }

    /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, X.E9B] */
    @Override // X.E67
    public final /* synthetic */ void invoke(C35672Dzh dzh, E9B e9b) {
        this.LIZLLL = dzh;
        this.LIZJ = String.valueOf(System.currentTimeMillis());
        C35629Dz0.LIZ(this.LIZ.getActivity(), this.LIZ);
    }

    @Override // X.E67
    public final void onTerminate() {
        this.LIZ = null;
    }
}