NotePad icon indicating copy to clipboard operation
NotePad copied to clipboard

feature/material_theme

Open mshdabiola opened this issue 7 months ago • 5 comments

PR Type

Enhancement, Tests


Description

  • Refactor UI components.

  • Add custom lint checks.

  • Update theme name.

  • Standardize UI components.


Changes walkthrough 📝

Relevant files
Bug fix
19 files
MainActivity.kt
Update theme name in MainActivity                                               
+2/-2     
ShareActivity.kt
Update theme name and button in ShareActivity                       
+5/-5     
MainNavigatin.kt
Update button composable in MainNavigation                             
+2/-2     
DetailScreen.kt
Update button composable in DetailScreen                                 
+11/-7   
DrawingBar.kt
Update Tab composable in DrawingBar                                           
+9/-11   
MainScreen.kt
Update button and alert composables in MainScreen               
+7/-7     
TopbarAndDialog.kt
Update button and alert composables in TopbarAndDialog     
+8/-8     
LabelScreen.kt
Update button composable in LabelScreen                                   
+7/-4     
OptionsDialog.kt
Update button composable in OptionsDialog                               
+2/-2     
Theme.kt
Rename SkTheme to NoteTheme                                                           
+1/-1     
ScreenshotHelper.kt
Update theme name in ScreenshotHelper                                       
+2/-2     
ColorDialog.kt
Update icons in ColorDialog                                                           
+3/-6     
DateDialog.kt
Update button composables in DateDialog                                   
+4/-4     
FlowLayout.kt
Update theme in FlowLayout preview                                             
+2/-2     
MainActions.kt
Update icons in ImageDialog                                                           
+3/-5     
NewDialog.kt
Update button composables in NewDialog                                     
+5/-5     
RemainderCard.kt
Update icons in ReminderCard                                                         
+3/-3     
TimeDialog.kt
Update button composables in TimeDialog                                   
+4/-4     
WaitingUi.kt
Update loading wheel                                                                         
+2/-2     
Dependencies
3 files
build.gradle.kts
Add lint module build file                                                             
+44/-0   
settings.gradle.kts
Add lint module                                                                                   
+2/-6     
libs.versions.toml
Add kotlin-test dependency                                                             
+1/-0     
Tests
6 files
NotepadIssueRegistry.kt
Add lint registry                                                                               
+27/-0   
TestMethodNameDetector.kt
Add test method name detector                                                       
+111/-0 
DesignSystemDetector.kt
Add design system detector                                                             
+102/-0 
TestMethodNameDetectorTest.kt
Add test for test method name detector                                     
+123/-0 
DesignSystemDetectorTest.kt
Add test for design system detector                                           
+164/-0 
com.android.tools.lint.client.api.IssueRegistry
Add lint registry entry                                                                   
+17/-0   
Configuration changes
1 files
build.gradle.kts
Enable lint checks for designsystem module                             
+1/-1     
Enhancement
2 files
Button.kt
Add NoteTextButton composable                                                       
+29/-4   
NoteIcon.kt
Add Alarm and Repeat icons                                                             
+4/-0     
Miscellaneous
4 files
NoteficationDialog.kt
Remove file                                                                                           
+0/-376 
NotifySneackerUi.kt
Remove file                                                                                           
+0/-32   
TimeExtention.kt
Remove file                                                                                           
+0/-73   
TimeZoneBroadcastReceiver.kt
Remove file                                                                                           
+0/-38   

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • mshdabiola avatar Jun 11 '25 07:06 mshdabiola

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Potential Incompleteness

    The DesignSystemDetector relies on hardcoded names of Compose Material composables and their design system equivalents. This approach might break if the names change in future updates. Consider a more robust mechanism, perhaps using reflection or a configuration file, to avoid hardcoding.

    class DesignSystemDetector : Detector(), Detector.UastScanner {
    
        override fun getApplicableUastTypes(): List<Class<out UElement>> = listOf(
            UCallExpression::class.java,
            UQualifiedReferenceExpression::class.java,
        )
    
        override fun createUastHandler(context: JavaContext): UElementHandler =
            object : UElementHandler() {
                override fun visitCallExpression(node: UCallExpression) {
                    val name = node.methodName ?: return
                    val preferredName = METHOD_NAMES[name] ?: return
                    reportIssue(context, node, name, preferredName)
                }
    
                override fun visitQualifiedReferenceExpression(node: UQualifiedReferenceExpression) {
                    val name = node.receiver.asRenderString()
                    val preferredName = RECEIVER_NAMES[name] ?: return
                    reportIssue(context, node, name, preferredName)
                }
            }
    
        companion object {
            @JvmField
            val ISSUE: Issue = Issue.create(
                id = "DesignSystem",
                briefDescription = "Design system",
                explanation = "This check highlights calls in code that use Compose Material " +
                    "composables instead of equivalents from the Now in Android design system " +
                    "module.",
                category = Category.CUSTOM_LINT_CHECKS,
                priority = 7,
                severity = Severity.ERROR,
                implementation = Implementation(
                    DesignSystemDetector::class.java,
                    Scope.JAVA_FILE_SCOPE,
                ),
            )
    
            // Unfortunately :lint is a Java module and thus can't depend on the :core-designsystem
            // Android module, so we can't use composable function references (eg. ::Button.name)
            // instead of hardcoded names.
            val METHOD_NAMES = mapOf(
                "MaterialTheme" to "NoteTheme",
                "Button" to "NoteButton",
                "OutlinedButton" to "NoteOutlinedButton",
                "TextButton" to "NoteTextButton",
                "FilterChip" to "NoteFilterChip",
                "ElevatedFilterChip" to "NoteFilterChip",
                "NavigationBar" to "NoteNavigationBar",
                "NavigationBarItem" to "NoteNavigationBarItem",
                "NavigationRail" to "NoteNavigationRail",
                "NavigationRailItem" to "NoteNavigationRailItem",
                "TabRow" to "NoteTabRow",
                "Tab" to "NoteTab",
                "IconToggleButton" to "NoteIconToggleButton",
                "FilledIconToggleButton" to "NoteIconToggleButton",
                "FilledTonalIconToggleButton" to "NoteIconToggleButton",
                "OutlinedIconToggleButton" to "NoteIconToggleButton",
                "CenterAlignedTopAppBar" to "NoteTopAppBar",
                "SmallTopAppBar" to "NoteTopAppBar",
                "MediumTopAppBar" to "NoteTopAppBar",
                "LargeTopAppBar" to "NoteTopAppBar",
            )
            val RECEIVER_NAMES = mapOf(
                "Icons" to "NoteIcons",
            )
    
            fun reportIssue(
                context: JavaContext,
                node: UElement,
                name: String,
                preferredName: String,
            ) {
                context.report(
                    ISSUE,
                    node,
                    context.getLocation(node),
                    "Using $name instead of $preferredName",
                )
            }
        }
    }
    
    Regex Inefficiency

    The regular expression used in detectFormat ("""[^\W_]+(_[^\W_]+){1,2}""".toRegex()) might not be the most efficient way to check for the given_when_then or when_then format. Consider a more targeted approach or a different method for improved performance, especially with larger test suites.

    class TestMethodNameDetector : Detector(), SourceCodeScanner {
    
        override fun applicableAnnotations() = listOf("org.junit.Test")
    
        override fun visitAnnotationUsage(
            context: JavaContext,
            element: UElement,
            annotationInfo: AnnotationInfo,
            usageInfo: AnnotationUsageInfo,
        ) {
            val method = usageInfo.referenced as? PsiMethod ?: return
    
            method.detectPrefix(context, usageInfo)
            method.detectFormat(context, usageInfo)
        }
    
        private fun JavaContext.isAndroidTest() = Path("androidTest") in file.toPath()
    
        private fun PsiMethod.detectPrefix(
            context: JavaContext,
            usageInfo: AnnotationUsageInfo,
        ) {
            if (!name.startsWith("test")) return
            context.report(
                issue = PREFIX,
                scope = usageInfo.usage,
                location = context.getNameLocation(this),
                message = PREFIX.getBriefDescription(RAW),
                quickfixData = LintFix.create()
                    .name("Remove prefix")
                    .replace().pattern("""test[\s_]*""")
                    .with("")
                    .autoFix()
                    .build(),
            )
        }
    
        private fun PsiMethod.detectFormat(
            context: JavaContext,
            usageInfo: AnnotationUsageInfo,
        ) {
            if (!context.isAndroidTest()) return
            if ("""[^\W_]+(_[^\W_]+){1,2}""".toRegex().matches(name)) return
            context.report(
                issue = FORMAT,
                scope = usageInfo.usage,
                location = context.getNameLocation(this),
                message = FORMAT.getBriefDescription(RAW),
            )
        }
    
        companion object {
    
            private fun issue(
                id: String,
                briefDescription: String,
                explanation: String,
            ): Issue = Issue.create(
                id = id,
                briefDescription = briefDescription,
                explanation = explanation,
                category = TESTING,
                priority = 5,
                severity = WARNING,
                implementation = Implementation(
                    TestMethodNameDetector::class.java,
                    EnumSet.of(JAVA_FILE, TEST_SOURCES),
                ),
            )
    
            @JvmField
            val PREFIX: Issue = issue(
                id = "TestMethodPrefix",
                briefDescription = "Test method starts with `test`",
                explanation = "Test method should not start with `test`.",
            )
    
            @JvmField
            val FORMAT: Issue = issue(
                id = "TestMethodFormat",
                briefDescription = "Test method does not follow the `given_when_then` or `when_then` format",
                explanation = "Test method should follow the `given_when_then` or `when_then` format.",
            )
        }
    }
    

    github-actions[bot] avatar Jun 11 '25 07:06 github-actions[bot]

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Improve button accessibility

    The NoteTextButton for adding items only contains an icon. Adding descriptive text
    to the button will significantly improve accessibility and usability for users who
    rely on screen readers or have difficulty interpreting icons. Consider adding a
    Text composable within the button's content.

    feature/detail/src/main/kotlin/com/mshdabiola/detail/DetailScreen.kt [583-586]

     NoteTextButton(onClick = addItem) {
    -                         Icon(imageVector = NoteIcon.Add, contentDescription = "")
    +                         Icon(imageVector = NoteIcon.Add, contentDescription = "Add Item")
    +                         Text("Add Item")
    
    Suggestion importance[1-10]: 8

    __

    Why: Adding descriptive text to the button improves accessibility and usability. This is an important accessibility improvement.

    Medium
    Customize the theme's appearance

    The NoteTheme composable is used without specifying any parameters for customizing
    the theme's appearance. Consider adding parameters like colorScheme or typography
    to tailor the theme to your application's needs. This will improve the visual
    consistency and branding of your app.

    app/src/fossReliant/kotlin/com/mshdabiola/playnotepad/MainActivity.kt [100-104]

     NoteTheme(
                     androidTheme = shouldUseAndroidTheme(uiState),
                     darkTheme = darkTheme,
                     disableDynamicTheming = shouldDisableDynamicTheming(uiState),
    +                colorScheme = if (darkTheme) darkColorScheme else lightColorScheme, //Example
                 ) {
    
    Suggestion importance[1-10]: 7

    __

    Why: Adding a colorScheme parameter to NoteTheme improves visual consistency. The suggestion to add colorScheme is reasonable, but it's not a critical change.

    Medium
    Customize theme colors dynamically

    The NoteTheme composable lacks parameters for color scheme customization. Adding a
    colorScheme parameter allows for dynamic theme adjustments based on user preferences
    or app states, enhancing the user experience and visual appeal. Consider using a
    conditional statement to select appropriate color schemes for light and dark modes.

    app/src/main/java/com/mshdabiola/playnotepad/ShareActivity.kt [125-128]

     NoteTheme(
                 darkTheme = darkTheme,
                 disableDynamicTheming = shouldDisableDynamicTheming(uiState),
    +            colorScheme = if (darkTheme) darkColorScheme else lightColorScheme, //Example
             ) {
    
    Suggestion importance[1-10]: 7

    __

    Why: Dynamic theme adjustments enhance user experience. The suggestion is valid, but the impact is not major.

    Medium
    Add tab text labels

    The NoteTab composables lack text labels. Adding descriptive text labels to each
    tab will greatly improve usability and accessibility, allowing users to quickly
    understand the function of each tab without relying solely on icons. Ensure that
    the text is concise and informative.

    feature/drawing/src/main/java/com/mshdabiola/drawing/DrawingBar.kt [93-98]

     NoteTab(
                      selected = pagerState.currentPage == 0,
                      onClick = {
                          controller.draw_mode = DRAW_MODE.ERASE
                          isUp = if (pagerState.currentPage == 0) {
    +                     true else false
    +                 },
    +                 text = { Text("Erase") }, //Example
    +             )
    
    Suggestion importance[1-10]: 7

    __

    Why: Adding text labels to tabs improves usability and accessibility. The suggestion is good, but not critical.

    Medium

    github-actions[bot] avatar Jun 11 '25 07:06 github-actions[bot]

    Test results

    27 tests  ±0   27 ✅ ±0   17s ⏱️ -1s 18 suites ±0    0 💤 ±0  18 files   ±0    0 ❌ ±0 

    Results for commit 447cd933. ± Comparison against base commit 9db04f8a.

    :recycle: This comment has been updated with latest results.

    github-actions[bot] avatar Jun 11 '25 07:06 github-actions[bot]

    Codecov Report

    Attention: Patch coverage is 0% with 113 lines in your changes missing coverage. Please review.

    Project coverage is 0.89%. Comparing base (9db04f8) to head (447cd93). Report is 4 commits behind head on develop.

    Files with missing lines Patch % Lines
    ...main/java/com/mshdabiola/playnotepad/ui/NoteApp.kt 0.00% 27 Missing :warning:
    ...in/com/mshdabiola/designsystem/component/Button.kt 0.00% 16 Missing :warning:
    ...com/mshdabiola/designsystem/component/TopAppBar.kt 0.00% 12 Missing :warning:
    .../main/kotlin/com/mshdabiola/detail/DetailScreen.kt 0.00% 10 Missing :warning:
    ...src/main/java/com/mshdabiola/drawing/DrawingBar.kt 0.00% 6 Missing :warning:
    ...va/com/mshdabiola/selectlabelscreen/LabelScreen.kt 0.00% 5 Missing :warning:
    ...n/java/com/mshdabiola/playnotepad/ShareActivity.kt 0.00% 3 Missing :warning:
    ...otlin/com/mshdabiola/designsystem/icon/NoteIcon.kt 0.00% 3 Missing :warning:
    ...i/src/main/kotlin/com/mshdabiola/ui/ColorDialog.kt 0.00% 3 Missing :warning:
    .../ui/src/main/kotlin/com/mshdabiola/ui/NewDialog.kt 0.00% 3 Missing :warning:
    ... and 15 more
    Additional details and impacted files
    @@            Coverage Diff             @@
    ##           develop    #113      +/-   ##
    ==========================================
    + Coverage     0.88%   0.89%   +0.01%     
    ==========================================
      Files          156     151       -5     
      Lines         6868    6782      -86     
      Branches       540     530      -10     
    ==========================================
      Hits            61      61              
    + Misses        6794    6708      -86     
      Partials        13      13              
    

    :umbrella: View full report in Codecov by Sentry.
    :loudspeaker: Have feedback on the report? Share it here.

    :rocket: New features to boost your workflow:
    • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

    codecov-commenter avatar Jun 11 '25 07:06 codecov-commenter

    [!IMPORTANT]

    Review skipped

    More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

    96 files out of 212 files are above the max files limit of 100. Please upgrade to Pro plan to get higher limits.

    You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

    ✨ Finishing Touches
    • [ ] 📝 Generate Docstrings
    🧪 Generate unit tests
    • [ ] Create PR with unit tests
    • [ ] Post copyable unit tests in a comment
    • [ ] Commit unit tests in branch feature/material_theme

    Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

    ❤️ Share
    🪧 Tips

    Chat

    There are 3 ways to chat with CodeRabbit:

    • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
      • I pushed a fix in commit <commit_id>, please review it.
      • Open a follow-up GitHub issue for this discussion.
    • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
    • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
      • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
      • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

    Support

    Need help? Create a ticket on our support page for assistance with any issues or questions.

    CodeRabbit Commands (Invoked using PR/Issue comments)

    Type @coderabbitai help to get the list of available commands.

    Other keywords and placeholders

    • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
    • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
    • Add @coderabbitai anywhere in the PR title to generate the title automatically.

    CodeRabbit Configuration File (.coderabbit.yaml)

    • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
    • Please see the configuration documentation for more information.
    • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

    Status, Documentation and Community

    • Visit our Status Page to check the current availability of CodeRabbit.
    • Visit our Documentation for detailed information on how to use CodeRabbit.
    • Join our Discord Community to get help, request features, and share feedback.
    • Follow us on X/Twitter for updates and announcements.

    coderabbitai[bot] avatar Aug 25 '25 10:08 coderabbitai[bot]