Skip to content

Commit b3cdb8e

Browse files
committed
fix: merge conflict editor UX
1 parent 6dde28f commit b3cdb8e

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

app/src/main/java/com/viscouspot/gitsync/MainActivity.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,12 @@ class MainActivity : AppCompatActivity() {
643643
return@setOnClickListener
644644
}
645645

646+
merge.text = "..."
647+
merge.isEnabled = false
648+
merge.backgroundTintList = ColorStateList.valueOf(getColor(R.color.card_secondary_bg))
649+
merge.setTextColor(getColor(R.color.textSecondary))
650+
abortMerge.visibility = View.GONE
651+
646652
CoroutineScope(Dispatchers.Default).launch {
647653
val authCredentials = settingsManager.getGitAuthCredentials()
648654
if (settingsManager.getGitDirUri() == null || authCredentials.first == "" || authCredentials.second == "") return@launch
@@ -714,25 +720,20 @@ class MainActivity : AppCompatActivity() {
714720
while (reader.readLine().also { line = it } != null) {
715721
lineCount += 1
716722
when {
717-
inConflict -> {
718-
conflictBuilder.append(line).append("\n")
719-
}
720-
line!!.startsWith(getString(R.string.conflict_start)) -> {
721-
if (conflictBuilder.isNotEmpty()) {
722-
conflictSections.add(conflictBuilder.toString().trim())
723-
conflictEditorInput.adapter?.notifyItemInserted(conflictSections.size)
724-
conflictBuilder.clear()
725-
}
726-
inConflict = true
727-
conflictBuilder.append(line).append("\n")
728-
}
729723
line!!.startsWith(getString(R.string.conflict_end)) -> {
730724
conflictBuilder.append(line)
731725
conflictSections.add(conflictBuilder.toString().trim())
732726
conflictEditorInput.adapter?.notifyItemInserted(conflictSections.size)
733727
conflictBuilder.clear()
734728
inConflict = false
735729
}
730+
inConflict -> {
731+
conflictBuilder.append(line).append("\n")
732+
}
733+
line!!.startsWith(getString(R.string.conflict_start)) -> {
734+
inConflict = true
735+
conflictBuilder.append(line).append("\n")
736+
}
736737
else -> {
737738
conflictSections.add(line!!.trim())
738739
conflictEditorInput.adapter?.notifyItemInserted(conflictSections.size)

app/src/main/java/com/viscouspot/gitsync/ui/adapter/ConflictEditorAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ConflictEditorAdapter (
7070

7171
val lines = dataSet[position].split("\n")
7272
val startIndex = lines.indexOfFirst { it.contains(context.getString(R.string.conflict_start)) }
73-
val midIndex = lines.indexOfLast { it.contains(context.getString(R.string.conflict_separator)) }
73+
val midIndex = lines.indexOfFirst { it.contains(context.getString(R.string.conflict_separator)) }
7474
val endIndex = lines.indexOfLast { it.contains(context.getString(R.string.conflict_end)) }
7575

7676
val localLines = lines.subList(startIndex+1, midIndex)

app/src/main/java/com/viscouspot/gitsync/util/GitManager.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,12 @@ class GitManager(private val context: Context, private val activity: AppCompatAc
285285
remote = "origin"
286286
}
287287
if (result.mergeResult.failingPaths != null && result.mergeResult.failingPaths.containsValue(ResolveMerger.MergeFailureReason.DIRTY_WORKTREE)) {
288+
log(LogType.PullFromRepo, "Merge conflict")
288289
return false
289290
}
290291

291292
if (!result.mergeResult.mergeStatus.isSuccessful) {
293+
log(LogType.PullFromRepo, "Checkout conflict")
292294
sendCheckoutConflictNotification(context)
293295
return null
294296
}
@@ -309,6 +311,7 @@ class GitManager(private val context: Context, private val activity: AppCompatAc
309311
return false
310312
} catch (e: WrongRepositoryStateException) {
311313
if (e.message?.contains(context.getString(R.string.merging_exception_message)) == true) {
314+
log(LogType.PullFromRepo, "Merge conflict")
312315
return false
313316
}
314317
log(context, LogType.PullFromRepo, e)

0 commit comments

Comments
 (0)