package com.ifpdos.factorytest;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.core.internal.view.SupportMenu;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.ifpdos.factorytest.auto.CameraTestTask;
import com.ifpdos.factorytest.auto.DetectPreloaderBTask;
import com.ifpdos.factorytest.auto.MicTestTask;
import com.ifpdos.factorytest.auto.TestTask;
import com.ifpdos.factorytest.auto.TestTaskStatusEnum;
import com.ifpdos.factorytest.auto.UdiTestTask;
import com.ifpdos.factorytest.auto.WifiTestTask;
import com.ifpdos.factorytest.auto.WiredNetWorkTestTask;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Predicate;
import io.reactivex.schedulers.Schedulers;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes.dex */
public class CvtFactoryTestActivity extends Activity {
    private static final String TAG = "CvtFactoryTestActivity";
    RecyclerViewAdapter mRecyclerViewAdapter;
    private Disposable mTimeDisposable;
    private String timeTips;
    private TextView timeTv;
    private boolean mAllTestPass = true;
    private long mStartTime = 0;

    @Override // android.app.Activity
    protected void onCreate(Bundle bundle) {
        Log.d(TAG, "onCreate setLanguage");
        LanguageHelper.INSTANCE.setLanguage(this);
        super.onCreate(bundle);
        setContentView(R.layout.activity_device_check);
        this.timeTv = (TextView) findViewById(R.id.textView_check_time);
        this.timeTips = getString(R.string.check_time_tips);
        ArrayList arrayList = new ArrayList();
        arrayList.add(new UdiTestTask());
        if (ConfigParser.hasMic()) {
            arrayList.add(new MicTestTask());
        }
        if (ConfigParser.hasCamera()) {
            arrayList.add(new CameraTestTask());
        }
        if (ConfigParser.hasEth()) {
            arrayList.add(new WiredNetWorkTestTask());
        }
        if (ConfigParser.hasWifi()) {
            arrayList.add(new WifiTestTask());
        }
        if (ConfigParser.needDetectBPartitionB()) {
            arrayList.add(new DetectPreloaderBTask());
            if (!PreloaderBDetect.CheckPartitionB()) {
                findViewById(R.id.ignore).setVisibility(4);
                findViewById(R.id.exit).setVisibility(4);
            }
        }
        this.mRecyclerViewAdapter = new RecyclerViewAdapter(this, arrayList);
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.test_task_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(this.mRecyclerViewAdapter);
        Button button = (Button) findViewById(R.id.ignore);
        button.setOnClickListener(new View.OnClickListener() { // from class: com.ifpdos.factorytest.CvtFactoryTestActivity$$ExternalSyntheticLambda1
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                this.f$0.lambda$onCreate$0(view);
            }
        });
        button.setFocusableInTouchMode(true);
        button.requestFocus();
        ((Button) findViewById(R.id.exit)).setOnClickListener(new View.OnClickListener() { // from class: com.ifpdos.factorytest.CvtFactoryTestActivity$$ExternalSyntheticLambda2
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                this.f$0.lambda$onCreate$1(view);
            }
        });
        startTimeTask();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void lambda$onCreate$0(View view) {
        startMainTestActivity();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void lambda$onCreate$1(View view) {
        finish();
    }

    private void updateTimeTips() {
        this.timeTv.setText(String.format(Locale.ENGLISH, this.timeTips, Long.valueOf(this.mStartTime / 3600), Long.valueOf((this.mStartTime % 3600) / 60), Long.valueOf(this.mStartTime % 60)));
    }

    private void startTimeTask() {
        this.mTimeDisposable = Observable.interval(0L, 1L, TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer() { // from class: com.ifpdos.factorytest.CvtFactoryTestActivity$$ExternalSyntheticLambda0
            @Override // io.reactivex.functions.Consumer
            public final void accept(Object obj) throws Exception {
                this.f$0.lambda$startTimeTask$2((Long) obj);
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void lambda$startTimeTask$2(Long l) throws Exception {
        this.mStartTime++;
        updateTimeTips();
    }

    private void stopTimeTask() {
        Disposable disposable = this.mTimeDisposable;
        if (disposable == null || disposable.isDisposed()) {
            return;
        }
        Log.d(TAG, "stopTimeTask");
        this.mTimeDisposable.dispose();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void startMainTestActivity() {
        Log.d(TAG, "startMainTestActivity");
        startActivity(new Intent(this, (Class<?>) MainTestActivity.class));
        finish();
    }

    @Override // android.app.Activity
    protected void onResume() {
        super.onResume();
        this.mRecyclerViewAdapter.startTestTask();
    }

    @Override // android.app.Activity
    protected void onDestroy() {
        super.onDestroy();
        stopTimeTask();
        this.mRecyclerViewAdapter.stopTestTask();
    }

    private static class ViewHolder extends RecyclerView.ViewHolder {
        private Context mContext;
        private TextView mTestName;
        private TextView mTestResult;

        ViewHolder(View view) {
            super(view);
            this.mTestName = (TextView) view.findViewById(R.id.test_name);
            this.mTestResult = (TextView) view.findViewById(R.id.test_result);
            this.mContext = view.getContext();
        }

        void refreshTest(String str, TestTaskStatusEnum testTaskStatusEnum) {
            this.mTestName.setText(str);
            int i = AnonymousClass1.$SwitchMap$com$ifpdos$factorytest$auto$TestTaskStatusEnum[testTaskStatusEnum.ordinal()];
            if (i == 1) {
                this.mTestResult.setText(this.mContext.getString(R.string.success));
                this.mTestResult.setTextColor(-16711936);
            } else if (i == 2 || i == 3) {
                this.mTestResult.setText(this.mContext.getString(R.string.str_testing));
                this.mTestResult.setTextColor(ViewCompat.MEASURED_STATE_MASK);
            } else {
                this.mTestResult.setText(this.mContext.getString(R.string.ir_test_failed));
                this.mTestResult.setTextColor(SupportMenu.CATEGORY_MASK);
            }
        }
    }

    /* JADX INFO: renamed from: com.ifpdos.factorytest.CvtFactoryTestActivity$1, reason: invalid class name */
    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$ifpdos$factorytest$auto$TestTaskStatusEnum;

        static {
            int[] iArr = new int[TestTaskStatusEnum.values().length];
            $SwitchMap$com$ifpdos$factorytest$auto$TestTaskStatusEnum = iArr;
            try {
                iArr[TestTaskStatusEnum.PASS.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$ifpdos$factorytest$auto$TestTaskStatusEnum[TestTaskStatusEnum.TESTING.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$com$ifpdos$factorytest$auto$TestTaskStatusEnum[TestTaskStatusEnum.NOSTART.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    class RecyclerViewAdapter extends RecyclerView.Adapter<ViewHolder> {
        Disposable mDisposable;
        private Handler mHandler;
        private LayoutInflater mLayoutInflater;
        private List<TestTask> mTestTaskList;

        RecyclerViewAdapter(Context context, List<TestTask> list) {
            this.mHandler = new Handler(CvtFactoryTestActivity.this.getMainLooper());
            this.mLayoutInflater = LayoutInflater.from(context);
            this.mTestTaskList = list;
        }

        @Override // androidx.recyclerview.widget.RecyclerView.Adapter
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            return new ViewHolder(this.mLayoutInflater.inflate(R.layout.list_item_device_test, viewGroup, false));
        }

        @Override // androidx.recyclerview.widget.RecyclerView.Adapter
        public void onBindViewHolder(ViewHolder viewHolder, int i) {
            String testName = this.mTestTaskList.get(i).getTestName(CvtFactoryTestActivity.this);
            TestTaskStatusEnum testResult = this.mTestTaskList.get(i).getTestResult();
            Log.d(CvtFactoryTestActivity.TAG, "testName: " + testName + " testResult: " + testResult.name());
            viewHolder.refreshTest(testName, testResult);
        }

        @Override // androidx.recyclerview.widget.RecyclerView.Adapter
        public int getItemCount() {
            return this.mTestTaskList.size();
        }

        /* JADX INFO: Access modifiers changed from: private */
        public void startTestTask() {
            this.mDisposable = Observable.interval(0L, 3L, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).filter(new Predicate() { // from class: com.ifpdos.factorytest.CvtFactoryTestActivity$RecyclerViewAdapter$$ExternalSyntheticLambda1
                @Override // io.reactivex.functions.Predicate
                public final boolean test(Object obj) {
                    return this.f$0.lambda$startTestTask$0((Long) obj);
                }
            }).observeOn(AndroidSchedulers.mainThread()).takeUntil(new Predicate() { // from class: com.ifpdos.factorytest.CvtFactoryTestActivity$RecyclerViewAdapter$$ExternalSyntheticLambda2
                @Override // io.reactivex.functions.Predicate
                public final boolean test(Object obj) {
                    return this.f$0.lambda$startTestTask$1((Long) obj);
                }
            }).subscribe(new Consumer() { // from class: com.ifpdos.factorytest.CvtFactoryTestActivity$RecyclerViewAdapter$$ExternalSyntheticLambda3
                @Override // io.reactivex.functions.Consumer
                public final void accept(Object obj) throws Exception {
                    this.f$0.lambda$startTestTask$2((Long) obj);
                }
            });
        }

        /* JADX INFO: Access modifiers changed from: private */
        public /* synthetic */ boolean lambda$startTestTask$0(Long l) throws Exception {
            int i = 0;
            for (int i2 = 0; i2 < this.mTestTaskList.size(); i2++) {
                if (this.mTestTaskList.get(i2).getTestResult() == TestTaskStatusEnum.FAIL || this.mTestTaskList.get(i2).getTestResult() == TestTaskStatusEnum.NOSTART) {
                    this.mTestTaskList.get(i2).setTestResult(TestTaskStatusEnum.TESTING);
                    this.mHandler.post(new Runnable() { // from class: com.ifpdos.factorytest.CvtFactoryTestActivity$RecyclerViewAdapter$$ExternalSyntheticLambda0
                        @Override // java.lang.Runnable
                        public final void run() {
                            this.f$0.notifyDataSetChanged();
                        }
                    });
                    Log.d(CvtFactoryTestActivity.TAG, "auto check start: " + this.mTestTaskList.get(i2).getTestName(CvtFactoryTestActivity.this.getApplicationContext()));
                    boolean zStartTest = this.mTestTaskList.get(i2).startTest();
                    this.mHandler.post(new Runnable() { // from class: com.ifpdos.factorytest.CvtFactoryTestActivity$RecyclerViewAdapter$$ExternalSyntheticLambda0
                        @Override // java.lang.Runnable
                        public final void run() {
                            this.f$0.notifyDataSetChanged();
                        }
                    });
                    if (!zStartTest) {
                        i++;
                    }
                }
            }
            CvtFactoryTestActivity.this.mAllTestPass = i == 0;
            return l.longValue() == 10 || CvtFactoryTestActivity.this.mAllTestPass;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public /* synthetic */ boolean lambda$startTestTask$1(Long l) throws Exception {
            return l.longValue() == 10 || CvtFactoryTestActivity.this.mAllTestPass;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public /* synthetic */ void lambda$startTestTask$2(Long l) throws Exception {
            Log.d(CvtFactoryTestActivity.TAG, "subscribe,is all test task pass: " + CvtFactoryTestActivity.this.mAllTestPass);
            notifyDataSetChanged();
            if (CvtFactoryTestActivity.this.mAllTestPass) {
                Handler handler = this.mHandler;
                final CvtFactoryTestActivity cvtFactoryTestActivity = CvtFactoryTestActivity.this;
                handler.postDelayed(new Runnable() { // from class: com.ifpdos.factorytest.CvtFactoryTestActivity$RecyclerViewAdapter$$ExternalSyntheticLambda4
                    @Override // java.lang.Runnable
                    public final void run() {
                        cvtFactoryTestActivity.startMainTestActivity();
                    }
                }, 300L);
            }
        }

        /* JADX INFO: Access modifiers changed from: private */
        public void stopTestTask() {
            Disposable disposable = this.mDisposable;
            if (disposable == null || disposable.isDisposed()) {
                return;
            }
            this.mDisposable.dispose();
        }
    }

    @Override // android.app.Activity, android.content.ComponentCallbacks
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        Log.d(TAG, "onConfigurationChanged setLanguage");
        LanguageHelper.INSTANCE.setLanguage(this);
    }
}
