package epson.print.imgsel;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.epson.cameracopy.p006ui.ImagePreviewActivity;
import epson.common.ScalableImageView;
import epson.print.R;

public class ImageViewMultiSelectFragment extends ImageViewBaseFragment {
    protected MyToggleButton mMyToggleButton;

    public static ImageViewMultiSelectFragment newInstance(String str) {
        ImageViewMultiSelectFragment imageViewMultiSelectFragment = new ImageViewMultiSelectFragment();
        Bundle bundle = new Bundle();
        bundle.putString(ImagePreviewActivity.PARAM_PICTURE_FILENAME, str);
        imageViewMultiSelectFragment.setArguments(bundle);
        return imageViewMultiSelectFragment;
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_image_view_multi, viewGroup, false);
        this.mImageView = (ScalableImageView) inflate.findViewById(R.id.imageView);
        this.mProgressBar = (ProgressBar) inflate.findViewById(R.id.imageLoadProgressBar);
        this.mMyToggleButton = new MyToggleButton(this, inflate.findViewById(R.id.myToggle), this.mListener.getSelector().isSelected(this.mFileName));
        super.onCreateView(layoutInflater, viewGroup, bundle);
        return inflate;
    }

    /* access modifiers changed from: private */
    public void selectImageOnMultiFileMode(boolean z) {
        ImageSelector selector = this.mListener.getSelector();
        if (!z) {
            selector.remove(this.mFileName);
        } else if (!selector.canAdd()) {
            MyToggleButton myToggleButton = this.mMyToggleButton;
            if (myToggleButton != null) {
                myToggleButton.forceSetChecked(false);
            }
            try {
                LocalAlertDialogFragment.newInstance(getString(R.string.max_image), 2).show(getChildFragmentManager(), "alert dialog");
                return;
            } catch (IllegalStateException unused) {
                return;
            }
        } else {
            selector.add(this.mFileName);
        }
        getActivity().invalidateOptionsMenu();
    }

    static class MyToggleButton {
        private ImageViewMultiSelectFragment mImageViewMultiSelectFragment;
        private boolean mMyToggleChecked;
        private ImageView mToggleImage;
        private TextView mToggleText;

        public MyToggleButton(ImageViewMultiSelectFragment imageViewMultiSelectFragment, View view, boolean z) {
            this.mImageViewMultiSelectFragment = imageViewMultiSelectFragment;
            init(view, z);
        }

        public void init(View view, boolean z) {
            this.mToggleImage = (ImageView) view.findViewById(R.id.myToggleImage);
            this.mToggleImage.setClickable(false);
            this.mToggleText = (TextView) view.findViewById(R.id.myToggleText);
            this.mToggleText.setClickable(false);
            view.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    MyToggleButton.this.toggleCheckStatus();
                }
            });
            forceSetChecked(z);
        }

        /* access modifiers changed from: private */
        public void toggleCheckStatus() {
            setMyChecked(!this.mToggleImage.isSelected());
        }

        public void forceSetChecked(boolean z) {
            this.mMyToggleChecked = z;
            syncTextState();
            this.mToggleImage.setSelected(this.mMyToggleChecked);
        }

        private void setMyChecked(boolean z) {
            if (z != this.mMyToggleChecked) {
                forceSetChecked(z);
                execCallback();
            }
        }

        private void execCallback() {
            ImageViewMultiSelectFragment imageViewMultiSelectFragment = this.mImageViewMultiSelectFragment;
            if (imageViewMultiSelectFragment != null) {
                imageViewMultiSelectFragment.selectImageOnMultiFileMode(this.mMyToggleChecked);
            }
        }

        private void syncTextState() {
            if (this.mMyToggleChecked) {
                this.mToggleText.setText(R.string.imgsel_view_pager_toggle_on);
            } else {
                this.mToggleText.setText(R.string.imgsel_view_pager_toggle_off);
            }
        }
    }
}
