Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0 package com.thinkingahead.stockges.config;
- 1
- 2 import android.app.Activity;
- 3 import android.app.AlertDialog;
- 4 import android.content.Context;
- 5 import android.content.DialogInterface;
- 6 import android.content.Intent;
- 7 import android.content.res.Configuration;
- 8 import android.util.Log;
- 9 import android.view.Menu;
- 10 import android.view.MenuInflater;
- 11 import android.view.MenuItem;
- 12 import android.view.View;
- 13 import android.widget.*;
- 14 import androidx.annotation.NonNull;
- 15 import androidx.fragment.app.Fragment;
- 16 import androidx.recyclerview.widget.DividerItemDecoration;
- 17 import androidx.recyclerview.widget.LinearLayoutManager;
- 18 import androidx.recyclerview.widget.RecyclerView;
- 19 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
- 20 import com.google.android.gms.tasks.OnCompleteListener;
- 21 import com.google.android.gms.tasks.Task;
- 22 import com.google.android.material.floatingactionbutton.FloatingActionButton;
- 23 import com.google.firebase.auth.*;
- 24 import com.google.firebase.database.DataSnapshot;
- 25 import com.google.firebase.database.DatabaseError;
- 26 import com.google.firebase.database.DatabaseReference;
- 27 import com.google.firebase.database.ValueEventListener;
- 28 import com.google.zxing.integration.android.IntentIntegrator;
- 29 import com.google.zxing.integration.android.IntentResult;
- 30 import com.thinkingahead.stockges.R;
- 31 import com.thinkingahead.stockges.activity.*;
- 32 import com.thinkingahead.stockges.adapter.AdapterRecyclerProdutos;
- 33 import com.thinkingahead.stockges.helper.RecyclerItemClickListener;
- 34 import com.thinkingahead.stockges.model.Frases;
- 35 import com.thinkingahead.stockges.model.Produtos;
- 36 import mehdi.sakout.aboutpage.AboutPage;
- 37
- 38 import java.util.Iterator;
- 39 import java.util.List;
- 40 import java.util.Random;
- 41 import java.util.UUID;
- 42
- 43 import static com.thinkingahead.stockges.fragments.ListarFragment.listaProdutos;
- 44
- 45
- 46 public class Configs {
- 47
- 48
- 49 public static Boolean isResultadoFull = false;
- 50 public static String resultado = null;
- 51 public static int childrenCount = 0;
- 52 public static String userID;
- 53
- 54 // Geral - Begin
- 55
- 56 public static void configuracaoRecyclerView(RecyclerView recyclerView, AdapterRecyclerProdutos adapterRecyclerProdutos, Context context) {
- 57
- 58 RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
- 59 recyclerView.setLayoutManager(layoutManager);
- 60 recyclerView.setHasFixedSize(true);
- 61 recyclerView.setAdapter(adapterRecyclerProdutos);
- 62 recyclerView.addItemDecoration(new DividerItemDecoration(context, LinearLayout.VERTICAL));
- 63
- 64 }
- 65
- 66 public static void refreshRecyclerProdutos(final Context context, final SwipeRefreshLayout swipeRefreshLayout, final AdapterRecyclerProdutos adapterRecyclerProdutos, final DatabaseReference produtosRef, final View rootView, final TextView textStatus) {
- 67
- 68 swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- 69 @Override
- 70 public void onRefresh() {
- 71 try {
- 72 ValueEventListener valueEventListenerProdutos = null;
- 73 valueEventListenerProdutos = recuperarProdutos(valueEventListenerProdutos, produtosRef, listaProdutos, rootView, adapterRecyclerProdutos, context, textStatus);
- 74
- 75 swipeRefreshLayout.setRefreshing(false);
- 76 produtosRef.removeEventListener(valueEventListenerProdutos);
- 77 Toast.makeText(context, "Lista Atualizada com Sucesso!", Toast.LENGTH_SHORT).show();
- 78
- 79 } catch (Exception e) {
- 80 e.printStackTrace();
- 81 Toast.makeText(context, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 82 }
- 83
- 84 }
- 85 });
- 86
- 87 }
- 88
- 89 public static ValueEventListener recuperarProdutos(ValueEventListener valueEventListenerProdutos, DatabaseReference produtosRef, final List<Produtos> listaProdutos, final View rootView, final AdapterRecyclerProdutos adapterRecyclerProdutos, final Context context, final TextView textStatus) {
- 90 try {
- 91 valueEventListenerProdutos = produtosRef.addValueEventListener(new ValueEventListener() {
- 92 @Override
- 93 public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
- 94 listaProdutos.clear();
- 95 for (DataSnapshot dados : dataSnapshot.getChildren()) {
- 96
- 97 Produtos produto = dados.getValue(Produtos.class);
- 98
- 99 listaProdutos.add(produto);
- 100 }
- 101
- 102 setChildrenCount((int) dataSnapshot.getChildrenCount());
- 103 recyclerStatus(textStatus);
- 104 rootView.findViewById(R.id.carregamentoInicial).setVisibility(View.GONE);
- 105 adapterRecyclerProdutos.notifyDataSetChanged();
- 106
- 107 }
- 108
- 109 @Override
- 110 public void onCancelled(@NonNull DatabaseError databaseError) {
- 111
- 112 }
- 113 });
- 114 return valueEventListenerProdutos;
- 115 } catch (Exception e) {
- 116 e.printStackTrace();
- 117 Toast.makeText(context, "", Toast.LENGTH_SHORT).show();
- 118 }
- 119
- 120 return valueEventListenerProdutos;
- 121
- 122 }
- 123
- 124 public static void removerValueEventListener(DatabaseReference databaseReference, ValueEventListener valueEventListener, Context context) {
- 125 try {
- 126 databaseReference.removeEventListener(valueEventListener);
- 127 } catch (Exception e) {
- 128 Toast.makeText(context, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 129 e.printStackTrace();
- 130 }
- 131 }
- 132
- 133 public static void recyclerStatus(TextView textStatus) {
- 134
- 135 int recyclerSize = getChildrenCount();
- 136
- 137 if (recyclerSize > 0) {
- 138 textStatus.setVisibility(View.GONE);
- 139 } else {
- 140 textStatus.setVisibility(View.VISIBLE);
- 141 }
- 142
- 143 }
- 144
- 145 public static String getResultado() {
- 146 return resultado;
- 147 }
- 148
- 149 public static void setResultado(String resultado) {
- 150 Configs.resultado = resultado;
- 151 }
- 152
- 153 public static String getUserID() {
- 154 return userID;
- 155 }
- 156
- 157 public static void setUserID(String userID) {
- 158 Configs.userID = userID;
- 159 }
- 160
- 161 // Geral - End
- 162
- 163 // InicioFragment - Begin
- 164
- 165 public static ValueEventListener fraseInspiradora(DatabaseReference databaseReference, final TextView textFrase, final Context context) {
- 166
- 167 final Random random = new Random();
- 168 ValueEventListener valueEventListener;
- 169
- 170 valueEventListener = databaseReference.child("frases").addValueEventListener(new ValueEventListener() {
- 171 @Override
- 172 public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
- 173
- 174 try {
- 175
- 176 Frases frase;
- 177
- 178 setChildrenCount((int) dataSnapshot.getChildrenCount());
- 179 int rand = random.nextInt(childrenCount);
- 180
- 181 Iterator itr = dataSnapshot.getChildren().iterator();
- 182
- 183 for (int i = 0; i < rand; i++) {
- 184 itr.next();
- 185 }
- 186
- 187 DataSnapshot childSnapshot = (DataSnapshot) itr.next();
- 188 frase = childSnapshot.getValue(Frases.class);
- 189 if (frase != null) {
- 190 textFrase.setText('"' + frase.getFrase() + '"' + "\nAutor: " + frase.getAutor());
- 191 } else {
- 192 textFrase.setText("Nenhuma Frase Encontrada :(");
- 193 }
- 194
- 195
- 196 } catch (Exception e) {
- 197 e.printStackTrace();
- 198 Toast.makeText(context, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 199 }
- 200
- 201
- 202 }
- 203
- 204 @Override
- 205 public void onCancelled(@NonNull DatabaseError databaseError) {
- 206
- 207 }
- 208 });
- 209
- 210 return valueEventListener;
- 211
- 212 }
- 213
- 214 public static void definirNomeUtilizador(TextView textIntro, Context context) {
- 215 try {
- 216
- 217 // Partir o Email em 2 partes antes do @ e depois do @, e ficar com a parte antes do @ e utilizar a mesma como nome de Utilizador
- 218 String user = ConfiguracaoFireBase.getFirebaseAuth().getCurrentUser().getEmail();
- 219 String[] parts = user.split("(?=@)");
- 220 String utilizador = parts[0];
- 221
- 222 // Aqui definimos o valor do Utilizador de "Administrador", se ele o for
- 223 if (utilizador.equals("thinkingaheadapps")) {
- 224 utilizador = "Administrador";
- 225
- 226 }
- 227
- 228 textIntro.setText(utilizador);
- 229
- 230 } catch (Exception e) {
- 231 e.printStackTrace();
- 232 Toast.makeText(context, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 233 }
- 234
- 235 }
- 236
- 237 public static int getChildrenCount() {
- 238 return childrenCount;
- 239 }
- 240
- 241 public static void setChildrenCount(int childrenCount) {
- 242 Configs.childrenCount = childrenCount;
- 243 }
- 244
- 245 // InicioFragment - End
- 246
- 247 // InserirFragment - Begin
- 248
- 249 public static void enviarProduto(FloatingActionButton fab, final TextView textCodigo, final TextView textDescricao, final TextView textQuantidade, final Context context) {
- 250 fab.setOnClickListener(new View.OnClickListener() {
- 251 @Override
- 252 public void onClick(View view) {
- 253 try {
- 254
- 255 String codigo = textCodigo.getText().toString();
- 256 String descricao = textDescricao.getText().toString();
- 257 String quantidade = textQuantidade.getText().toString();
- 258 String uniqueID = UUID.randomUUID().toString();
- 259
- 260 if (!codigo.isEmpty() || !descricao.isEmpty() || !quantidade.isEmpty()) {
- 261 Produtos produto = new Produtos(codigo, descricao, quantidade, uniqueID);
- 262 produto.guardarDados();
- 263
- 264 Toast.makeText(context, "Produto Enviado com Sucesso!", Toast.LENGTH_SHORT).show();
- 265 limparCamposInserir(textCodigo, textQuantidade, textDescricao);
- 266
- 267 setIsResultadoFull(false);
- 268 } else {
- 269 Toast.makeText(context, "Preencha pelo menos um Campo!", Toast.LENGTH_SHORT).show();
- 270 }
- 271
- 272 } catch (Exception e) {
- 273 Toast.makeText(context, "Falha ao Enviar Produto!" + e.getMessage(), Toast.LENGTH_SHORT).show();
- 274 }
- 275 }
- 276 });
- 277 }
- 278
- 279 public static void abrirLeitorDeBarras(ImageButton imagemCamara, final Fragment fragment) {
- 280 imagemCamara.setOnClickListener(new View.OnClickListener() {
- 281 @Override
- 282 public void onClick(View view) {
- 283 fragment.startActivity(new Intent(fragment.getContext(), QrCodeActivity.class));
- 284 setIsResultadoFull(true);
- 285 }
- 286 });
- 287 }
- 288
- 289 public static void inserirCodigoProduto(TextView textCodigo) {
- 290
- 291 resultado = Configs.getResultado();
- 292
- 293 if (isResultadoFull) {
- 294 textCodigo.setText(resultado);
- 295 }
- 296
- 297 if (!isResultadoFull) {
- 298 textCodigo.setText("");
- 299 }
- 300
- 301 }
- 302
- 303 private static void limparCamposInserir(TextView textCodigo, TextView textQuantidade, TextView textDescricao) {
- 304 textCodigo.setText("");
- 305 textQuantidade.setText("");
- 306 textDescricao.setText("");
- 307 }
- 308
- 309 // InserirFragment - End
- 310
- 311 // RemoverFragment - Begin
- 312
- 313 public static void recyclerRemover(final Context c, RecyclerView recyclerView, final DatabaseReference firebaseRef, final AdapterRecyclerProdutos adapterRecyclerProdutos) {
- 314 recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(c, recyclerView, new RecyclerItemClickListener.OnItemClickListener() {
- 315 @Override
- 316 public void onItemClick(View view, int position) {
- 317
- 318 }
- 319
- 320 @Override
- 321 public void onLongItemClick(View view, final int position) {
- 322 final Produtos produto = listaProdutos.get(position);
- 323 final DatabaseReference produtosRef = firebaseRef.child(userID).child("produtos");
- 324
- 325 AlertDialog.Builder dialog = new AlertDialog.Builder(c);
- 326
- 327 // Configurar Título e Mensagem
- 328 dialog.setTitle("Confirmar Exclusão");
- 329 dialog.setCancelable(false);
- 330 dialog.setMessage("Deseja remover o produto: " + produto.getCodigo());
- 331 dialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
- 332 @Override
- 333 public void onClick(DialogInterface dialog, int which) {
- 334 try {
- 335 produtosRef.child(produto.getUniqueID()).removeValue();
- 336 adapterRecyclerProdutos.notifyItemRemoved(position);
- 337 Toast.makeText(c, "Eliminado com Sucesso!", Toast.LENGTH_SHORT).show();
- 338 adapterRecyclerProdutos.notifyDataSetChanged();
- 339
- 340 } catch (Exception e) {
- 341 Toast.makeText(c, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 342
- 343 }
- 344
- 345 }
- 346 });
- 347 dialog.setNegativeButton("Não", null);
- 348 dialog.show();
- 349 }
- 350
- 351 @Override
- 352 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- 353
- 354 }
- 355 }));
- 356 }
- 357
- 358 // RemoverFragment - End
- 359
- 360 // AtualizarFragment - Begin
- 361
- 362 public static void recyclerAtualizar(final Context c, RecyclerView recyclerView, final AdapterRecyclerProdutos adapterRecyclerProdutos) {
- 363 recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(c, recyclerView, new RecyclerItemClickListener.OnItemClickListener() {
- 364 @Override
- 365 public void onItemClick(final View view, int position) {
- 366
- 367
- 368 }
- 369
- 370 @Override
- 371 public void onLongItemClick(View view, final int position) {
- 372
- 373 final Produtos produto = listaProdutos.get(position);
- 374
- 375 AlertDialog.Builder dialog = new AlertDialog.Builder(c);
- 376
- 377 // Configurar Título e Produto
- 378 dialog.setTitle("Confirmar Atualização");
- 379 dialog.setCancelable(false);
- 380 dialog.setMessage("Deseja atualizar o produto: " + produto.getCodigo());
- 381 dialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
- 382 @Override
- 383 public void onClick(DialogInterface dialog, int which) {
- 384 try {
- 385 Intent i = new Intent(c, AtualizarActivity.class);
- 386 i.putExtra("posicao", position);
- 387 c.startActivity(i);
- 388 adapterRecyclerProdutos.notifyDataSetChanged();
- 389 } catch (Exception e) {
- 390 Toast.makeText(c, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 391
- 392 }
- 393
- 394 }
- 395 });
- 396 dialog.setNegativeButton("Não", null);
- 397 dialog.show();
- 398
- 399 }
- 400
- 401 @Override
- 402 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- 403
- 404 }
- 405 }));
- 406 }
- 407
- 408 // AtualizarFragment - End
- 409
- 410 // SobreFragment - Begin
- 411
- 412 public static View verificaoDoTema(Context context) {
- 413 View aboutPage = null;
- 414
- 415 try {
- 416 int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
- 417
- 418 switch (currentNightMode) {
- 419 case Configuration.UI_MODE_NIGHT_NO:
- 420 aboutPage = new AboutPage(context)
- 421 .isRTL(false)
- 422 .setImage(R.drawable.tautau_mascote_oculos)
- 423 .setDescription("Somos especializados, focados, divertidos e diretos. Vamos vestir a camisola da tua marca, empresa ou projeto com o objetivo de te proporcionar os melhores resultados. Esta é a nossa garantia.")
- 424 .addGroup("Ótimos Serviços, Profissionais Experientes")
- 425 .addEmail("geral@tautau.pt")
- 426 .addWebsite("https://tautau.pt/")
- 427 .addFacebook("tautauagency")
- 428 .addInstagram("tautauagency/")
- 429 .enableDarkMode(false)
- 430 .create();
- 431 break;
- 432 case Configuration.UI_MODE_NIGHT_YES:
- 433 aboutPage = new AboutPage(context)
- 434 .isRTL(false)
- 435 .setImage(R.drawable.tautau_mascote_oculos)
- 436 .setDescription("Somos especializados, focados, divertidos e diretos. Vamos vestir a camisola da tua marca, empresa ou projeto com o objetivo de te proporcionar os melhores resultados. Esta é a nossa garantia.")
- 437 .addGroup("Ótimos Serviços, Profissionais Experientes")
- 438 .addEmail("geral@tautau.pt")
- 439 .addWebsite("https://tautau.pt/")
- 440 .addFacebook("tautauagency")
- 441 .addInstagram("tautauagency/")
- 442 .enableDarkMode(true)
- 443 .create();
- 444 break;
- 445 default:
- 446 Toast.makeText(context, "Erro: " + currentNightMode, Toast.LENGTH_SHORT).show();
- 447 throw new IllegalStateException("Unexpected value: " + currentNightMode);
- 448 }
- 449 } catch (Exception e) {
- 450 Toast.makeText(context, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 451 e.printStackTrace();
- 452 }
- 453
- 454 return aboutPage;
- 455
- 456 }
- 457
- 458 public static View definicaoDoLayoutSobre(View aboutPage, View view) {
- 459 if (aboutPage != null) {
- 460 return aboutPage;
- 461 } else {
- 462 aboutPage = view;
- 463 }
- 464 return aboutPage;
- 465 }
- 466
- 467 // SobreFragment - End
- 468
- 469 // FraseActivity - Begin
- 470
- 471 public static void adicionarFrase(Button buttonConfirmar, final EditText editAutor, final EditText editFrase, final Context c, final Activity activity) {
- 472 buttonConfirmar.setOnClickListener(new View.OnClickListener() {
- 473 @Override
- 474 public void onClick(View view) {
- 475
- 476 String autor = editAutor.getText().toString();
- 477 String fraseInspiradora = editFrase.getText().toString();
- 478 String childLength = String.valueOf(getChildrenCount() + 1);
- 479
- 480 try {
- 481 Frases frase = new Frases();
- 482 frase.setFrase(fraseInspiradora);
- 483 frase.setId(childLength);
- 484 frase.setAutor(autor);
- 485 frase.guardar();
- 486
- 487 limparCamposFrase(editAutor, editFrase);
- 488 Toast.makeText(c, "Frase adicionada com Sucesso!", Toast.LENGTH_SHORT).show();
- 489 activity.finish();
- 490 } catch (Exception e) {
- 491 e.printStackTrace();
- 492 Toast.makeText(c, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 493 }
- 494
- 495
- 496 }
- 497 });
- 498 }
- 499
- 500 private static void limparCamposFrase(EditText editAutor, EditText editFrase) {
- 501
- 502 editAutor.setText("");
- 503 editFrase.setText("");
- 504
- 505 }
- 506
- 507 // FraseActivity - End
- 508
- 509 // AtualizarActivity - Begin
- 510
- 511 public static void atualizarProduto(FloatingActionButton fab, final Produtos produto, final TextView textCodigo, final TextView textDescricao, final TextView textQuantidade, final Activity activity, ImageButton imageReader) {
- 512 fab.setOnClickListener(new View.OnClickListener() {
- 513 @Override
- 514 public void onClick(View view) {
- 515
- 516 produto.setCodigo(textCodigo.getText().toString());
- 517 produto.setDescricao(textDescricao.getText().toString());
- 518 produto.setQuantidade(textQuantidade.getText().toString());
- 519
- 520 produto.guardarDados();
- 521
- 522 Toast.makeText(activity.getApplicationContext(), "Produto Atualizado com Sucesso!", Toast.LENGTH_SHORT).show();
- 523 limparCamposAtualizar(textCodigo, textQuantidade, textDescricao);
- 524 setIsResultadoFull(false);
- 525 activity.finish();
- 526 }
- 527 });
- 528
- 529 imageReader.setOnClickListener(new View.OnClickListener() {
- 530 @Override
- 531 public void onClick(View view) {
- 532 activity.startActivity(new Intent(activity.getApplicationContext(), QrCodeActivity.class));
- 533 setIsResultadoFull(true);
- 534 }
- 535 });
- 536
- 537 Log.i("msg", "resultado:" + getIsResultadoFull());
- 538
- 539 }
- 540
- 541 private static void limparCamposAtualizar(TextView textCodigo, TextView textQuantidade, TextView textDescricao) {
- 542 textCodigo.setText("");
- 543 textQuantidade.setText("");
- 544 textDescricao.setText("");
- 545 }
- 546
- 547 public static void atualizarCodigoProduto(Context context, TextView textCodigo, Produtos produto) {
- 548 String resultado = Configs.getResultado();
- 549
- 550 try {
- 551 if (Configs.getIsResultadoFull()) {
- 552 textCodigo.setText(resultado);
- 553 } else {
- 554 textCodigo.setText(produto.getCodigo());
- 555 }
- 556 } catch (Exception e) {
- 557 e.printStackTrace();
- 558 Toast.makeText(context, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 559 }
- 560
- 561 }
- 562
- 563 public static Boolean getIsResultadoFull() {
- 564 return isResultadoFull;
- 565 }
- 566
- 567 public static void setIsResultadoFull(Boolean isResultadoFull) {
- 568 Configs.isResultadoFull = isResultadoFull;
- 569 }
- 570
- 571 // AtualizarActivity - End
- 572
- 573 // HomeActivity - Begin
- 574
- 575 public static void configuracaoMenuHome(MenuItem item, Activity activity) {
- 576 switch (item.getItemId()) {
- 577 case R.id.menuSair:
- 578 ConfiguracaoFireBase.getFirebaseAuth().signOut();
- 579 activity.startActivity(new Intent(activity.getApplicationContext(), MainActivity.class));
- 580 activity.finish();
- 581 break;
- 582 case R.id.menuAdicionarFrase:
- 583 activity.startActivity(new Intent(activity.getApplicationContext(), AdicionarFraseActivity.class));
- 584 break;
- 585 case R.id.menuRemoverFrase:
- 586 activity.startActivity(new Intent(activity.getApplicationContext(), RemoverFraseActivity.class));
- 587 break;
- 588 }
- 589 }
- 590
- 591 public static void definicaoMenuHome(Menu menu, Activity activity) {
- 592 MenuInflater inflater = activity.getMenuInflater();
- 593 inflater.inflate(R.menu.menu_home, menu);
- 594 }
- 595
- 596 public static void definirUserNameFireBase() {
- 597
- 598 // Partir o Email em 2 partes antes do @ e depois do @, e ficar com a parte antes do @ e utilizar a mesma como nome de Utilizador
- 599 String user = ConfiguracaoFireBase.getFirebaseAuth().getCurrentUser().getEmail();
- 600 String[] parts = user.split("(?=@)");
- 601 String utilizador = parts[0];
- 602
- 603 UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
- 604 .setDisplayName(utilizador).build();
- 605
- 606 ConfiguracaoFireBase.getFirebaseAuth().getCurrentUser().updateProfile(profileUpdates);
- 607
- 608 }
- 609
- 610 public static void definirPerfil(TextView textUserName, TextView textEmail, Context context) {
- 611 try {
- 612 textUserName.setText(ConfiguracaoFireBase.getFirebaseAuth().getCurrentUser().getDisplayName());
- 613 textEmail.setText(ConfiguracaoFireBase.getFirebaseAuth().getCurrentUser().getEmail());
- 614
- 615 } catch (Exception e) {
- 616 e.printStackTrace();
- 617 Toast.makeText(context, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 618 }
- 619 }
- 620
- 621 // HomeActivity - End
- 622
- 623 // LoadingActivity - Begin
- 624
- 625 public static void configuracaoDoLoadingInicial(final Activity activity, final Intent mainActivity) {
- 626 new java.util.Timer().schedule(
- 627 new java.util.TimerTask() {
- 628 @Override
- 629 public void run() {
- 630 activity.startActivity(mainActivity);
- 631 activity.finish();
- 632 }
- 633 },
- 634 3000
- 635 );
- 636 }
- 637
- 638 // LoadingActivity - End
- 639
- 640 // MainActivity - Begin
- 641
- 642 public static void loginUtilizador(FirebaseAuth mAuth, final EditText textEmail, final EditText textPassword, final Activity activity) {
- 643
- 644 try {
- 645 mAuth.signInWithEmailAndPassword(textEmail.getText().toString(), textPassword.getText().toString()).addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
- 646 @Override
- 647 public void onComplete(@NonNull Task<AuthResult> task) {
- 648 if (task.isSuccessful()) {
- 649 Toast.makeText(activity.getApplicationContext(), "Login Efetuado com Sucesso!", Toast.LENGTH_SHORT).show();
- 650 limparCamposLogin(textEmail, textPassword);
- 651 Intent intent = new Intent(activity.getApplicationContext(), HomeActivity.class);
- 652 activity.startActivity(intent);
- 653 } else {
- 654 String excecao;
- 655
- 656 try {
- 657 throw task.getException();
- 658 } catch (FirebaseAuthInvalidUserException e) {
- 659 excecao = "Utilizador não Registado";
- 660 } catch (FirebaseAuthInvalidCredentialsException e) {
- 661 excecao = "Credenciais Incorretas";
- 662 } catch (Exception e) {
- 663 excecao = "Erro ao fazer Login: " + e.getMessage();
- 664 e.printStackTrace();
- 665 }
- 666
- 667 Toast.makeText(activity.getApplicationContext(), excecao, Toast.LENGTH_SHORT).show();
- 668
- 669 }
- 670 }
- 671 });
- 672
- 673 } catch (Exception e) {
- 674 e.printStackTrace();
- 675 Toast.makeText(activity, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 676 }
- 677
- 678 }
- 679
- 680 public static void verificarUtilizador(FirebaseAuth mAuth, Activity activity, Intent mainIntent) {
- 681 try {
- 682
- 683 if (mAuth.getCurrentUser() != null) {
- 684 setUserID(FirebaseAuth.getInstance().getCurrentUser().getUid());
- 685 activity.startActivity(mainIntent);
- 686 activity.finish();
- 687 }
- 688
- 689 } catch (Exception e) {
- 690 e.printStackTrace();
- 691 Toast.makeText(activity.getApplicationContext(), "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 692 }
- 693 }
- 694
- 695 // SobreActivity - Begin
- 696
- 697 public static void configuracaoMenuMain(MenuItem item, Activity activity) {
- 698 switch (item.getItemId()) {
- 699 case R.id.menuSobre:
- 700 ConfiguracaoFireBase.getFirebaseAuth().signOut();
- 701 activity.startActivity(new Intent(activity.getApplicationContext(), SobreActivity.class));
- 702 break;
- 703 case R.id.menuEsquecerPassword:
- 704 activity.startActivity(new Intent(activity.getApplicationContext(), EsquecerPasswordActivity.class));
- 705 break;
- 706 }
- 707 }
- 708
- 709 public static void definicaoMenuMain(Menu menu, Activity activity) {
- 710 MenuInflater inflater = activity.getMenuInflater();
- 711 inflater.inflate(R.menu.menu_main, menu);
- 712 }
- 713
- 714 // SobreActivity - End
- 715
- 716 public static void botaoLogin(Button buttonLogin, final EditText textEmail, final EditText textPassword, final Activity activity, final FirebaseAuth mAuth) {
- 717 buttonLogin.setOnClickListener(new View.OnClickListener() {
- 718 @Override
- 719 public void onClick(View view) {
- 720 try {
- 721
- 722 if (!textEmail.getText().toString().equals("")) {
- 723 if (!textPassword.getText().toString().equals("")) {
- 724 loginUtilizador(mAuth, textEmail, textPassword, activity);
- 725 } else {
- 726 Toast.makeText(activity.getApplicationContext(), "Introduza a Password!", Toast.LENGTH_SHORT).show();
- 727 }
- 728 } else {
- 729 Toast.makeText(activity.getApplicationContext(), "Introduza o Email!", Toast.LENGTH_SHORT).show();
- 730 }
- 731
- 732 } catch (Exception e) {
- 733 e.printStackTrace();
- 734 Toast.makeText(activity.getApplicationContext(), "Tente Novamente!", Toast.LENGTH_SHORT).show();
- 735 }
- 736
- 737
- 738 }
- 739 });
- 740 }
- 741
- 742 private static void limparCamposLogin(EditText textEmail, EditText textPassword) {
- 743 textEmail.setText("");
- 744 textPassword.setText("");
- 745 }
- 746
- 747 // MainActivity - End
- 748
- 749 // QrCodeActivity - Begin
- 750
- 751 public static void scanCode(IntentIntegrator integrator, Activity activity) {
- 752
- 753 try {
- 754 integrator.setCaptureActivity(CapturaActivity.class);
- 755 integrator.setOrientationLocked(false);
- 756 integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
- 757 integrator.setPrompt("Procurando Código de Barras...");
- 758 integrator.initiateScan();
- 759
- 760 } catch (Exception e) {
- 761 e.printStackTrace();
- 762 Toast.makeText(activity, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 763 }
- 764
- 765
- 766 }
- 767
- 768 public static void lerCodigoDeBarras(int requestCode, int resultCode, Intent data, final Activity activity, final IntentIntegrator integrator) {
- 769
- 770 try {
- 771
- 772 IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
- 773 setResultado(result.getContents());
- 774
- 775 if (result != null) {
- 776 if (result.getContents() != null) {
- 777 AlertDialog.Builder builder = new AlertDialog.Builder(activity);
- 778 builder.setCancelable(false);
- 779 builder.setMessage(result.getContents());
- 780 builder.setTitle("Resultado:");
- 781 builder.setPositiveButton("Novamente", new DialogInterface.OnClickListener() {
- 782 @Override
- 783 public void onClick(DialogInterface dialogInterface, int i) {
- 784 Configs.scanCode(integrator, activity);
- 785 }
- 786 }).setNegativeButton("Sair", new DialogInterface.OnClickListener() {
- 787 @Override
- 788 public void onClick(DialogInterface dialogInterface, int i) {
- 789 activity.finish();
- 790 }
- 791 });
- 792 AlertDialog dialog = builder.create();
- 793 dialog.show();
- 794 } else {
- 795 Toast.makeText(activity.getApplicationContext(), "Sem Resultados", Toast.LENGTH_LONG).show();
- 796 activity.finish();
- 797 }
- 798 }
- 799
- 800 } catch (Exception e) {
- 801 e.printStackTrace();
- 802 Toast.makeText(activity, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- 803 }
- 804
- 805
- 806 }
- 807
- 808 // QrCodeActivity - End
- 809
- 810 // Adapter - Begin
- 811
- 812 // NENHUM CODIGO AQUI
- 813 // PARA FACILITAR DECIDI DEIXAR O CÓDIGO NO ADAPTER
- 814
- 815 // Adapter - End
- 816
- 817
- 818}
- 819
Add Comment
Please, Sign In to add comment