Skip to content
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

Enum-ify Theme. #89

Merged
merged 8 commits into from
Jan 28, 2024
Merged

Enum-ify Theme. #89

merged 8 commits into from
Jan 28, 2024

Conversation

juleskers
Copy link
Collaborator

Per discussion in #88 , I think I can make at least the Theme reflection there cleaner by making it an Enum instead of a class with static self-constants.
That can be done as a separate change, which is this PR. If this is acceptable, I'll rebase #88 onto this after it's merged.

While Enum-ifying Theme, I noticed that it's a bit inconsistent that only big keys are theme-able.
Pulling the color-decision for the small/flat keys into Theme as well allows some unification of drawing logic in PianoCanvas.
Right now, flat keys are still hardcoded black, but this improvement means that if we ever want to make colorful flat keys, we need to adapt only Theme, which satisfies the Single-Responsibility-Principle.

The drawing-simplifications are further aided by making more of the "big vs small key area" logic internally handled in Piano.
Ideally the property that "odd keyIdx == small key" should be a completely invisible implementation detail of Piano.
I'm close to that goal, but not all the way there.


One thing I don't like about this MR is that we now need a mock for android.graphics.Color, since the enum-constants for Theme are now evaluated at static-initialiser time. Previously, since we didn't actually use the colors, we didn't run into this, as the classloader doesn´t load static fields until somebody accesses the first one (and then it loads all static fields in that class).
For the moment, I've gone the simple-but-boilerplate-y route that I previously took for Log: provide a stub test-double that shadows the android-class, only during tests.
I guess this is an example of why one should normally have wrappers and adapter-classes to isolate ones business logic from such "external" library stuff.
Please let me know how much this bugs you; the alternative would be code Theme against a com.nicobrailo.pianoli.Color, and only convert to android.graphics.Colors once we get to drawing in PianoCanvas.

@pserwylo
Copy link
Collaborator

Looks good. First time reviewing on my mobile, a little squishy, but I got there.

Once rebased, I'll give it another quick check, plus a run and a test some time soon. Then I reckon we cut a release to get all your good stuff out. The sooner we get the tech changes out, the easier to diagnose any accidental bugs, and we can also get the user facing feature of the new melody out too.

Jules Kerssemakers added 8 commits January 22, 2024 12:00
Since this shifts the color-evaluation to static-initializer time,
we additionally need to mock Android.graphics.Color, so that
our Theme-using tests continue to work.
Move the Context-dependence 'up' to PianoCanvas for now.
This will prevent app-crashes if we ever seriously mishandle
preferences in a future release.
Bug introduced in 2018 with commit cf8bd94.
That converted a null-return to KeyArea(0,0,0,0), but forgot
to update the matching check in the rendering logic.
This:
 - makes small keys theme-able in the future, and
 - brings the drawing implementation for both key-types
   closer together.
Logic outside of Piano shouldn't have to care about the relationship
between key-index odd/even and big-vs-small-ness of the keys.
We're not completely there yet, due to the z-index draw ordering,
but it's definitely an improvement.

- Style: convert snake_case names to proper camelCase, where touched.
@juleskers
Copy link
Collaborator Author

juleskers commented Jan 22, 2024

Thanks for the review, Peter! (And the thumbs-up, Nico)

I've rebased, and added a small round of additional javadoc to the themes themselves.
From my perspective, this is ready to merge.

I couldn't find any issues in 5 minutes of on-device testing on my phone, and theme switching still worked.
Also, all the flat keys are still there (and still black), despite/because of my changes, so it seems I didn't break rendering 🎉

I did run into #75 again; I'm suspecting an interaction between rotation and the lock-screen that warrants some testing.
It seems semi-reproducible when I'm uploading a build from my desktop, and then unlock from portrait.


As for mobile reviewing: I find that landscape-rotation is a must for code-view, and even then it usually wraps lines.
The changed-word-highlighting is very useful though, and in general I find it fascinating what kind of computer wizardry we can do from our pants-pockets these days 😄

@pserwylo
Copy link
Collaborator

LGTM. Thanks for rebasing. I'll merge them prep a new release.

@pserwylo pserwylo merged commit d17f656 into nicolasbrailo:master Jan 28, 2024
@juleskers juleskers deleted the theme-cleanup branch January 29, 2024 19:10
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 this pull request may close these issues.

2 participants