wordpress-mobile / AztecEditor-Android

A reusable native Android rich text editor component.
Mozilla Public License 2.0
675 stars 112 forks source link

Add option to set placeholder size based on the item shown #986

Closed planarvoid closed 1 year ago

planarvoid commented 1 year ago

Fix

This PR adds an option to the placeholder sizing where you can define placeholder size based on the item (and the AztecAttributes). This is good for things like images and videos which might not always be in landscape/portrait and showing them differently might result in a non-perfect experience

Test

  1. Set up MainActivity with the placeholder manager and the ImageWithCaptionAdapter. The steps are:
    • Create PlaceholderManager in the onCreate method in MainActivity passing in the visualEditor
    • Call placeholderManager.registerAdapter(ImageWithCaptionAdapter()) to register the ImageWithCaptionAdapter
    • Call aztec.addPlugin(placeholderManager)
    • Call aztec.addOnMediaDeletedListener(placeholderManager)
  2. Modify the getWidth and getHeight methods in order to change them based on the item shown. For example:
    • Set EXAMPLE to <placeholder type=\"image_with_caption\" src=\"https://file-examples.com/storage/febc474733629f43d9f078c/2017/10/file_example_JPG_100kB.jpg\" caption=\"1\"><br><placeholder type=\"image_with_caption\" src=\"https://file-examples.com/storage/febc474733629f43d9f078c/2017/10/file_example_JPG_100kB.jpg\" caption=\"2\">
    • Modify getHeight method in ImageWithCaptionAdapter so that it returns different value based on the caption attribute`
  3. Run the app
  4. Notice the images are drawn differently

Review

@danilo04

Make sure strings will be translated: