package com.scottyab.rootbeer.sample;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.scottyab.rootbeer.sample.CheckRootTask;
import java.util.ArrayList;
import java.util.Iterator;
import uk.co.barbuzz.beerprogressview.BeerProgressView;
/* loaded from: classes.dex */
public class MainActivity extends AppCompatActivity implements CheckRootTask.OnCheckRootFinishedListener {
    private static final String GITHUB_LINK = "https://github.com/scottyab/rootbeer";
    private BeerProgressView beerView;
    private ArrayList<ImageView> checkRootImageViewList;
    private FloatingActionButton floatingActionButton;
    private AlertDialog infoDialog;
    private TextViewFont isRootedText;
    private TextView isRootedTextDisclaimer;
    private MainActivity mActivity;

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.support.v4.app.BaseFragmentActivityGingerbread, android.app.Activity
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        this.mActivity = this;
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        this.beerView = (BeerProgressView) findViewById(R.id.loadingRootCheckBeerView);
        this.isRootedText = (TextViewFont) findViewById(R.id.content_main_is_rooted_text);
        this.isRootedTextDisclaimer = (TextView) findViewById(R.id.content_mainisRootedTextDisclaimer);
        ImageView rootCheck1ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_1);
        ImageView rootCheck2ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_2);
        ImageView rootCheck3ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_3);
        ImageView rootCheck4ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_4);
        ImageView rootCheck5ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_5);
        ImageView rootCheck6ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_6);
        ImageView rootCheck7ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_7);
        ImageView rootCheck8ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_8);
        ImageView rootCheck9ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_9);
        ImageView rootCheck10ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_10);
        ImageView rootCheck11ImageView = (ImageView) findViewById(R.id.content_main_root_check_image_11);
        this.checkRootImageViewList = new ArrayList<>();
        this.checkRootImageViewList.add(rootCheck1ImageView);
        this.checkRootImageViewList.add(rootCheck2ImageView);
        this.checkRootImageViewList.add(rootCheck3ImageView);
        this.checkRootImageViewList.add(rootCheck4ImageView);
        this.checkRootImageViewList.add(rootCheck5ImageView);
        this.checkRootImageViewList.add(rootCheck6ImageView);
        this.checkRootImageViewList.add(rootCheck7ImageView);
        this.checkRootImageViewList.add(rootCheck8ImageView);
        this.checkRootImageViewList.add(rootCheck9ImageView);
        this.checkRootImageViewList.add(rootCheck10ImageView);
        this.checkRootImageViewList.add(rootCheck11ImageView);
        this.floatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
        this.floatingActionButton.setOnClickListener(new View.OnClickListener() { // from class: com.scottyab.rootbeer.sample.MainActivity.1
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                MainActivity.this.floatingActionButton.setVisibility(8);
                MainActivity.this.resetRootCheckImages();
                CheckRootTask checkRootTask = new CheckRootTask(MainActivity.this.mActivity, MainActivity.this.mActivity, MainActivity.this.beerView, MainActivity.this.checkRootImageViewList);
                checkRootTask.execute(true);
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void resetRootCheckImages() {
        this.isRootedText.setVisibility(8);
        Iterator<ImageView> it = this.checkRootImageViewList.iterator();
        while (it.hasNext()) {
            ImageView imageView = it.next();
            imageView.setImageDrawable(null);
        }
    }

    @Override // android.app.Activity
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override // android.app.Activity
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_github) {
            Intent i = new Intent("android.intent.action.VIEW");
            i.setData(Uri.parse(GITHUB_LINK));
            startActivity(i);
            return true;
        } else if (id == R.id.action_info) {
            showInfoDialog();
            return true;
        } else {
            return super.onOptionsItemSelected(item);
        }
    }

    private void showInfoDialog() {
        if (this.infoDialog == null || !this.infoDialog.isShowing()) {
            this.infoDialog = new AlertDialog.Builder(this).setTitle(R.string.app_name).setMessage(R.string.info_details).setCancelable(true).setPositiveButton("ok", new DialogInterface.OnClickListener() { // from class: com.scottyab.rootbeer.sample.MainActivity.3
                @Override // android.content.DialogInterface.OnClickListener
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).setNegativeButton("More info", new DialogInterface.OnClickListener() { // from class: com.scottyab.rootbeer.sample.MainActivity.2
                @Override // android.content.DialogInterface.OnClickListener
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    MainActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(MainActivity.GITHUB_LINK)));
                }
            }).create();
            this.infoDialog.show();
        }
    }

    @Override // com.scottyab.rootbeer.sample.CheckRootTask.OnCheckRootFinishedListener
    public void onCheckRootFinished(boolean isRooted) {
        this.floatingActionButton.setVisibility(0);
        this.isRootedText.setText(isRooted ? "ROOTED*" : "NOT ROOTED");
        this.isRootedTextDisclaimer.setVisibility(isRooted ? 0 : 8);
        this.isRootedText.setTextColor(isRooted ? getResources().getColor(R.color.fail) : getResources().getColor(R.color.pass));
        this.isRootedText.setVisibility(0);
    }
}
