Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 55
ADFA-3718 | Require scrolling to end before project creation#1321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.itsaky.androidide.utils | ||
| import android.content.Context | ||
| import com.itsaky.androidide.R | ||
| import com.itsaky.androidide.roomData.recentproject.RecentProject | ||
| import com.itsaky.androidide.tasks.executeAsyncProvideError | ||
| import com.itsaky.androidide.templates.ProjectTemplateRecipeResult | ||
| import com.itsaky.androidide.templates.StringParameter | ||
| import com.itsaky.androidide.templates.Template | ||
| import com.itsaky.androidide.templates.impl.ConstraintVerifier | ||
| class ProjectCreationManager(private val context: Context) { | ||
| fun execute( | ||
| template: Template<*>, | ||
| onStart: () -> Unit, | ||
| onSuccess: (ProjectTemplateRecipeResult, RecentProject) -> Unit, | ||
| onError: (String) -> Unit | ||
| ) { | ||
| val isValid = template.parameters.filterIsInstance<StringParameter>().all { param -> | ||
| ConstraintVerifier.isValid(param.value, param.constraints) | ||
| } | ||
| if (!isValid) { | ||
| onError(context.getString(R.string.msg_invalid_project_details)) | ||
| return | ||
| } | ||
| onStart() | ||
| executeAsyncProvideError({ | ||
| template.recipe.execute(TemplateRecipeExecutor(context.applicationContext)) | ||
| }) { result, err -> | ||
| if (result == null || err != null || result !is ProjectTemplateRecipeResult) { | ||
| err?.printStackTrace() | ||
| val errorMsg = err?.cause?.message ?: err?.message ?: context.getString(R.string.project_creation_failed) | ||
| onError(errorMsg) | ||
| return@executeAsyncProvideError | ||
| } | ||
| val now = System.currentTimeMillis().toString() | ||
| val project = RecentProject( | ||
| location = result.data.projectDir.path, | ||
| name = result.data.name, | ||
| createdAt = now, | ||
| lastModified = now, | ||
| templateName = template.templateNameStr, | ||
| language = result.data.language?.name ?: "unknown" | ||
| ) | ||
| onSuccess(result, project) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package com.itsaky.androidide.utils.ui | ||
| import android.view.View | ||
| import android.view.ViewTreeObserver | ||
| import androidx.recyclerview.widget.LinearLayoutManager | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| /** | ||
| * Monitors a [RecyclerView] to detect when the user scrolls to the bottom. | ||
| * Once the bottom is reached, the state is locked to `true` until manually reset or the layout width changes. | ||
| * | ||
| * @param recyclerView The list to monitor. | ||
| * @param onScrollStateChanged Callback invoked when the [hasReachedEnd] state changes. | ||
| */ | ||
| class TemplateScrollGateKeeper( | ||
jatezzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| private val recyclerView: RecyclerView, | ||
| private var onScrollStateChanged: (() -> Unit)? | ||
| ) { | ||
| /** | ||
| * `true` if the user has scrolled to the bottom of the list at least once. | ||
| */ | ||
| var hasReachedEnd = false | ||
| private set | ||
| private var lastWidth = -1 | ||
| private val scrollListener = object : RecyclerView.OnScrollListener() { | ||
| override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { | ||
| checkIfReachedEnd() | ||
| } | ||
| } | ||
| private val layoutChangeListener = View.OnLayoutChangeListener { _, left, _, right, _, _, _, _, _ -> | ||
| val currentWidth = right - left | ||
| if (lastWidth != -1 && lastWidth != currentWidth) { | ||
| hasReachedEnd = false | ||
| onScrollStateChanged?.invoke() | ||
| } | ||
| lastWidth = currentWidth | ||
| } | ||
| private val globalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener { | ||
| checkIfReachedEnd() | ||
| } | ||
| /** | ||
| * Attaches scroll and layout listeners to the [RecyclerView]. | ||
| */ | ||
| fun attach() { | ||
| recyclerView.addOnScrollListener(scrollListener) | ||
| recyclerView.addOnLayoutChangeListener(layoutChangeListener) | ||
| recyclerView.viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener) | ||
| } | ||
| /** | ||
| * Detaches listeners from the [RecyclerView] to prevent memory leaks. | ||
| */ | ||
| fun detach() { | ||
| recyclerView.removeOnScrollListener(scrollListener) | ||
| recyclerView.removeOnLayoutChangeListener(layoutChangeListener) | ||
| if (recyclerView.viewTreeObserver.isAlive) { | ||
| recyclerView.viewTreeObserver.removeOnGlobalLayoutListener(globalLayoutListener) | ||
| } | ||
| onScrollStateChanged = null | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| /** | ||
| * Resets the gatekeeper state and notifies the callback. | ||
| */ | ||
| fun reset() { | ||
| hasReachedEnd = false | ||
| lastWidth = -1 | ||
| onScrollStateChanged?.invoke() | ||
| } | ||
| /** | ||
| * Evaluates the scroll position and updates [hasReachedEnd] if the bottom is reached. | ||
| */ | ||
| fun checkIfReachedEnd() { | ||
| if (hasReachedEnd) return | ||
| val layoutManager = recyclerView.layoutManager as? LinearLayoutManager ?: return | ||
| val itemCount = layoutManager.itemCount | ||
| if (itemCount == 0) return | ||
| val lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition() | ||
| if (lastVisibleItem == RecyclerView.NO_POSITION) return | ||
| val isAtBottom = !recyclerView.canScrollVertically(1) | ||
| if (lastVisibleItem >= itemCount - 1 || isAtBottom) { | ||
| hasReachedEnd = true | ||
| onScrollStateChanged?.invoke() | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -67,6 +67,18 @@ | ||
| app:layout_constraintBottom_toBottomOf="parent" | ||
| app:layout_constraintStart_toStartOf="parent" /> | ||
| <ImageView | ||
| android:id="@+id/scrollIndicator" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:importantForAccessibility="no" | ||
| android:layout_marginEnd="8dp" | ||
| android:src="@drawable/ic_arrow_down" | ||
| app:tint="?attr/colorPrimary" | ||
| app:layout_constraintEnd_toStartOf="@id/finish" | ||
| app:layout_constraintTop_toTopOf="@id/finish" | ||
| app:layout_constraintBottom_toBottomOf="@id/finish" /> | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| <com.google.android.material.button.MaterialButton | ||
| android:id="@+id/finish" | ||
| android:layout_width="wrap_content" | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.