Fixed user storage
This commit is contained in:
parent
4b78cb5f37
commit
a3aa30c6d7
|
|
@ -12,6 +12,6 @@
|
|||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-03-18T14:41:30.662193Z" />
|
||||
<timeTargetWasSelectedWithDropDown value="2023-03-18T17:23:33.549301Z" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -3,8 +3,6 @@ package xyz.r0r5chach.cpsAssist.login;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import xyz.r0r5chach.cpsAssist.R;
|
||||
|
||||
|
|
@ -14,6 +12,6 @@ public class LoginActivity extends AppCompatActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
findViewById(R.id.loginButton).setOnClickListener(new OnClickListener(findViewById(R.id.userNameField), findViewById(R.id.passwordField)));
|
||||
findViewById(R.id.loginButton).setOnClickListener(new OnClickListener(findViewById(R.id.userNameField), findViewById(R.id.passwordField), getString(R.string.users)));
|
||||
}
|
||||
}
|
||||
|
|
@ -2,19 +2,12 @@ package xyz.r0r5chach.cpsAssist.login;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import xyz.r0r5chach.cpsAssist.ArrayTools;
|
||||
import xyz.r0r5chach.cpsAssist.home.HomeActivity;
|
||||
import xyz.r0r5chach.cpsAssist.notes.NotesActivity;
|
||||
/**
|
||||
* This Class defines the definition of the OnCLickListener for the LoginActivity
|
||||
* @author r0r5chach
|
||||
|
|
@ -32,10 +25,6 @@ public class OnClickListener implements View.OnClickListener{
|
|||
* This attribute stores the View for the password field of the UI
|
||||
*/
|
||||
private final EditText passwordField;
|
||||
/**
|
||||
* This attribute stores the properties for the activity
|
||||
*/
|
||||
private Properties props;
|
||||
/**
|
||||
* This attribute stores a list of users' usernames and password
|
||||
*/
|
||||
|
|
@ -45,9 +34,8 @@ public class OnClickListener implements View.OnClickListener{
|
|||
* @param usernameField the View for the username field of the UI
|
||||
* @param passwordField the View for the password field of the UI
|
||||
*/
|
||||
public OnClickListener(EditText usernameField, EditText passwordField) {
|
||||
loadProperties();
|
||||
initUsers();
|
||||
public OnClickListener(EditText usernameField, EditText passwordField, String users) {
|
||||
initUsers(users);
|
||||
this.currentAttempts = 0;
|
||||
this.usernameField = usernameField;
|
||||
this.passwordField = passwordField;
|
||||
|
|
@ -65,7 +53,7 @@ public class OnClickListener implements View.OnClickListener{
|
|||
}
|
||||
|
||||
if (isUser(inputs)) {
|
||||
Intent home = new Intent(view.getContext(), HomeActivity.class);
|
||||
Intent home = new Intent(view.getContext(), NotesActivity.class);
|
||||
home.putExtra("username", inputs[0]);
|
||||
view.getContext().startActivity(home);
|
||||
((Activity)view.getContext()).finish();
|
||||
|
|
@ -75,25 +63,11 @@ public class OnClickListener implements View.OnClickListener{
|
|||
Toast.makeText(view.getContext(), "Incorrect Username/Password!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This method loads the properties for the activity from resources
|
||||
*/
|
||||
private void loadProperties() {
|
||||
props = new Properties();
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
props.loadFromXML(Files.newInputStream(Paths.get(Objects.requireNonNull(LoginActivity.class.getResource("values/properties_login.xml")).getPath())));
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This method initializes the users array from the activity properties
|
||||
*/
|
||||
private void initUsers() {
|
||||
String[] users = props.getProperty("users").split("%");
|
||||
private void initUsers(String usersString) {
|
||||
String[] users = usersString.split("%");
|
||||
this.users = new String[users.length][2];
|
||||
for (int i = 0; i < users.length; i++) {
|
||||
String[] details = users[i].split("#");
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties>
|
||||
<entry key="users">josh#pass%kofi#pass%jaiwin#pass</entry>
|
||||
</properties>
|
||||
|
|
@ -3,4 +3,5 @@
|
|||
<string name="usernameFieldHint">Username</string>
|
||||
<string name="passwordFieldHint">Password</string>
|
||||
<string name="loginButtonText">Login</string>
|
||||
<string name="users">josh#pass%kofi#pass%jaiwin#pass</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue