Skip to content

Conversation

tuancoltech
Copy link
Member

@tuancoltech tuancoltech commented Mar 18, 2025

  • Implement function to check for package installation.
  • Implement function to parse data from Bundle

Summary by CodeRabbit

  • New Features
    • Introduced a check that verifies whether a required package is installed on your device. If it isn’t, an alert dialog appears with a message and actionable button to help guide you toward correcting the issue.
    • Added new functions for enhanced compatibility with different Android API levels, allowing for the retrieval of parcelable objects from Bundles.

@tuancoltech tuancoltech self-assigned this Mar 18, 2025
@tuancoltech tuancoltech requested a review from jo-elimu March 18, 2025 08:25
Copy link

coderabbitai bot commented Mar 18, 2025

Walkthrough

The changes introduce new extension functions for the Context and Bundle classes. The isPackageInstalled function checks if a specified package is installed by querying the package manager, logging the version code if found, and handling errors with an AlertDialog. Additionally, two functions, getParcelableCompat and getParcelableArrayListCompat, are added to the Bundle class to retrieve parcelable objects and lists, respectively, ensuring compatibility with different Android API levels.

Changes

File Path Change Summary
utils/.../ContextExt.kt Added fun Context.isPackageInstalled(...): Checks for a package installation, logs package details when available, displays an AlertDialog on failure, and attempts to start an activity upon user interaction.
utils/.../BundleExt.kt Added fun <T> Bundle?.getParcelableCompat(...): Retrieves a parcelable object with API level compatibility. Added fun <T : android.os.Parcelable> Bundle?.getParcelableArrayListCompat(...): Retrieves an ArrayList of parcelable objects with API level compatibility.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Ctx as Context Extension
    participant PM as PackageManager
    participant Dialog as AlertDialog

    Caller->>Ctx: isPackageInstalled(packageName, launchPackage, launchClass, dialogMessage, buttonText)
    Ctx->>PM: getPackageInfo(packageName)
    alt Package Exists
        PM-->>Ctx: PackageInfo (includes version code)
        Ctx-->>Caller: true
    else Package Not Found
        PM-->>Ctx: NameNotFoundException
        Ctx->>Ctx: Log exception
        Ctx->>Dialog: Show AlertDialog (dialogMessage, buttonText)
        Dialog->>Ctx: User clicks button
        Ctx->>Ctx: Create Intent(launchPackage, launchClass)
        Ctx->>Ctx: startActivity(intent)
        alt Activity Launch Fails
            Ctx-->>Caller: false
        else Activity Launched
            Ctx-->>Caller: false
        end
    end
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
utils/src/main/java/ai/elimu/common/utils/ContextExt.kt (5)

10-14: Consider separating UI logic from the installation check
You're mixing user interaction (alert dialog) with the straightforward check for a package's presence. Splitting the concerns can improve maintainability and testability.


15-19: Use getLongVersionCode() for better forward compatibility
versionCode is deprecated in newer API levels. Switch to longVersionCode to handle large version numbers.


20-39: Avoid printing stack traces in production
Consider using a logging framework or removing e.printStackTrace() to prevent leaking sensitive information in logs.


20-39: Allow cancelling the dialog
setCancelable(false) can be distressing to users if they want to dismiss it without launching the activity. Consider making the dialog cancelable for a better UX.


26-34: Narrow the catch block
Catching Exception is broad. Consider catching specific exceptions (e.g., ActivityNotFoundException) for more targeted error handling and logging.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb4c6ad and e5f4c99.

📒 Files selected for processing (1)
  • utils/src/main/java/ai/elimu/common/utils/ContextExt.kt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (ubuntu-latest, 17)
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (macos-latest, 21)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
utils/src/main/java/ai/elimu/common/utils/BundleExt.kt (1)

1-23: Consider adding documentation to clarify usage

While the implementation is correct, adding KDoc comments would make the code more maintainable and easier for other developers to understand. Documentation should explain the purpose of these extension functions and provide example usage.

 package ai.elimu.common.utils

 import android.os.Build
 import android.os.Bundle

+/**
+ * Gets a parcelable object from the Bundle in a way that's compatible with all Android API levels.
+ *
+ * @param key The key to retrieve the parcelable object.
+ * @param clazz The class of the parcelable object.
+ * @return The parcelable object, or null if not found.
+ */
 fun <T> Bundle?.getParcelableCompat(key: String, clazz: Class<T>): T? {
     return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
         this?.getParcelable(key, clazz)
     } else {
         @Suppress("DEPRECATION")
         this?.getParcelable(key)
     }
 }

+/**
+ * Gets an ArrayList of parcelable objects from the Bundle in a way that's compatible with all Android API levels.
+ *
+ * @param key The key to retrieve the ArrayList.
+ * @param clazz The class of the parcelable objects in the ArrayList.
+ * @return The ArrayList of parcelable objects, or null if not found.
+ */
 fun <T : android.os.Parcelable> Bundle?.getParcelableArrayListCompat(key: String, clazz: Class<T>)
         : java.util.ArrayList<T>? {
     return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
         this?.getParcelableArrayList(key, clazz)
     } else {
         @Suppress("DEPRECATION")
         this?.getParcelableArrayList(key)
     }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5f4c99 and 7e45ea1.

📒 Files selected for processing (1)
  • utils/src/main/java/ai/elimu/common/utils/BundleExt.kt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: build (macos-latest, 17)
🔇 Additional comments (3)
utils/src/main/java/ai/elimu/common/utils/BundleExt.kt (3)

6-13: Well-implemented compatibility wrapper for getParcelable

This is a good implementation of a compatibility wrapper for the getParcelable method that handles the API level differences between Android Tiramisu (API 33) and earlier versions. The approach correctly uses the new type-safe method for newer Android versions while falling back to the deprecated method for older versions.


15-23: Well-implemented compatibility wrapper for getParcelableArrayList

The implementation correctly handles the API differences for retrieving an ArrayList of Parcelables across Android versions. The code follows the same pattern as the previous function, maintaining consistency in the codebase.


1-5: Note: PR objective and implementation mismatch

The PR objective mentions implementing a function to check for package installation, but this file only contains Bundle extension functions for Parcelable compatibility. According to the AI summary, the package installation check function (isPackageInstalled) is implemented in a different file (ContextExt.kt) which is not included in this review.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
utils/src/main/java/ai/elimu/common/utils/BundleExt.kt (1)

13-20: Restrict the type parameter to Parcelable.
Consider making <T : Parcelable> for type safety and avoiding potential runtime cast issues.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e45ea1 and bc6828f.

📒 Files selected for processing (1)
  • utils/src/main/java/ai/elimu/common/utils/BundleExt.kt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (windows-latest, 21)
🔇 Additional comments (5)
utils/src/main/java/ai/elimu/common/utils/BundleExt.kt (5)

1-2: No content to comment.


3-5: Imports look fine.


6-12: Good documentation.


22-28: Documentation is clear.


29-37: Implementation is valid.

@tuancoltech tuancoltech merged commit 3208293 into main Mar 18, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ☑️

Development

Successfully merging this pull request may close these issues.

2 participants