Skip to content

ADFA-2673 | Refactor and centralize auto-open project logic#899

Merged
jatezzz merged 1 commit intostagefrom
refactor/ADFA-2673-auto-open-logic
Feb 4, 2026
Merged

ADFA-2673 | Refactor and centralize auto-open project logic#899
jatezzz merged 1 commit intostagefrom
refactor/ADFA-2673-auto-open-logic

Conversation

@jatezzz
Copy link
Collaborator

@jatezzz jatezzz commented Jan 28, 2026

Description

This PR refactors the project opening logic to centralize the "Auto Open" feature within MainActivity, removing the dependency on RecentProjectsFragment for this task. It introduces a robust fallback mechanism that scans the file system to ensure the project exists before attempting to open it.

Details

  • Refactor: Extracted project validation methods (findValidProjects, isValidProjectDirectory, etc.) from RecentProjectsFragment into a new utility file ProjectValidations.kt to allow shared access.
  • Logic Update: Updated MainActivity.tryOpenLastProject() to run on Dispatchers.IO. It now verifies physically existing projects.
  • Fallback Mechanism: If the lastOpenedProject preference points to a non-existent directory (or is empty), the app now automatically attempts to open the most recently modified valid project found in the projects directory.
  • UX Improvement: Added guard clauses to prevent "Project does not exist" toast messages on fresh installations.
Screen.Recording.2026-01-28.at.2.02.06.PM.mov

Ticket

ADFA-2673

Observation

The validation logic was duplicated and isolated in the fragment previously. Moving it to ProjectValidations.kt makes it reusable and testable. The new logic in MainActivity handles edge cases where the user might have deleted the project folder externally.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

Warning

Rate limit exceeded

@jatezzz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 23 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Centralizes project validation into new utilities and updates project-opening flows: MainActivity moves last-project discovery to an IO coroutine, adds handleOpenProject(root: File) for permission-guarded opening, and RecentProjectsFragment now uses shared validation utilities instead of local helpers. (46 words)

Changes

Cohort / File(s) Summary
Project validation utilities
app/src/main/java/com/itsaky/androidide/utils/ProjectValidations.kt
Adds centralized project validation and discovery functions: findValidProjects, isValidProjectDirectory, isValidProjectOrContainerDirectory, isPluginProject, and File.isProjectCandidateDir().
MainActivity project opening
app/src/main/java/com/itsaky/androidide/activities/MainActivity.kt
Moves last-project discovery into IO dispatcher using findValidProjects and withContext; guards openLastProject() with savedInstanceState == null; adds handleOpenProject(root: File) to centralize permission checks and opening; updates permission/open call sites to accept root: File.
RecentProjectsFragment cleanup
app/src/main/java/com/itsaky/androidide/fragments/RecentProjectsFragment.kt
Removes local validation helpers and auto-open-on-boot behavior; delegates project discovery and validation to centralized utilities (findValidProjects, isValidProjectOrContainerDirectory, isProjectCandidateDir, isValidProjectDirectory).

Sequence Diagram

sequenceDiagram
    participant UI as MainActivity (UI)
    participant IO as IO Dispatcher
    participant PV as ProjectValidations
    participant Handler as handleOpenProject
    participant Perm as Permission flow

    UI->>IO: tryOpenLastProject()
    IO->>PV: findValidProjects(projectsRoot)
    PV-->>IO: validProjects
    IO-->>UI: candidateProject (withContext Main)
    alt project found
        UI->>Handler: handleOpenProject(root)
        Handler->>Perm: check confirmProjectOpen / permissions
        alt confirmation required
            Perm-->>UI: askProjectOpenPermission(root)
        else no confirmation
            Handler-->>UI: openProject(root)
        end
    else no project found
        UI->>UI: show missing / skip auto-open
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • itsaky-adfa
  • dara-abijo-adfa
  • jomen-adfa

Poem

🐰 I hopped through folders, soft and spry,

Found project roots beneath the rye,
I asked politely, then I leapt,
Opened doors the rabbit kept,
Code carrots glinting in my eye 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main change: refactoring and centralizing auto-open project logic from RecentProjectsFragment into MainActivity and ProjectValidations.kt.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the refactoring of project validation methods, logic updates to MainActivity, the fallback mechanism, and UX improvements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/ADFA-2673-auto-open-logic

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@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: 1

🤖 Fix all issues with AI agents
In `@app/src/main/java/com/itsaky/androidide/activities/MainActivity.kt`:
- Around line 262-285: The auto-open logic in tryOpenLastProject currently only
considers projects returned by findValidProjects(Environment.PROJECTS_DIR),
which skips a valid GeneralPreferences.lastOpenedProject if it's outside
PROJECTS_DIR; change the selection so you first check if
GeneralPreferences.lastOpenedProject is non-blank and points to an existing
valid project (use isValidProjectDirectory(path) or equivalent) and if so set
projectToOpen to that File, otherwise fall back to selecting the most recent
project from findValidProjects(Environment.PROJECTS_DIR); keep the existing UI
branch that calls handleOpenProject(projectToOpen) and the flashInfo path for
missing lastOpenedPath.

@jatezzz jatezzz requested a review from a team January 29, 2026 13:09
@jatezzz jatezzz force-pushed the refactor/ADFA-2673-auto-open-logic branch from e536016 to e82ba6a Compare January 29, 2026 16:43
@jatezzz jatezzz force-pushed the refactor/ADFA-2673-auto-open-logic branch from 4eb5896 to 7c12bd2 Compare January 30, 2026 13:16
Copy link
Contributor

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/src/main/java/com/itsaky/androidide/fragments/RecentProjectsFragment.kt (1)

285-291: ⚠️ Potential issue | 🟡 Minor

Potential race condition: insertProjectFromFolder is not awaited before opening the project.

At lines 322-328, you correctly collect jobs and call joinAll() before opening. However, here the project is opened immediately after insertProjectFromFolder without waiting for the insertion to complete. If the insertion is asynchronous, the database entry may not exist when subsequent operations (e.g., onResume calling loadProjects) execute.

🔧 Proposed fix to await the insertion
 if (isValidProjectDirectory(directory)) {
-    viewModel.insertProjectFromFolder(
+    val job = viewModel.insertProjectFromFolder(
         name = directory.name,
         location = directory.absolutePath
     )
+    viewLifecycleScope.launch {
+        job.join()
+        openProject(root = directory)
+    }
+    return
+}
-
-    openProject(root = directory)
-    return
-}

Alternatively, if the insertion is synchronous or fire-and-forget by design, consider adding a comment clarifying the intent.

@jatezzz jatezzz force-pushed the refactor/ADFA-2673-auto-open-logic branch 6 times, most recently from 3f9beab to d66b45d Compare February 4, 2026 16:18
…ve validation utils to shared file and improve startup project detection
@jatezzz jatezzz force-pushed the refactor/ADFA-2673-auto-open-logic branch from f1dee78 to d28722e Compare February 4, 2026 16:56
@jatezzz jatezzz merged commit 5a2a97f into stage Feb 4, 2026
2 checks passed
@jatezzz jatezzz deleted the refactor/ADFA-2673-auto-open-logic branch February 4, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants