corrigir os novos erros amnhã e adicionar qual tipo de sexo a pessoa é no register
This commit is contained in:
@@ -10,44 +10,81 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class PerfilActivity extends AppCompatActivity {
|
||||
|
||||
private TextView tvPerfilPontos, tvPerfilDesafios, tvPerfilSequencia;
|
||||
private TextView tvPerfilNome, tvPerfilPontos, tvPerfilDesafios, tvPerfilSequencia;
|
||||
private TextView tvPerfilEmail, tvPerfilPassword;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_perfil);
|
||||
|
||||
tvPerfilPontos = findViewById(R.id.tvPerfilPontos);
|
||||
tvPerfilDesafios = findViewById(R.id.tvPerfilDesafios);
|
||||
tvPerfilSequencia = findViewById(R.id.tvPerfilSequencia);
|
||||
try {
|
||||
tvPerfilNome = findViewById(R.id.tvPerfilNome);
|
||||
tvPerfilPontos = findViewById(R.id.tvPerfilPontos);
|
||||
tvPerfilDesafios = findViewById(R.id.tvPerfilDesafios);
|
||||
tvPerfilSequencia = findViewById(R.id.tvPerfilSequencia);
|
||||
|
||||
Button btnDefinicoes = findViewById(R.id.btnDefinicoes);
|
||||
TextView btnVoltar = findViewById(R.id.btnVoltarPerfil);
|
||||
// Ligar os novos textos do Email e Password
|
||||
tvPerfilEmail = findViewById(R.id.tvPerfilEmail);
|
||||
tvPerfilPassword = findViewById(R.id.tvPerfilPassword);
|
||||
|
||||
// Ler a pontuação guardada (vamos ligar isto mais à frente)
|
||||
Button btnDefinicoes = findViewById(R.id.btnDefinicoes);
|
||||
TextView btnVoltar = findViewById(R.id.btnVoltarPerfil);
|
||||
|
||||
if (btnDefinicoes != null) {
|
||||
btnDefinicoes.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(PerfilActivity.this, DefinicoesActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
if (btnVoltar != null) {
|
||||
btnVoltar.setOnClickListener(v -> finish());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, "Erro visual. Verifica o layout.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
carregarProgresso();
|
||||
|
||||
// Botão Definições
|
||||
btnDefinicoes.setOnClickListener(v -> {
|
||||
// Quando tiveres o ecrã de definições criado, trocas o Toast por isto:
|
||||
// Intent intent = new Intent(PerfilActivity.this, DefinicoesActivity.class);
|
||||
// startActivity(intent);
|
||||
Toast.makeText(this, "A abrir Definições...", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
|
||||
// Botão Voltar (manda-te de volta para o Home/Menu)
|
||||
btnVoltar.setOnClickListener(v -> finish());
|
||||
}
|
||||
|
||||
private void carregarProgresso() {
|
||||
SharedPreferences prefs = getSharedPreferences("DadosGamificacao", MODE_PRIVATE);
|
||||
try {
|
||||
// Puxa o nome, email e password
|
||||
SharedPreferences perfilPrefs = getSharedPreferences("MeusDadosApp", MODE_PRIVATE);
|
||||
|
||||
int pontos = prefs.getInt("pontos", 0);
|
||||
int desafios = prefs.getInt("desafios", 0);
|
||||
int sequencia = prefs.getInt("sequencia", 1);
|
||||
if (tvPerfilNome != null) tvPerfilNome.setText(perfilPrefs.getString("nome", "Utilizador"));
|
||||
if (tvPerfilEmail != null) tvPerfilEmail.setText(perfilPrefs.getString("email", "Sem Email"));
|
||||
if (tvPerfilPassword != null) tvPerfilPassword.setText(perfilPrefs.getString("password", "********"));
|
||||
|
||||
tvPerfilPontos.setText(String.valueOf(pontos));
|
||||
tvPerfilDesafios.setText(String.valueOf(desafios));
|
||||
tvPerfilSequencia.setText(String.valueOf(sequencia));
|
||||
// Puxa pontos e desafios
|
||||
int pontos = 0;
|
||||
int desafios = 0;
|
||||
try {
|
||||
pontos = perfilPrefs.getInt("pontos", 0);
|
||||
desafios = perfilPrefs.getInt("desafios_concluidos", 0);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
String pts = perfilPrefs.getString("pontos", "0");
|
||||
pontos = Integer.parseInt(pts.replaceAll("[^0-9]", ""));
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
// Puxa a sequência
|
||||
SharedPreferences gamificacaoPrefs = getSharedPreferences("DadosGamificacao", MODE_PRIVATE);
|
||||
int sequencia = gamificacaoPrefs.getInt("sequencia", 1);
|
||||
|
||||
if (tvPerfilPontos != null) tvPerfilPontos.setText(String.valueOf(pontos));
|
||||
if (tvPerfilDesafios != null) tvPerfilDesafios.setText(String.valueOf(desafios));
|
||||
if (tvPerfilSequencia != null) tvPerfilSequencia.setText(String.valueOf(sequencia));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user