forked from DigitalCampus/oppia-mobile-android
/
PasswordDialogFragment.java
87 lines (76 loc) · 3.31 KB
/
PasswordDialogFragment.java
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
/*
* This file is part of OppiaMobile - https://digital-campus.org/
*
* OppiaMobile is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OppiaMobile 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OppiaMobile. If not, see <http://www.gnu.org/licenses/>.
*/
package org.digitalcampus.oppia.fragments;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.application.AdminSecurityManager;
import org.digitalcampus.oppia.utils.ui.SimpleAnimator;
public class PasswordDialogFragment extends DialogFragment {
private AdminSecurityManager.AuthListener listener;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Oppia_AlertDialogStyle);
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dialog_password, null))
.setPositiveButton(R.string.ok, null)
.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
@Override
public void onStart()
{
super.onStart();
final AlertDialog d = (AlertDialog)getDialog();
if(d != null)
{
Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
positiveButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
EditText passwordField = (EditText) d.findViewById(R.id.admin_password_field);
View errorMessage = d.findViewById(R.id.admin_password_error);
String password = passwordField.getText().toString();
//If the user leave the input blank, we don't perform any action
if (password.equals("")) return;
boolean passCorrect = AdminSecurityManager.checkAdminPassword(PasswordDialogFragment.this.getActivity(), password);
if(passCorrect) {
d.dismiss();
if (listener != null) {
listener.onPermissionGranted();
}
}
else{
errorMessage.setVisibility(View.VISIBLE);
SimpleAnimator.fade(errorMessage, SimpleAnimator.FADE_IN);
passwordField.setText("");
}
}
});
}
}
public void setListener(AdminSecurityManager.AuthListener listener){
this.listener = listener;
}
}