package com.epson.memcardacc;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.epson.memcardacc.MemcardTempAlertDialog;
import epson.print.ActivityRequestPermissions;


public class MemcardTop extends MemcardTopSuper {
    private static final int REQEST_RUNTIMEPERMMISSION = 1;

    protected int getStorageSetType() {
        return 1;
    }

    protected void onCreate(Bundle bundle) {
        mBitmapCache = MemcardBitmapCache.getInstance(this);
        if (mBitmapCache == null || !mBitmapCache.checkEnv()) {
            new MemcardTempAlertDialog().showAlertDialog(this, new MemcardTempAlertDialog.DialogCallback() {
                public void onPositiveCallback() {
                    MemcardTop.this.finish();
                }
            });
        }
        if (bundle == null) {
            CifsAccess.clearSmbAuthInfo();
        }
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_memcard_top);
        setActionBar((int) R.string.FunctionName_iPrint_MemoryCard, true);
        mLaunchType = 0;
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == 1 && i2 == -1) {
            startReader();
        }
    }

    public void copy_term_to_mem(View view) {
        if (mLaunchType == 0) {
            mLaunchType = 1;
            startMemcardStorageCheck();
        }
    }

    public void copy_term_from_mem(View view) {
        if (mLaunchType == 0) {
            if (ActivityRequestPermissions.isRuntimePermissionSupported()) {
                String[] strArr = {"android.permission.WRITE_EXTERNAL_STORAGE"};
                ActivityRequestPermissions.Permission permission = new ActivityRequestPermissions.Permission(strArr[0], new String[]{getString(R.string.permission_dialog_title), getString(R.string.permission_dialog_title)}, new String[]{ActivityRequestPermissions.DialogParameter.setMessage2((Context) this, getString(R.string.permission_dialog_message_storage)), ActivityRequestPermissions.DialogParameter.setMessage3A((Context) this, getString(R.string.permission_dialog_message_storage), getString(R.string.permission_function_storage))});
                if (!ActivityRequestPermissions.checkPermission(this, strArr)) {
                    ActivityRequestPermissions.requestPermission((Activity) this, permission, 1);
                    return;
                }
            }
            startReader();
        }
    }

    private void startReader() {
        mLaunchType = 2;
        startMemcardStorageCheck();
    }

    public void back_home_button_clicked(View view) {
        finish();
    }

    public void launchWriterActivity() {
        startActivity(new Intent(this, LocalImageSelectActivity.class));
    }

    public void launchReaderActivity(int i) {
        Intent intent = new Intent(this, MemcardImageGrid.class);
        intent.putExtra("memcard_storage_type", i);
        startActivity(intent);
    }
}
