-
-
Notifications
You must be signed in to change notification settings - Fork 24
ADFA-2880: Git commit operations #1074
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
3efacae
feat(ADFA-2880): Commit changes
dara-abijo-adfa 432b2d5
feat(ADFA-2880): View git commit history
dara-abijo-adfa a9f43ef
Merge branch 'stage' into ADFA-2880-git-commit
dara-abijo-adfa 11c78bb
Merge branch 'stage' into ADFA-2880-git-commit-operations
dara-abijo-adfa 7c3965c
Merge branch 'stage' into ADFA-2880-git-commit-operations
dara-abijo-adfa 84fb63a
feat(ADFA-2880): Set up git preferences
dara-abijo-adfa 9238949
feat(ADFA-2880): Set commit author
dara-abijo-adfa 3712a0c
feat(ADFA-2880): Show commits that have not been pushed
dara-abijo-adfa 561c233
fix(ADFA-2880): Update view id
dara-abijo-adfa 020432d
Merge branch 'stage' into ADFA-2880-git-commit-operations
dara-abijo-adfa 26c26ee
refactor(ADFA-2880): Extract string resource
dara-abijo-adfa b5f4e2d
feat(ADFA-2880): Handle commit history errors
dara-abijo-adfa c70eaf1
fic(ADFA-2880): Clear inputs after commit succeeds
dara-abijo-adfa edc90aa
fix(ADFA-2880): Resolve issue with showing author error message prema…
dara-abijo-adfa 29e7f34
feat(ADFA-2880): Show git author identity values
dara-abijo-adfa 7fcd137
fix(ADFA-2880): Prevent memory leaks
dara-abijo-adfa 30dd707
fix(ADFA-2880): Verify clone success before state update
dara-abijo-adfa 4847480
Merge branch 'stage' into ADFA-2880-git-commit-operations
dara-abijo-adfa 4b5f63e
Merge branch 'stage' into ADFA-2880-git-commit-operations
dara-abijo-adfa a976a09
feat(ADFA-2880): Differentiate no repo from no commits
dara-abijo-adfa 6f42415
fix(ADFA-2880): Fix race condition
dara-abijo-adfa 0f2d9a5
Merge branch 'stage' into ADFA-2880-git-commit-operations
dara-abijo-adfa 5d4c206
feat(ADFA-2880): Colour-code local and remote commits
dara-abijo-adfa 87b3f61
refactor(ADFA-2880): Move strings to resources module
dara-abijo-adfa 7d01a8a
Merge branch 'stage' into ADFA-2880-git-commit-operations
dara-abijo-adfa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/itsaky/androidide/fragments/git/GitCommitHistoryDialog.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package com.itsaky.androidide.fragments.git | ||
|
|
||
| import android.os.Bundle | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import androidx.fragment.app.DialogFragment | ||
| import androidx.fragment.app.activityViewModels | ||
| import androidx.lifecycle.lifecycleScope | ||
| import androidx.recyclerview.widget.DividerItemDecoration | ||
| import androidx.recyclerview.widget.LinearLayoutManager | ||
| import com.itsaky.androidide.R | ||
| import com.itsaky.androidide.databinding.DialogGitCommitHistoryBinding | ||
| import com.itsaky.androidide.fragments.git.adapter.GitCommitHistoryAdapter | ||
| import com.itsaky.androidide.git.core.models.CommitHistoryUiState | ||
| import com.itsaky.androidide.viewmodel.GitBottomSheetViewModel | ||
| import kotlinx.coroutines.flow.collectLatest | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| class GitCommitHistoryDialog : DialogFragment() { | ||
|
|
||
| private var _binding: DialogGitCommitHistoryBinding? = null | ||
| private val binding get() = _binding!! | ||
| private val viewModel: GitBottomSheetViewModel by activityViewModels() | ||
| private lateinit var commitHistoryAdapter: GitCommitHistoryAdapter | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setStyle(STYLE_NORMAL, R.style.Theme_AndroidIDE) | ||
| } | ||
|
|
||
| override fun onCreateView( | ||
| inflater: LayoutInflater, | ||
| container: ViewGroup?, | ||
| savedInstanceState: Bundle? | ||
| ): View { | ||
| _binding = DialogGitCommitHistoryBinding.inflate(inflater, container, false) | ||
| return binding.root | ||
| } | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
| commitHistoryAdapter = GitCommitHistoryAdapter() | ||
| val linearLayoutManager = LinearLayoutManager(requireContext()) | ||
| val dividerItemDecoration = DividerItemDecoration( | ||
| binding.rvCommitHistory.context, | ||
| linearLayoutManager.orientation | ||
| ) | ||
| binding.rvCommitHistory.apply { | ||
| layoutManager = linearLayoutManager | ||
| addItemDecoration(dividerItemDecoration) | ||
| adapter = commitHistoryAdapter | ||
| } | ||
|
|
||
| viewModel.getCommitHistoryList() | ||
|
|
||
| viewLifecycleOwner.lifecycleScope.launch { | ||
| viewModel.commitHistory.collectLatest { state -> | ||
| when (state) { | ||
| is CommitHistoryUiState.Loading -> { | ||
| binding.progressBar.visibility = View.VISIBLE | ||
| 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 | ||
| binding.rvCommitHistory.visibility = View.VISIBLE | ||
| commitHistoryAdapter.submitList(state.commits) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun onDestroyView() { | ||
| super.onDestroyView() | ||
| _binding = null | ||
| } | ||
|
|
||
| } |
61 changes: 61 additions & 0 deletions
61
app/src/main/java/com/itsaky/androidide/fragments/git/adapter/GitCommitHistoryAdapter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package com.itsaky.androidide.fragments.git.adapter | ||
|
|
||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import androidx.recyclerview.widget.DiffUtil | ||
| import androidx.recyclerview.widget.ListAdapter | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.itsaky.androidide.R | ||
| import com.itsaky.androidide.databinding.ItemGitCommitBinding | ||
| import com.itsaky.androidide.git.core.models.GitCommit | ||
| import java.text.SimpleDateFormat | ||
| import java.util.Date | ||
| import java.util.Locale | ||
|
|
||
| class GitCommitHistoryAdapter : | ||
| ListAdapter<GitCommit, GitCommitHistoryAdapter.ViewHolder>(DiffCallback()) { | ||
|
|
||
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
| val binding = ItemGitCommitBinding.inflate( | ||
| LayoutInflater.from(parent.context), parent, false | ||
| ) | ||
| return ViewHolder(binding) | ||
| } | ||
|
|
||
| override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
| val commit = getItem(position) | ||
| holder.bind(commit) | ||
| } | ||
|
|
||
| class ViewHolder(private val binding: ItemGitCommitBinding) : | ||
| RecyclerView.ViewHolder(binding.root) { | ||
|
|
||
| private val dateFormat = SimpleDateFormat("dd MMM yyyy, HH:mm", Locale.getDefault()) | ||
|
|
||
| fun bind(commit: GitCommit) { | ||
| binding.apply { | ||
| tvCommitMessage.text = commit.message | ||
| tvCommitAuthor.text = commit.authorName | ||
| tvCommitTime.text = dateFormat.format(Date(commit.timestamp)) | ||
| imgNotPushedCommit.setImageResource(if (commit.hasBeenPushed) R.drawable.ic_cloud_done else R.drawable.ic_upload) | ||
| imgNotPushedCommit.contentDescription = if (commit.hasBeenPushed) { | ||
| binding.root.context.getString(R.string.commit_pushed) | ||
| } else { | ||
| binding.root.context.getString(R.string.commit_not_pushed) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class DiffCallback : DiffUtil.ItemCallback<GitCommit>() { | ||
| override fun areItemsTheSame(oldItem: GitCommit, newItem: GitCommit): Boolean { | ||
| return oldItem.hash == newItem.hash | ||
| } | ||
|
|
||
| override fun areContentsTheSame(oldItem: GitCommit, newItem: GitCommit): Boolean { | ||
| return oldItem == newItem | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.