Welcome to mirror list, hosted at ThFree Co, Russian Federation.

VaultLockScreenFragment.java « fragments « passman « app « wolfi « es « java « main « src « app - github.com/nextcloud/passman-android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a8b06a4a338f1d185545035f888d43c363ef4e83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
 * Passman Android App
 *
 * @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
 * @license GNU AGPL version 3 or any later version
 * <p>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * <p>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * <p>
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package es.wolfi.app.passman.fragments;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import es.wolfi.app.passman.R;
import es.wolfi.passman.API.Vault;
import es.wolfi.utils.KeyStoreUtils;


/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link VaultUnlockInteractionListener} interface
 * to handle interaction events.
 * Use the {@link VaultLockScreenFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class VaultLockScreenFragment extends Fragment {
    private Vault vault;

    private VaultUnlockInteractionListener mListener;

    @BindView(R.id.fragment_vault_name)
    TextView vault_name;
    @BindView(R.id.fragment_vault_password)
    EditText vault_password;
    @BindView(R.id.fragment_vault_unlock)
    FloatingActionButton btn_unlock;
    @BindView(R.id.vault_lock_screen_chk_save_pw)
    CheckBox chk_save;

    public VaultLockScreenFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param vault The vault
     * @return A new instance of fragment VaultLockScreenFragment.
     */
    public static VaultLockScreenFragment newInstance(Vault vault) {
        VaultLockScreenFragment fragment = new VaultLockScreenFragment();
        fragment.vault = vault;
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_vault_lock_screen, container, false);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof VaultUnlockInteractionListener) {
            mListener = (VaultUnlockInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement VaultUnlockInteractionListener");
        }
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (vault != null) {
            ButterKnife.bind(this, view);
            Log.e("VaultLockScreenFragment", "Vault guid: ".concat(vault.guid));
            vault_name.setText(vault.name);
        } else {
            Toast.makeText(getContext(), R.string.error_occurred, Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @OnClick(R.id.fragment_vault_unlock)
    void onBtnUnlockClick() {
        if (vault.unlock(vault_password.getText().toString())) {
            if (chk_save.isChecked()) {
                KeyStoreUtils.putStringAndCommit(vault.guid, vault_password.getText().toString());
            }
            mListener.onVaultUnlock(vault);
            return;
        }
        Toast.makeText(getContext(), R.string.wrong_vault_pw, Toast.LENGTH_LONG).show();
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface VaultUnlockInteractionListener {
        void onVaultUnlock(Vault vault);
    }
}