package net.micode.notes.ui;

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

import androidx.appcompat.app.AppCompatActivity;

import net.micode.notes.R;
import net.micode.notes.model.WorkingNote;

public class DeletePasscodeActivity extends AppCompatActivity {
    private LockPatternView mLockPatternView;
    private String mPasswordStr;

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

        mLockPatternView = (LockPatternView) findViewById(R.id.lockView);
        Intent pre = getIntent();
        final Long noteId = pre.getLongExtra(Intent.EXTRA_UID, 0);

        mLockPatternView.setLockListener(new LockPatternView.OnLockListener() {
            WorkingNote mWorkingNote = WorkingNote.load(DeletePasscodeActivity.this,noteId);
            String password = mWorkingNote.getPasscode();
            @Override
            public void getStringPassword(String password) {
                mPasswordStr = password;
            }

            @Override
            public boolean isPassword() {
                if (mPasswordStr.equals(password)) {
                    Toast.makeText(DeletePasscodeActivity.this, R.string.note_passcode_deleted, Toast.LENGTH_SHORT).show();
                    mWorkingNote.setPasscode("");
                    mWorkingNote.saveNote();
                    NoteEditActivity Activity = new NoteEditActivity();
                    Activity.NoteEditActivity.finish();
                    Intent intent = new Intent(DeletePasscodeActivity.this, NoteEditActivity.class);
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.putExtra(Intent.EXTRA_UID, noteId);
                    startActivity(intent);
                    DeletePasscodeActivity.this.finish();
                } else {
                    Toast.makeText(DeletePasscodeActivity.this, "密码不正确", Toast.LENGTH_SHORT).show();
                }
                return false;
            }
        });

    }
}
