package com.shukria.softpos.ui;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.shukria.softpos.R;
import com.shukria.softpos.Utils;

public class NfcErrorActivity extends AppCompatActivity {

    private TextView titleText;
    private TextView subtitleText;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.nfc_error_activity);
        initUI();
    }

    @Override
    protected void onResume() {
        super.onResume();
        syncWithNfcStatus(Utils.deviceNfcStatus(this));
    }

    private void initUI() {
        // Find views
        titleText = findViewById(R.id.titleText);
        subtitleText = findViewById(R.id.subtitleText);
    }

    private void syncWithNfcStatus(Utils.DeviceNfcStatus deviceNfcStatus) {
        switch (deviceNfcStatus) {
            case NO_NFC: {
                titleText.setText("Unsupported device");
                subtitleText.setText("This app requires NFC to run");
                break;
            }

            case NFC_DISABLED: {
                titleText.setText("NFC Disabled");
                subtitleText.setText("Please enable NFC");
                // Could open settings here to allow use to enabled NFC
                // startActivity(new Intent(Settings.ACTION_NFC_SETTINGS))
                break;
            }

            case NFC_ENABLED: {
                startActivity(new Intent(this, MainActivity.class));
                finish();
                break;
            }
        }
    }

}
