package com.epson.iprint.storage;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
import epson.print.R;

public abstract class StorageProcessActivity extends StorageActivity {
    public static final String EXTRA_UPLOADFILE_LIST = "Extra.Uploadfile.List";
    private static final String StorageServiceNameKey = "storage.service.name";
    private boolean bEnableSighIn = true;
    private String mServerName;
    private StorageServiceClient mStorageServiceClient;

    public enum ProcessType {
        DOWNLOAD,
        UPLOAD
    }

    public enum SignInStatus {
        SIGNED_IN,
        SIGNED_OUT
    }

    private abstract void onSignInStatus(SignInStatus signInStatus);

    private abstract void onUpdateProcessView();

    public /* bridge */ /* synthetic */ boolean isConnected() {
        return super.isConnected();
    }

    public static Intent getProcessIntent(Context context, String str, ProcessType processType) {
        if (processType == ProcessType.DOWNLOAD) {
            return null;
        }
        Intent intent = new Intent(context, StorageProcessUploadActivity.class);
        setCommonExtra(intent, str);
        return intent;
    }

    protected static void setCommonExtra(Intent intent, String str) {
        intent.putExtra(StorageServiceNameKey, str);
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        init();
    }

    protected void onStart() {
        super.onStart();
        updateSignInStatus();
        if (this.mStorageServiceClient.isSignedIn(this)) {
            onUpdateProcessView();
        }
    }

    protected void onResume() {
        super.onResume();
        updateSignInStatus();
    }

    public StorageServiceClient getStorageClient() {
        return this.mStorageServiceClient;
    }

    private void onSignIn() {
        startActivity(StorageSignInActivity.getStartIntent(this, this.mServerName, this.mStorageServiceClient.getStorageServiceName(this)));
    }

    private void onSignOut() {
        this.mStorageServiceClient.revokeSignedInData(this);
        updateSignInStatus();
    }

    private void init() {
        String stringExtra = getIntent().getStringExtra(StorageServiceNameKey);
        this.mServerName = stringExtra;
        this.mStorageServiceClient = StorageServiceClient.getClient(stringExtra);
    }

    private void updateSignInRequest(SignInStatus signInStatus) {
        TextView textView = (TextView) findViewById(16908292);
        if (signInStatus == SignInStatus.SIGNED_IN) {
            textView.setVisibility(8);
            return;
        }
        textView.setText(getString(R.string.sign_in_request));
        textView.setTypeface((Typeface) null, 1);
        textView.setTextSize(18.0f);
        textView.setVisibility(0);
    }

    public void updateSignInStatus() {
        SignInStatus signInStatus;
        WiFiDirectManager.setPriorityToSimpleAP(this, false);
        if (this.mStorageServiceClient.isSignedIn(this)) {
            signInStatus = SignInStatus.SIGNED_IN;
        } else {
            signInStatus = SignInStatus.SIGNED_OUT;
        }
        invalidateOptionsMenu();
        updateSignInRequest(signInStatus);
        onSignInStatus(signInStatus);
    }

    private void setSignInButtonEnabled(boolean z) {
        this.bEnableSighIn = z;
        invalidateOptionsMenu();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        switch (menuItem.getItemId()) {
            case R.id.menu_signin /*2131231253*/:
                onSignIn();
                return true;
            case R.id.menu_signout /*2131231254*/:
                onSignOut();
                return true;
            default:
                return super.onOptionsItemSelected(menuItem);
        }
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.C2138menu.menu_sign_inout, menu);
        if (this.mStorageServiceClient.isSignedIn(this)) {
            menu.removeItem(R.id.menu_signin);
            menu.findItem(R.id.menu_signout).setEnabled(this.bEnableSighIn);
        } else {
            menu.removeItem(R.id.menu_signout);
            menu.findItem(R.id.menu_signin).setEnabled(this.bEnableSighIn);
        }
        return super.onCreateOptionsMenu(menu);
    }
}
