Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Add logic for offline game - PART 2 #349

Merged
merged 2 commits into from
May 26, 2022
Merged

Add logic for offline game - PART 2 #349

merged 2 commits into from
May 26, 2022

Conversation

MaximeZmt
Copy link
Owner

@MaximeZmt MaximeZmt commented May 26, 2022

The new test coverage is a bit low, but it does not affect so much the overall coverage. So I will merge it like that and add tests if I have time and if it does not break ci.

@MaximeZmt MaximeZmt self-assigned this May 26, 2022
@MaximeZmt MaximeZmt linked an issue May 26, 2022 that may be closed by this pull request
@MaximeZmt MaximeZmt changed the title add logic for offline game Add logic for offline game - PART 2 May 26, 2022
goneView = requireView().findViewById<LinearLayout>(R.id.chooseGame),
visibleView = requireView().findViewById<ConstraintLayout>(R.id.chooseSetting)
)
} else{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

visibleView = requireView().findViewById<ConstraintLayout>(R.id.genrePerScoreboard))
if (playOffline) {
chooseGenre(method = LastfmMethod.BY_ARTIST.method, artist = "Personalized", mode = R.string.gameGenre_byArtistSearch, playOffline = playOffline)
} else {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

@@ -216,22 +221,30 @@ class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSe
* @param tag: tag (genre) to fetch songs from: used in BY_TAG method
* @param mode: official game mode name
*/
private fun chooseGenre(method: String = "", artist: String = "", tag: String = "", mode: Int = 0) {
private fun chooseGenre(method: String = "", artist: String = "", tag: String = "", mode: Int = 0, playOffline: Boolean = false) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method chooseGenre has 5 arguments (exceeds 4 allowed). Consider refactoring.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more useful to make playOffline a private field with a setter function to avoid this refactoring issue?

@MaximeZmt MaximeZmt marked this pull request as ready for review May 26, 2022 10:09
@MaximeZmt MaximeZmt requested a review from kamilababayeva May 26, 2022 10:13
@codeclimate
Copy link

codeclimate bot commented May 26, 2022

Code Climate has analyzed commit 1efcd80 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 2

The test coverage on the diff in this pull request is 70.5% (80% is the threshold).

This pull request will bring the total coverage in the repository to 84.3% (-0.9% change).

View more on Code Climate.

Comment on lines +244 to +245
goneView = requireView().findViewById<LinearLayout>(R.id.genrePerScoreboard),
visibleView = requireView().findViewById<ConstraintLayout>(R.id.chooseSetting)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the CodeClimate issue, we can make the toggleViewsVisibility function take just a single boolean if the two arguments are always the same but switched around(i.e instead of tVV(a, b) you call tVV(b, a)) so the duplication can be fixed. Not an urgent thing, but could be useful if we want to refactor in the future

Copy link
Collaborator

@Tsathogguaa Tsathogguaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! Left some comments about maintainability so that we can refer to them in the future.

Copy link
Collaborator

@kamilababayeva kamilababayeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for changes! I am wondering if some logic can be tested for offline game.

if (playOffline) {
toggleViewsVisibility(
goneView = requireView().findViewById<LinearLayout>(R.id.chooseGame),
visibleView = requireView().findViewById<ConstraintLayout>(R.id.chooseSetting)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it testable?

toggleViewsVisibility(goneView = vmGameSetup.view.findViewById<LinearLayout>(R.id.chooseGame),
visibleView = vmGameSetup.view.findViewById<ConstraintLayout>(R.id.genrePerScoreboard))
if (playOffline) {
chooseGenre(method = LastfmMethod.BY_ARTIST.method, artist = "Personalized", mode = R.string.gameGenre_byArtistSearch, playOffline = playOffline)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it testable?

@MaximeZmt MaximeZmt merged commit 6612749 into main May 26, 2022
@MaximeZmt MaximeZmt deleted the maximezmt/offline2 branch May 26, 2022 11:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Manage online and offline feature on the app (#322)
3 participants