How guolindev/permissionx works
Main Components
• Sample Application (“app”):
• Represents the client-side usage of the PermissionX library.
• Contains UI elements such as MainActivity, MainFragment, custom dialogs, and layouts.
• PermissionX Library (“permissionx”):
• Core library logic that encapsulates the permission request process.
• Contains several sub-modules/components:
– Permission Mediator (e.g., PermissionMediator.kt, PermissionX.java) which acts as the entry point.
– Request Handling Module (e.g., classes in the "request" package like ChainTask, RequestBuilder, and various specialized Request classes for background location, notifications, etc.).
– Callback Interfaces (e.g., ExplainReasonCallback, ForwardToSettingsCallback, RequestCallback) responsible for receiving events from the Android OS permission system.
– Dialog Components (in the "dialog" package) that create and display the rationale dialog, default dialogs, and a dialog fragment for permissions explanation.
• Android System/OS:
• Represents the underlying Android permission management system where runtime permissions are actually granted or denied by the user.
Defining Relationships and Interactions
• The Sample Application calls the PermissionX API (by calling PermissionX.init(activity)) to request permissions.
• The PermissionX Library uses the Permission Mediator to build a chain of permission request tasks:
• It first checks for permissions, then, if necessary, calls callback methods (onExplainRequestReason or onForwardToSettings) before finally executing the actual permission request.
• The Callbacks then interact with the Dialog components to display dialogs, and the user’s responses are propagated back through the PermissionX flow.
• Ultimately, the library communicates with the Android OS (invoking system APIs) to perform the actual permission request.
Architectural Patterns and Design Principles
• Separation of Concerns: The sample app is strictly a consumer of the library, while the library itself cleanly separates UI/dialog handling, callback handling, and task chaining.
• Chain-of-Responsibility: The “request” package reflects a chain-based design where a series of permission related tasks are sequentially processed.
• Modularity and Reusability: By isolating different concerns (callbacks, dialogs, request tasks), the library is extensible and easily maintained.
Relevant Technologies, Frameworks, and Libraries
• Android Framework: The project relies on core Android SDK components (activities, fragments, manifest, etc.).
• Kotlin and Java: Code is written in both Kotlin (majority of the code, especially in the sample app and some of the library classes) and Java (supporting compatibility and API exposure).
• Gradle and Gradle Kotlin DSL: Project configuration and dependency management use Gradle scripts (build.gradle.kts, settings.gradle.kts, etc.).