Description
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
-
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
andSeekArc
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; } }
- Parse the degree from the
-
Refactor Each Listener
Update each
OnEditorActionListener
to utilize the new helper method, passing the appropriateTextView
andSeekArc
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
, anddegreeText4
, 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
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.