Use custom alert builder for all dialogs [skip ci]

This commit is contained in:
Sadwhy 2025-01-09 18:34:22 +06:00 committed by GitHub
parent f9f9767ecc
commit 3ac9307329
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 1471 additions and 1251 deletions

File diff suppressed because it is too large Load diff

View file

@ -19,6 +19,7 @@ import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.util.customAlertDialog
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -57,23 +58,16 @@ class SettingsAnimeActivity : AppCompatActivity() {
desc = getString(R.string.purge_anime_downloads_desc), desc = getString(R.string.purge_anime_downloads_desc),
icon = R.drawable.ic_round_delete_24, icon = R.drawable.ic_round_delete_24,
onClick = { onClick = {
val dialog = AlertDialog.Builder(context, R.style.MyPopup) context.customAlertDialog().apply {
.setTitle(R.string.purge_anime_downloads) setTitle(R.string.purge_anime_downloads)
.setMessage( setMessage(R.string.purge_confirm, getString(R.string.anime))
getString( setPosButton(R.string.yes, onClick = {
R.string.purge_confirm,
getString(R.string.anime)
)
)
.setPositiveButton(R.string.yes) { dialog, _ ->
val downloadsManager = Injekt.get<DownloadsManager>() val downloadsManager = Injekt.get<DownloadsManager>()
downloadsManager.purgeDownloads(MediaType.ANIME) downloadsManager.purgeDownloads(MediaType.ANIME)
dialog.dismiss() })
}.setNegativeButton(R.string.no) { dialog, _ -> setNegButton(R.string.no)
dialog.dismiss() show()
}.create() }
dialog.window?.setDimAmount(0.8f)
dialog.show()
} }
), ),

View file

@ -45,7 +45,6 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.util.UUID import java.util.UUID
class SettingsCommonActivity : AppCompatActivity() { class SettingsCommonActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingsCommonBinding private lateinit var binding: ActivitySettingsCommonBinding
private lateinit var launcher: LauncherWrapper private lateinit var launcher: LauncherWrapper
@ -62,18 +61,22 @@ class SettingsCommonActivity : AppCompatActivity() {
registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri -> registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
if (uri != null) { if (uri != null) {
try { try {
val jsonString = contentResolver.openInputStream(uri)?.readBytes() val jsonString =
contentResolver.openInputStream(uri)?.readBytes()
?: throw Exception("Error reading file") ?: throw Exception("Error reading file")
val name = DocumentFile.fromSingleUri(this, uri)?.name ?: "settings" val name = DocumentFile.fromSingleUri(this, uri)?.name ?: "settings"
//.sani is encrypted, .ani is not // .sani is encrypted, .ani is not
if (name.endsWith(".sani")) { if (name.endsWith(".sani")) {
passwordAlertDialog(false) { password -> passwordAlertDialog(false) { password ->
if (password != null) { if (password != null) {
val salt = jsonString.copyOfRange(0, 16) val salt = jsonString.copyOfRange(0, 16)
val encrypted = jsonString.copyOfRange(16, jsonString.size) val encrypted = jsonString.copyOfRange(16, jsonString.size)
val decryptedJson = try { val decryptedJson =
try {
PreferenceKeystore.decryptWithPassword( PreferenceKeystore.decryptWithPassword(
password, encrypted, salt password,
encrypted,
salt,
) )
} catch (e: Exception) { } catch (e: Exception) {
toast(getString(R.string.incorrect_password)) toast(getString(R.string.incorrect_password))
@ -100,7 +103,6 @@ class SettingsCommonActivity : AppCompatActivity() {
launcher = LauncherWrapper(this, contract) launcher = LauncherWrapper(this, contract)
binding.apply { binding.apply {
settingsCommonLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> { settingsCommonLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = statusBarHeight topMargin = statusBarHeight
bottomMargin = navBarHeight bottomMargin = navBarHeight
@ -108,7 +110,8 @@ class SettingsCommonActivity : AppCompatActivity() {
commonSettingsBack.setOnClickListener { commonSettingsBack.setOnClickListener {
onBackPressedDispatcher.onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
val exDns = listOf( val exDns =
listOf(
"None", "None",
"Cloudflare", "Cloudflare",
"Google", "Google",
@ -122,13 +125,15 @@ class SettingsCommonActivity : AppCompatActivity() {
"Controld", "Controld",
"Njalla", "Njalla",
"Shecan", "Shecan",
"Libre" "Libre",
) )
settingsExtensionDns.setText(exDns[PrefManager.getVal(PrefName.DohProvider)]) settingsExtensionDns.setText(exDns[PrefManager.getVal(PrefName.DohProvider)])
settingsExtensionDns.setAdapter( settingsExtensionDns.setAdapter(
ArrayAdapter( ArrayAdapter(
context, R.layout.item_dropdown, exDns context,
) R.layout.item_dropdown,
exDns,
),
) )
settingsExtensionDns.setOnItemClickListener { _, _, i, _ -> settingsExtensionDns.setOnItemClickListener { _, _, i, _ ->
PrefManager.setVal(PrefName.DohProvider, i) PrefManager.setVal(PrefName.DohProvider, i)
@ -136,7 +141,8 @@ class SettingsCommonActivity : AppCompatActivity() {
restartApp() restartApp()
} }
settingsRecyclerView.adapter = SettingsAdapter( settingsRecyclerView.adapter =
SettingsAdapter(
arrayListOf( arrayListOf(
Settings( Settings(
type = 1, type = 1,
@ -147,21 +153,11 @@ class SettingsCommonActivity : AppCompatActivity() {
startActivity( startActivity(
Intent( Intent(
context, context,
UserInterfaceSettingsActivity::class.java UserInterfaceSettingsActivity::class.java,
) ),
) )
}, },
isActivity = true isActivity = true,
),
Settings(
type = 2,
name = getString(R.string.open_animanga_directly),
desc = getString(R.string.open_animanga_directly_info),
icon = R.drawable.ic_round_search_24,
isChecked = PrefManager.getVal(PrefName.AniMangaSearchDirect),
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.AniMangaSearchDirect, isChecked)
}
), ),
Settings( Settings(
type = 1, type = 1,
@ -174,13 +170,13 @@ class SettingsCommonActivity : AppCompatActivity() {
setTitle(getString(R.string.download_manager)) setTitle(getString(R.string.download_manager))
singleChoiceItems( singleChoiceItems(
managers, managers,
PrefManager.getVal(PrefName.DownloadManager) PrefManager.getVal(PrefName.DownloadManager),
) { count -> ) { count ->
PrefManager.setVal(PrefName.DownloadManager, count) PrefManager.setVal(PrefName.DownloadManager, count)
} }
show() show()
} }
} },
), ),
Settings( Settings(
type = 1, type = 1,
@ -202,8 +198,10 @@ class SettingsCommonActivity : AppCompatActivity() {
PrefManager.setVal(PrefName.AppPassword, password) PrefManager.setVal(PrefName.AppPassword, password)
if (view.biometricCheckbox.isChecked) { if (view.biometricCheckbox.isChecked) {
val canBiometricPrompt = val canBiometricPrompt =
BiometricManager.from(applicationContext) BiometricManager
.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK) == BiometricManager.BIOMETRIC_SUCCESS .from(applicationContext)
.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK) ==
BiometricManager.BIOMETRIC_SUCCESS
if (canBiometricPrompt) { if (canBiometricPrompt) {
val biometricPrompt = val biometricPrompt =
@ -211,7 +209,7 @@ class SettingsCommonActivity : AppCompatActivity() {
val token = UUID.randomUUID().toString() val token = UUID.randomUUID().toString()
PrefManager.setVal( PrefManager.setVal(
PrefName.BiometricToken, PrefName.BiometricToken,
token token,
) )
toast(R.string.success) toast(R.string.success)
} }
@ -219,7 +217,6 @@ class SettingsCommonActivity : AppCompatActivity() {
BiometricPromptUtils.createPromptInfo(this@SettingsCommonActivity) BiometricPromptUtils.createPromptInfo(this@SettingsCommonActivity)
biometricPrompt.authenticate(promptInfo) biometricPrompt.authenticate(promptInfo)
} }
} else { } else {
PrefManager.setVal(PrefName.BiometricToken, "") PrefManager.setVal(PrefName.BiometricToken, "")
toast(R.string.success) toast(R.string.success)
@ -239,7 +236,7 @@ class SettingsCommonActivity : AppCompatActivity() {
view.passwordInput.requestFocus() view.passwordInput.requestFocus()
val canAuthenticate = val canAuthenticate =
BiometricManager.from(applicationContext).canAuthenticate( BiometricManager.from(applicationContext).canAuthenticate(
BiometricManager.Authenticators.BIOMETRIC_WEAK BiometricManager.Authenticators.BIOMETRIC_WEAK,
) == BiometricManager.BIOMETRIC_SUCCESS ) == BiometricManager.BIOMETRIC_SUCCESS
view.biometricCheckbox.isVisible = canAuthenticate view.biometricCheckbox.isVisible = canAuthenticate
view.biometricCheckbox.isChecked = view.biometricCheckbox.isChecked =
@ -249,8 +246,7 @@ class SettingsCommonActivity : AppCompatActivity() {
} }
show() show()
} }
} },
), ),
Settings( Settings(
type = 1, type = 1,
@ -259,24 +255,26 @@ class SettingsCommonActivity : AppCompatActivity() {
icon = R.drawable.backup_restore, icon = R.drawable.backup_restore,
onClick = { onClick = {
StoragePermissions.downloadsPermission(context) StoragePermissions.downloadsPermission(context)
val selectedArray = mutableListOf(false)
val filteredLocations = Location.entries.filter { it.exportable } val filteredLocations = Location.entries.filter { it.exportable }
selectedArray.addAll(List(filteredLocations.size - 1) { false }) val selectedArray = BooleanArray(filteredLocations.size) { false }
val dialog = AlertDialog.Builder(context, R.style.MyPopup) context.customAlertDialog().apply {
.setTitle(R.string.backup_restore).setMultiChoiceItems( setTitle(R.string.backup_restore)
multiChoiceItems(
filteredLocations.map { it.name }.toTypedArray(), filteredLocations.map { it.name }.toTypedArray(),
selectedArray.toBooleanArray() selectedArray,
) { _, which, isChecked -> ) { updatedSelection ->
selectedArray[which] = isChecked for (i in updatedSelection.indices) {
}.setPositiveButton(R.string.button_restore) { dialog, _ -> selectedArray[i] = updatedSelection[i]
}
}
setPosButton(R.string.button_restore) {
openDocumentLauncher.launch(arrayOf("*/*")) openDocumentLauncher.launch(arrayOf("*/*"))
dialog.dismiss() }
}.setNegativeButton(R.string.button_backup) { dialog, _ -> setNegButton(R.string.button_backup) {
if (!selectedArray.contains(true)) { if (!selectedArray.contains(true)) {
toast(R.string.no_location_selected) toast(R.string.no_location_selected)
return@setNegativeButton return@setNegButton
} }
dialog.dismiss()
val selected = val selected =
filteredLocations.filterIndexed { index, _ -> selectedArray[index] } filteredLocations.filterIndexed { index, _ -> selectedArray[index] }
if (selected.contains(Location.Protected)) { if (selected.contains(Location.Protected)) {
@ -286,7 +284,7 @@ class SettingsCommonActivity : AppCompatActivity() {
"DantotsuSettings", "DantotsuSettings",
PrefManager.exportAllPrefs(selected), PrefManager.exportAllPrefs(selected),
context, context,
password password,
) )
} else { } else {
toast(R.string.password_cannot_be_empty) toast(R.string.password_cannot_be_empty)
@ -297,14 +295,13 @@ class SettingsCommonActivity : AppCompatActivity() {
"DantotsuSettings", "DantotsuSettings",
PrefManager.exportAllPrefs(selected), PrefManager.exportAllPrefs(selected),
context, context,
null null,
) )
} }
}.setNeutralButton(R.string.cancel) { dialog, _ -> }
dialog.dismiss() setNeutralButton(R.string.cancel) {}
}.create() show()
dialog.window?.setDimAmount(0.8f) }
dialog.show()
}, },
), ),
Settings( Settings(
@ -325,7 +322,9 @@ class SettingsCommonActivity : AppCompatActivity() {
PrefManager.getVal<String>(PrefName.DownloadsDir) PrefManager.getVal<String>(PrefName.DownloadsDir)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
Injekt.get<DownloadsManager>().moveDownloadsDir( Injekt.get<DownloadsManager>().moveDownloadsDir(
context, Uri.parse(oldUri), Uri.parse(newUri) context,
Uri.parse(oldUri),
Uri.parse(newUri),
) { finished, message -> ) { finished, message ->
if (finished) { if (finished) {
toast(getString(R.string.success)) toast(getString(R.string.success))
@ -343,7 +342,7 @@ class SettingsCommonActivity : AppCompatActivity() {
setNegButton(R.string.cancel) setNegButton(R.string.cancel)
show() show()
} }
} },
), ),
Settings( Settings(
type = 2, type = 2,
@ -353,7 +352,7 @@ class SettingsCommonActivity : AppCompatActivity() {
isChecked = PrefManager.getVal(PrefName.ContinueMedia), isChecked = PrefManager.getVal(PrefName.ContinueMedia),
switch = { isChecked, _ -> switch = { isChecked, _ ->
PrefManager.setVal(PrefName.ContinueMedia, isChecked) PrefManager.setVal(PrefName.ContinueMedia, isChecked)
} },
), ),
Settings( Settings(
type = 2, type = 2,
@ -364,7 +363,7 @@ class SettingsCommonActivity : AppCompatActivity() {
switch = { isChecked, _ -> switch = { isChecked, _ ->
PrefManager.setVal(PrefName.HidePrivate, isChecked) PrefManager.setVal(PrefName.HidePrivate, isChecked)
restartApp() restartApp()
} },
), ),
Settings( Settings(
type = 2, type = 2,
@ -374,7 +373,7 @@ class SettingsCommonActivity : AppCompatActivity() {
isChecked = PrefManager.getVal(PrefName.SearchSources), isChecked = PrefManager.getVal(PrefName.SearchSources),
switch = { isChecked, _ -> switch = { isChecked, _ ->
PrefManager.setVal(PrefName.SearchSources, isChecked) PrefManager.setVal(PrefName.SearchSources, isChecked)
} },
), ),
Settings( Settings(
type = 2, type = 2,
@ -384,7 +383,7 @@ class SettingsCommonActivity : AppCompatActivity() {
isChecked = PrefManager.getVal(PrefName.RecentlyListOnly), isChecked = PrefManager.getVal(PrefName.RecentlyListOnly),
switch = { isChecked, _ -> switch = { isChecked, _ ->
PrefManager.setVal(PrefName.RecentlyListOnly, isChecked) PrefManager.setVal(PrefName.RecentlyListOnly, isChecked)
} },
), ),
Settings( Settings(
type = 2, type = 2,
@ -396,23 +395,27 @@ class SettingsCommonActivity : AppCompatActivity() {
PrefManager.setVal(PrefName.AdultOnly, isChecked) PrefManager.setVal(PrefName.AdultOnly, isChecked)
restartApp() restartApp()
}, },
isVisible = Anilist.adult isVisible = Anilist.adult,
),
), ),
)
) )
settingsRecyclerView.apply { settingsRecyclerView.apply {
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
setHasFixedSize(true) setHasFixedSize(true)
} }
var previousStart: View = when (PrefManager.getVal<Int>(PrefName.DefaultStartUpTab)) { var previousStart: View =
when (PrefManager.getVal<Int>(PrefName.DefaultStartUpTab)) {
0 -> uiSettingsAnime 0 -> uiSettingsAnime
1 -> uiSettingsHome 1 -> uiSettingsHome
2 -> uiSettingsManga 2 -> uiSettingsManga
else -> uiSettingsHome else -> uiSettingsHome
} }
previousStart.alpha = 1f previousStart.alpha = 1f
fun uiDefault(mode: Int, current: View) {
fun uiDefault(
mode: Int,
current: View,
) {
previousStart.alpha = 0.33f previousStart.alpha = 0.33f
previousStart = current previousStart = current
current.alpha = 1f current.alpha = 1f
@ -431,11 +434,13 @@ class SettingsCommonActivity : AppCompatActivity() {
uiSettingsManga.setOnClickListener { uiSettingsManga.setOnClickListener {
uiDefault(2, it) uiDefault(2, it)
} }
} }
} }
private fun passwordAlertDialog(isExporting: Boolean, callback: (CharArray?) -> Unit) { private fun passwordAlertDialog(
isExporting: Boolean,
callback: (CharArray?) -> Unit,
) {
val password = CharArray(16).apply { fill('0') } val password = CharArray(16).apply { fill('0') }
// Inflate the dialog layout // Inflate the dialog layout
@ -445,7 +450,9 @@ class SettingsCommonActivity : AppCompatActivity() {
box.setSingleLine() box.setSingleLine()
val dialog = val dialog =
AlertDialog.Builder(this, R.style.MyPopup).setTitle(getString(R.string.enter_password)) AlertDialog
.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.enter_password))
.setView(dialogView.root) .setView(dialogView.root)
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel) { dialog, _ -> .setNegativeButton(R.string.cancel) { dialog, _ ->
@ -457,7 +464,10 @@ class SettingsCommonActivity : AppCompatActivity() {
fun handleOkAction() { fun handleOkAction() {
val editText = dialogView.userAgentTextBox val editText = dialogView.userAgentTextBox
if (editText.text?.isNotBlank() == true) { if (editText.text?.isNotBlank() == true) {
editText.text?.toString()?.trim()?.toCharArray(password) editText.text
?.toString()
?.trim()
?.toCharArray(password)
dialog.dismiss() dialog.dismiss()
callback(password) callback(password)
} else { } else {
@ -473,18 +483,20 @@ class SettingsCommonActivity : AppCompatActivity() {
} }
} }
dialogView.subtitle.visibility = View.VISIBLE dialogView.subtitle.visibility = View.VISIBLE
if (!isExporting) dialogView.subtitle.text = if (!isExporting) {
dialogView.subtitle.text =
getString(R.string.enter_password_to_decrypt_file) getString(R.string.enter_password_to_decrypt_file)
}
dialog.window?.apply {
dialog.window?.setDimAmount(0.8f) setDimAmount(0.8f)
attributes.windowAnimations = android.R.style.Animation_Dialog
}
dialog.show() dialog.show()
// Override the positive button here // Override the positive button here
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
handleOkAction() handleOkAction()
} }
} }
} }

View file

@ -82,18 +82,9 @@ class SettingsNotificationActivity : AppCompatActivity() {
setTitle(R.string.subscriptions_checking_time) setTitle(R.string.subscriptions_checking_time)
singleChoiceItems(timeNames, curTime) { i -> singleChoiceItems(timeNames, curTime) { i ->
curTime = i curTime = i
it.settingsTitle.text = getString( it.settingsTitle.text = getString(R.string.subscriptions_checking_time_s, timeNames[i])
R.string.subscriptions_checking_time_s, PrefManager.setVal(PrefName.SubscriptionNotificationInterval, curTime)
timeNames[i] TaskScheduler.create(context, PrefManager.getVal(PrefName.UseAlarmManager)).scheduleAllTasks(context)
)
PrefManager.setVal(
PrefName.SubscriptionNotificationInterval,
curTime
)
TaskScheduler.create(
context,
PrefManager.getVal(PrefName.UseAlarmManager)
).scheduleAllTasks(context)
} }
show() show()
} }
@ -128,26 +119,26 @@ class SettingsNotificationActivity : AppCompatActivity() {
PrefManager.getVal<Set<String>>(PrefName.AnilistFilteredTypes) PrefManager.getVal<Set<String>>(PrefName.AnilistFilteredTypes)
.toMutableSet() .toMutableSet()
val selected = types.map { filteredTypes.contains(it) }.toBooleanArray() val selected = types.map { filteredTypes.contains(it) }.toBooleanArray()
val dialog = AlertDialog.Builder(context, R.style.MyPopup) context.customAlertDialog().apply {
.setTitle(R.string.anilist_notification_filters) setTitle(R.string.anilist_notification_filters)
.setMultiChoiceItems( multiChoiceItems(
types.map { name -> types.map { name ->
name.replace("_", " ").lowercase().replaceFirstChar { name.replace("_", " ").lowercase().replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString()
} } }.toTypedArray(),
}.toTypedArray(),
selected selected
) { _, which, isChecked -> ) { updatedSelected ->
val type = types[which] types.forEachIndexed { index, type ->
if (isChecked) { if (updatedSelected[index]) {
filteredTypes.add(type) filteredTypes.add(type)
} else { } else {
filteredTypes.remove(type) filteredTypes.remove(type)
} }
}
PrefManager.setVal(PrefName.AnilistFilteredTypes, filteredTypes) PrefManager.setVal(PrefName.AnilistFilteredTypes, filteredTypes)
}.create() }
dialog.window?.setDimAmount(0.8f) show()
dialog.show() }
} }
), ),
@ -160,27 +151,24 @@ class SettingsNotificationActivity : AppCompatActivity() {
desc = getString(R.string.anilist_notifications_checking_time_desc), desc = getString(R.string.anilist_notifications_checking_time_desc),
icon = R.drawable.ic_round_notifications_none_24, icon = R.drawable.ic_round_notifications_none_24,
onClick = { onClick = {
val selected = context.customAlertDialog().apply {
PrefManager.getVal<Int>(PrefName.AnilistNotificationInterval) setTitle(R.string.subscriptions_checking_time)
val dialog = AlertDialog.Builder(context, R.style.MyPopup) singleChoiceItems(
.setTitle(R.string.subscriptions_checking_time)
.setSingleChoiceItems(
aItems.toTypedArray(), aItems.toTypedArray(),
selected PrefManager.getVal<Int>(PrefName.AnilistNotificationInterval)
) { dialog, i -> ) { i ->
PrefManager.setVal(PrefName.AnilistNotificationInterval, i) PrefManager.setVal(PrefName.AnilistNotificationInterval, i)
it.settingsTitle.text = it.settingsTitle.text =
getString( getString(
R.string.anilist_notifications_checking_time, R.string.anilist_notifications_checking_time,
aItems[i] aItems[i]
) )
dialog.dismiss()
TaskScheduler.create( TaskScheduler.create(
context, PrefManager.getVal(PrefName.UseAlarmManager) context, PrefManager.getVal(PrefName.UseAlarmManager)
).scheduleAllTasks(context) ).scheduleAllTasks(context)
}.create() }
dialog.window?.setDimAmount(0.8f) show()
dialog.show() }
} }
), ),
Settings( Settings(
@ -192,27 +180,24 @@ class SettingsNotificationActivity : AppCompatActivity() {
desc = getString(R.string.comment_notification_checking_time_desc), desc = getString(R.string.comment_notification_checking_time_desc),
icon = R.drawable.ic_round_notifications_none_24, icon = R.drawable.ic_round_notifications_none_24,
onClick = { onClick = {
val selected = context.customAlertDialog().apply {
PrefManager.getVal<Int>(PrefName.CommentNotificationInterval) setTitle(R.string.subscriptions_checking_time)
val dialog = AlertDialog.Builder(context, R.style.MyPopup) singleChoiceItems(
.setTitle(R.string.subscriptions_checking_time)
.setSingleChoiceItems(
cItems.toTypedArray(), cItems.toTypedArray(),
selected PrefManager.getVal<Int>(PrefName.CommentNotificationInterval)
) { dialog, i -> ) { i ->
PrefManager.setVal(PrefName.CommentNotificationInterval, i) PrefManager.setVal(PrefName.CommentNotificationInterval, i)
it.settingsTitle.text = it.settingsTitle.text =
getString( getString(
R.string.comment_notification_checking_time, R.string.comment_notification_checking_time,
cItems[i] cItems[i]
) )
dialog.dismiss()
TaskScheduler.create( TaskScheduler.create(
context, PrefManager.getVal(PrefName.UseAlarmManager) context, PrefManager.getVal(PrefName.UseAlarmManager)
).scheduleAllTasks(context) ).scheduleAllTasks(context)
}.create() }
dialog.window?.setDimAmount(0.8f) show()
dialog.show() }
} }
), ),
Settings( Settings(
@ -239,10 +224,10 @@ class SettingsNotificationActivity : AppCompatActivity() {
isChecked = PrefManager.getVal(PrefName.UseAlarmManager), isChecked = PrefManager.getVal(PrefName.UseAlarmManager),
switch = { isChecked, view -> switch = { isChecked, view ->
if (isChecked) { if (isChecked) {
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup) context.customAlertDialog().apply {
.setTitle(R.string.use_alarm_manager) setTitle(R.string.use_alarm_manager)
.setMessage(R.string.use_alarm_manager_confirm) setMessage(R.string.use_alarm_manager_confirm)
.setPositiveButton(R.string.use) { dialog, _ -> setPosButton(R.string.use) {
PrefManager.setVal(PrefName.UseAlarmManager, true) PrefManager.setVal(PrefName.UseAlarmManager, true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!(getSystemService(Context.ALARM_SERVICE) as AlarmManager).canScheduleExactAlarms()) { if (!(getSystemService(Context.ALARM_SERVICE) as AlarmManager).canScheduleExactAlarms()) {
@ -252,15 +237,13 @@ class SettingsNotificationActivity : AppCompatActivity() {
view.settingsButton.isChecked = true view.settingsButton.isChecked = true
} }
} }
dialog.dismiss() }
}.setNegativeButton(R.string.cancel) { dialog, _ -> setNegButton(R.string.cancel) {
view.settingsButton.isChecked = false view.settingsButton.isChecked = false
PrefManager.setVal(PrefName.UseAlarmManager, false) PrefManager.setVal(PrefName.UseAlarmManager, false)
}
dialog.dismiss() show()
}.create() }
alertDialog.window?.setDimAmount(0.8f)
alertDialog.show()
} else { } else {
PrefManager.setVal(PrefName.UseAlarmManager, false) PrefManager.setVal(PrefName.UseAlarmManager, false)
TaskScheduler.create(context, true).cancelAllTasks() TaskScheduler.create(context, true).cancelAllTasks()