Skip to content

Commit

Permalink
fix: disallow adding repo with same name
Browse files Browse the repository at this point in the history
  • Loading branch information
ViscousPot committed Jan 16, 2025
1 parent 0ed927c commit 43a3e5b
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions app/src/main/java/com/viscouspot/gitsync/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,28 @@ class MainActivity : AppCompatActivity() {
.setTitle(getString(R.string.add_repository))
.setCancelable(1)
.setView(keyInput)
.setPositiveButton(R.string.add) { _, _ ->
val repoNames = repoManager.getRepoNames().toMutableList()
repoNames.add(input.text.toString())

repoManager.setRepoNames(repoNames)
repoManager.setRepoIndex(repoNames.indexOf(input.text.toString()))

updateRepoButtons()
refreshAll()
}
.setPositiveButton(R.string.add) { _, _ -> }
.setNegativeButton(android.R.string.cancel) { _, _ -> }
.apply {
setOnShowListener {
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener listener@{
val repoNames = repoManager.getRepoNames().toMutableList()
if (repoNames.contains(input.text.toString())) {
input.setText("${input.text}2")
return@listener
}

repoNames.add(input.text.toString())

repoManager.setRepoNames(repoNames)
repoManager.setRepoIndex(repoNames.indexOf(input.text.toString()))

updateRepoButtons()
refreshAll()
dismiss()
}
}
}
.show()
}
}
Expand Down

0 comments on commit 43a3e5b

Please sign in to comment.