Compare commits
2 Commits
d8199843b2
...
be0f1dbf04
Author | SHA1 | Date |
---|---|---|
liuyx | be0f1dbf04 | 2 years ago |
liuyx | 2379c7e7d6 | 2 years ago |
@ -1,14 +1,65 @@
|
|||||||
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 {
|
public class UserInfoActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
|
||||||
|
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