<commit_before>package de.avalax.fitbuddy.app.swipeBar;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import de.avalax.fitbuddy.app.R;
import de.avalax.fitbuddy.core.workout.Exercise;
import de.avalax.fitbuddy.core.workout.Set;

public class VerticalProgressbarView extends FrameLayout {
    private TextView maxValueTextView;
    private TextView valueTextView;
    private ImageView imageView;

    public VerticalProgressbarView(Context context) {
        super(context);
        init(context);
    }

    public VerticalProgressbarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
        attributs(attrs);
    }

    public VerticalProgressbarView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
        attributs(attrs);
    }

    private void init(Context context) {
        inflate(context, R.layout.view_vertical_progressbar, this);
        maxValueTextView = (TextView) findViewById(R.id.maxValueTextView);
        valueTextView = (TextView) findViewById(R.id.valueTextView);
        imageView = (ImageView) findViewById(R.id.verticalProgressBar);
    }

    private void attributs(AttributeSet attrs) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ProgressBar);
        imageView.setImageDrawable(a.getDrawable(R.styleable.ProgressBar_progressbar));
        imageView.setBackgroundColor(a.getColor(R.styleable.ProgressBar_background, R.color.primary_background));
        a.recycle();
    }

    public void updateProgressbar(Exercise exercise) {
        //TODO: extract calculation
        int currentValue = exercise.getSetNumber() - (exercise.getCurrentSet().getReps() == 0 ? 1 : 0);
        int maxValue = exercise.getMaxSets();
        String currentValueText = String.valueOf(exercise.getSetNumber());
        String maxValueText = String.valueOf(maxValue);
        updateProgressbar(currentValue, maxValue, currentValueText, maxValueText);
    }

    public void updateProgressbar(Set set) {
        int currentValue = set.getReps();
        int maxValue = set.getMaxReps();
        updateProgressbar(currentValue, maxValue, String.valueOf(currentValue), String.valueOf(maxValue));
    }

    private void updateProgressbar(float currentValue, int maxValue, String currentValueText, String maxValueText) {
        valueTextView.setText(currentValueText);
        maxValueTextView.setText(maxValueText);
        imageView.setImageLevel(calculateProgressbarHeight(currentValue, maxValue));
        postInvalidate();
    }

    private int calculateProgressbarHeight(float currentValue, int maxValue) {
        float scale = currentValue / maxValue;
        return Math.round(scale * 10000);
    }
}<commit_msg>#38 visual feedback for sets progressbar only changes when a set is changed<commit_after>package de.avalax.fitbuddy.app.swipeBar;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import de.avalax.fitbuddy.app.R;
import de.avalax.fitbuddy.core.workout.Exercise;
import de.avalax.fitbuddy.core.workout.Set;

public class VerticalProgressbarView extends FrameLayout {
    private TextView maxValueTextView;
    private TextView valueTextView;
    private ImageView imageView;

    public VerticalProgressbarView(Context context) {
        super(context);
        init(context);
    }

    public VerticalProgressbarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
        attributs(attrs);
    }

    public VerticalProgressbarView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
        attributs(attrs);
    }

    private void init(Context context) {
        inflate(context, R.layout.view_vertical_progressbar, this);
        maxValueTextView = (TextView) findViewById(R.id.maxValueTextView);
        valueTextView = (TextView) findViewById(R.id.valueTextView);
        imageView = (ImageView) findViewById(R.id.verticalProgressBar);
    }

    private void attributs(AttributeSet attrs) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ProgressBar);
        imageView.setImageDrawable(a.getDrawable(R.styleable.ProgressBar_progressbar));
        imageView.setBackgroundColor(a.getColor(R.styleable.ProgressBar_background, R.color.primary_background));
        a.recycle();
    }

    public void updateProgressbar(Exercise exercise) {
        int currentValue = exercise.getSetNumber() - 1;
        int maxValue = exercise.getMaxSets() - 1;
        String currentValueText = String.valueOf(exercise.getSetNumber());
        String maxValueText = String.valueOf(exercise.getMaxSets());
        updateProgressbar(currentValue, maxValue, currentValueText, maxValueText);
    }

    public void updateProgressbar(Set set) {
        int currentValue = set.getReps();
        int maxValue = set.getMaxReps();
        updateProgressbar(currentValue, maxValue, String.valueOf(currentValue), String.valueOf(maxValue));
    }

    private void updateProgressbar(int currentValue, int maxValue, String currentValueText, String maxValueText) {
        valueTextView.setText(currentValueText);
        maxValueTextView.setText(maxValueText);
        imageView.setImageLevel(calculateProgressbarHeight(currentValue, maxValue));
        postInvalidate();
    }

    private int calculateProgressbarHeight(float currentValue, int maxValue) {
        float scale = currentValue / maxValue;
        return Math.round(scale * 10000);
    }
}
{'fraction_non_alphanumeric': 0.09306289415374126, 'fraction_numerical': 0.0028975626384864497, 'mean_word_length': 3.8415841584158414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '682169', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1579, 'n_words': 321}