Skip to content

Conversation

@ISNIT0
Copy link
Member

@ISNIT0 ISNIT0 commented Jan 8, 2025

Only partially transitioned to it, but this PR moves the following functionality into "plugins".

The purpose of this plugin system is to make it much easier and simpler to extend the camera without significant code re-factors or merge conflicts. Even more important nowadays when significant code might be touched/modified/written by LLMs.

It has also allowed us to move individual feature logic out of the ViewModel, and into their own relevant areas of code, making reading through much easier.

The following functionality now lives in plugins:

  • Zooming (ZoomBasePlugin)
  • The Zoom Bar (ZoomBarPlugin)
  • Pinch To Zoom (PinchToZoomPlugin)
  • Manual Focus (FocusBasePlugin)
  • TapToFocus (TapToFocusPlugin)
  • Flash & Flash Toggle (FlashPlugin)
  • AspectRatio & Toggle (AspectRatioPlugin)

Other functionality that ought to be moved to plugins in the future:

  • Shutter Flash (visual + noise + haptics + config/settings)
  • Video Capture generally
  • Capture modes more generally, somehow (TBD)

This system makes it easy to do various things, including:

  • Add new persisted config & toggles (more framework-level settings UI to come)
  • Extend the preview and image capture pipelines
  • Add new UI elements to the main app
  • Include/exclude certain functionality (in future, perhaps controlled by build flags)

In future, it'll also make it easy to manipulate imageAnalysis pipelines (e.g. for QR Code Scanning, Portrait Mode, etc.)

I'll write a silly example plugin and add some documentation alongside to explain how to use this soon.

@julianharty julianharty self-assigned this Jan 8, 2025
Copy link
Collaborator

@julianharty julianharty left a comment

Choose a reason for hiding this comment

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

Overall this PR is very encouraging, by using a plug in architecture. I've added various comments in an initial code review - I hope at least some are useful at this early stage of the project.

//--------------------------------------------------------------------------------
init {

// Some settings affect use-cases
Copy link
Collaborator

Choose a reason for hiding this comment

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

...for example? i.e. can you add at least one reason or example to this comment please?

@@ -0,0 +1,105 @@
package co.stonephone.stonecamera.plugins
Copy link
Collaborator

Choose a reason for hiding this comment

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

❓ I'm a great fan of providing file level documentation that describes the purpose of a file. This file's name left me guessing what the purpose of it is. What do you think in terms of such documentation??

Copy link
Member Author

Choose a reason for hiding this comment

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

This is helpful for LLMs!

// If difference in zoom is above threshold, we auto-cancel focus
// if (kotlin.math.abs(zoomFactor - oldZoom) > ZOOM_CANCEL_THRESHOLD) {
// cancelFocus("zoom changed by more than $ZOOM_CANCEL_THRESHOLD")
// }
Copy link
Collaborator

Choose a reason for hiding this comment

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

❔ Why keep these 3 lines of commented-out code?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the logic is now missing, and I want to remember the maths :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

❔ remove once the code's been merged?

Copy link
Collaborator

@julianharty julianharty left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for the various updates to improve the code documentation.

// ZoomBar depends on ZoomBase, etc.
val PLUGINS = listOf(
ZoomBasePlugin(),
ZoomBarPlugin(),
Copy link
Collaborator

@vckttr vckttr Jan 9, 2025

Choose a reason for hiding this comment

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

maybe consider inheriting ZoomBarPlugin from ZoomBasePlugin to get rid of dependency on load?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was imagining in this way we'd be able to replace the zoom behaviour by just switching the plugin. (e.g. some OEM wants zoom to be much slower or faster)


val shootModes = arrayOf("Photo", "Video")

// Order here is important, they are loaded and initialised in the order they are listed
Copy link
Collaborator

Choose a reason for hiding this comment

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

just as an alternative for the future
some kind of priority discriminator (e.g. stage) can help to not care about the order in the list here but will decrease readability

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that could make sense - we definitely need to do that for the settings items (e.g. we should be able to configure the order and position of the settings controls, separately from the order plugins are initialised)

@ISNIT0 ISNIT0 requested a review from vckttr January 9, 2025 12:20
@ISNIT0 ISNIT0 merged commit 8f7b067 into main Jan 9, 2025
1 check passed
@ISNIT0 ISNIT0 deleted the ISNIT0/plugins branch January 9, 2025 12:53
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.

4 participants