feat: repo editor in extension window (#332)

* fix: error checking in repo editor

* feat: edit repos from extension page
This commit is contained in:
TwistedUmbrellaX 2024-04-07 22:27:27 -04:00 committed by GitHub
parent f96d2ffaa5
commit 29e115ce41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 253 additions and 99 deletions

View file

@ -593,71 +593,50 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
bindingExtensions = ActivitySettingsExtensionsBinding.bind(binding.root).apply {
fun setExtensionOutput() {
animeRepoInventory.removeAllViews()
PrefManager.getVal<Set<String>>(PrefName.AnimeExtensionRepos).forEach { item ->
val view = ItemRepositoryBinding.inflate(
LayoutInflater.from(animeRepoInventory.context), animeRepoInventory, true
)
view.repositoryItem.text = item.replace("https://raw.githubusercontent.com/", "")
view.repositoryItem.setOnClickListener {
AlertDialog.Builder(this@SettingsActivity, R.style.MyPopup)
.setTitle("Delete Anime Repository")
.setMessage(item)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
val anime = PrefManager.getVal<Set<String>>(PrefName.AnimeExtensionRepos).minus(item)
PrefManager.setVal(PrefName.AnimeExtensionRepos, anime)
it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
setExtensionOutput()
CoroutineScope(Dispatchers.IO).launch {
animeExtensionManager.findAvailableExtensions()
}
dialog.dismiss()
}
.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
.create()
.show()
}
view.repositoryItem.setOnLongClickListener {
copyToClipboard(item, true)
true
}
fun setExtensionOutput(repoInventory: ViewGroup, type: MediaType) {
repoInventory.removeAllViews()
val prefName: PrefName? = when (type) {
MediaType.ANIME -> { PrefName.AnimeExtensionRepos }
MediaType.MANGA -> { PrefName.MangaExtensionRepos }
else -> { null }
}
animeRepoInventory.isVisible = animeRepoInventory.childCount > 0
mangaRepoInventory.removeAllViews()
PrefManager.getVal<Set<String>>(PrefName.MangaExtensionRepos).forEach { item ->
val view = ItemRepositoryBinding.inflate(
LayoutInflater.from(mangaRepoInventory.context), mangaRepoInventory, true
)
view.repositoryItem.text = item.replace("https://raw.githubusercontent.com/", "")
view.repositoryItem.setOnClickListener {
AlertDialog.Builder(this@SettingsActivity, R.style.MyPopup)
.setTitle("Delete Manga Repository")
.setMessage(item)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
val manga = PrefManager.getVal<Set<String>>(PrefName.MangaExtensionRepos).minus(item)
PrefManager.setVal(PrefName.MangaExtensionRepos, manga)
it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
setExtensionOutput()
CoroutineScope(Dispatchers.IO).launch {
mangaExtensionManager.findAvailableExtensions()
prefName?.let { repoList ->
PrefManager.getVal<Set<String>>(repoList).forEach { item ->
val view = ItemRepositoryBinding.inflate(
LayoutInflater.from(repoInventory.context), repoInventory, true
)
view.repositoryItem.text = item.removePrefix("https://raw.githubusercontent.com")
view.repositoryItem.setOnClickListener {
AlertDialog.Builder(this@SettingsActivity, R.style.MyPopup)
.setTitle(R.string.rem_repository)
.setMessage(item)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
val repos = PrefManager.getVal<Set<String>>(repoList).minus(item)
PrefManager.setVal(repoList, repos)
setExtensionOutput(repoInventory, type)
CoroutineScope(Dispatchers.IO).launch {
when (type) {
MediaType.ANIME -> { animeExtensionManager.findAvailableExtensions() }
MediaType.MANGA -> { mangaExtensionManager.findAvailableExtensions() }
else -> { }
}
}
dialog.dismiss()
}
dialog.dismiss()
}
.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
.create()
.show()
}
view.repositoryItem.setOnLongClickListener {
copyToClipboard(item, true)
true
.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
.create()
.show()
}
view.repositoryItem.setOnLongClickListener {
it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
copyToClipboard(item, true)
true
}
}
repoInventory.isVisible = repoInventory.childCount > 0
}
mangaRepoInventory.isVisible = mangaRepoInventory.childCount > 0
}
fun processUserInput(input: String, mediaType: MediaType) {
@ -670,6 +649,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
CoroutineScope(Dispatchers.IO).launch {
animeExtensionManager.findAvailableExtensions()
}
setExtensionOutput(animeRepoInventory, MediaType.ANIME)
}
if (mediaType == MediaType.MANGA) {
val manga =
@ -678,8 +658,8 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
CoroutineScope(Dispatchers.IO).launch {
mangaExtensionManager.findAvailableExtensions()
}
setExtensionOutput(mangaRepoInventory, MediaType.MANGA)
}
setExtensionOutput()
}
fun processEditorAction(dialog: AlertDialog, editText: EditText, mediaType: MediaType) {
@ -688,15 +668,20 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
(keyEvent?.action == KeyEvent.ACTION_UP
&& keyEvent.keyCode == KeyEvent.KEYCODE_ENTER)
) {
processUserInput(textView.text.toString(), mediaType)
dialog.dismiss()
return@setOnEditorActionListener true
return@setOnEditorActionListener if (textView.text.isNullOrBlank()) {
false
} else {
processUserInput(textView.text.toString(), mediaType)
dialog.dismiss()
true
}
}
false
}
}
setExtensionOutput()
setExtensionOutput(animeRepoInventory, MediaType.ANIME)
setExtensionOutput(mangaRepoInventory, MediaType.MANGA)
animeAddRepository.setOnClickListener {
val dialogView = layoutInflater.inflate(R.layout.dialog_user_agent, null)
val editText =
@ -704,16 +689,11 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
hint = getString(R.string.anime_add_repository)
}
val alertDialog = AlertDialog.Builder(this@SettingsActivity, R.style.MyPopup)
.setTitle(R.string.add_repository)
.setMessage("Add additional repo for anime extensions")
.setTitle(R.string.anime_add_repository)
.setView(dialogView)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
processUserInput(editText.text.toString(), MediaType.ANIME)
dialog.dismiss()
}
.setNeutralButton(getString(R.string.reset)) { dialog, _ ->
PrefManager.removeVal(PrefName.DefaultUserAgent)
editText.setText("")
if (!editText.text.isNullOrBlank())
processUserInput(editText.text.toString(), MediaType.ANIME)
dialog.dismiss()
}
.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
@ -733,16 +713,11 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
hint = getString(R.string.manga_add_repository)
}
val alertDialog = AlertDialog.Builder(this@SettingsActivity, R.style.MyPopup)
.setTitle(R.string.add_repository)
.setTitle(R.string.manga_add_repository)
.setView(dialogView)
.setMessage("Add additional repo for manga extensions")
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
processUserInput(editText.text.toString(), MediaType.MANGA)
dialog.dismiss()
}
.setNeutralButton(getString(R.string.reset)) { dialog, _ ->
PrefManager.removeVal(PrefName.DefaultUserAgent)
editText.setText("")
if (!editText.text.isNullOrBlank())
processUserInput(editText.text.toString(), MediaType.MANGA)
dialog.dismiss()
}
.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->