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 @@ -53,8 +53,8 @@ class EditorBottomSheetTabAdapter(
const val TAB_DIAGNOSTICS = 3
const val TAB_SEARCH_RESULTS = 4
const val TAB_DEBUGGER = 5
const val TAB_AGENT = 6
const val TAB_GIT = 7
const val TAB_GIT = 6
const val TAB_AGENT = 7
}

private val allTabs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
}
}
}

else -> {
val dialog = GitDiffViewerDialog.newInstance(change.path)
dialog.show(childFragmentManager, "GitDiffViewerDialog")
Expand Down Expand Up @@ -97,7 +98,8 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
viewModel.currentBranch.collectLatest { branchName ->
if (branchName != null) {
binding.tvBranchName.visibility = View.VISIBLE
binding.tvBranchName.text = getString(R.string.current_branch_name, branchName)
binding.tvBranchName.text =
getString(R.string.current_branch_name, branchName)
} else {
binding.tvBranchName.visibility = View.GONE
}
Expand All @@ -108,7 +110,8 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
viewModel.isGitRepository,
viewModel.gitStatus
) { isRepo, status ->
val allChanges = status.staged + status.unstaged + status.untracked + status.conflicted
val allChanges =
status.staged + status.unstaged + status.untracked + status.conflicted

when {
!isRepo -> binding.apply {
Expand All @@ -120,6 +123,7 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
commitHistoryButton.visibility = View.GONE
btnAbortMerge.visibility = View.GONE
}

allChanges.isEmpty() -> binding.apply {
emptyView.visibility = View.VISIBLE
emptyView.text = getString(R.string.no_uncommitted_changes)
Expand All @@ -129,14 +133,17 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
commitHistoryButton.visibility = View.VISIBLE
btnAbortMerge.visibility = View.GONE
}

else -> {
binding.apply {
emptyView.visibility = View.GONE
recyclerView.visibility = View.VISIBLE
commitSection.visibility = View.VISIBLE
authorWarning.visibility = if (hasAuthorInfo()) View.GONE else View.VISIBLE
authorWarning.visibility =
if (hasAuthorInfo()) View.GONE else View.VISIBLE
commitHistoryButton.visibility = View.VISIBLE
btnAbortMerge.visibility = if (status.isMerging) View.VISIBLE else View.GONE
btnAbortMerge.visibility =
if (status.isMerging) View.VISIBLE else View.GONE
}
fileChangeAdapter.submitList(allChanges)
}
Expand Down Expand Up @@ -164,8 +171,10 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {

private fun updateAuthorUI() {
val hasAuthor = hasAuthorInfo()
val allChanges = viewModel.gitStatus.value.staged + viewModel.gitStatus.value.unstaged + viewModel.gitStatus.value.untracked + viewModel.gitStatus.value.conflicted
binding.authorWarning.visibility = if (!hasAuthor && allChanges.isNotEmpty()) View.VISIBLE else View.GONE
val allChanges =
viewModel.gitStatus.value.staged + viewModel.gitStatus.value.unstaged + viewModel.gitStatus.value.untracked + viewModel.gitStatus.value.conflicted
binding.authorWarning.visibility =
if (!hasAuthor && allChanges.isNotEmpty()) View.VISIBLE else View.GONE
validateCommitButton()
}

Expand Down Expand Up @@ -229,7 +238,8 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {

private fun showAuthorPopup() {
val name = GitPreferences.userName.orEmpty().ifBlank { getString(R.string.author_not_set) }
val email = GitPreferences.userEmail.orEmpty().ifBlank { getString(R.string.author_not_set) }
val email =
GitPreferences.userEmail.orEmpty().ifBlank { getString(R.string.author_not_set) }
val message = getString(R.string.git_committing_as, name) + "\n" +
getString(R.string.git_committing_email, email) + "\n\n" +
getString(R.string.git_update_config_in_preferences)
Expand Down Expand Up @@ -264,7 +274,8 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
}

dialog.show()
dialog.findViewById<TextView>(android.R.id.message)?.movementMethod = LinkMovementMethod.getInstance()
dialog.findViewById<TextView>(android.R.id.message)?.movementMethod =
LinkMovementMethod.getInstance()
}

private fun validateCommitButton() {
Expand All @@ -288,17 +299,20 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
binding.btnPull.isEnabled = true
binding.pullProgress.visibility = View.GONE
}

is PullUiState.Pulling -> {
binding.btnPull.isEnabled = false
binding.pullProgress.visibility = View.VISIBLE
}

is PullUiState.Success -> {
binding.btnPull.isEnabled = true
binding.pullProgress.visibility = View.GONE
flashSuccess(R.string.pull_successful)
viewModel.resetPullState()
refreshEditorContent()
}

is PullUiState.Conflicts -> {
binding.btnPull.isEnabled = true
binding.pullProgress.visibility = View.GONE
Expand All @@ -313,12 +327,16 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
viewModel.resetPullState()
refreshEditorContent()
}

is PullUiState.Error -> {
binding.btnPull.isEnabled = true
binding.pullProgress.visibility = View.GONE
val message =
state.message ?: state.errorResId?.let { resId ->
if (state.errorArgs != null) getString(resId, *state.errorArgs.toTypedArray()) else getString(resId)
state.message ?: state.errorResId?.let { resId ->
if (state.errorArgs != null) getString(
resId,
*state.errorArgs.toTypedArray()
) else getString(resId)
}
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.pull_failed)
Expand All @@ -332,19 +350,6 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
}
}

binding.btnPull.setOnClickListener {
checkUnsavedChangesAndProceed {
val username = credentialsManager.getUsername()
val token = credentialsManager.getToken()
if (!username.isNullOrBlank() && !token.isNullOrBlank()) {
viewModel.pull(username, token)
} else {
showGitCredentialsDialog(
credentialsManager = credentialsManager,
positiveButtonTextResId = R.string.pull
) { user, accessToken ->
viewModel.pull(user, accessToken)}}

binding.btnPull.apply {
setOnClickListener {
checkUnsavedChangesAndProceed {
Expand All @@ -364,7 +369,7 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
}
setTooltipOnView(TooltipTag.GIT_PULL)
}
}}}
}

private fun refreshEditorContent(force: Boolean = false) {
val activity = requireActivity()
Expand Down Expand Up @@ -399,7 +404,7 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
_binding = null
}

fun AlertDialog.setTooltipOnDialog(tag: String) {
private fun AlertDialog.setTooltipOnDialog(tag: String) {
onLongPress { view ->
TooltipManager.showIdeCategoryTooltip(
context = view.context,
Expand All @@ -410,7 +415,7 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
}
}

fun View.setTooltipOnView(tag: String) {
private fun View.setTooltipOnView(tag: String) {
setOnLongClickListener { view ->
TooltipManager.showIdeCategoryTooltip(
context = view.context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ class GitCommitHistoryDialog : DialogFragment() {
linearLayoutManager.orientation
)

binding.root.applyLongPressRecursively(listOf(binding.btnPush, binding.rvCommitHistory)) { view ->
binding.root.applyLongPressRecursively(
listOf(
binding.btnPush,
binding.rvCommitHistory
)
) { view ->
TooltipManager.showIdeCategoryTooltip(
context = view.context,
anchorView = view,
Expand All @@ -76,6 +81,7 @@ class GitCommitHistoryDialog : DialogFragment() {
tag = TooltipTag.GIT_COMMIT_HISTORY
)
}
}

binding.btnBack.setOnClickListener {
dismiss()
Expand All @@ -91,18 +97,21 @@ class GitCommitHistoryDialog : DialogFragment() {
binding.emptyView.visibility = View.GONE
binding.rvCommitHistory.visibility = View.GONE
}

is CommitHistoryUiState.Empty -> {
binding.progressBar.visibility = View.GONE
binding.emptyView.visibility = View.VISIBLE
binding.emptyView.setText(R.string.no_commit_history)
binding.rvCommitHistory.visibility = View.GONE
}

is CommitHistoryUiState.Error -> {
binding.progressBar.visibility = View.GONE
binding.emptyView.visibility = View.VISIBLE
binding.emptyView.text = state.message ?: getString(R.string.unknown_error)
binding.rvCommitHistory.visibility = View.GONE
}

is CommitHistoryUiState.Success -> {
binding.progressBar.visibility = View.GONE
binding.emptyView.visibility = View.GONE
Expand All @@ -114,22 +123,9 @@ class GitCommitHistoryDialog : DialogFragment() {
}

setupPushUI()
}}
}

private fun setupPushUI() {
binding.btnPush.setOnClickListener {
val username = credentialsManager.getUsername()
val token = credentialsManager.getToken()
if (!username.isNullOrBlank() && !token.isNullOrBlank()) {
viewModel.push(username, token)
} else {
showGitCredentialsDialog(
credentialsManager = credentialsManager,
positiveButtonTextResId = R.string.push
) { user, accessToken ->
viewModel.push(user, accessToken)
}}

binding.btnPush.apply {
setOnClickListener {
val username = credentialsManager.getUsername()
Expand All @@ -139,9 +135,9 @@ class GitCommitHistoryDialog : DialogFragment() {
} else {
showGitCredentialsDialog(
credentialsManager = credentialsManager,
positiveButtonTextResId = R.string.pull
positiveButtonTextResId = R.string.push
) { user, accessToken ->
viewModel.pull(user, accessToken)
viewModel.push(user, accessToken)
}
}
}
Expand Down Expand Up @@ -169,25 +165,29 @@ class GitCommitHistoryDialog : DialogFragment() {
binding.btnPush.text = getString(R.string.push)
binding.pushProgress.visibility = View.GONE
}

is GitBottomSheetViewModel.PushUiState.Pushing -> {
binding.btnPush.isEnabled = false
binding.pushProgress.visibility = View.VISIBLE
}

is GitBottomSheetViewModel.PushUiState.Success -> {
binding.btnPush.isEnabled = true
binding.pushProgress.visibility = View.GONE
flashSuccess(R.string.push_successful)
viewModel.resetPushState()
dismiss()
}

is GitBottomSheetViewModel.PushUiState.Error -> {
binding.btnPush.isEnabled = true
binding.pushProgress.visibility = View.GONE
val message = if (state.errorResId != null && state.errorResId != R.string.unknown_error) {
getString(state.errorResId)
} else {
state.message ?: getString(R.string.unknown_error)
}
val message =
if (state.errorResId != null && state.errorResId != R.string.unknown_error) {
getString(state.errorResId)
} else {
state.message ?: getString(R.string.unknown_error)
}
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.push_failed)
.setMessage(message)
Expand All @@ -207,7 +207,8 @@ class GitCommitHistoryDialog : DialogFragment() {
}
}

}}

}

override fun onDestroyView() {
super.onDestroyView()
Expand Down
Loading