package com.zhihu.matisse.internal.ui;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import com.zhihu.matisse.R$id;
import com.zhihu.matisse.R$layout;
import com.zhihu.matisse.R$string;
import com.zhihu.matisse.internal.entity.Item;
import com.zhihu.matisse.internal.ui.widget.CheckRadioView;
import com.zhihu.matisse.internal.ui.widget.CheckView;
import ඓ.ᨨ.K.ඓ.ʬ.C0766;
import ඓ.ᨨ.K.ඓ.ඓ.C0771;
import ඓ.ᨨ.K.ඓ.K.C0778;
import ඓ.ᨨ.K.ඓ.K.C0781;
import ඓ.ᨨ.K.ඓ.㸾.C0793;
import ඓ.ᨨ.K.ඓ.㸾.ʬ.C0783;
import ඓ.ᨨ.K.ඓ.㸾.㸾.C0799;
import ඓ.ᨨ.K.㴹.AbstractC0806;
import ඓ.ᨨ.K.㴹.AbstractC0807;
import ඓ.ᨨ.K.㴹.AbstractC0808;
import ῲ.㗗.K.K.C2240;

public abstract class BasePreviewActivity extends AppCompatActivity implements View.OnClickListener, ViewPager.AbstractC0304, AbstractC0807 {

    /* renamed from: Ԕ  reason: contains not printable characters */
    public CheckRadioView f3342;

    /* renamed from: ؿ  reason: contains not printable characters */
    public FrameLayout f3343;

    /* renamed from: ඓ  reason: contains not printable characters */
    public C0778 f3344;

    /* renamed from: ᓣ  reason: contains not printable characters */
    public FrameLayout f3345;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public TextView f3346;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public TextView f3347;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public C0783 f3348;

    /* renamed from: 㑃  reason: contains not printable characters */
    public int f3349 = -1;

    /* renamed from: 㗗  reason: contains not printable characters */
    public boolean f3350;

    /* renamed from: 㗽  reason: contains not printable characters */
    public boolean f3351 = false;

    /* renamed from: 㳳  reason: contains not printable characters */
    public TextView f3352;

    /* renamed from: 㴹  reason: contains not printable characters */
    public ViewPager f3353;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final C0766 f3354 = new C0766(this);

    /* renamed from: 㿎  reason: contains not printable characters */
    public CheckView f3355;

    /* renamed from: 䁗  reason: contains not printable characters */
    public LinearLayout f3356;

    /* renamed from: com.zhihu.matisse.internal.ui.BasePreviewActivity$ῲ  reason: contains not printable characters */
    public class View$OnClickListenerC0566 implements View.OnClickListener {
        public View$OnClickListenerC0566() {
        }

        public void onClick(View view) {
            int r6 = BasePreviewActivity.this.m1920();
            if (r6 > 0) {
                C0799.m2386("", BasePreviewActivity.this.getString(R$string.error_over_original_count, new Object[]{Integer.valueOf(r6), Integer.valueOf(BasePreviewActivity.this.f3344.f3946)})).show(BasePreviewActivity.this.getSupportFragmentManager(), C0799.class.getName());
                return;
            }
            BasePreviewActivity basePreviewActivity = BasePreviewActivity.this;
            basePreviewActivity.f3350 = true ^ basePreviewActivity.f3350;
            basePreviewActivity.f3342.setChecked(basePreviewActivity.f3350);
            BasePreviewActivity basePreviewActivity2 = BasePreviewActivity.this;
            if (!basePreviewActivity2.f3350) {
                basePreviewActivity2.f3342.setColor(-1);
            }
            BasePreviewActivity basePreviewActivity3 = BasePreviewActivity.this;
            AbstractC0808 k = basePreviewActivity3.f3344.f3962;
            if (k != null) {
                k.m2397(basePreviewActivity3.f3350);
            }
        }
    }

    /* renamed from: com.zhihu.matisse.internal.ui.BasePreviewActivity$K  reason: contains not printable characters */
    public class View$OnClickListenerC0567 implements View.OnClickListener {
        public View$OnClickListenerC0567() {
        }

        public void onClick(View view) {
            BasePreviewActivity basePreviewActivity = BasePreviewActivity.this;
            C0783 r0 = basePreviewActivity.f3348;
            Item item = r0.f3974.get(basePreviewActivity.f3353.getCurrentItem());
            boolean z = false;
            if (BasePreviewActivity.this.f3354.m2326(item)) {
                BasePreviewActivity.this.f3354.m2314(item);
                BasePreviewActivity basePreviewActivity2 = BasePreviewActivity.this;
                if (basePreviewActivity2.f3344.f3961) {
                    basePreviewActivity2.f3355.setCheckedNum(Integer.MIN_VALUE);
                } else {
                    basePreviewActivity2.f3355.setChecked(false);
                }
            } else {
                BasePreviewActivity basePreviewActivity3 = BasePreviewActivity.this;
                C0781 r2 = basePreviewActivity3.f3354.m2312(item);
                C0781.m2362(basePreviewActivity3, r2);
                if (r2 == null) {
                    z = true;
                }
                if (z) {
                    BasePreviewActivity.this.f3354.m2322(item);
                    BasePreviewActivity basePreviewActivity4 = BasePreviewActivity.this;
                    if (basePreviewActivity4.f3344.f3961) {
                        basePreviewActivity4.f3355.setCheckedNum(basePreviewActivity4.f3354.m2315(item));
                    } else {
                        basePreviewActivity4.f3355.setChecked(true);
                    }
                }
            }
            BasePreviewActivity.this.m1921();
            BasePreviewActivity basePreviewActivity5 = BasePreviewActivity.this;
            AbstractC0806 r02 = basePreviewActivity5.f3344.f3959;
            if (r02 != null) {
                r02.m2395(basePreviewActivity5.f3354.m2311(), BasePreviewActivity.this.f3354.m2316());
            }
        }
    }

    @Override // androidx.activity.ComponentActivity
    public void onBackPressed() {
        m1923(false);
        super.onBackPressed();
    }

    public void onClick(View view) {
        if (view.getId() == R$id.button_back) {
            onBackPressed();
        } else if (view.getId() == R$id.button_apply) {
            m1923(true);
            finish();
        }
    }

    @Override // androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity
    public void onCreate(Bundle bundle) {
        setTheme(C0778.C0779.f3967.f3963);
        super.onCreate(bundle);
        if (!C0778.C0779.f3967.f3951) {
            setResult(0);
            finish();
            return;
        }
        setContentView(R$layout.activity_media_preview);
        int i = Build.VERSION.SDK_INT;
        getWindow().addFlags(67108864);
        this.f3344 = C0778.C0779.f3967;
        if (this.f3344.f3949 != -1) {
            setRequestedOrientation(this.f3344.f3949);
        }
        if (bundle == null) {
            this.f3354.m2320(getIntent().getBundleExtra("extra_default_bundle"));
            this.f3350 = getIntent().getBooleanExtra("extra_result_original_enable", false);
        } else {
            this.f3354.m2320(bundle);
            this.f3350 = bundle.getBoolean("checkState");
        }
        this.f3347 = (TextView) findViewById(R$id.button_back);
        this.f3352 = (TextView) findViewById(R$id.button_apply);
        this.f3346 = (TextView) findViewById(R$id.size);
        this.f3347.setOnClickListener(this);
        this.f3352.setOnClickListener(this);
        this.f3353 = (ViewPager) findViewById(R$id.pager);
        this.f3353.addOnPageChangeListener(this);
        this.f3348 = new C0783(getSupportFragmentManager());
        this.f3353.setAdapter(this.f3348);
        this.f3355 = (CheckView) findViewById(R$id.check_view);
        this.f3355.setCountable(this.f3344.f3961);
        this.f3343 = (FrameLayout) findViewById(R$id.bottom_toolbar);
        this.f3345 = (FrameLayout) findViewById(R$id.top_toolbar);
        this.f3355.setOnClickListener(new View$OnClickListenerC0567());
        this.f3356 = (LinearLayout) findViewById(R$id.originalLayout);
        this.f3342 = (CheckRadioView) findViewById(R$id.original);
        this.f3356.setOnClickListener(new View$OnClickListenerC0566());
        m1921();
    }

    @Override // androidx.viewpager.widget.ViewPager.AbstractC0304
    public void onPageScrollStateChanged(int i) {
    }

    @Override // androidx.viewpager.widget.ViewPager.AbstractC0304
    public void onPageScrolled(int i, float f, int i2) {
    }

    @Override // androidx.viewpager.widget.ViewPager.AbstractC0304
    public void onPageSelected(int i) {
        C0783 r0 = (C0783) this.f3353.getAdapter();
        int i2 = this.f3349;
        if (!(i2 == -1 || i2 == i)) {
            ((C0793) r0.m3950((ViewGroup) this.f3353, i2)).m2379();
            Item item = r0.f3974.get(i);
            if (this.f3344.f3961) {
                int r1 = this.f3354.m2315(item);
                this.f3355.setCheckedNum(r1);
                if (r1 > 0) {
                    this.f3355.setEnabled(true);
                } else {
                    this.f3355.setEnabled(true ^ this.f3354.m2318());
                }
            } else {
                boolean r12 = this.f3354.m2326(item);
                this.f3355.setChecked(r12);
                if (r12) {
                    this.f3355.setEnabled(true);
                } else {
                    this.f3355.setEnabled(true ^ this.f3354.m2318());
                }
            }
            m1922(item);
        }
        this.f3349 = i;
    }

    @Override // androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity
    public void onSaveInstanceState(Bundle bundle) {
        this.f3354.m2317(bundle);
        bundle.putBoolean("checkState", this.f3350);
        super.onSaveInstanceState(bundle);
    }

    /* renamed from: ؿ  reason: contains not printable characters */
    public final int m1920() {
        int r0 = this.f3354.m2325();
        int i = 0;
        for (int i2 = 0; i2 < r0; i2++) {
            Item item = this.f3354.m2319().get(i2);
            if (item.m1916() && C0771.m2341(item.f3336) > ((float) this.f3344.f3946)) {
                i++;
            }
        }
        return i;
    }

    /* renamed from: ᓣ  reason: contains not printable characters */
    public final void m1921() {
        int r0 = this.f3354.m2325();
        if (r0 == 0) {
            this.f3352.setText(R$string.button_apply_default);
            this.f3352.setEnabled(false);
        } else if (r0 != 1 || !this.f3344.m2361()) {
            this.f3352.setEnabled(true);
            this.f3352.setText(getString(R$string.button_apply, new Object[]{Integer.valueOf(r0)}));
        } else {
            this.f3352.setText(R$string.button_apply_default);
            this.f3352.setEnabled(true);
        }
        if (this.f3344.f3948) {
            this.f3356.setVisibility(0);
            this.f3342.setChecked(this.f3350);
            if (!this.f3350) {
                this.f3342.setColor(-1);
            }
            if (m1920() > 0 && this.f3350) {
                C0799.m2386("", getString(R$string.error_over_original_size, new Object[]{Integer.valueOf(this.f3344.f3946)})).show(getSupportFragmentManager(), C0799.class.getName());
                this.f3342.setChecked(false);
                this.f3342.setColor(-1);
                this.f3350 = false;
                return;
            }
            return;
        }
        this.f3356.setVisibility(8);
    }

    @Override // ඓ.ᨨ.K.㴹.AbstractC0807
    /* renamed from: 㸾  reason: contains not printable characters */
    public void m1924() {
        if (this.f3344.f3965) {
            if (this.f3351) {
                this.f3345.animate().setInterpolator(new C2240()).translationYBy((float) this.f3345.getMeasuredHeight()).start();
                this.f3343.animate().translationYBy((float) (-this.f3343.getMeasuredHeight())).setInterpolator(new C2240()).start();
            } else {
                this.f3345.animate().setInterpolator(new C2240()).translationYBy((float) (-this.f3345.getMeasuredHeight())).start();
                this.f3343.animate().setInterpolator(new C2240()).translationYBy((float) this.f3343.getMeasuredHeight()).start();
            }
            this.f3351 = !this.f3351;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m1922(Item item) {
        if (item.m1912()) {
            this.f3346.setVisibility(0);
            TextView textView = this.f3346;
            textView.setText(C0771.m2341(item.f3336) + "M");
        } else {
            this.f3346.setVisibility(8);
        }
        if (item.m1913()) {
            this.f3356.setVisibility(8);
        } else if (this.f3344.f3948) {
            this.f3356.setVisibility(0);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m1923(boolean z) {
        Intent intent = new Intent();
        intent.putExtra("extra_result_bundle", this.f3354.m2323());
        intent.putExtra("extra_result_apply", z);
        intent.putExtra("extra_result_original_enable", this.f3350);
        setResult(-1, intent);
    }
}
