[skip ci] feat: new settings UI

This commit is contained in:
aayush262 2024-04-17 14:35:53 +05:30
parent 91d1d2cf1d
commit cd3bb20afd
11 changed files with 170 additions and 209 deletions

View file

@ -48,7 +48,13 @@ class SettingsExtensionsActivity: AppCompatActivity() {
binding = ActivitySettingsExtensionsBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.apply {
settingsExtensionsLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = statusBarHeight
bottomMargin = navBarHeight
}
extensionSettingsBack.setOnClickListener{
onBackPressedDispatcher.onBackPressed()
}
fun setExtensionOutput(repoInventory: ViewGroup, type: MediaType) {
repoInventory.removeAllViews()
val prefName: PrefName? = when (type) {
@ -70,7 +76,7 @@ class SettingsExtensionsActivity: AppCompatActivity() {
LayoutInflater.from(repoInventory.context), repoInventory, true
)
view.repositoryItem.text =
item.removePrefix("https://raw.githubusercontent.com")
item.removePrefix("https://raw.githubusercontent.com/")
view.repositoryItem.setOnClickListener {
AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.rem_repository).setMessage(item)
@ -107,7 +113,7 @@ class SettingsExtensionsActivity: AppCompatActivity() {
}
}
fun processUserInput(input: String, mediaType: MediaType) {
fun processUserInput(input: String, mediaType: MediaType, view: ViewGroup) {
val entry =
if (input.endsWith("/") || input.endsWith("index.min.json")) input.substring(
0,
@ -120,7 +126,7 @@ class SettingsExtensionsActivity: AppCompatActivity() {
CoroutineScope(Dispatchers.IO).launch {
animeExtensionManager.findAvailableExtensions()
}
setExtensionOutput(animeRepoInventory, MediaType.ANIME)
setExtensionOutput(view, MediaType.ANIME)
}
if (mediaType == MediaType.MANGA) {
val manga =
@ -129,17 +135,17 @@ class SettingsExtensionsActivity: AppCompatActivity() {
CoroutineScope(Dispatchers.IO).launch {
mangaExtensionManager.findAvailableExtensions()
}
setExtensionOutput(mangaRepoInventory, MediaType.MANGA)
setExtensionOutput(view, MediaType.MANGA)
}
}
fun processEditorAction(dialog: AlertDialog, editText: EditText, mediaType: MediaType) {
fun processEditorAction(dialog: AlertDialog, editText: EditText, mediaType: MediaType, view: ViewGroup) {
editText.setOnEditorActionListener { textView, action, keyEvent ->
if (action == EditorInfo.IME_ACTION_SEARCH || action == EditorInfo.IME_ACTION_DONE || (keyEvent?.action == KeyEvent.ACTION_UP && keyEvent.keyCode == KeyEvent.KEYCODE_ENTER)) {
return@setOnEditorActionListener if (textView.text.isNullOrBlank()) {
false
} else {
processUserInput(textView.text.toString(), mediaType)
processUserInput(textView.text.toString(), mediaType, view)
dialog.dismiss()
true
}
@ -147,131 +153,141 @@ class SettingsExtensionsActivity: AppCompatActivity() {
false
}
}
settingsExtensionsLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = statusBarHeight
bottomMargin = navBarHeight
}
extensionSettingsBack.setOnClickListener{
onBackPressedDispatcher.onBackPressed()
}
setExtensionOutput(animeRepoInventory, MediaType.ANIME)
setExtensionOutput(mangaRepoInventory, MediaType.MANGA)
animeAddRepository.setOnClickListener {
val dialogView = layoutInflater.inflate(R.layout.dialog_user_agent, null)
val editText =
dialogView.findViewById<TextInputEditText>(R.id.userAgentTextBox).apply {
hint = getString(R.string.anime_add_repository)
}
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.anime_add_repository).setView(dialogView)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
if (!editText.text.isNullOrBlank()) processUserInput(
editText.text.toString(),
MediaType.ANIME
)
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create()
settingsRecyclerView.adapter = SettingsAdapter(
arrayListOf(
Settings(
type = 1,
name = getString(R.string.anime_add_repository),
desc = getString(R.string.anime_add_repository),
icon = R.drawable.ic_github,
onClick = {
val dialogView = layoutInflater.inflate(R.layout.dialog_user_agent, null)
val editText =
dialogView.findViewById<TextInputEditText>(R.id.userAgentTextBox).apply {
hint = getString(R.string.anime_add_repository)
}
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.anime_add_repository).setView(dialogView)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
if (!editText.text.isNullOrBlank()) processUserInput(
editText.text.toString(),
MediaType.ANIME,
it.attachView
)
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create()
processEditorAction(alertDialog, editText, MediaType.ANIME)
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
}
mangaAddRepository.setOnClickListener {
val dialogView = layoutInflater.inflate(R.layout.dialog_user_agent, null)
val editText =
dialogView.findViewById<TextInputEditText>(R.id.userAgentTextBox).apply {
hint = getString(R.string.manga_add_repository)
}
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.manga_add_repository).setView(dialogView)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
if (!editText.text.isNullOrBlank()) processUserInput(
editText.text.toString(),
MediaType.MANGA
)
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create()
processEditorAction(alertDialog, editText, MediaType.MANGA)
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
}
}
binding.settingsRecyclerView.adapter = SettingsAdapter(
arrayListOf(
Settings(
type = 1,
name = getString(R.string.user_agent),
desc = getString(R.string.NSFWExtention),
icon = R.drawable.ic_round_video_settings_24,
onClick = {
val dialogView = DialogUserAgentBinding.inflate(layoutInflater)
val editText = dialogView.userAgentTextBox
editText.setText(PrefManager.getVal<String>(PrefName.DefaultUserAgent))
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.user_agent).setView(dialogView.root)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
PrefManager.setVal(PrefName.DefaultUserAgent, editText.text.toString())
dialog.dismiss()
}.setNeutralButton(getString(R.string.reset)) { dialog, _ ->
PrefManager.removeVal(PrefName.DefaultUserAgent)
editText.setText("")
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create()
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
}
),
Settings(
type = 2,
name = getString(R.string.force_legacy_installer),
desc = getString(R.string.force_legacy_installer),
icon = R.drawable.ic_round_new_releases_24,
isChecked = extensionInstaller.get() == BasePreferences.ExtensionInstaller.LEGACY,
switch = { isChecked, _ ->
if (isChecked) {
extensionInstaller.set(BasePreferences.ExtensionInstaller.LEGACY)
} else {
extensionInstaller.set(BasePreferences.ExtensionInstaller.PACKAGEINSTALLER)
processEditorAction(alertDialog, editText, MediaType.ANIME, it.attachView)
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
},
attach = { view ->
setExtensionOutput(view, MediaType.ANIME)
}
}
),
Settings(
type = 1,
name = getString(R.string.manga_add_repository),
desc = getString(R.string.manga_add_repository),
icon = R.drawable.ic_github,
onClick = {
val dialogView = layoutInflater.inflate(R.layout.dialog_user_agent, null)
val editText =
dialogView.findViewById<TextInputEditText>(R.id.userAgentTextBox).apply {
hint = getString(R.string.manga_add_repository)
}
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.manga_add_repository).setView(dialogView)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
if (!editText.text.isNullOrBlank()) processUserInput(
editText.text.toString(),
MediaType.MANGA,
it.attachView
)
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create()
),
Settings(
type = 2,
name = getString(R.string.skip_loading_extension_icons),
desc = getString(R.string.skip_loading_extension_icons),
icon = R.drawable.ic_round_no_icon_24,
isChecked = PrefManager.getVal(PrefName.SkipExtensionIcons),
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.SkipExtensionIcons, isChecked)
}
),
Settings(
type = 2,
name = getString(R.string.NSFWExtention),
desc = getString(R.string.NSFWExtention),
icon = R.drawable.ic_round_nsfw_24,
isChecked = PrefManager.getVal(PrefName.NSFWExtension),
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.NSFWExtension, isChecked)
}
processEditorAction(alertDialog, editText, MediaType.MANGA, it.attachView)
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
},
attach = { view ->
setExtensionOutput(view, MediaType.MANGA)
}
),
Settings(
type = 1,
name = getString(R.string.user_agent),
desc = getString(R.string.NSFWExtention),
icon = R.drawable.ic_round_video_settings_24,
onClick = {
val dialogView = DialogUserAgentBinding.inflate(layoutInflater)
val editText = dialogView.userAgentTextBox
editText.setText(PrefManager.getVal<String>(PrefName.DefaultUserAgent))
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.user_agent).setView(dialogView.root)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
PrefManager.setVal(PrefName.DefaultUserAgent, editText.text.toString())
dialog.dismiss()
}.setNeutralButton(getString(R.string.reset)) { dialog, _ ->
PrefManager.removeVal(PrefName.DefaultUserAgent)
editText.setText("")
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create()
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
}
),
Settings(
type = 2,
name = getString(R.string.force_legacy_installer),
desc = getString(R.string.force_legacy_installer),
icon = R.drawable.ic_round_new_releases_24,
isChecked = extensionInstaller.get() == BasePreferences.ExtensionInstaller.LEGACY,
switch = { isChecked, _ ->
if (isChecked) {
extensionInstaller.set(BasePreferences.ExtensionInstaller.LEGACY)
} else {
extensionInstaller.set(BasePreferences.ExtensionInstaller.PACKAGEINSTALLER)
}
}
),
Settings(
type = 2,
name = getString(R.string.skip_loading_extension_icons),
desc = getString(R.string.skip_loading_extension_icons),
icon = R.drawable.ic_round_no_icon_24,
isChecked = PrefManager.getVal(PrefName.SkipExtensionIcons),
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.SkipExtensionIcons, isChecked)
}
),
Settings(
type = 2,
name = getString(R.string.NSFWExtention),
desc = getString(R.string.NSFWExtention),
icon = R.drawable.ic_round_nsfw_24,
isChecked = PrefManager.getVal(PrefName.NSFWExtension),
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.NSFWExtension, isChecked)
}
)
)
)
)
binding.settingsRecyclerView.apply {
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
setHasFixedSize(true)
settingsRecyclerView.apply {
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
setHasFixedSize(true)
}
}
}
}