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);
SharedPreferences currentUserThings = getSharedPreferences("userData", MODE_PRIVATE);
SharedPreferences currentUserThings = getApplicationContext().getSharedPreferences("UserData", MODE_PRIVATE);
String user = currentUserThings.getString("username", "");
if (user != null)
userGreeting.setText("Welcome " + user + "!");
}
}

View File

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