Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class EditorBottomSheetTabAdapter(
title = fragmentActivity.getString(R.string.git_title),
fragmentClass = GitBottomSheetFragment::class.java,
itemId = TAB_GIT,
tooltipTag = TooltipTag.PROJECT_GIT,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
Expand All @@ -22,9 +23,12 @@ import com.itsaky.androidide.databinding.FragmentGitBottomSheetBinding
import com.itsaky.androidide.fragments.git.adapter.GitFileChangeAdapter
import com.itsaky.androidide.git.core.GitCredentialsManager
import com.itsaky.androidide.git.core.models.ChangeType
import com.itsaky.androidide.idetooltips.TooltipManager
import com.itsaky.androidide.idetooltips.TooltipTag
import com.itsaky.androidide.interfaces.IEditorHandler
import com.itsaky.androidide.preferences.internal.GitPreferences
import com.itsaky.androidide.utils.flashSuccess
import com.itsaky.androidide.utils.onLongPress
import com.itsaky.androidide.viewmodel.BottomSheetViewModel
import com.itsaky.androidide.viewmodel.GitBottomSheetViewModel
import com.itsaky.androidide.viewmodel.GitBottomSheetViewModel.PullUiState
Expand Down Expand Up @@ -81,6 +85,13 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {

binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = fileChangeAdapter
binding.recyclerView.onLongPress { _ ->
TooltipManager.showIdeCategoryTooltip(
context = requireContext(),
anchorView = binding.recyclerView,
tag = TooltipTag.PROJECT_GIT_FILES,
)
}

viewLifecycleOwner.lifecycleScope.launch {
launch {
Expand Down Expand Up @@ -136,9 +147,12 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {

setupCommitUI()

binding.commitHistoryButton.setOnClickListener {
val dialog = GitCommitHistoryDialog()
dialog.show(childFragmentManager, "CommitHistoryDialog")
binding.commitHistoryButton.apply {
setOnClickListener {
val dialog = GitCommitHistoryDialog()
dialog.show(childFragmentManager, "CommitHistoryDialog")
}
setTooltipOnView(TooltipTag.PROJECT_GIT_COMMIT_HISTORY)
}

setupPullUI()
Expand All @@ -164,44 +178,53 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
binding.commitSummary.doAfterTextChanged { validateCommitButton() }
binding.commitDescription.doAfterTextChanged { validateCommitButton() }

binding.btnAbortMerge.setOnClickListener {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.abort_merge)
.setMessage(R.string.confirm_abort_merge)
.setPositiveButton(R.string.abort_merge) { _, _ ->
viewModel.abortMerge {
val activity = requireActivity()
if (activity is EditorHandlerActivity) {
activity.checkForExternalFileChanges(force = true)
binding.btnAbortMerge.apply {
setOnClickListener {
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.abort_merge)
.setMessage(R.string.confirm_abort_merge)
.setPositiveButton(R.string.abort_merge) { _, _ ->
viewModel.abortMerge {
val activity = requireActivity()
if (activity is EditorHandlerActivity) {
activity.checkForExternalFileChanges(force = true)
}
}
}
}
.setNegativeButton(android.R.string.cancel, null)
.show()
.setNegativeButton(android.R.string.cancel, null)
.create()
dialog.setTooltipOnDialog(TooltipTag.GIT_DIALOG_ABORT_MERGE)
dialog.show()
}
setTooltipOnView(TooltipTag.PROJECT_GIT_ABORT)
}

binding.authorAvatar.setOnClickListener {
showAuthorPopup()
binding.authorAvatar.apply {
setOnClickListener { showAuthorPopup() }
setTooltipOnView(TooltipTag.PROJECT_GIT_ID)
}

binding.commitButton.setOnClickListener {
checkUnsavedChangesAndProceed {
val summary = binding.commitSummary.text?.toString()?.trim() ?: ""
val description = binding.commitDescription.text?.toString()?.trim()

if (summary.isNotEmpty() && fileChangeAdapter.selectedFiles.isNotEmpty() && hasAuthorInfo()) {
viewModel.commitChanges(
summary = summary,
description = description,
selectedPaths = fileChangeAdapter.selectedFiles.toList()
) {
// Clear the inputs on successful commit
binding.commitSummary.text?.clear()
binding.commitDescription.text?.clear()
fileChangeAdapter.selectedFiles.clear()
binding.commitButton.apply {
setOnClickListener {
checkUnsavedChangesAndProceed {
val summary = binding.commitSummary.text?.toString()?.trim() ?: ""
val description = binding.commitDescription.text?.toString()?.trim()

if (summary.isNotEmpty() && fileChangeAdapter.selectedFiles.isNotEmpty() && hasAuthorInfo()) {
viewModel.commitChanges(
summary = summary,
description = description,
selectedPaths = fileChangeAdapter.selectedFiles.toList()
) {
// Clear the inputs on successful commit
binding.commitSummary.text?.clear()
binding.commitDescription.text?.clear()
fileChangeAdapter.selectedFiles.clear()
}
}
}
}
setTooltipOnView(TooltipTag.PROJECT_GIT_COMMIT)
}
}

Expand Down Expand Up @@ -281,11 +304,13 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
binding.btnPull.isEnabled = true
binding.pullProgress.visibility = View.GONE
val message = state.message ?: getString(R.string.info_merge_conflicts)
MaterialAlertDialogBuilder(requireContext())
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.merge_conflicts))
.setMessage(message)
.setPositiveButton(android.R.string.ok, null)
.show()
.create()
dialog.setTooltipOnDialog(TooltipTag.GIT_DIALOG_MERGE_CONFLICTS)
dialog.show()
viewModel.resetPullState()
refreshEditorContent()
}
Expand All @@ -296,26 +321,31 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
state.message ?: state.errorResId?.let { resId ->
if (state.errorArgs != null) getString(resId, *state.errorArgs.toTypedArray()) else getString(resId)
}
MaterialAlertDialogBuilder(requireContext())
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.pull_failed)
.setMessage(message)
.setPositiveButton(android.R.string.ok, null)
.show()
.create()
dialog.setTooltipOnDialog(TooltipTag.GIT_DIALOG_PULL_FAIL)
dialog.show()
}
}
}
}

binding.btnPull.setOnClickListener {
checkUnsavedChangesAndProceed {
val username = credentialsManager.getUsername()
val token = credentialsManager.getToken()
if (!username.isNullOrBlank() && !token.isNullOrBlank()) {
viewModel.pull(username, token)
} else {
showCredentialsDialog()
binding.btnPull.apply {
setOnClickListener {
checkUnsavedChangesAndProceed {
val username = credentialsManager.getUsername()
val token = credentialsManager.getToken()
if (!username.isNullOrBlank() && !token.isNullOrBlank()) {
viewModel.pull(username, token)
} else {
showCredentialsDialog()
}
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
setTooltipOnView(TooltipTag.GIT_PULL)
}
}

Expand Down Expand Up @@ -353,7 +383,7 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
private fun checkUnsavedChangesAndProceed(action: () -> Unit) {
val handler = requireActivity() as? IEditorHandler
if (handler?.areFilesModified() == true) {
MaterialAlertDialogBuilder(requireContext())
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.title_files_unsaved)
.setMessage(R.string.msg_save_before_git_action)
.setPositiveButton(R.string.save_before_git_action) { _, _ ->
Expand All @@ -363,7 +393,9 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
action()
}
.setNeutralButton(android.R.string.cancel, null)
.show()
.create()
dialog.setTooltipOnDialog(TooltipTag.GIT_DIALOG_SAVE)
dialog.show()
} else {
action()
}
Expand All @@ -373,4 +405,26 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
super.onDestroyView()
_binding = null
}

fun AlertDialog.setTooltipOnDialog(tag: String) {
onLongPress { view ->
TooltipManager.showIdeCategoryTooltip(
context = view.context,
anchorView = view,
tag = tag
)
true
}
}

fun View.setTooltipOnView(tag: String) {
setOnLongClickListener { view ->
TooltipManager.showIdeCategoryTooltip(
context = view.context,
anchorView = view,
tag = tag
)
true
}
}
Comment thread
dara-abijo-adfa marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import com.itsaky.androidide.databinding.DialogGitCredentialsBinding
import com.itsaky.androidide.fragments.git.adapter.GitCommitHistoryAdapter
import com.itsaky.androidide.git.core.GitCredentialsManager
import com.itsaky.androidide.git.core.models.CommitHistoryUiState
import com.itsaky.androidide.idetooltips.TooltipManager
import com.itsaky.androidide.idetooltips.TooltipTag
import com.itsaky.androidide.utils.applyLongPressRecursively
import com.itsaky.androidide.utils.flashSuccess
import com.itsaky.androidide.utils.onLongPress
import com.itsaky.androidide.viewmodel.GitBottomSheetViewModel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -52,12 +56,34 @@ class GitCommitHistoryDialog : DialogFragment() {
binding.rvCommitHistory.context,
linearLayoutManager.orientation
)

binding.root.applyLongPressRecursively(listOf(binding.btnPush, binding.rvCommitHistory)) { view ->
TooltipManager.showIdeCategoryTooltip(
context = view.context,
anchorView = view,
tag = TooltipTag.GIT_COMMIT_HISTORY
)
true
}

binding.rvCommitHistory.onLongPress {
TooltipManager.showIdeCategoryTooltip(
context = binding.root.context,
anchorView = binding.root,
tag = TooltipTag.GIT_COMMIT_HISTORY
)
}

binding.rvCommitHistory.apply {
layoutManager = linearLayoutManager
addItemDecoration(dividerItemDecoration)
adapter = commitHistoryAdapter
}

binding.btnBack.setOnClickListener {
dismiss()
}

viewModel.getCommitHistoryList()

viewLifecycleOwner.lifecycleScope.launch {
Expand Down Expand Up @@ -94,13 +120,23 @@ class GitCommitHistoryDialog : DialogFragment() {
}

private fun setupPushUI() {
binding.btnPush.setOnClickListener {
val username = credentialsManager.getUsername()
val token = credentialsManager.getToken()
if (!username.isNullOrBlank() && !token.isNullOrBlank()) {
viewModel.push(username, token)
} else {
showCredentialsDialog()
binding.btnPush.apply {
setOnClickListener {
val username = credentialsManager.getUsername()
val token = credentialsManager.getToken()
if (!username.isNullOrBlank() && !token.isNullOrBlank()) {
viewModel.push(username, token)
} else {
showCredentialsDialog()
}
}
setOnLongClickListener { view ->
TooltipManager.showIdeCategoryTooltip(
context = view.context,
anchorView = view,
tag = TooltipTag.GIT_PUSH
)
true
}
}

Expand Down Expand Up @@ -137,11 +173,20 @@ class GitCommitHistoryDialog : DialogFragment() {
} else {
state.message ?: getString(R.string.unknown_error)
}
MaterialAlertDialogBuilder(requireContext())
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.push_failed)
.setMessage(message)
.setPositiveButton(android.R.string.ok, null)
.show()
.create()
dialog.onLongPress {
TooltipManager.showIdeCategoryTooltip(
context = binding.root.context,
anchorView = binding.root,
tag = TooltipTag.GIT_DIALOG_PUSH_FAIL
)
true
}
dialog.show()
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/res/layout/dialog_git_commit_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@
android:layout_height="match_parent"
android:background="?colorSurface">

<ImageView
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/navigate_up"
android:padding="16dp"
android:src="@drawable/ic_back"
app:layout_constraintBottom_toBottomOf="@id/tv_commit_history"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Comment thread
coderabbitai[bot] marked this conversation as resolved.

<TextView
android:id="@+id/tv_commit_history"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="16dp"
android:paddingVertical="16dp"
android:text="@string/git_commit_history"
app:layout_constraintEnd_toStartOf="@id/btnPush"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/btnBack"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButton
Expand Down
Loading
Loading