Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.aleksander.sportsapp.activities.viewLoaders.stworzTrening;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.support.annotation.NonNull;
- import android.support.v7.app.AlertDialog;
- import android.view.View;
- import android.widget.GridLayout;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.NumberPicker;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import com.example.aleksander.sportsapp.model.Cwiczenie;
- import com.example.aleksander.sportsapp.model.Cwiczenie_dodawanie;
- import com.example.aleksander.sportsapp.tools.GUITools;
- import java.util.ArrayList;
- /**
- * Created by Aleksander on 21.06.2018.
- */
- public class StworzTreningPickerAlertBuilder {
- public static AlertDialog.Builder createAlert(final Context appContext, final ArrayList<Cwiczenie_dodawanie> lista,
- final int position, final ListView lista_cwiczen, ArrayList<Cwiczenie_dodawanie> plan_treningowy) {
- final Cwiczenie cwiczenie = lista.get(position).getCwiczenie();
- if (cwiczenie.getPartia() == 6) { //cardio alert
- return provideCardioAlert(appContext, cwiczenie, lista, position, lista_cwiczen, plan_treningowy);
- } else {
- return provideNormalAlert(appContext, cwiczenie, lista, position, lista_cwiczen, plan_treningowy);
- }
- }
- private static AlertDialog.Builder provideCardioAlert(Context appContext, Cwiczenie cwiczenie, ArrayList<Cwiczenie_dodawanie> lista, int position, ListView lista_cwiczen, ArrayList<Cwiczenie_dodawanie> plan_treningowy) {
- android.support.v7.app.AlertDialog.Builder alert = new android.support.v7.app.AlertDialog.Builder(appContext);
- alert.setTitle(cwiczenie.getNazwa());
- TextView textCzas = provideTextView(appContext, "Czas");
- final NumberPicker pickerCzas = provideNumberPicker(appContext, 1, 200, 45);
- alert.setView(createRelativeLayout(appContext, textCzas, pickerCzas));
- alert.setPositiveButton("Dodaj", providePositiveOnClick(appContext, null,null, pickerCzas, cwiczenie, position, lista, lista_cwiczen, plan_treningowy));
- alert.setNegativeButton("Anuluj", provideNegativeOnClick());
- return alert;
- }
- private static LinearLayout createRelativeLayout(Context appContext, TextView textCzas, NumberPicker pickerCzas) {
- LinearLayout widokCzasu = new LinearLayout(appContext);
- widokCzasu.setOrientation(LinearLayout.VERTICAL);
- widokCzasu.addView(textCzas);
- widokCzasu.addView(pickerCzas);
- return widokCzasu;
- }
- private static AlertDialog.Builder provideNormalAlert(Context appContext, Cwiczenie cwiczenie, ArrayList<Cwiczenie_dodawanie> lista, int position, ListView lista_cwiczen, ArrayList<Cwiczenie_dodawanie> plan_treningowy) {
- android.support.v7.app.AlertDialog.Builder alert = new android.support.v7.app.AlertDialog.Builder(appContext);
- alert.setTitle(cwiczenie.getNazwa());
- final NumberPicker pickerSerie = provideNumberPicker(appContext, 1, 10, 3);
- final NumberPicker pickerPowtorzenia = provideNumberPicker(appContext, 1, 40, 12);
- TextView textSerie = provideTextView(appContext, "Serie");
- TextView textPowtorzenia = provideTextView(appContext, "Powtórzenia");
- alert.setView(createGridLayout(appContext, pickerSerie, pickerPowtorzenia, textSerie, textPowtorzenia));
- alert.setPositiveButton("Dodaj", providePositiveOnClick(appContext, pickerPowtorzenia, pickerSerie, null, cwiczenie, position, lista, lista_cwiczen, plan_treningowy));
- alert.setNegativeButton("Anuluj", provideNegativeOnClick());
- return alert;
- }
- private static DialogInterface.OnClickListener provideNegativeOnClick() {
- return new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- GUITools.toast("Anulowano");
- }
- };
- }
- private static DialogInterface.OnClickListener providePositiveOnClick(final Context appContext, final NumberPicker pickerPowtorzenia,
- final NumberPicker pickerSerie, final NumberPicker pickerCzas,
- final Cwiczenie cwiczenie, final int position,
- final ArrayList<Cwiczenie_dodawanie> lista,
- final ListView lista_cwiczen, ArrayList<Cwiczenie_dodawanie> plan_treningowy) {
- int powtorzenia = pickerPowtorzenia != null ? pickerPowtorzenia.getValue() : 0;
- int serie = pickerSerie != null ? pickerSerie.getValue() : 0;
- int czas = pickerCzas != null ? pickerCzas.getValue() : 0;
- return new StworzTreningAlertOnDodajCwiczenieClickListener(appContext, powtorzenia, serie, czas, cwiczenie, position, lista, lista_cwiczen, plan_treningowy);
- }
- @NonNull
- private static GridLayout createGridLayout(Context appContext, NumberPicker pickerSerie, NumberPicker pickerPowtorzenia, TextView textSerie, TextView textPowtorzenia) {
- GridLayout layout = new GridLayout(appContext);
- layout.setColumnCount(2);
- layout.setRowCount(2);
- layout.addView(textSerie, new GridLayout.LayoutParams(GridLayout.spec(0), GridLayout.spec(0)));
- layout.addView(textPowtorzenia, new GridLayout.LayoutParams(GridLayout.spec(0), GridLayout.spec(1)));
- layout.addView(pickerSerie, new GridLayout.LayoutParams(GridLayout.spec(1), GridLayout.spec(0)));
- layout.addView(pickerPowtorzenia, new GridLayout.LayoutParams(GridLayout.spec(1), GridLayout.spec(1)));
- return layout;
- }
- @NonNull
- private static TextView provideTextView(Context appContext, String serie) {
- TextView textSerie = new TextView(appContext);
- textSerie.setText(serie);
- return textSerie;
- }
- @NonNull
- private static NumberPicker provideNumberPicker(Context appContext, int minValue, int maxValue, int defaultValue) {
- final NumberPicker pickerPowtorzenia = new NumberPicker(appContext);
- pickerPowtorzenia.setMinValue(minValue);
- pickerPowtorzenia.setMaxValue(maxValue);
- pickerPowtorzenia.setValue(defaultValue);
- return pickerPowtorzenia;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement