Skip to content

Commit 43a3e5b

Browse files
committed
fix: disallow adding repo with same name
1 parent 0ed927c commit 43a3e5b

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -499,17 +499,28 @@ class MainActivity : AppCompatActivity() {
499499
.setTitle(getString(R.string.add_repository))
500500
.setCancelable(1)
501501
.setView(keyInput)
502-
.setPositiveButton(R.string.add) { _, _ ->
503-
val repoNames = repoManager.getRepoNames().toMutableList()
504-
repoNames.add(input.text.toString())
505-
506-
repoManager.setRepoNames(repoNames)
507-
repoManager.setRepoIndex(repoNames.indexOf(input.text.toString()))
508-
509-
updateRepoButtons()
510-
refreshAll()
511-
}
502+
.setPositiveButton(R.string.add) { _, _ -> }
512503
.setNegativeButton(android.R.string.cancel) { _, _ -> }
504+
.apply {
505+
setOnShowListener {
506+
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener listener@{
507+
val repoNames = repoManager.getRepoNames().toMutableList()
508+
if (repoNames.contains(input.text.toString())) {
509+
input.setText("${input.text}2")
510+
return@listener
511+
}
512+
513+
repoNames.add(input.text.toString())
514+
515+
repoManager.setRepoNames(repoNames)
516+
repoManager.setRepoIndex(repoNames.indexOf(input.text.toString()))
517+
518+
updateRepoButtons()
519+
refreshAll()
520+
dismiss()
521+
}
522+
}
523+
}
513524
.show()
514525
}
515526
}

0 commit comments

Comments
 (0)