a acabar
This commit is contained in:
@@ -9,6 +9,7 @@ import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -83,9 +84,7 @@ public class CriarContaActivity extends AppCompatActivity {
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
if (user != null) {
|
||||
// Conta criada com sucesso - redirecionar para TelaInicialActivity
|
||||
Toast.makeText(this,
|
||||
"Conta criada com sucesso! Bem-vindo, " + nome,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(this, "Conta criada com sucesso! Bem-vindo, " + nome);
|
||||
|
||||
// Redirecionar para TelaInicialActivity apenas após sucesso
|
||||
Intent intent = new Intent(CriarContaActivity.this, TelaInicialActivity.class);
|
||||
@@ -107,7 +106,7 @@ public class CriarContaActivity extends AppCompatActivity {
|
||||
errorMessage = "Palavra-passe muito fraca. Use uma palavra-passe mais forte.";
|
||||
}
|
||||
}
|
||||
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
|
||||
CustomToast.error(this, errorMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.widget.Spinner;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.FileProvider;
|
||||
@@ -90,6 +91,9 @@ public class DefinicoesActivity extends AppCompatActivity {
|
||||
String savedName = prefs.getString("username", "");
|
||||
String savedPhotoUri = prefs.getString("profile_photo_uri", "");
|
||||
|
||||
boolean savedNotifications = prefs.getBoolean("notifications_enabled", true);
|
||||
switchNotifications.setChecked(savedNotifications);
|
||||
|
||||
if (!savedPhotoUri.isEmpty()) {
|
||||
selectedImageUri = Uri.parse(savedPhotoUri);
|
||||
try {
|
||||
@@ -149,6 +153,7 @@ public class DefinicoesActivity extends AppCompatActivity {
|
||||
btnSaveSettings.setOnClickListener(v -> {
|
||||
SharedPreferences.Editor editor = getSharedPreferences("LifeGridPrefs", Context.MODE_PRIVATE).edit();
|
||||
editor.putString("username", etUsername.getText().toString().trim());
|
||||
editor.putBoolean("notifications_enabled", switchNotifications.isChecked());
|
||||
if (selectedImageUri != null) {
|
||||
editor.putString("profile_photo_uri", selectedImageUri.toString());
|
||||
try {
|
||||
@@ -159,7 +164,7 @@ public class DefinicoesActivity extends AppCompatActivity {
|
||||
}
|
||||
editor.apply();
|
||||
|
||||
Toast.makeText(this, "Definições guardadas com sucesso!", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(this, "Definições guardadas com sucesso!");
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -98,7 +99,7 @@ public class DocumentosActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onCancelled(@NonNull DatabaseError error) {
|
||||
Toast.makeText(DocumentosActivity.this, "Erro ao carregar documentos.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(DocumentosActivity.this, "Erro ao carregar documentos.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -95,7 +96,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
emailEditText.setError("Por favor, digite o seu e-mail primeiro.");
|
||||
emailEditText.requestFocus();
|
||||
Toast.makeText(LoginActivity.this, "Digite o seu e-mail para recuperar a palavra-passe.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.info(LoginActivity.this, "Digite o seu e-mail para recuperar a palavra-passe.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -145,7 +146,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
String welcome = user != null && !TextUtils.isEmpty(user.getEmail())
|
||||
? "Bem-vindo, " + user.getEmail()
|
||||
: "Login realizado com sucesso!";
|
||||
Toast.makeText(this, welcome, Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(this, welcome);
|
||||
|
||||
// Redirecionar para TelaInicialActivity após login bem-sucedido
|
||||
Intent intent = new Intent(LoginActivity.this, TelaInicialActivity.class);
|
||||
@@ -153,9 +154,8 @@ public class LoginActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
finish(); // Fechar LoginActivity para não poder voltar com back button
|
||||
} else {
|
||||
Toast.makeText(this,
|
||||
task.getException() != null ? task.getException().getMessage() : "Falha no login",
|
||||
Toast.LENGTH_LONG).show();
|
||||
CustomToast.error(this,
|
||||
task.getException() != null ? task.getException().getMessage() : "Falha no login");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -173,13 +173,11 @@ public class LoginActivity extends AppCompatActivity {
|
||||
.addOnCompleteListener(this, task -> {
|
||||
toggleLoading(false);
|
||||
if (task.isSuccessful()) {
|
||||
Toast.makeText(this,
|
||||
"Email de recuperação enviado para " + email,
|
||||
Toast.LENGTH_LONG).show();
|
||||
CustomToast.success(this,
|
||||
"Email de recuperação enviado para " + email);
|
||||
} else {
|
||||
Toast.makeText(this,
|
||||
task.getException() != null ? task.getException().getMessage() : "Erro ao enviar email",
|
||||
Toast.LENGTH_LONG).show();
|
||||
CustomToast.error(this,
|
||||
task.getException() != null ? task.getException().getMessage() : "Erro ao enviar email");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -92,9 +93,8 @@ public class RecupearPasswordActivity extends AppCompatActivity {
|
||||
toggleLoading(false);
|
||||
if (task.isSuccessful()) {
|
||||
// Email enviado com sucesso
|
||||
Toast.makeText(this,
|
||||
"Email de recuperação enviado para " + email + "\nVerifique sua caixa de entrada.",
|
||||
Toast.LENGTH_LONG).show();
|
||||
CustomToast.success(this,
|
||||
"Email de recuperação enviado para " + email + "\nVerifique sua caixa de entrada.");
|
||||
// Limpar o campo após sucesso
|
||||
emailEditText4.setText("");
|
||||
} else {
|
||||
@@ -113,7 +113,7 @@ public class RecupearPasswordActivity extends AppCompatActivity {
|
||||
errorMessage = "Muitas tentativas. Tente novamente mais tarde.";
|
||||
}
|
||||
}
|
||||
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
|
||||
CustomToast.error(this, errorMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.auth.FirebaseUser;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
@@ -155,7 +156,7 @@ public class TelaInicialActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void processInvoiceImage(android.net.Uri imageUri) {
|
||||
Toast.makeText(this, "A processar fatura com IA...", Toast.LENGTH_LONG).show();
|
||||
CustomToast.info(this, "A processar fatura com IA...");
|
||||
InvoiceScannerHelper.scanInvoice(this, imageUri, new InvoiceScannerHelper.ScanCallback() {
|
||||
@Override
|
||||
public void onSuccess(double valor, String descricao, String categoria, String data) {
|
||||
@@ -181,7 +182,7 @@ public class TelaInicialActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
runOnUiThread(() -> Toast.makeText(TelaInicialActivity.this, error, Toast.LENGTH_LONG).show());
|
||||
runOnUiThread(() -> CustomToast.error(TelaInicialActivity.this, error));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -189,11 +190,11 @@ public class TelaInicialActivity extends AppCompatActivity {
|
||||
private void uploadDocumentoToFirebase(android.net.Uri imageUri, String descricao, String data) {
|
||||
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
|
||||
if (user == null) {
|
||||
Toast.makeText(this, "Utilizador não autenticado.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(this, "Utilizador não autenticado.");
|
||||
return;
|
||||
}
|
||||
|
||||
Toast.makeText(this, "A guardar documento na Cloud...", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.info(this, "A guardar documento na Cloud...");
|
||||
|
||||
String fileName = "invoice_" + System.currentTimeMillis() + ".jpg";
|
||||
com.google.firebase.storage.StorageReference storageRef = com.google.firebase.storage.FirebaseStorage.getInstance().getReference()
|
||||
@@ -208,14 +209,14 @@ public class TelaInicialActivity extends AppCompatActivity {
|
||||
com.example.lifegrid.models.Documento doc = new com.example.lifegrid.models.Documento(descricao, data, downloadUrl);
|
||||
dbRef.setValue(doc).addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
Toast.makeText(TelaInicialActivity.this, "Documento guardado com sucesso!", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(TelaInicialActivity.this, "Documento guardado com sucesso!");
|
||||
} else {
|
||||
Toast.makeText(TelaInicialActivity.this, "Erro ao guardar dados na Cloud.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(TelaInicialActivity.this, "Erro ao guardar dados na Cloud.");
|
||||
}
|
||||
});
|
||||
});
|
||||
}).addOnFailureListener(e -> {
|
||||
Toast.makeText(this, "Erro ao enviar imagem para a Cloud.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(this, "Erro ao enviar imagem para a Cloud.");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -47,7 +48,7 @@ public class DocumentoAdapter extends RecyclerView.Adapter<DocumentoAdapter.Docu
|
||||
if (url != null && !url.isEmpty()) {
|
||||
downloadFile(url, holder.tvDescricao.getText().toString());
|
||||
} else {
|
||||
Toast.makeText(context, "URL inválido para o documento.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(context, "URL inválido para o documento.");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -70,11 +71,11 @@ public class DocumentoAdapter extends RecyclerView.Adapter<DocumentoAdapter.Docu
|
||||
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
if (manager != null) {
|
||||
manager.enqueue(request);
|
||||
Toast.makeText(context, "Transferência iniciada. Verifique as notificações.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.info(context, "Transferência iniciada. Verifique as notificações.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(context, "Erro ao iniciar transferência.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(context, "Erro ao iniciar transferência.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -106,7 +107,7 @@ public class MetaAdapter extends RecyclerView.Adapter<MetaAdapter.MetaViewHolder
|
||||
double valorAdicional = Double.parseDouble(input);
|
||||
listener.onAddValueClick(meta, valorAdicional, holder.etAdicionarValor);
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(v.getContext(), "Valor inválido", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(v.getContext(), "Valor inválido");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
@@ -159,18 +160,18 @@ public class AtivosFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCancelled(@NonNull DatabaseError error) {
|
||||
Toast.makeText(requireContext(), "Erro ao carregar ativos.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(requireContext(), "Erro ao carregar ativos.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshAtivoPrice(Ativos ativo, String key) {
|
||||
if (ativo.getTicker() == null || ativo.getTicker().isEmpty()) {
|
||||
Toast.makeText(requireContext(), "Este ativo não tem um Ticker definido.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.info(requireContext(), "Este ativo não tem um Ticker definido.");
|
||||
return;
|
||||
}
|
||||
|
||||
Toast.makeText(requireContext(), "A atualizar " + ativo.getTicker() + "...", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.info(requireContext(), "A atualizar " + ativo.getTicker() + "...");
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
@@ -205,14 +206,14 @@ public class AtivosFragment extends Fragment {
|
||||
handler.post(() -> {
|
||||
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
|
||||
databaseReference.child("users").child(userId).child("ativos").child(key).child("precoAtual").setValue(regularMarketPrice);
|
||||
Toast.makeText(requireContext(), "Preço atualizado: " + regularMarketPrice + "€", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(requireContext(), "Preço atualizado: " + regularMarketPrice + "€");
|
||||
});
|
||||
} else {
|
||||
handler.post(() -> Toast.makeText(requireContext(), "Erro ao contactar a API.", Toast.LENGTH_SHORT).show());
|
||||
handler.post(() -> CustomToast.error(requireContext(), "Erro ao contactar a API."));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
handler.post(() -> Toast.makeText(requireContext(), "Ativo não encontrado ou erro de rede.", Toast.LENGTH_SHORT).show());
|
||||
handler.post(() -> CustomToast.error(requireContext(), "Ativo não encontrado ou erro de rede."));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -283,9 +284,9 @@ public class AtivosFragment extends Fragment {
|
||||
boolean isCriptomoeda = "Criptomoedas".equals(tipo);
|
||||
|
||||
if (nome.isEmpty() || quantidade.isEmpty() || precoCompra.isEmpty() || dataCompra.isEmpty() || spinnerTipoAtivo.getSelectedItemPosition() == 0) {
|
||||
Toast.makeText(requireContext(), "Por favor, preencha os campos obrigatórios.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.info(requireContext(), "Por favor, preencha os campos obrigatórios.");
|
||||
} else if (isCriptomoeda && ticker.isEmpty()) {
|
||||
Toast.makeText(requireContext(), "Por favor, preencha o Símbolo da Criptomoeda.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.info(requireContext(), "Por favor, preencha o Símbolo da Criptomoeda.");
|
||||
} else {
|
||||
Ativos ativos = new Ativos(nome, quantidade, Double.parseDouble(precoCompra), Double.parseDouble(precoCompra), dataCompra, tipo, ticker);
|
||||
|
||||
@@ -298,7 +299,7 @@ public class AtivosFragment extends Fragment {
|
||||
|
||||
|
||||
dialog.dismiss();
|
||||
Toast.makeText(requireContext(), "Ativo adicionado com sucesso!", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(requireContext(), "Ativo adicionado com sucesso!");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import com.example.lifegrid.R;
|
||||
import com.example.lifegrid.models.Transacao;
|
||||
@@ -135,9 +136,7 @@ public class GraficosFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCancelled(@NonNull DatabaseError error) {
|
||||
if (getContext() != null) {
|
||||
Toast.makeText(getContext(), "Erro ao carregar transações.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
CustomToast.error(requireContext(), "Erro ao carregar transações.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import com.example.lifegrid.R;
|
||||
import com.example.lifegrid.models.Transacao;
|
||||
@@ -218,7 +219,7 @@ public class HomeFragment extends Fragment {
|
||||
@Override
|
||||
public void onCancelled(@NonNull DatabaseError error) {
|
||||
if (isAdded()) {
|
||||
Toast.makeText(getContext(), "Erro ao carregar dados", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(requireContext(), "Erro ao carregar dados");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
@@ -87,7 +88,7 @@ public class MetasFragment extends Fragment {
|
||||
.setPositiveButton("Sim", (dialog, which) -> {
|
||||
if (databaseReference != null && userId != null && meta.getId() != null) {
|
||||
databaseReference.child("users").child(userId).child("metas").child(meta.getId()).removeValue();
|
||||
Toast.makeText(requireContext(), "Meta excluída.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(requireContext(), "Meta excluída.");
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Não", null)
|
||||
@@ -117,8 +118,17 @@ public class MetasFragment extends Fragment {
|
||||
databaseReference.child("users").child(userId).child("transacoes").child(key).setValue(transacao);
|
||||
}
|
||||
|
||||
double targetVal = 0;
|
||||
try {
|
||||
targetVal = Double.parseDouble(meta.getValor().replace(",", "."));
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
editText.setText("");
|
||||
Toast.makeText(requireContext(), "Valor adicionado e despesa registada!", Toast.LENGTH_SHORT).show();
|
||||
if (targetVal > 0 && novoValor >= targetVal) {
|
||||
CustomToast.success(requireContext(), "Parabéns! Alcançou a sua meta: " + meta.getNome() + "!");
|
||||
} else {
|
||||
CustomToast.success(requireContext(), "Valor adicionado e despesa registada!");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -161,7 +171,7 @@ public class MetasFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCancelled(@NonNull DatabaseError error) {
|
||||
Toast.makeText(requireContext(), "Erro ao carregar metas.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(requireContext(), "Erro ao carregar metas.");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -212,7 +222,7 @@ public class MetasFragment extends Fragment {
|
||||
|
||||
|
||||
if (nome.isEmpty() || categoria.isEmpty() || valor.isEmpty() || data.isEmpty()) {
|
||||
Toast.makeText(requireContext(), "Por favor, preencha todos os campos.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.info(requireContext(), "Por favor, preencha todos os campos.");
|
||||
} else {
|
||||
// Aqui seria a lógica para guardar na Firebase
|
||||
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
|
||||
@@ -223,7 +233,7 @@ public class MetasFragment extends Fragment {
|
||||
|
||||
|
||||
dialog.dismiss();
|
||||
Toast.makeText(requireContext(), "Meta criada com sucesso!", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(requireContext(), "Meta criada com sucesso!");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.example.lifegrid.utils.CustomToast;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
@@ -108,7 +109,7 @@ public class TransacoesFragment extends Fragment {
|
||||
.setPositiveButton("Sim", (dialog, which) -> {
|
||||
if (databaseReference != null && userId != null && transacao.getId() != null) {
|
||||
databaseReference.child("users").child(userId).child("transacoes").child(transacao.getId()).removeValue();
|
||||
Toast.makeText(requireContext(), "Transação excluída.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(requireContext(), "Transação excluída.");
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Não", null)
|
||||
@@ -144,7 +145,7 @@ public class TransacoesFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCancelled(@NonNull DatabaseError error) {
|
||||
Toast.makeText(requireContext(), "Erro ao carregar transações.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.error(requireContext(), "Erro ao carregar transações.");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -295,7 +296,7 @@ public class TransacoesFragment extends Fragment {
|
||||
|
||||
|
||||
if (valor.isEmpty() || descricao.isEmpty() || data.isEmpty() || spinnerCategoria.getSelectedItemPosition() == 0) {
|
||||
Toast.makeText(requireContext(), "Por favor, preencha todos os campos.", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.info(requireContext(), "Por favor, preencha todos os campos.");
|
||||
} else {
|
||||
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
|
||||
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
|
||||
@@ -305,7 +306,7 @@ public class TransacoesFragment extends Fragment {
|
||||
|
||||
|
||||
dialog.dismiss();
|
||||
Toast.makeText(requireContext(), "Transação adicionada com sucesso!", Toast.LENGTH_SHORT).show();
|
||||
CustomToast.success(requireContext(), "Transação adicionada com sucesso!");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.example.lifegrid.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.lifegrid.R;
|
||||
|
||||
public class CustomToast {
|
||||
|
||||
public enum Type {
|
||||
SUCCESS,
|
||||
ERROR,
|
||||
INFO
|
||||
}
|
||||
|
||||
public static void show(Context context, String message, Type type) {
|
||||
if (context == null) return;
|
||||
|
||||
try {
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View layout = inflater.inflate(R.layout.custom_toast, null);
|
||||
|
||||
ImageView iconView = layout.findViewById(R.id.toast_icon);
|
||||
TextView textView = layout.findViewById(R.id.toast_text);
|
||||
|
||||
textView.setText(message);
|
||||
|
||||
switch (type) {
|
||||
case SUCCESS:
|
||||
iconView.setImageResource(R.drawable.ic_toast_success);
|
||||
break;
|
||||
case ERROR:
|
||||
iconView.setImageResource(R.drawable.ic_toast_error);
|
||||
break;
|
||||
case INFO:
|
||||
default:
|
||||
iconView.setImageResource(R.drawable.ic_toast_info);
|
||||
break;
|
||||
}
|
||||
|
||||
Toast toast = new Toast(context.getApplicationContext());
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
toast.setView(layout);
|
||||
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 150);
|
||||
toast.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void success(Context context, String message) {
|
||||
show(context, message, Type.SUCCESS);
|
||||
}
|
||||
|
||||
public static void error(Context context, String message) {
|
||||
show(context, message, Type.ERROR);
|
||||
}
|
||||
|
||||
public static void info(Context context, String message) {
|
||||
show(context, message, Type.INFO);
|
||||
}
|
||||
}
|
||||
6
app/src/main/res/drawable/custom_toast_bg.xml
Normal file
6
app/src/main/res/drawable/custom_toast_bg.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#1A1A1A" />
|
||||
<corners android:radius="24dp" />
|
||||
<stroke android:width="1dp" android:color="#333333" />
|
||||
</shape>
|
||||
9
app/src/main/res/drawable/ic_toast_error.xml
Normal file
9
app/src/main/res/drawable/ic_toast_error.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#E74C3C"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2V7h2v6z"/>
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_toast_info.xml
Normal file
9
app/src/main/res/drawable/ic_toast_info.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#3498DB"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2V7h2v2z"/>
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_toast_success.xml
Normal file
9
app/src/main/res/drawable/ic_toast_success.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#2ECC71"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,17l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z"/>
|
||||
</vector>
|
||||
28
app/src/main/res/layout/custom_toast.xml
Normal file
28
app/src/main/res/layout/custom_toast.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:background="@drawable/custom_toast_bg"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="10dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toast_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:contentDescription="Toast status icon" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toast_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxWidth="260dp"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="sans-serif-medium" />
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user