Skip to content

Refactor Degree Parsing and Updating Logic into a Helper Method #2665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks
sourcery-ai bot opened this issue Apr 2, 2025 · 2 comments · Fixed by #2666
Closed
3 tasks

Refactor Degree Parsing and Updating Logic into a Helper Method #2665

sourcery-ai bot opened this issue Apr 2, 2025 · 2 comments · Fixed by #2666

Comments

@sourcery-ai
Copy link

sourcery-ai bot commented Apr 2, 2025

Description

The current implementation contains duplicated logic for parsing and updating degree values across multiple listeners. This redundancy can be reduced by extracting the common logic into a helper method. This refactoring will improve code maintainability and readability.

Suggested Solution

  1. Extract a Helper Method

    Create a method processDegreeInput that handles the degree input parsing and updates the associated seek arc. This method should:

    • Parse the degree from the TextView.
    • Update the degree value and the SeekArc progress.
    • Handle invalid degree values by resetting the TextView and SeekArc and displaying a toast message.
    private void processDegreeInput(TextView degreeText, SeekArc seekArc) {
        int previousDegree = degree;
        String degreeStr = degreeText.getText().toString().trim();
        if (degreeStr.isEmpty()) {
            degree = (degree == 0) ? (int) (seekArc.getProgress() * 3.6) : previousDegree;
        } else {
            degree = Integer.parseInt(degreeStr);
        }
    
        if (degree > 360 || degree < 0) {
            degreeText.setText(getResources().getString(R.string.zero));
            seekArc.setProgress(0);
            toastInvalidValueMessage();
        } else {
            seekArc.setProgress((int) (degree / 3.6));
            editEnter = true;
        }
    }
  2. Refactor Each Listener

    Update each OnEditorActionListener to utilize the new helper method, passing the appropriate TextView and SeekArc as parameters.

    degreeText1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            removeStatusBar();
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                processDegreeInput(degreeText1, seekArc1);
            }
            return false;
        }
    });

    Repeat similarly for degreeText2, degreeText3, and degreeText4, passing the corresponding seek arc.

Action Items

  • Implement the processDegreeInput helper method.
  • Refactor existing listeners to use the new helper method.
  • Test to ensure functionality remains consistent and no regressions are introduced.

Notes

This refactoring task is currently out of scope for the ongoing pull request but should be addressed in a future update to enhance code quality.


This issue was identified by the sourcery-ai[bot] and acknowledged by contributor marcnause as a future improvement task.


I created this issue for @marcnause from #2652 (comment).

Tips and commands

Interacting with Sourcery

  • Generate a plan of action: Comment @sourcery-ai plan on this issue.
  • Generate a pull request for this issue: Comment @sourcery-ai develop to
    generate a PR that addresses this issue.

Getting Help

@MDJAVEED7
Copy link

MDJAVEED7 commented Apr 6, 2025

Is this issue solve? Else iam interested to work on this

@AsCress
Copy link
Collaborator

AsCress commented Apr 7, 2025

Closing as solved by #2666

@AsCress AsCress closed this as completed Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants