Shared Preference for current user name
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
package com.example.myapp_1;
|
package com.example.myapp_1;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@@ -13,10 +13,10 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||||||
import com.example.myapp_1.DB.DBOperations;
|
import com.example.myapp_1.DB.DBOperations;
|
||||||
|
|
||||||
public class LoginActivity extends AppCompatActivity {
|
public class LoginActivity extends AppCompatActivity {
|
||||||
|
SharedPreferences currentUserThings = getSharedPreferences("UserData", MODE_PRIVATE);
|
||||||
|
|
||||||
EditText username;
|
EditText username;
|
||||||
EditText password;
|
EditText password;
|
||||||
TextView forgetpassword;
|
|
||||||
Button login;
|
Button login;
|
||||||
Button signup;
|
Button signup;
|
||||||
|
|
||||||
@@ -30,17 +30,12 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
username = findViewById(R.id.editTextText);
|
username = findViewById(R.id.editTextText);
|
||||||
password = findViewById(R.id.editTextTextPassword);
|
password = findViewById(R.id.editTextTextPassword);
|
||||||
// forgetpassword = findViewById(R.id.forgetpass);
|
|
||||||
login = findViewById(R.id.button);
|
login = findViewById(R.id.loginButton);
|
||||||
signup = findViewById(R.id.button2);
|
signup = findViewById(R.id.signupButton);
|
||||||
guestLogin= findViewById(R.id.button3);
|
guestLogin= findViewById(R.id.guestButton);
|
||||||
// forgetpassword.setOnClickListener(new View.OnClickListener() {
|
|
||||||
// @Override
|
SharedPreferences.Editor editor = currentUserThings.edit();
|
||||||
// public void onClick(View v) {
|
|
||||||
// Intent newScreen = new Intent(getApplicationContext(), PasswordResetActivity.class);
|
|
||||||
// startActivity(newScreen);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
signup.setOnClickListener(new View.OnClickListener() {
|
signup.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@@ -54,6 +49,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
editor.putString("username", "Guest");
|
||||||
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
|
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
|
||||||
startActivity(newScreen);
|
startActivity(newScreen);
|
||||||
}
|
}
|
||||||
@@ -72,6 +68,7 @@ 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");
|
||||||
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
|
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
|
||||||
startActivity(newScreen);
|
startActivity(newScreen);
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class PasswordResetActivity extends AppCompatActivity {
|
|||||||
setContentView(R.layout.activity_password_reset);
|
setContentView(R.layout.activity_password_reset);
|
||||||
|
|
||||||
email = findViewById(R.id.editTextTextEmailAddress);
|
email = findViewById(R.id.editTextTextEmailAddress);
|
||||||
reset = findViewById(R.id.button3);
|
reset = findViewById(R.id.guestButton);
|
||||||
|
|
||||||
|
|
||||||
reset.setOnClickListener(new View.OnClickListener() {
|
reset.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
android:inputType="textPassword" />
|
android:inputType="textPassword" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button"
|
android:id="@+id/loginButton"
|
||||||
style="@android:style/Widget.Material.Button.Inset"
|
style="@android:style/Widget.Material.Button.Inset"
|
||||||
android:layout_width="311dp"
|
android:layout_width="311dp"
|
||||||
android:layout_height="60dp"
|
android:layout_height="60dp"
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button3"
|
android:id="@+id/guestButton"
|
||||||
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
|
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
|
||||||
android:layout_width="150dp"
|
android:layout_width="150dp"
|
||||||
android:layout_height="60dp"
|
android:layout_height="60dp"
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
android:text="Guest Login" />
|
android:text="Guest Login" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button2"
|
android:id="@+id/signupButton"
|
||||||
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
|
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
|
||||||
android:layout_width="150dp"
|
android:layout_width="150dp"
|
||||||
android:layout_height="60dp"
|
android:layout_height="60dp"
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/editTextTextMultiLine" />
|
app:layout_constraintTop_toBottomOf="@+id/editTextTextMultiLine" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button3"
|
android:id="@+id/guestButton"
|
||||||
android:layout_width="184dp"
|
android:layout_width="184dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="32dp"
|
||||||
|
|||||||
Reference in New Issue
Block a user