forked from PojavLauncherTeam/PojavLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalLoginFragment.java
More file actions
69 lines (54 loc) · 2.37 KB
/
Copy pathLocalLoginFragment.java
File metadata and controls
69 lines (54 loc) · 2.37 KB
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
package net.kdt.pojavlaunch.fragments;
import static net.kdt.pojavlaunch.Tools.hasOnlineProfile;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.extra.ExtraConstants;
import net.kdt.pojavlaunch.extra.ExtraCore;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LocalLoginFragment extends Fragment {
public static final String TAG = "LOCAL_LOGIN_FRAGMENT";
private final Pattern mUsernameValidationPattern;
private EditText mUsernameEditText;
public LocalLoginFragment(){
super(R.layout.fragment_local_login);
mUsernameValidationPattern = Pattern.compile("^[a-zA-Z0-9_]*$");
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
// This is overkill but meh
if (!hasOnlineProfile()){
Tools.swapFragment(requireActivity(), MainMenuFragment.class, MainMenuFragment.TAG, null);
}
mUsernameEditText = view.findViewById(R.id.login_edit_email);
view.findViewById(R.id.login_button).setOnClickListener(v -> {
if(!checkEditText()) {
Context context = v.getContext();
Tools.dialog(context, context.getString(R.string.local_login_bad_username_title), context.getString(R.string.local_login_bad_username_text));
return;
}
ExtraCore.setValue(ExtraConstants.MOJANG_LOGIN_TODO, new String[]{
mUsernameEditText.getText().toString(), "" });
Tools.swapFragment(requireActivity(), MainMenuFragment.class, MainMenuFragment.TAG, null);
});
}
/** @return Whether the mail (and password) text are eligible to make an auth request */
private boolean checkEditText(){
String text = mUsernameEditText.getText().toString();
Matcher matcher = mUsernameValidationPattern.matcher(text);
return !(text.isEmpty()
|| text.length() < 3
|| text.length() > 16
|| !matcher.find()
|| new File(Tools.DIR_ACCOUNT_NEW + "/" + text + ".json").exists()
);
}
}