package net.micode.notes.ui;
import net.micode.notes.R;
import android.app.Activity;
import android.content.Intent; // 导入 Intent 类
import android.os.Bundle; // 导入 Bundle 类
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.ProgressDialog;

import android.widget.Toast;

public class LoginActivity extends Activity {
    private EditText accountEdit;
    private EditText passwordEdit; // 修正变量名
    private Button login;
    private Button cancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        // 初始化控件
        accountEdit = findViewById(R.id.account);
        passwordEdit = findViewById(R.id.password);
        login = findViewById(R.id.login);
        cancel = findViewById(R.id.cancel);

        // 设置取消按钮点击事件监听器
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(LoginActivity.this, R.string.app_already_quit, Toast.LENGTH_LONG).show();
                finish();
            }
        });

        // 设置登录按钮点击事件监听器
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String account = accountEdit.getText().toString();
                String password = passwordEdit.getText().toString();

                if (account.equals("sqr") && password.equals("123456")) {
                    // 如果登录成功，显示进度条，然后跳转到下一个界面
                    ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this);
                    progressDialog.setTitle(getString(R.string.Loading)); // 使用 getString 获取字符串资源
                    progressDialog.setMessage("Loading...");
                    progressDialog.setCancelable(true);
                    progressDialog.show();
                    Intent intent = new Intent(LoginActivity.this, NotesListActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    // 如果登录失败，显示提示信息
                    Toast.makeText(LoginActivity.this, R.string.invalid, Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
