package com.xplora.xpsettings.Activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.FrameLayout;


import com.xplora.xpsettings.R;

public class WifiLoginActivity extends BaseActivity {
    EditText password;
    FrameLayout check;

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_SWIPE_TO_DISMISS);
        setContentView(R.layout.activity_wifi_login);
        password = findViewById(R.id.password);
        password.requestFocus();
        password.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                    showWiFi();
                }
                return false;
            }
        });

        check = findViewById(R.id.check);
        check.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.putExtra("ssid", getIntent().getStringExtra("ssid"));
            intent.putExtra("bssid", getIntent().getStringExtra("bssid"));
            intent.putExtra("password", password.getText().toString().trim());
            setResult(-1, intent);
            finish();
        });
    }

    private void showWiFi() {
        Intent intent = new Intent();
        intent.putExtra("ssid", getIntent().getStringExtra("ssid"));
        intent.putExtra("bssid", getIntent().getStringExtra("bssid"));
        intent.putExtra("password", password.getText().toString().trim());
        setResult(-1, intent);
        finish();
    }
}