Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. package com.example.aleksander.sportsapp.activities.viewLoaders.stworzTrening;
  2.  
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.support.annotation.NonNull;
  6. import android.support.v7.app.AlertDialog;
  7. import android.view.View;
  8. import android.widget.GridLayout;
  9. import android.widget.LinearLayout;
  10. import android.widget.ListView;
  11. import android.widget.NumberPicker;
  12. import android.widget.RelativeLayout;
  13. import android.widget.TextView;
  14.  
  15. import com.example.aleksander.sportsapp.model.Cwiczenie;
  16. import com.example.aleksander.sportsapp.model.Cwiczenie_dodawanie;
  17. import com.example.aleksander.sportsapp.tools.GUITools;
  18.  
  19. import java.util.ArrayList;
  20.  
  21. /**
  22. * Created by Aleksander on 21.06.2018.
  23. */
  24.  
  25. public class StworzTreningPickerAlertBuilder {
  26.  
  27. public static AlertDialog.Builder createAlert(final Context appContext, final ArrayList<Cwiczenie_dodawanie> lista,
  28. final int position, final ListView lista_cwiczen, ArrayList<Cwiczenie_dodawanie> plan_treningowy) {
  29. final Cwiczenie cwiczenie = lista.get(position).getCwiczenie();
  30. if (cwiczenie.getPartia() == 6) { //cardio alert
  31. return provideCardioAlert(appContext, cwiczenie, lista, position, lista_cwiczen, plan_treningowy);
  32. } else {
  33. return provideNormalAlert(appContext, cwiczenie, lista, position, lista_cwiczen, plan_treningowy);
  34. }
  35. }
  36.  
  37. private static AlertDialog.Builder provideCardioAlert(Context appContext, Cwiczenie cwiczenie, ArrayList<Cwiczenie_dodawanie> lista, int position, ListView lista_cwiczen, ArrayList<Cwiczenie_dodawanie> plan_treningowy) {
  38. android.support.v7.app.AlertDialog.Builder alert = new android.support.v7.app.AlertDialog.Builder(appContext);
  39. alert.setTitle(cwiczenie.getNazwa());
  40. TextView textCzas = provideTextView(appContext, "Czas");
  41. final NumberPicker pickerCzas = provideNumberPicker(appContext, 1, 200, 45);
  42.  
  43. alert.setView(createRelativeLayout(appContext, textCzas, pickerCzas));
  44.  
  45. alert.setPositiveButton("Dodaj", providePositiveOnClick(appContext, null,null, pickerCzas, cwiczenie, position, lista, lista_cwiczen, plan_treningowy));
  46. alert.setNegativeButton("Anuluj", provideNegativeOnClick());
  47. return alert;
  48. }
  49.  
  50. private static LinearLayout createRelativeLayout(Context appContext, TextView textCzas, NumberPicker pickerCzas) {
  51. LinearLayout widokCzasu = new LinearLayout(appContext);
  52. widokCzasu.setOrientation(LinearLayout.VERTICAL);
  53. widokCzasu.addView(textCzas);
  54. widokCzasu.addView(pickerCzas);
  55. return widokCzasu;
  56. }
  57.  
  58. private static AlertDialog.Builder provideNormalAlert(Context appContext, Cwiczenie cwiczenie, ArrayList<Cwiczenie_dodawanie> lista, int position, ListView lista_cwiczen, ArrayList<Cwiczenie_dodawanie> plan_treningowy) {
  59. android.support.v7.app.AlertDialog.Builder alert = new android.support.v7.app.AlertDialog.Builder(appContext);
  60. alert.setTitle(cwiczenie.getNazwa());
  61.  
  62. final NumberPicker pickerSerie = provideNumberPicker(appContext, 1, 10, 3);
  63. final NumberPicker pickerPowtorzenia = provideNumberPicker(appContext, 1, 40, 12);
  64. TextView textSerie = provideTextView(appContext, "Serie");
  65. TextView textPowtorzenia = provideTextView(appContext, "Powtórzenia");
  66.  
  67. alert.setView(createGridLayout(appContext, pickerSerie, pickerPowtorzenia, textSerie, textPowtorzenia));
  68. alert.setPositiveButton("Dodaj", providePositiveOnClick(appContext, pickerPowtorzenia, pickerSerie, null, cwiczenie, position, lista, lista_cwiczen, plan_treningowy));
  69. alert.setNegativeButton("Anuluj", provideNegativeOnClick());
  70. return alert;
  71. }
  72.  
  73. private static DialogInterface.OnClickListener provideNegativeOnClick() {
  74. return new DialogInterface.OnClickListener() {
  75. public void onClick(DialogInterface dialog, int whichButton) {
  76. GUITools.toast("Anulowano");
  77. }
  78. };
  79. }
  80.  
  81. private static DialogInterface.OnClickListener providePositiveOnClick(final Context appContext, final NumberPicker pickerPowtorzenia,
  82. final NumberPicker pickerSerie, final NumberPicker pickerCzas,
  83. final Cwiczenie cwiczenie, final int position,
  84. final ArrayList<Cwiczenie_dodawanie> lista,
  85. final ListView lista_cwiczen, ArrayList<Cwiczenie_dodawanie> plan_treningowy) {
  86.  
  87. int powtorzenia = pickerPowtorzenia != null ? pickerPowtorzenia.getValue() : 0;
  88. int serie = pickerSerie != null ? pickerSerie.getValue() : 0;
  89. int czas = pickerCzas != null ? pickerCzas.getValue() : 0;
  90. return new StworzTreningAlertOnDodajCwiczenieClickListener(appContext, powtorzenia, serie, czas, cwiczenie, position, lista, lista_cwiczen, plan_treningowy);
  91. }
  92.  
  93. @NonNull
  94. private static GridLayout createGridLayout(Context appContext, NumberPicker pickerSerie, NumberPicker pickerPowtorzenia, TextView textSerie, TextView textPowtorzenia) {
  95. GridLayout layout = new GridLayout(appContext);
  96. layout.setColumnCount(2);
  97. layout.setRowCount(2);
  98. layout.addView(textSerie, new GridLayout.LayoutParams(GridLayout.spec(0), GridLayout.spec(0)));
  99. layout.addView(textPowtorzenia, new GridLayout.LayoutParams(GridLayout.spec(0), GridLayout.spec(1)));
  100. layout.addView(pickerSerie, new GridLayout.LayoutParams(GridLayout.spec(1), GridLayout.spec(0)));
  101. layout.addView(pickerPowtorzenia, new GridLayout.LayoutParams(GridLayout.spec(1), GridLayout.spec(1)));
  102. return layout;
  103. }
  104.  
  105.  
  106. @NonNull
  107. private static TextView provideTextView(Context appContext, String serie) {
  108. TextView textSerie = new TextView(appContext);
  109. textSerie.setText(serie);
  110. return textSerie;
  111. }
  112.  
  113. @NonNull
  114. private static NumberPicker provideNumberPicker(Context appContext, int minValue, int maxValue, int defaultValue) {
  115. final NumberPicker pickerPowtorzenia = new NumberPicker(appContext);
  116. pickerPowtorzenia.setMinValue(minValue);
  117. pickerPowtorzenia.setMaxValue(maxValue);
  118. pickerPowtorzenia.setValue(defaultValue);
  119.  
  120. return pickerPowtorzenia;
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement