Skip to content

Latest commit

 

History

History
299 lines (252 loc) · 16.3 KB

problems.md

File metadata and controls

299 lines (252 loc) · 16.3 KB

Issues in kmpuiviews Module (Generated by Junie)

This document outlines various issues, code smells, and areas for improvement in the kmpuiviews module.

General Issues

  1. Lack of Documentation: Most classes, functions, and properties lack proper documentation, making it difficult to understand their purpose and usage.
  2. Inconsistent Error Messages: Error messages in staticCompositionLocalOf declarations are inconsistent - some are empty strings, some are descriptive, and some are generic.
  3. Hardcoded Values: Many hardcoded values without explanation (e.g., cache sizes, time intervals).
  4. Missing Imports: Some files reference classes or functions without proper imports.
  5. Global Constants: Use of global constants like USE_NAV3 makes code less testable and harder to maintain.
  6. Duplicate Navigation Implementations: The codebase maintains two separate navigation implementations (Navigation2Actions and Navigation3Actions) controlled by a global flag, increasing maintenance burden.
  7. Inconsistent Parameter Handling: Different implementations handle parameters differently ( e.g., Navigation2Actions vs Navigation3Actions handling of empty strings).

File-Specific Issues

ComposableUtils.kt

  1. Mixed Responsibilities: The file contains multiple unrelated utilities that should be separated into different files.
  2. Missing Import: Reference to LocalSettingsHandling.current without proper import.
  3. Infinite Loop: RecordTimeSpentDoing() function has an infinite loop in a LaunchedEffect, which could cause performance issues.
  4. Unused Code: ComponentState enum is defined but not used anywhere in the file.
  5. Poor Organization: CustomAdaptive class and calculateCellsCrossAxisSizeImpl function could be moved to a separate file focused on grid-related utilities.

Utils.kt

  1. Missing Imports: References to Cached.cache and dispatchIo() without proper imports.
  2. Undocumented Constant: The constant USE_NAV3 is defined without documentation explaining its purpose.
  3. Generic File Name: The file name "Utils.kt" is too generic and doesn't describe the specific utilities it contains.
  4. Undocumented Function: The function loadItem lacks documentation.

Cache.kt

  1. Commented-Out Code: The ExpirableLRUCache class has commented-out code in the LinkedHashMap initialization.
  2. Unreliable Time Comparison: The recycle method uses Clock.System.now().nanosecondsOfSecond for time comparison, which might not be reliable for measuring elapsed time.
  3. Incomplete LRU Implementation: The cycleKeyMap method doesn't properly implement LRU eviction logic since the commented-out code was responsible for that.
  4. Hardcoded Values: The Cached object uses hardcoded values (minimal size of 10 and flush interval of 5 minutes) without explanation.
  5. Lack of Documentation: No documentation for the Cached object.

FlowUtils.kt

  1. Error Swallowing: The dispatchIoAndCatchList function catches exceptions, logs them, and then emits an empty list, which might hide errors from the caller.
  2. Undocumented Function: The recordFirebaseException function is called without documentation about what it does.
  3. Lack of Documentation: No documentation for the utility functions.

CompositionLocals.kt

  1. Default Implementation: The LocalCurrentSource provides a default implementation of CurrentSourceRepository() which might not be appropriate.
  2. Global Constant Dependency: The KmpLocalCompositionSetup function uses the global constant USE_NAV3 to determine which navigation actions to use.
  3. Complex Error Handling: The UriHandler implementation has a complex error handling chain that might be hard to debug.
  4. Missing Import: Reference to DateTimeFormatItem without proper import.
  5. Lack of Documentation: No documentation for the composition locals or the setup function.

AccountInfoScreen.kt

  1. Repetitive Code: Lots of repetitive code in the LazyColumn items, with many CategoryGroup blocks that follow the same pattern.
  2. Overloaded Functions: The AccountInfoItem function is overloaded with two nearly identical implementations that differ only in the type of the amount parameter.
  3. Empty Parameter: The ImageLoaderChoice component is used with an empty name parameter.
  4. Null Handling: The profileUrl parameter is used with orEmpty() which might not be the best way to handle null values.
  5. Scattered Conditional Rendering: Conditional rendering based on appConfig.buildType is scattered throughout the code.
  6. Lack of Documentation: No documentation for the screen or its components.

AccountInfoViewModel.kt

  1. Excessive Flow Combination: The combine operator is used with 12 flows, which is excessive and makes the code hard to read and maintain.
  2. Error-Prone Constructor: The AccountInfoCount constructor that takes an Array<Int> is error-prone because it relies on the order of the flows in the combine operator.
  3. Inefficient Flow Creation: The flow { emit(translationModelHandler.modelList().size) } creates a new flow for each emission.
  4. Expensive Operations: The sourceRepository.sources.map { ... } performs filtering and grouping operations on each emission, which could be expensive.
  5. Lack of Error Handling: No error handling in the flow chain.
  6. Undocumented Function: The fireListener function is called without documentation about what it does.
  7. Redundant Empty Object: The AccountInfoCount.Empty object could be replaced with a default parameter constructor.

Navigation-Related Files

NavigationActions.kt

  1. Lack of Documentation: The interface lacks documentation for its methods, making it difficult to understand their purpose and usage.
  2. Mixed Responsibilities: The interface contains methods for both navigation and UI state management (e.g., currentDestination).
  3. Generic Method Names: Methods like navigate and popBackStack are too generic and don't convey their specific behavior.

Navigation2Actions.kt

  1. Inconsistent Navigation Options: Some navigation methods include options like launchSingleTop and restoreState, while others don't.
  2. Hardcoded Values: Hardcoded values like "NA" for empty titles and descriptions.
  3. Duplicate URL Encoding: URL encoding is duplicated across multiple methods.
  4. Complex Destination Checking: The isTopLevelDestinationInHierarchy method uses complex string operations to check destinations.

Navigation3Actions.kt

  1. Custom Back Stack Implementation: Uses a custom TopLevelBackStack class instead of the standard navigation library's back stack.
  2. Commented-Out Code: Contains commented-out code like //navBackStack.add(nav) and //return navBackStack.lastOrNull() == screen.
  3. Inefficient Back Stack Clearing: The clearBackStack method uses a loop to remove items from the back stack, which is inefficient.
  4. Inconsistent Error Handling: No error handling for cases where the back stack might be empty.

UI Components

BackButton.kt

  1. Missing Content Description: The Icon in the BackButton lacks a content description, which is problematic for accessibility.
  2. No Customization Options: The BackButton doesn't allow for customization of appearance or behavior.
  3. No Error Handling: No error handling for cases where navigation might fail.

OtakuScaffold.kt

  1. Duplicate Code: Three scaffold implementations (OtakuHazeScaffold, OtakuScaffold, NormalOtakuScaffold) with significant code duplication.
  2. Inconsistent Padding Handling: OtakuScaffold and OtakuHazeScaffold combine padding with LocalNavHostPadding, but NormalOtakuScaffold doesn't.
  3. Unclear Usage Guidance: No documentation explaining when to use each scaffold variant.
  4. Hardcoded Default Values: Default values like WindowInsets(0.dp) are hardcoded without explanation.
  5. Layered Abstractions: OtakuHazeScaffold wraps HazeScaffold, creating unnecessary layers of abstraction.
  6. Inconsistent Parameter Naming: Parameter names differ between OtakuHazeScaffold and HazeScaffold (e.g., state vs hazeState).

HazeScaffold.kt

  1. Complex Implementation: Contains a complex custom layout implementation that's difficult to understand and maintain.
  2. Undocumented Composition Locals: Uses composition locals like LocalScaffoldContentPadding without proper documentation.
  3. Copied Code: Explicitly states it's copied from another project with modifications, which could lead to maintenance issues.
  4. Utility Extensions: Contains utility extension functions like plus and minus for PaddingValues that should be in a separate utility file.
  5. Inline Utility Function: The thenIf modifier extension is unrelated to the scaffold functionality and should be in a separate utility file.

BottomSheetDeleteScaffold.kt

  1. Excessive File Length: The file is 866 lines long, making it difficult to understand and maintain.
  2. Multiple Similar Implementations: Contains multiple similar implementations ( BottomSheetDeleteScaffold, BottomSheetDeleteGridScaffold, ModalBottomSheetDelete) with significant code duplication.
  3. Commented-Out Code: Contains commented-out code that should be removed or implemented properly.
  4. TODO Comments: Contains TODO comments indicating incomplete work.
  5. Duplicate Helper Functions: DeleteItemView and DeleteItemDragSelectView are nearly identical with duplicated logic.
  6. Hardcoded Values: Contains hardcoded values like WindowInsets(0.dp) without explanation.
  7. No Documentation: Lacks documentation for the components and their parameters.
  8. Nested AlertDialogs: Contains nested AlertDialogs which can lead to confusing UI behavior.
  9. Hardcoded Colors: Uses hardcoded colors like Color.Red instead of using theme colors.
  10. Missing Accessibility: Icons lack content descriptions, which is problematic for accessibility.
  11. Duplicate Logic: The confirmation dialogs for deletion have duplicate logic across different components.
  12. Complex State Management: Uses multiple state variables and complex state management logic.

LimitedBottomSheetScaffold.kt

  1. Lack of Documentation: No KDoc comments explaining the purpose of the component or its parameters.
  2. Complex Animation Logic: Animation logic is complex and spread across multiple classes.
  3. Hardcoded Values: Contains hardcoded values like corner radius constants.
  4. Nested Scaffold: Uses a nested Scaffold inside another Scaffold, which can lead to performance issues.
  5. Complex State Management: Uses complex state management with multiple state variables.
  6. No Accessibility Considerations: No accessibility considerations for the bottom sheet.

ListBottomSheet.kt

  1. Lack of Documentation: No KDoc comments explaining the purpose of the component or its parameters.
  2. Missing Accessibility: Icons lack content descriptions, which is problematic for accessibility.
  3. Hardcoded Values: Contains hardcoded values like spacing (2.dp) without explanation.
  4. No Error Handling: No error handling for cases where the list might be empty.
  5. Inconsistent Parameter Naming: Parameter naming is inconsistent with other components ( e.g., "list" vs "listOfItems").
  6. Limited Customization: Offers limited customization options compared to other bottom sheet implementations.

MultipleActions.kt

  1. Lack of Documentation: No KDoc comments explaining the purpose of the component or its parameters.
  2. Hardcoded Values: Contains hardcoded values like animation delays (250ms) and width (64.dp) without explanation.
  3. Generic Content Description: Uses a generic content description "Localized description" instead of a meaningful one.
  4. Complex Animation Logic: Uses complex animation logic with multiple animations combined.
  5. Tight Coupling: The component is tightly coupled to specific navigation actions and data structures.
  6. No Error Handling: No error handling for cases where the actions might be null or invalid.
  7. Performance Concerns: The use of coroutines for simple state changes (show/hide) might be overkill and could lead to performance issues.

InfiniteListHandler.kt

  1. Lack of Documentation: No KDoc comments explaining the purpose or usage of the functions.
  2. Code Duplication: The two functions have similar logic with slight differences.
  3. Inconsistent Implementation: The LazyListState version drops the first emission while the LazyGridState version doesn't.
  4. No Error Handling: No handling for potential exceptions during collection.
  5. Mutable State Variable: The LazyGridState version uses a mutable state variable ( lastTotalItems) that could be handled differently.

General Patterns of Issues

After analyzing multiple files in the kmpuiviews module, several patterns of issues emerge:

  1. Code Duplication: Many components have multiple similar implementations with significant code duplication (e.g., scaffolds, bottom sheets).
  2. Lack of Documentation: Most files lack proper documentation for classes, functions, and parameters.
  3. Large Files: Many files are excessively long and contain multiple components or utilities that should be separated.
  4. Mixed Responsibilities: Files often contain unrelated functionality that should be separated into different files.
  5. Hardcoded Values: Hardcoded values are used throughout the codebase without explanation.
  6. Commented-Out Code: Many files contain commented-out code that should be removed or implemented properly.
  7. Inconsistent Parameter Naming: Parameter names are inconsistent across similar components.
  8. Utility Functions in Component Files: Utility functions are often defined in component files instead of dedicated utility files.
  9. Complex Implementations: Many components have complex implementations that are difficult to understand and maintain.
  10. Lack of Error Handling: Many components lack proper error handling for edge cases.

Recommendations

  1. Add Documentation: Add KDoc comments to all public classes, functions, and properties.
  2. Split Large Files: Split files with mixed responsibilities into smaller, more focused files.
  3. Improve Error Handling: Add proper error handling to all asynchronous operations.
  4. Remove Commented-Out Code: Remove or fix commented-out code.
  5. Use Dependency Injection: Replace global constants and singletons with proper dependency injection.
  6. Add Unit Tests: Add unit tests to ensure the code works as expected and to prevent regressions.
  7. Refactor Repetitive Code: Extract repetitive code into reusable functions or components.
  8. Optimize Flow Operations: Optimize flow operations to avoid unnecessary work.
  9. Use Default Parameters: Replace overloaded functions with default parameters where appropriate.
  10. Improve Null Handling: Use more robust null handling patterns.
  11. Consolidate Navigation Implementations: Choose one navigation approach (either Navigation2 or Navigation3) and standardize the codebase on it.
  12. Improve Accessibility: Add proper content descriptions to all UI elements for better accessibility.
  13. Create Base Components: Create base components that can be extended for specific use cases to reduce code duplication.
  14. Standardize Error Messages: Use consistent error messages in staticCompositionLocalOf declarations.
  15. Extract Constants: Extract hardcoded values into well-named constants with proper documentation.
  16. Reduce Coupling: Reduce tight coupling between components to improve testability and maintainability.
  17. Optimize Performance: Review and optimize performance-critical code, especially animations and state management.
  18. Standardize Parameter Naming: Use consistent parameter naming across similar components.
  19. Improve Component Reusability: Design components to be more reusable and less specific to particular use cases.
  20. Add Proper Error Boundaries: Implement error boundaries to prevent crashes and provide better user feedback.