feat: optimize Alert Dialogs

This commit is contained in:
aayush262 2024-06-13 19:15:55 +05:30
parent 1670383619
commit 124c8f5ed7
31 changed files with 739 additions and 837 deletions

View file

@ -35,6 +35,7 @@ import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.util.customAlertDialog
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
@ -178,25 +179,20 @@ class ExtensionsActivity : AppCompatActivity() {
entry.name.lowercase().replace("_", " ")
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() }
}.toTypedArray()
val builder = AlertDialog.Builder(this, R.style.MyPopup)
val listOrder: String = PrefManager.getVal(PrefName.LangSort)
val index = LanguageMapper.Companion.Language.entries.toTypedArray()
.indexOfFirst { it.code == listOrder }
builder.setTitle("Language")
builder.setSingleChoiceItems(languageOptions, index) { dialog, i ->
PrefManager.setVal(
PrefName.LangSort,
LanguageMapper.Companion.Language.entries[i].code
)
val currentFragment =
supportFragmentManager.findFragmentByTag("f${viewPager.currentItem}")
if (currentFragment is SearchQueryHandler) {
currentFragment.notifyDataChanged()
customAlertDialog().apply {
setTitle("Language")
singleChoiceItems(languageOptions, index) { selected ->
PrefManager.setVal(PrefName.LangSort, LanguageMapper.Companion.Language.entries[selected].code)
val currentFragment = supportFragmentManager.findFragmentByTag("f${viewPager.currentItem}")
if (currentFragment is SearchQueryHandler) {
currentFragment.notifyDataChanged()
}
}
dialog.dismiss()
show()
}
val dialog = builder.show()
dialog.window?.setDimAmount(0.8f)
}
binding.settingsContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = statusBarHeight
@ -247,10 +243,10 @@ class ExtensionsActivity : AppCompatActivity() {
)
view.repositoryItem.text = item.removePrefix("https://raw.githubusercontent.com")
view.repositoryItem.setOnClickListener {
AlertDialog.Builder(this@ExtensionsActivity, R.style.MyPopup)
.setTitle(R.string.rem_repository)
.setMessage(item)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
customAlertDialog().apply {
setTitle(R.string.rem_repository)
setMessage(item)
setPosButton(R.string.ok) {
val repos = PrefManager.getVal<Set<String>>(prefName).minus(item)
PrefManager.setVal(prefName, repos)
repoInventory.removeView(view.root)
@ -267,13 +263,10 @@ class ExtensionsActivity : AppCompatActivity() {
else -> {}
}
}
dialog.dismiss()
}
.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
.create()
.show()
setNegButton(R.string.cancel)
show()
}
}
view.repositoryItem.setOnLongClickListener {
it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
@ -324,20 +317,18 @@ class ExtensionsActivity : AppCompatActivity() {
dialogView.repoInventory.apply {
getSavedRepositories(this, type)
}
val alertDialog = AlertDialog.Builder(this@ExtensionsActivity, R.style.MyPopup)
.setTitle(R.string.edit_repositories)
.setView(dialogView.root)
.setPositiveButton(getString(R.string.add)) { _, _ ->
if (!dialogView.repositoryTextBox.text.isNullOrBlank())
processUserInput(dialogView.repositoryTextBox.text.toString(), type)
}
.setNegativeButton(getString(R.string.close)) { dialog, _ ->
dialog.dismiss()
}
.create()
processEditorAction(dialogView.repositoryTextBox, type)
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
customAlertDialog().apply {
setTitle(R.string.edit_repositories)
setCustomView(dialogView.root)
setPosButton(R.string.add) {
if (!dialogView.repositoryTextBox.text.isNullOrBlank()) {
processUserInput(dialogView.repositoryTextBox.text.toString(), type)
}
}
setNegButton(R.string.close)
show()
}
}
}
}

View file

@ -25,13 +25,15 @@ import androidx.viewpager2.widget.ViewPager2
import ani.dantotsu.R
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.databinding.FragmentExtensionsBinding
import ani.dantotsu.others.LanguageMapper
import ani.dantotsu.others.LanguageMapper.Companion.getLanguageName
import ani.dantotsu.parsers.AnimeSources
import ani.dantotsu.settings.extensionprefs.AnimeSourcePreferencesFragment
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.snackString
import ani.dantotsu.util.Logger
import ani.dantotsu.util.customAlertDialog
import com.google.android.material.tabs.TabLayout
import com.google.android.material.textfield.TextInputLayout
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
@ -72,16 +74,15 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
if (allSettings.isNotEmpty()) {
var selectedSetting = allSettings[0]
if (allSettings.size > 1) {
val names = allSettings.map { LanguageMapper.getLanguageName(it.lang) }
val names = allSettings.map { getLanguageName(it.lang) }
.toTypedArray()
var selectedIndex = 0
val dialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
.setTitle("Select a Source")
.setSingleChoiceItems(names, selectedIndex) { dialog, which ->
requireContext().customAlertDialog().apply {
setTitle("Select a Source")
singleChoiceItems(names, selectedIndex) { which ->
itemSelected = true
selectedIndex = which
selectedSetting = allSettings[selectedIndex]
dialog.dismiss()
val fragment =
AnimeSourcePreferencesFragment().getInstance(selectedSetting.id) {
@ -93,13 +94,13 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
.addToBackStack(null)
.commit()
}
.setOnDismissListener {
onDismiss {
if (!itemSelected) {
changeUIVisibility(true)
}
}
.show()
dialog.window?.setDimAmount(0.8f)
show()
}
} else {
// If there's only one setting, proceed with the fragment transaction
val fragment =
@ -295,7 +296,7 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val extension = getItem(position)
val nsfw = if (extension.isNsfw) "(18+)" else ""
val lang = LanguageMapper.getLanguageName(extension.lang)
val lang = getLanguageName(extension.lang)
holder.extensionNameTextView.text = extension.name
val versionText = "$lang ${extension.versionName} $nsfw"
holder.extensionVersionTextView.text = versionText

View file

@ -34,6 +34,7 @@ import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.snackString
import ani.dantotsu.util.Logger
import ani.dantotsu.util.customAlertDialog
import com.google.android.material.tabs.TabLayout
import com.google.android.material.textfield.TextInputLayout
import eu.kanade.tachiyomi.data.notification.Notifications
@ -74,13 +75,12 @@ class InstalledMangaExtensionsFragment : Fragment(), SearchQueryHandler {
val names = allSettings.map { LanguageMapper.getLanguageName(it.lang) }
.toTypedArray()
var selectedIndex = 0
val dialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
.setTitle("Select a Source")
.setSingleChoiceItems(names, selectedIndex) { dialog, which ->
requireContext().customAlertDialog().apply {
setTitle("Select a Source")
singleChoiceItems(names, selectedIndex) { which ->
itemSelected = true
selectedIndex = which
selectedSetting = allSettings[selectedIndex]
dialog.dismiss()
// Move the fragment transaction here
val fragment =
@ -93,13 +93,13 @@ class InstalledMangaExtensionsFragment : Fragment(), SearchQueryHandler {
.addToBackStack(null)
.commit()
}
.setOnDismissListener {
onDismiss {
if (!itemSelected) {
changeUIVisibility(true)
}
}
.show()
dialog.window?.setDimAmount(0.8f)
show()
}
} else {
// If there's only one setting, proceed with the fragment transaction
val fragment =

View file

@ -28,6 +28,7 @@ import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.toast
import ani.dantotsu.util.customAlertDialog
import com.google.android.material.slider.Slider.OnChangeListener
import kotlin.math.roundToInt
@ -100,20 +101,19 @@ class PlayerSettingsActivity : AppCompatActivity() {
R.string.default_playback_speed,
speedsName[PrefManager.getVal(PrefName.DefaultSpeed)]
)
val speedDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.default_speed))
binding.playerSettingsSpeed.setOnClickListener {
val dialog =
speedDialog.setSingleChoiceItems(
customAlertDialog().apply {
setTitle(getString(R.string.default_speed))
singleChoiceItems(
speedsName,
PrefManager.getVal(PrefName.DefaultSpeed)
) { dialog, i ->
) { i ->
PrefManager.setVal(PrefName.DefaultSpeed, i)
binding.playerSettingsSpeed.text =
getString(R.string.default_playback_speed, speedsName[i])
dialog.dismiss()
}.show()
dialog.window?.setDimAmount(0.8f)
}
show()
}
}
binding.playerSettingsCursedSpeeds.isChecked = PrefManager.getVal(PrefName.CursedSpeeds)
@ -278,17 +278,17 @@ class PlayerSettingsActivity : AppCompatActivity() {
}
val resizeModes = arrayOf("Original", "Zoom", "Stretch")
val resizeDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.default_resize_mode))
binding.playerResizeMode.setOnClickListener {
val dialog = resizeDialog.setSingleChoiceItems(
resizeModes,
PrefManager.getVal<Int>(PrefName.Resize)
) { dialog, count ->
PrefManager.setVal(PrefName.Resize, count)
dialog.dismiss()
}.show()
dialog.window?.setDimAmount(0.8f)
customAlertDialog().apply {
setTitle(getString(R.string.default_resize_mode))
singleChoiceItems(
resizeModes,
PrefManager.getVal<Int>(PrefName.Resize)
) { count ->
PrefManager.setVal(PrefName.Resize, count)
}
show()
}
}
fun toggleSubOptions(isChecked: Boolean) {
@ -332,18 +332,18 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Blue",
"Magenta"
)
val primaryColorDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.primary_sub_color))
binding.videoSubColorPrimary.setOnClickListener {
val dialog = primaryColorDialog.setSingleChoiceItems(
colorsPrimary,
PrefManager.getVal(PrefName.PrimaryColor)
) { dialog, count ->
PrefManager.setVal(PrefName.PrimaryColor, count)
dialog.dismiss()
updateSubPreview()
}.show()
dialog.window?.setDimAmount(0.8f)
customAlertDialog().apply {
setTitle(getString(R.string.primary_sub_color))
singleChoiceItems(
colorsPrimary,
PrefManager.getVal(PrefName.PrimaryColor)
) { count ->
PrefManager.setVal(PrefName.PrimaryColor, count)
updateSubPreview()
}
show()
}
}
val colorsSecondary = arrayOf(
"Black",
@ -359,32 +359,32 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Magenta",
"Transparent"
)
val secondaryColorDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.outline_sub_color))
binding.videoSubColorSecondary.setOnClickListener {
val dialog = secondaryColorDialog.setSingleChoiceItems(
colorsSecondary,
PrefManager.getVal(PrefName.SecondaryColor)
) { dialog, count ->
PrefManager.setVal(PrefName.SecondaryColor, count)
dialog.dismiss()
updateSubPreview()
}.show()
dialog.window?.setDimAmount(0.8f)
customAlertDialog().apply {
setTitle(getString(R.string.outline_sub_color))
singleChoiceItems(
colorsSecondary,
PrefManager.getVal(PrefName.SecondaryColor)
) { count ->
PrefManager.setVal(PrefName.SecondaryColor, count)
updateSubPreview()
}
show()
}
}
val typesOutline = arrayOf("Outline", "Shine", "Drop Shadow", "None")
val outlineDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.outline_type))
binding.videoSubOutline.setOnClickListener {
val dialog = outlineDialog.setSingleChoiceItems(
typesOutline,
PrefManager.getVal(PrefName.Outline)
) { dialog, count ->
PrefManager.setVal(PrefName.Outline, count)
dialog.dismiss()
updateSubPreview()
}.show()
dialog.window?.setDimAmount(0.8f)
customAlertDialog().apply {
setTitle(getString(R.string.outline_type))
singleChoiceItems(
typesOutline,
PrefManager.getVal(PrefName.Outline)
) { count ->
PrefManager.setVal(PrefName.Outline, count)
updateSubPreview()
}
show()
}
}
val colorsSubBackground = arrayOf(
"Transparent",
@ -400,18 +400,18 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Blue",
"Magenta"
)
val subBackgroundDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.sub_background_color_select))
binding.videoSubColorBackground.setOnClickListener {
val dialog = subBackgroundDialog.setSingleChoiceItems(
colorsSubBackground,
PrefManager.getVal(PrefName.SubBackground)
) { dialog, count ->
PrefManager.setVal(PrefName.SubBackground, count)
dialog.dismiss()
updateSubPreview()
}.show()
dialog.window?.setDimAmount(0.8f)
customAlertDialog().apply {
setTitle(getString(R.string.sub_background_color_select))
singleChoiceItems(
colorsSubBackground,
PrefManager.getVal(PrefName.SubBackground)
) { count ->
PrefManager.setVal(PrefName.SubBackground, count)
updateSubPreview()
}
show()
}
}
val colorsSubWindow = arrayOf(
@ -428,18 +428,18 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Blue",
"Magenta"
)
val subWindowDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.sub_window_color_select))
binding.videoSubColorWindow.setOnClickListener {
val dialog = subWindowDialog.setSingleChoiceItems(
colorsSubWindow,
PrefManager.getVal(PrefName.SubWindow)
) { dialog, count ->
PrefManager.setVal(PrefName.SubWindow, count)
dialog.dismiss()
updateSubPreview()
}.show()
dialog.window?.setDimAmount(0.8f)
customAlertDialog().apply {
setTitle(getString(R.string.sub_window_color_select))
singleChoiceItems(
colorsSubWindow,
PrefManager.getVal(PrefName.SubWindow)
) { count ->
PrefManager.setVal(PrefName.SubWindow, count)
updateSubPreview()
}
show()
}
}
binding.videoSubAlpha.value = PrefManager.getVal(PrefName.SubAlpha)
@ -459,18 +459,18 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Levenim MT Bold",
"Blocky"
)
val fontDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.subtitle_font))
binding.videoSubFont.setOnClickListener {
val dialog = fontDialog.setSingleChoiceItems(
fonts,
PrefManager.getVal(PrefName.Font)
) { dialog, count ->
PrefManager.setVal(PrefName.Font, count)
dialog.dismiss()
updateSubPreview()
}.show()
dialog.window?.setDimAmount(0.8f)
customAlertDialog().apply {
setTitle(getString(R.string.subtitle_font))
singleChoiceItems(
fonts,
PrefManager.getVal(PrefName.Font)
) { count ->
PrefManager.setVal(PrefName.Font, count)
updateSubPreview()
}
show()
}
}
binding.subtitleFontSize.setText(PrefManager.getVal<Int>(PrefName.FontSize).toString())
binding.subtitleFontSize.setOnEditorActionListener { _, actionId, _ ->

View file

@ -20,6 +20,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.R
import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.databinding.ActivitySettingsCommonBinding
import ani.dantotsu.databinding.DialogSetPasswordBinding
import ani.dantotsu.databinding.DialogUserAgentBinding
import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.initActivity
@ -37,6 +38,7 @@ import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.toast
import ani.dantotsu.util.LauncherWrapper
import ani.dantotsu.util.StoragePermissions
import ani.dantotsu.util.customAlertDialog
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
@ -160,18 +162,16 @@ class SettingsCommonActivity : AppCompatActivity() {
icon = R.drawable.ic_download_24,
onClick = {
val managers = arrayOf("Default", "1DM", "ADM")
val downloadManagerDialog =
AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.download_manager)
var downloadManager: Int = PrefManager.getVal(PrefName.DownloadManager)
val dialog = downloadManagerDialog.setSingleChoiceItems(
managers, downloadManager
) { dialog, count ->
downloadManager = count
PrefManager.setVal(PrefName.DownloadManager, downloadManager)
dialog.dismiss()
}.show()
dialog.window?.setDimAmount(0.8f)
customAlertDialog().apply {
setTitle(getString(R.string.download_manager))
singleChoiceItems(
managers,
PrefManager.getVal(PrefName.DownloadManager)
) { count ->
PrefManager.setVal(PrefName.DownloadManager, count)
}
show()
}
}
),
Settings(
@ -180,90 +180,67 @@ class SettingsCommonActivity : AppCompatActivity() {
desc = getString(R.string.app_lock_desc),
icon = R.drawable.ic_round_lock_open_24,
onClick = {
val passwordDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.app_lock)
.setView(R.layout.dialog_set_password)
.setPositiveButton(R.string.ok) { dialog, _ ->
val passwordInput =
(dialog as AlertDialog).findViewById<EditText>(R.id.passwordInput)
val confirmPasswordInput =
dialog.findViewById<EditText>(R.id.confirmPasswordInput)
val forgotPasswordCheckbox =
dialog.findViewById<CheckBox>(R.id.forgotPasswordCheckbox)
if (forgotPasswordCheckbox?.isChecked == true) {
customAlertDialog().apply {
val view = DialogSetPasswordBinding.inflate(layoutInflater)
setTitle(R.string.app_lock)
setCustomView(view.root)
setPosButton(R.string.ok) {
if (view.forgotPasswordCheckbox.isChecked) {
PrefManager.setVal(PrefName.OverridePassword, true)
}
val password = passwordInput?.text.toString()
val confirmPassword = confirmPasswordInput?.text.toString()
val password = view.passwordInput.text.toString()
val confirmPassword = view.confirmPasswordInput.text.toString()
if (password == confirmPassword && password.isNotEmpty()) {
PrefManager.setVal(PrefName.AppPassword, password)
if (dialog.findViewById<CheckBox>(R.id.biometricCheckbox)?.isChecked == true) {
if (view.biometricCheckbox.isChecked) {
val canBiometricPrompt =
BiometricManager.from(applicationContext)
.canAuthenticate(
BiometricManager.Authenticators.BIOMETRIC_WEAK
) == BiometricManager.BIOMETRIC_SUCCESS
.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK) == BiometricManager.BIOMETRIC_SUCCESS
if (canBiometricPrompt) {
val biometricPrompt =
BiometricPromptUtils.createBiometricPrompt(
this@SettingsCommonActivity
) { _ ->
BiometricPromptUtils.createBiometricPrompt(this@SettingsCommonActivity) { _ ->
val token = UUID.randomUUID().toString()
PrefManager.setVal(
PrefName.BiometricToken,
token
)
toast(R.string.success)
dialog.dismiss()
}
val promptInfo =
BiometricPromptUtils.createPromptInfo(
this@SettingsCommonActivity
)
BiometricPromptUtils.createPromptInfo(this@SettingsCommonActivity)
biometricPrompt.authenticate(promptInfo)
}
} else {
PrefManager.setVal(PrefName.BiometricToken, "")
toast(R.string.success)
dialog.dismiss()
}
} else {
toast(R.string.password_mismatch)
}
}
.setNegativeButton(R.string.cancel) { dialog, _ ->
dialog.dismiss()
}
.setNeutralButton(R.string.remove) { dialog, _ ->
setNegButton(R.string.cancel)
setNeutralButton(R.string.remove){
PrefManager.setVal(PrefName.AppPassword, "")
PrefManager.setVal(PrefName.BiometricToken, "")
PrefManager.setVal(PrefName.OverridePassword, false)
toast(R.string.success)
dialog.dismiss()
}
.create()
passwordDialog.window?.setDimAmount(0.8f)
passwordDialog.setOnShowListener {
passwordDialog.findViewById<EditText>(R.id.passwordInput)
?.requestFocus()
val biometricCheckbox =
passwordDialog.findViewById<CheckBox>(R.id.biometricCheckbox)
val forgotPasswordCheckbox =
passwordDialog.findViewById<CheckBox>(R.id.forgotPasswordCheckbox)
val canAuthenticate =
BiometricManager.from(applicationContext).canAuthenticate(
BiometricManager.Authenticators.BIOMETRIC_WEAK
) == BiometricManager.BIOMETRIC_SUCCESS
biometricCheckbox?.isVisible = canAuthenticate
biometricCheckbox?.isChecked =
PrefManager.getVal(PrefName.BiometricToken, "").isNotEmpty()
forgotPasswordCheckbox?.isChecked =
PrefManager.getVal(PrefName.OverridePassword)
setOnShowListener {
view.passwordInput.requestFocus()
val canAuthenticate =
BiometricManager.from(applicationContext).canAuthenticate(
BiometricManager.Authenticators.BIOMETRIC_WEAK
) == BiometricManager.BIOMETRIC_SUCCESS
view.biometricCheckbox.isVisible = canAuthenticate
view.biometricCheckbox.isChecked =
PrefManager.getVal(PrefName.BiometricToken, "").isNotEmpty()
view.forgotPasswordCheckbox.isChecked =
PrefManager.getVal(PrefName.OverridePassword)
}
show()
}
passwordDialog.show()
}
),

View file

@ -81,11 +81,11 @@ class SettingsExtensionsActivity : AppCompatActivity() {
view.repositoryItem.text =
item.removePrefix("https://raw.githubusercontent.com/")
view.repositoryItem.setOnClickListener {
AlertDialog.Builder(context, 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)
context.customAlertDialog().apply {
setTitle(R.string.rem_repository)
setMessage(item)
setPosButton(R.string.ok) {
val repos = PrefManager.getVal<Set<String>>(repoList).minus(item)
PrefManager.setVal(repoList, repos)
setExtensionOutput(repoInventory, type)
CoroutineScope(Dispatchers.IO).launch {
@ -93,18 +93,16 @@ class SettingsExtensionsActivity : AppCompatActivity() {
MediaType.ANIME -> {
animeExtensionManager.findAvailableExtensions()
}
MediaType.MANGA -> {
mangaExtensionManager.findAvailableExtensions()
}
else -> {}
}
}
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create().show()
}
setNegButton(R.string.cancel)
show()
}
}
view.repositoryItem.setOnLongClickListener {
it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
@ -209,27 +207,27 @@ class SettingsExtensionsActivity : AppCompatActivity() {
val editText = dialogView.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.root)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
context.customAlertDialog().apply {
setTitle(R.string.manga_add_repository)
setCustomView(dialogView.root)
setPosButton(R.string.ok) {
if (!editText.text.isNullOrBlank()) processUserInput(
editText.text.toString(),
MediaType.MANGA,
it.attachView
)
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create()
}
setNegButton(R.string.cancel)
attach { dialog ->
processEditorAction(
dialog,
editText,
MediaType.MANGA,
it.attachView
)
}
}.show()
processEditorAction(
alertDialog,
editText,
MediaType.MANGA,
it.attachView
)
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
},
attach = {
setExtensionOutput(it.attachView, MediaType.MANGA)
@ -258,24 +256,18 @@ class SettingsExtensionsActivity : AppCompatActivity() {
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, _ ->
context.customAlertDialog().apply {
setTitle(R.string.user_agent)
setCustomView(dialogView.root)
setPosButton(R.string.ok) {
PrefManager.setVal(PrefName.DefaultUserAgent, editText.text.toString())
}
setNeutralButton(R.string.reset) {
PrefManager.removeVal(PrefName.DefaultUserAgent)
editText.setText("")
dialog.dismiss()
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}.create()
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
}
setNegButton(R.string.cancel)
}.show()
}
),
Settings(

View file

@ -25,6 +25,7 @@ import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.util.customAlertDialog
import java.util.Locale
class SettingsNotificationActivity : AppCompatActivity() {
@ -77,26 +78,16 @@ class SettingsNotificationActivity : AppCompatActivity() {
desc = getString(R.string.subscriptions_info),
icon = R.drawable.ic_round_notifications_none_24,
onClick = {
val speedDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.subscriptions_checking_time)
val dialog =
speedDialog.setSingleChoiceItems(timeNames, curTime) { dialog, i ->
context.customAlertDialog().apply {
setTitle(R.string.subscriptions_checking_time)
singleChoiceItems(timeNames, curTime) { i ->
curTime = i
it.settingsTitle.text =
getString(
R.string.subscriptions_checking_time_s,
timeNames[i]
)
PrefManager.setVal(
PrefName.SubscriptionNotificationInterval,
curTime
)
dialog.dismiss()
TaskScheduler.create(
context, PrefManager.getVal(PrefName.UseAlarmManager)
).scheduleAllTasks(context)
}.show()
dialog.window?.setDimAmount(0.8f)
it.settingsTitle.text = getString(R.string.subscriptions_checking_time_s, timeNames[i])
PrefManager.setVal(PrefName.SubscriptionNotificationInterval, curTime)
TaskScheduler.create(context, PrefManager.getVal(PrefName.UseAlarmManager)).scheduleAllTasks(context)
}
show()
}
},
onLongClick = {
TaskScheduler.create(

View file

@ -39,9 +39,9 @@ class UserInterfaceSettingsActivity : AppCompatActivity() {
binding.uiSettingsHomeLayout.setOnClickListener {
val set = PrefManager.getVal<List<Boolean>>(PrefName.HomeLayout).toMutableList()
val views = resources.getStringArray(R.array.home_layouts)
customAlertDialog()
.setTitle(getString(R.string.home_layout_show))
.multiChoiceItems(
customAlertDialog().apply {
setTitle(getString(R.string.home_layout_show))
multiChoiceItems(
items = views,
checkedItems = PrefManager.getVal<List<Boolean>>(PrefName.HomeLayout).toBooleanArray()
) { selectedItems ->
@ -49,11 +49,13 @@ class UserInterfaceSettingsActivity : AppCompatActivity() {
set[i] = selectedItems[i]
}
}
.setPosButton("Done") {
setPosButton(R.string.ok) {
PrefManager.setVal(PrefName.HomeLayout, set)
restartApp()
}
.show()
show()
}
}
binding.uiSettingsSmallView.isChecked = PrefManager.getVal(PrefName.SmallView)

View file

@ -22,6 +22,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
CheckUpdate(Pref(Location.General, Boolean::class, true)),
VerboseLogging(Pref(Location.General, Boolean::class, false)),
DohProvider(Pref(Location.General, Int::class, 0)),
HidePrivate(Pref(Location.General, Boolean::class, false)),
DefaultUserAgent(
Pref(
Location.General,