defeated again by capitalisation

This commit is contained in:
2023-12-20 11:36:51 +02:00
parent 5a8301b07d
commit 76e9b2ea46
2 changed files with 30 additions and 38 deletions

View File

@@ -45,10 +45,12 @@ public class HomeActivity extends AppCompatActivity {
} }
}); });
TextView userGreeting = findViewById(R.id.userGreeting); TextView userGreeting = findViewById(R.id.userGreeting);
SharedPreferences currentUserThings = getSharedPreferences("userData", MODE_PRIVATE); SharedPreferences currentUserThings = getApplicationContext().getSharedPreferences("UserData", MODE_PRIVATE);
String user = currentUserThings.getString("username", ""); String user = currentUserThings.getString("username", "");
if (user != null)
userGreeting.setText("Welcome " + user + "!"); userGreeting.setText("Welcome " + user + "!");
} }
} }

View File

@@ -3,7 +3,6 @@ package com.example.myapp_1;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
@@ -36,27 +35,18 @@ public class LoginActivity extends AppCompatActivity {
guestLogin= findViewById(R.id.guestButton); guestLogin= findViewById(R.id.guestButton);
SharedPreferences.Editor editor = currentUserThings.edit(); SharedPreferences.Editor editor = currentUserThings.edit();
signup.setOnClickListener(new View.OnClickListener() { signup.setOnClickListener(v -> {
@Override
public void onClick(View v) {
Intent newScreen = new Intent(getApplicationContext(), SigninActivity.class); Intent newScreen = new Intent(getApplicationContext(), SigninActivity.class);
startActivity(newScreen); startActivity(newScreen);
}
}); });
guestLogin.setOnClickListener(new View.OnClickListener(){ guestLogin.setOnClickListener(v -> {
@Override
public void onClick(View v) {
editor.putString("username", "Guest"); editor.putString("username", "Guest");
editor.apply();
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class); Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen); startActivity(newScreen);
}
}); });
login.setOnClickListener(new View.OnClickListener() { login.setOnClickListener(v -> {
@Override
public void onClick(View v) {
String username_data = username.getText().toString(); String username_data = username.getText().toString();
String password_data = password.getText().toString(); String password_data = password.getText().toString();
@@ -68,7 +58,8 @@ public class LoginActivity extends AppCompatActivity {
// Login successful // Login successful
// Proceed to the next screen or perform other actions // Proceed to the next screen or perform other actions
Toast.makeText(LoginActivity.this,"Welcome", Toast.LENGTH_LONG).show(); Toast.makeText(LoginActivity.this,"Welcome", Toast.LENGTH_LONG).show();
editor.putString("username", "Guest"); editor.putString("username", username_data);
editor.apply();
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class); Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen); startActivity(newScreen);
@@ -81,7 +72,6 @@ public class LoginActivity extends AppCompatActivity {
} }
}
}); });
} }
} }