Compare commits
No commits in common. 'be0f1dbf04211ac8d26e9117aa06d830d4a41fb5' and 'd8199843b24e93cfee41a060a791f2a1b72102a3' have entirely different histories.
be0f1dbf04
...
d8199843b2
@ -1,65 +1,14 @@
|
|||||||
package cc.liuyx.app;
|
package cc.liuyx.app;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class UserInfoActivity extends AppCompatActivity implements View.OnClickListener {
|
public class UserInfoActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private String username = "";
|
|
||||||
private String phone = "";
|
|
||||||
private String email = "";
|
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_user_info);
|
setContentView(R.layout.activity_user_info);
|
||||||
|
|
||||||
// 判断用户是否已经登录
|
|
||||||
// 如果未登录,则跳转至登录页面
|
|
||||||
SharedPreferences preferences = getSharedPreferences("loginStatus", MODE_PRIVATE);
|
|
||||||
boolean isLogin = preferences.getBoolean("isLoggedIn", false);
|
|
||||||
System.out.println(isLogin);
|
|
||||||
if (!isLogin) {
|
|
||||||
// 跳转到 LoginActivity
|
|
||||||
Intent intent = new Intent(UserInfoActivity.this, LoginActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
username = preferences.getString("username", null);
|
|
||||||
email = preferences.getString("email", null);
|
|
||||||
phone = preferences.getString("phone", null);
|
|
||||||
|
|
||||||
TextView userName = findViewById(R.id.user_username);
|
|
||||||
TextView userPhone = findViewById(R.id.user_phone);
|
|
||||||
TextView userEmail = findViewById(R.id.user_email);
|
|
||||||
userName.setText(userName.getText() + username);
|
|
||||||
userPhone.setText(userPhone.getText() + phone);
|
|
||||||
userEmail.setText(userEmail.getText() + email);
|
|
||||||
|
|
||||||
Button btnLogout = findViewById(R.id.logout);
|
|
||||||
btnLogout.setOnClickListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
if (view.getId() == R.id.logout) {
|
|
||||||
SharedPreferences preferences = getSharedPreferences("loginStatus", MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor edit = preferences.edit();
|
|
||||||
edit.remove("isLoggedIn");
|
|
||||||
edit.apply();
|
|
||||||
|
|
||||||
finish();
|
|
||||||
startActivity(new Intent(this, LoginActivity.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue