Anki-Android icon indicating copy to clipboard operation
Anki-Android copied to clipboard

Lint: enforce naming standards for some layouts

Open david-allison opened this issue 11 months ago • 11 comments

Layouts:

  • Activity -> activity_
  • Fragment -> fragment_
  • View -> view_
  • Dialog -> dialog_

Task

  • Layouts are stored in: https://github.com/ankidroid/Anki-Android/blob/0c1f02992ba45518b80ad7540b9f5ef1ff163a04/AnkiDroid/src/main/res/layout
    • and a few layout* subfolders of /res/
  • A layout which is associated with an activity should have an activity_ prefix
    • ❌ res/layout/deck_picker.xml
    • ✅ res/layout/activity_deck_picker.xml

This should be implemented in the following order:

  1. A lint rule should be created, for a constraint
  2. The lint breakages should be fixed in the same commit
  3. Repeat, for each of the 4 categories.

The implementation of the lint rules is the main complexity, I suspect that this should be partially implemented as an initial PR, and improved in a follow up PR

The easiest method of determining whether a layout is associated with an activity or Fragment is when it's passed into the constructor (see: vbpd)

https://github.com/ankidroid/Anki-Android/blob/c31281882b09e64b812bb89b8230b395e9531422/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateBrowserAppearanceEditor.kt#L44

This will handle a subset of activities and Fragments. Not all activities pass the layout into the constructor.

The more correct method is to use the name of the Binding class:

https://github.com/ankidroid/Anki-Android/blob/c31281882b09e64b812bb89b8230b395e9531422/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateBrowserAppearanceEditor.kt#L45

  • match the binding with the layout
  • determine the type of class that the binding is in

Prefer to be conservative: only raise a lint error if certain

david-allison avatar Dec 22 '25 02:12 david-allison

@david-allison I would like to work on this task. May I be assigned to it?

sonalyadav1 avatar Dec 22 '25 07:12 sonalyadav1

Sure! Thanks!

david-allison avatar Dec 22 '25 07:12 david-allison

Hi, @sonalyadav1 are you still working on this issue?

hemampandey avatar Dec 22 '25 17:12 hemampandey

It's been 12 hours, it'd be best to find a better issue. See here for our guidance:

https://github.com/ankidroid/Anki-Android/blob/main/CONTRIBUTING.md#selecting-an-issue-github-search

Please let me know if you need any more info, the CONTINUING page is new, and may need tweaking

david-allison avatar Dec 22 '25 18:12 david-allison

Hi, I’d like to work on this issue. Please let me know if it’s okay or if someone is already actively working on it.

PraneethKulukuri26 avatar Dec 25 '25 13:12 PraneethKulukuri26

Someone is already assigned, it's only been 3 days.

david-allison avatar Dec 25 '25 16:12 david-allison

Heyy, I would like to work on this issue if its not fixed yet

Osaidcodes avatar Jan 02 '26 21:01 Osaidcodes

@sonalyadav1, how're things going?

@Osaidcodes feel free, if there's no reply within 48 hours

david-allison avatar Jan 03 '26 00:01 david-allison

@david-allison I'm working on the issue and will raise a PR soon.

sonalyadav1 avatar Jan 03 '26 06:01 sonalyadav1

@david-allison should I work on this issue or is it fixed?

Osaidcodes avatar Jan 03 '26 21:01 Osaidcodes

@Osaidcodes A PR has been submitted, no point in duplicated effort here.

  • #19992

david-allison avatar Jan 04 '26 05:01 david-allison