chore: cleanup pt2

This commit is contained in:
rebelonion 2024-04-19 06:13:14 -05:00
parent 24147e746a
commit 70a50ece43
52 changed files with 501 additions and 294 deletions

View file

@ -6,20 +6,15 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.app.NotificationCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.R
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.databinding.FragmentExtensionsBinding
import ani.dantotsu.settings.paging.AnimeExtensionAdapter
import ani.dantotsu.settings.paging.AnimeExtensionsViewModel
import ani.dantotsu.settings.paging.AnimeExtensionsViewModelFactory
import ani.dantotsu.settings.paging.OnAnimeInstallClickListener
import ani.dantotsu.snackString
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
import eu.kanade.tachiyomi.extension.anime.model.AnimeExtension
import kotlinx.coroutines.flow.collectLatest

View file

@ -10,7 +10,7 @@ import ani.dantotsu.databinding.BottomSheetDiscordRpcBinding
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
class DiscordDialogFragment: BottomSheetDialogFragment() {
class DiscordDialogFragment : BottomSheetDialogFragment() {
private var _binding: BottomSheetDiscordRpcBinding? = null
private val binding get() = _binding!!
@ -22,11 +22,12 @@ class DiscordDialogFragment: BottomSheetDialogFragment() {
_binding = BottomSheetDiscordRpcBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
when (PrefManager.getCustomVal("discord_mode", "dantotsu")) {
"nothing" -> binding.radioNothing.isChecked= true
"nothing" -> binding.radioNothing.isChecked = true
"dantotsu" -> binding.radioDantotsu.isChecked = true
"anilist" -> binding.radioAnilist.isChecked = true
else -> binding.radioAnilist.isChecked = true
@ -35,7 +36,8 @@ class DiscordDialogFragment: BottomSheetDialogFragment() {
binding.showIcon.setOnCheckedChangeListener { _, isChecked ->
PrefManager.setVal(PrefName.ShowAniListIcon, isChecked)
}
binding.anilistLinkPreview.text = getString(R.string.anilist_link, PrefManager.getVal<String>(PrefName.AnilistUserName))
binding.anilistLinkPreview.text =
getString(R.string.anilist_link, PrefManager.getVal<String>(PrefName.AnilistUserName))
binding.radioGroup.setOnCheckedChangeListener { _, checkedId ->
val mode = when (checkedId) {

View file

@ -213,9 +213,17 @@ class ExtensionsActivity : AppCompatActivity() {
private fun getSavedRepositories(repoInventory: ViewGroup, type: MediaType) {
repoInventory.removeAllViews()
val prefName: PrefName? = when (type) {
MediaType.ANIME -> { PrefName.AnimeExtensionRepos }
MediaType.MANGA -> { PrefName.MangaExtensionRepos }
else -> { null }
MediaType.ANIME -> {
PrefName.AnimeExtensionRepos
}
MediaType.MANGA -> {
PrefName.MangaExtensionRepos
}
else -> {
null
}
}
prefName?.let { repoList ->
PrefManager.getVal<Set<String>>(repoList).forEach { item ->
@ -233,9 +241,15 @@ class ExtensionsActivity : AppCompatActivity() {
repoInventory.removeView(view.root)
CoroutineScope(Dispatchers.IO).launch {
when (type) {
MediaType.ANIME -> { animeExtensionManager.findAvailableExtensions() }
MediaType.MANGA -> { mangaExtensionManager.findAvailableExtensions() }
else -> { }
MediaType.ANIME -> {
animeExtensionManager.findAvailableExtensions()
}
MediaType.MANGA -> {
mangaExtensionManager.findAvailableExtensions()
}
else -> {}
}
}
dialog.dismiss()
@ -274,9 +288,17 @@ class ExtensionsActivity : AppCompatActivity() {
private fun generateRepositoryButton(type: MediaType) {
val hintResource: Int? = when (type) {
MediaType.ANIME -> { R.string.anime_add_repository }
MediaType.MANGA -> { R.string.manga_add_repository }
else -> { null }
MediaType.ANIME -> {
R.string.anime_add_repository
}
MediaType.MANGA -> {
R.string.manga_add_repository
}
else -> {
null
}
}
hintResource?.let { res ->
binding.openSettingsButton.setOnClickListener {

View file

@ -11,7 +11,10 @@ import eu.kanade.tachiyomi.extension.InstallStep
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class InstallerSteps(private val notificationManager: NotificationManager, private val context: Context) {
class InstallerSteps(
private val notificationManager: NotificationManager,
private val context: Context
) {
fun onInstallStep(installStep: InstallStep, extra: () -> Unit) {
val builder = NotificationCompat.Builder(

View file

@ -6,20 +6,15 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.app.NotificationCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.R
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.databinding.FragmentExtensionsBinding
import ani.dantotsu.settings.paging.MangaExtensionAdapter
import ani.dantotsu.settings.paging.MangaExtensionsViewModel
import ani.dantotsu.settings.paging.MangaExtensionsViewModelFactory
import ani.dantotsu.settings.paging.OnMangaInstallClickListener
import ani.dantotsu.snackString
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
import eu.kanade.tachiyomi.extension.manga.model.MangaExtension
import kotlinx.coroutines.flow.collectLatest

View file

@ -24,7 +24,6 @@ import ani.dantotsu.others.getSerialized
import ani.dantotsu.parsers.Subtitle
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.internal.Pref
import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
@ -40,9 +39,10 @@ class PlayerSettingsActivity : AppCompatActivity() {
var media: Media? = null
var subtitle: Subtitle? = null
private val Int.toSP get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, this.toFloat(), Resources.getSystem().displayMetrics
)
private val Int.toSP
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, this.toFloat(), Resources.getSystem().displayMetrics
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -151,8 +151,10 @@ class PlayerSettingsActivity : AppCompatActivity() {
binding.playerSettingsTimeStampsAutoHide.isEnabled = isChecked
}
binding.playerSettingsTimeStampsAutoHide.isChecked = PrefManager.getVal(PrefName.AutoHideTimeStamps)
binding.playerSettingsTimeStampsAutoHide.isEnabled = binding.playerSettingsShowTimeStamp.isChecked
binding.playerSettingsTimeStampsAutoHide.isChecked =
PrefManager.getVal(PrefName.AutoHideTimeStamps)
binding.playerSettingsTimeStampsAutoHide.isEnabled =
binding.playerSettingsShowTimeStamp.isChecked
binding.playerSettingsTimeStampsAutoHide.setOnCheckedChangeListener { _, isChecked ->
PrefManager.setVal(PrefName.AutoHideTimeStamps, isChecked)
}
@ -484,10 +486,11 @@ class PlayerSettingsActivity : AppCompatActivity() {
updateSubPreview()
}
}
binding.subtitleTest.addOnChangeListener(object: Xpandable.OnChangeListener {
binding.subtitleTest.addOnChangeListener(object : Xpandable.OnChangeListener {
override fun onExpand() {
updateSubPreview()
}
override fun onRetract() {}
})
updateSubPreview()
@ -496,24 +499,26 @@ class PlayerSettingsActivity : AppCompatActivity() {
private fun updateSubPreview() {
binding.subtitleTestWindow.run {
alpha = PrefManager.getVal(PrefName.SubAlpha)
setBackgroundColor(when (PrefManager.getVal<Int>(PrefName.SubWindow)) {
0 -> Color.TRANSPARENT
1 -> Color.BLACK
2 -> Color.DKGRAY
3 -> Color.GRAY
4 -> Color.LTGRAY
5 -> Color.WHITE
6 -> Color.RED
7 -> Color.YELLOW
8 -> Color.GREEN
9 -> Color.CYAN
10 -> Color.BLUE
11 -> Color.MAGENTA
else -> Color.TRANSPARENT
})
setBackgroundColor(
when (PrefManager.getVal<Int>(PrefName.SubWindow)) {
0 -> Color.TRANSPARENT
1 -> Color.BLACK
2 -> Color.DKGRAY
3 -> Color.GRAY
4 -> Color.LTGRAY
5 -> Color.WHITE
6 -> Color.RED
7 -> Color.YELLOW
8 -> Color.GREEN
9 -> Color.CYAN
10 -> Color.BLUE
11 -> Color.MAGENTA
else -> Color.TRANSPARENT
}
)
}
binding.subtitleTestText.run {
textSize = PrefManager.getVal<Int>(PrefName.FontSize).toSP
textSize = PrefManager.getVal<Int>(PrefName.FontSize).toSP
typeface = when (PrefManager.getVal<Int>(PrefName.Font)) {
0 -> ResourcesCompat.getFont(this.context, R.font.poppins_semi_bold)
1 -> ResourcesCompat.getFont(this.context, R.font.poppins_bold)
@ -524,36 +529,40 @@ class PlayerSettingsActivity : AppCompatActivity() {
6 -> ResourcesCompat.getFont(this.context, R.font.blocky)
else -> ResourcesCompat.getFont(this.context, R.font.poppins_semi_bold)
}
setTextColor(when (PrefManager.getVal<Int>(PrefName.PrimaryColor)) {
0 -> Color.BLACK
1 -> Color.DKGRAY
2 -> Color.GRAY
3 -> Color.LTGRAY
4 -> Color.WHITE
5 -> Color.RED
6 -> Color.YELLOW
7 -> Color.GREEN
8 -> Color.CYAN
9 -> Color.BLUE
10 -> Color.MAGENTA
11 -> Color.TRANSPARENT
else -> Color.WHITE
})
setBackgroundColor(when (PrefManager.getVal<Int>(PrefName.SubBackground)) {
0 -> Color.TRANSPARENT
1 -> Color.BLACK
2 -> Color.DKGRAY
3 -> Color.GRAY
4 -> Color.LTGRAY
5 -> Color.WHITE
6 -> Color.RED
7 -> Color.YELLOW
8 -> Color.GREEN
9 -> Color.CYAN
10 -> Color.BLUE
11 -> Color.MAGENTA
else -> Color.TRANSPARENT
})
setTextColor(
when (PrefManager.getVal<Int>(PrefName.PrimaryColor)) {
0 -> Color.BLACK
1 -> Color.DKGRAY
2 -> Color.GRAY
3 -> Color.LTGRAY
4 -> Color.WHITE
5 -> Color.RED
6 -> Color.YELLOW
7 -> Color.GREEN
8 -> Color.CYAN
9 -> Color.BLUE
10 -> Color.MAGENTA
11 -> Color.TRANSPARENT
else -> Color.WHITE
}
)
setBackgroundColor(
when (PrefManager.getVal<Int>(PrefName.SubBackground)) {
0 -> Color.TRANSPARENT
1 -> Color.BLACK
2 -> Color.DKGRAY
3 -> Color.GRAY
4 -> Color.LTGRAY
5 -> Color.WHITE
6 -> Color.RED
7 -> Color.YELLOW
8 -> Color.GREEN
9 -> Color.CYAN
10 -> Color.BLUE
11 -> Color.MAGENTA
else -> Color.TRANSPARENT
}
)
}
}
}

View file

@ -5,15 +5,15 @@ import ani.dantotsu.databinding.ItemSettingsSwitchBinding
data class Settings(
val type: Int,
val name : String,
val name: String,
val desc: String,
val icon : Int,
val icon: Int,
val onClick: ((ItemSettingsBinding) -> Unit)? = null,
val onLongClick: (() -> Unit)? = null,
val switch: ((isChecked:Boolean , view: ItemSettingsSwitchBinding ) -> Unit)? = null,
val attach:((ItemSettingsBinding) -> Unit)? = null,
val attachToSwitch : ((ItemSettingsSwitchBinding) -> Unit)? = null,
val switch: ((isChecked: Boolean, view: ItemSettingsSwitchBinding) -> Unit)? = null,
val attach: ((ItemSettingsBinding) -> Unit)? = null,
val attachToSwitch: ((ItemSettingsSwitchBinding) -> Unit)? = null,
val isVisible: Boolean = true,
val isActivity: Boolean = false,
var isChecked : Boolean = false,
var isChecked: Boolean = false,
)

View file

@ -95,7 +95,7 @@ class SettingsAboutActivity : AppCompatActivity() {
Settings(
type = 1,
name = getString(R.string.devs),
desc= getString(R.string.devs_desc),
desc = getString(R.string.devs_desc),
icon = R.drawable.ic_round_accessible_forward_24,
onClick = {
DevelopersDialogFragment().show(supportFragmentManager, "dialog")
@ -131,7 +131,8 @@ class SettingsAboutActivity : AppCompatActivity() {
),
)
)
binding.settingsRecyclerView.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
binding.settingsRecyclerView.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
}
}
}

View file

@ -13,7 +13,6 @@ import ani.dantotsu.R
import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.discord.Discord
import ani.dantotsu.connections.mal.MAL
import ani.dantotsu.databinding.ActivitySettingsAboutBinding
import ani.dantotsu.databinding.ActivitySettingsAccountsBinding
import ani.dantotsu.initActivity
import ani.dantotsu.loadImage
@ -33,6 +32,7 @@ class SettingsAccountActivity : AppCompatActivity() {
private val restartMainActivity = object : OnBackPressedCallback(false) {
override fun handleOnBackPressed() = startMainActivity(this@SettingsAccountActivity)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ThemeManager(this).applyTheme()

View file

@ -12,7 +12,6 @@ import android.os.Bundle
import android.view.ViewGroup
import android.widget.TextView
import androidx.activity.addCallback
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.lifecycleScope
@ -69,11 +68,11 @@ class SettingsActivity : AppCompatActivity() {
bottomMargin = navBarHeight
}
onBackPressedDispatcher.addCallback(context){
onBackPressedDispatcher.addCallback(context) {
if (PrefManager.getCustomVal("reload", false)) {
startMainActivity(context)
PrefManager.setCustomVal("reload", false)
}else{
} else {
finish()
}
}
@ -278,6 +277,7 @@ class SettingsActivity : AppCompatActivity() {
?: "Unknown Architecture"
}
}
override fun onResume() {
ThemeManager(this).applyTheme()
super.onResume()

View file

@ -2,19 +2,14 @@ package ani.dantotsu.settings
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.R
import ani.dantotsu.addons.AddonDownloader
import ani.dantotsu.addons.AddonListener
import ani.dantotsu.addons.download.DownloadAddonManager
import ani.dantotsu.addons.torrent.ServerService
import ani.dantotsu.addons.torrent.TorrentAddonManager
@ -27,15 +22,12 @@ import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.toast
import ani.dantotsu.util.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import tachiyomi.core.util.lang.launchIO

View file

@ -22,7 +22,7 @@ import ani.dantotsu.themes.ThemeManager
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class SettingsAnimeActivity: AppCompatActivity(){
class SettingsAnimeActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingsAnimeBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -59,7 +59,12 @@ class SettingsAnimeActivity: AppCompatActivity(){
onClick = {
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.purge_anime_downloads)
.setMessage(getString(R.string.purge_confirm, getString(R.string.anime)))
.setMessage(
getString(
R.string.purge_confirm,
getString(R.string.anime)
)
)
.setPositiveButton(R.string.yes) { dialog, _ ->
val downloadsManager = Injekt.get<DownloadsManager>()
downloadsManager.purgeDownloads(MediaType.ANIME)

View file

@ -41,9 +41,10 @@ import kotlinx.coroutines.launch
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class SettingsCommonActivity: AppCompatActivity(){
class SettingsCommonActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingsCommonBinding
private lateinit var launcher: LauncherWrapper
@OptIn(DelicateCoroutinesApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -138,7 +139,12 @@ class SettingsCommonActivity: AppCompatActivity(){
desc = getString(R.string.ui_settings),
icon = R.drawable.ic_round_auto_awesome_24,
onClick = {
startActivity(Intent(context, UserInterfaceSettingsActivity::class.java))
startActivity(
Intent(
context,
UserInterfaceSettingsActivity::class.java
)
)
},
isActivity = true
),
@ -150,7 +156,8 @@ class SettingsCommonActivity: AppCompatActivity(){
onClick = {
val managers = arrayOf("Default", "1DM", "ADM")
val downloadManagerDialog =
AlertDialog.Builder(context, R.style.MyPopup).setTitle(R.string.download_manager)
AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.download_manager)
var downloadManager: Int = PrefManager.getVal(PrefName.DownloadManager)
val dialog = downloadManagerDialog.setSingleChoiceItems(
managers, downloadManager
@ -231,7 +238,8 @@ class SettingsCommonActivity: AppCompatActivity(){
launcher.registerForCallback { success ->
if (success) {
toast(getString(R.string.please_wait))
val newUri = PrefManager.getVal<String>(PrefName.DownloadsDir)
val newUri =
PrefManager.getVal<String>(PrefName.DownloadsDir)
GlobalScope.launch(Dispatchers.IO) {
Injekt.get<DownloadsManager>().moveDownloadsDir(
context, Uri.parse(oldUri), Uri.parse(newUri)
@ -262,7 +270,7 @@ class SettingsCommonActivity: AppCompatActivity(){
desc = getString(R.string.always_continue_content),
icon = R.drawable.ic_round_delete_24,
isChecked = PrefManager.getVal(PrefName.ContinueMedia),
switch = {isChecked, _ ->
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.ContinueMedia, isChecked)
}
),
@ -272,7 +280,7 @@ class SettingsCommonActivity: AppCompatActivity(){
desc = getString(R.string.search_source_list),
icon = R.drawable.ic_round_search_sources_24,
isChecked = PrefManager.getVal(PrefName.SearchSources),
switch = {isChecked, _ ->
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.SearchSources, isChecked)
}
),
@ -282,7 +290,7 @@ class SettingsCommonActivity: AppCompatActivity(){
desc = getString(R.string.recentlyListOnly),
icon = R.drawable.ic_round_new_releases_24,
isChecked = PrefManager.getVal(PrefName.RecentlyListOnly),
switch = {isChecked, _ ->
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.RecentlyListOnly, isChecked)
}
),
@ -292,7 +300,7 @@ class SettingsCommonActivity: AppCompatActivity(){
desc = getString(R.string.adult_only_content),
icon = R.drawable.ic_round_nsfw_24,
isChecked = PrefManager.getVal(PrefName.AdultOnly),
switch = {isChecked, _ ->
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.AdultOnly, isChecked)
restartApp()
},
@ -334,6 +342,7 @@ class SettingsCommonActivity: AppCompatActivity(){
}
}
private fun passwordAlertDialog(isExporting: Boolean, callback: (CharArray?) -> Unit) {
val password = CharArray(16).apply { fill('0') }

View file

@ -74,15 +74,15 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
binding.settingsLogin.setText(R.string.logout)
binding.settingsLogin.setOnClickListener {
val alertDialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
.setTitle("Logout")
.setMessage("Are you sure you want to logout?")
.setPositiveButton("Yes") { _, _ ->
Anilist.removeSavedToken()
dismiss()
startMainActivity(requireActivity())
}
.setNegativeButton("No") { _, _ -> }
.create()
.setTitle("Logout")
.setMessage("Are you sure you want to logout?")
.setPositiveButton("Yes") { _, _ ->
Anilist.removeSavedToken()
dismiss()
startMainActivity(requireActivity())
}
.setNegativeButton("No") { _, _ -> }
.create()
alertDialog.window?.setDimAmount(0.8f)
alertDialog.show()
}
@ -98,7 +98,7 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
}
binding.settingsNotificationCount.isVisible = Anilist.unreadNotificationCount > 0
binding.settingsNotificationCount.text = Anilist.unreadNotificationCount.toString()
binding.settingsUserAvatar.setOnClickListener{
binding.settingsUserAvatar.setOnClickListener {
ContextCompat.startActivity(
requireContext(), Intent(requireContext(), ProfileActivity::class.java)
.putExtra("userId", Anilist.userid), null

View file

@ -24,7 +24,6 @@ import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import com.google.android.material.textfield.TextInputEditText
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
@ -35,7 +34,7 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
class SettingsExtensionsActivity: AppCompatActivity() {
class SettingsExtensionsActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingsExtensionsBinding
private val extensionInstaller = Injekt.get<BasePreferences>().extensionInstaller()
private val animeExtensionManager: AnimeExtensionManager by injectLazy()
@ -52,7 +51,7 @@ class SettingsExtensionsActivity: AppCompatActivity() {
topMargin = statusBarHeight
bottomMargin = navBarHeight
}
extensionSettingsBack.setOnClickListener{
extensionSettingsBack.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
fun setExtensionOutput(repoInventory: ViewGroup, type: MediaType) {
@ -139,7 +138,12 @@ class SettingsExtensionsActivity: AppCompatActivity() {
}
}
fun processEditorAction(dialog: AlertDialog, editText: EditText, mediaType: MediaType, view: ViewGroup) {
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()) {
@ -163,8 +167,8 @@ class SettingsExtensionsActivity: AppCompatActivity() {
onClick = {
val dialogView = DialogUserAgentBinding.inflate(layoutInflater)
val editText = dialogView.userAgentTextBox.apply {
hint = getString(R.string.anime_add_repository)
}
hint = getString(R.string.anime_add_repository)
}
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.anime_add_repository).setView(dialogView.root)
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
@ -178,7 +182,12 @@ class SettingsExtensionsActivity: AppCompatActivity() {
dialog.dismiss()
}.create()
processEditorAction(alertDialog, editText, MediaType.ANIME, it.attachView)
processEditorAction(
alertDialog,
editText,
MediaType.ANIME,
it.attachView
)
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
},
@ -194,8 +203,8 @@ class SettingsExtensionsActivity: AppCompatActivity() {
onClick = {
val dialogView = DialogUserAgentBinding.inflate(layoutInflater)
val editText = dialogView.userAgentTextBox.apply {
hint = getString(R.string.manga_add_repository)
}
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, _ ->
@ -209,7 +218,12 @@ class SettingsExtensionsActivity: AppCompatActivity() {
dialog.dismiss()
}.create()
processEditorAction(alertDialog, editText, MediaType.MANGA, it.attachView)
processEditorAction(
alertDialog,
editText,
MediaType.MANGA,
it.attachView
)
alertDialog.show()
alertDialog.window?.setDimAmount(0.8f)
},
@ -229,7 +243,10 @@ class SettingsExtensionsActivity: AppCompatActivity() {
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())
PrefManager.setVal(
PrefName.DefaultUserAgent,
editText.text.toString()
)
dialog.dismiss()
}.setNeutralButton(getString(R.string.reset)) { dialog, _ ->
PrefManager.removeVal(PrefName.DefaultUserAgent)
@ -248,7 +265,7 @@ class SettingsExtensionsActivity: AppCompatActivity() {
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,
isChecked = extensionInstaller.get() == BasePreferences.ExtensionInstaller.LEGACY,
switch = { isChecked, _ ->
if (isChecked) {
extensionInstaller.set(BasePreferences.ExtensionInstaller.LEGACY)

View file

@ -22,7 +22,7 @@ import ani.dantotsu.themes.ThemeManager
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class SettingsMangaActivity: AppCompatActivity(){
class SettingsMangaActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingsMangaBinding
override fun onCreate(savedInstanceState: Bundle?) {
@ -82,7 +82,12 @@ class SettingsMangaActivity: AppCompatActivity(){
onClick = {
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.purge_manga_downloads)
.setMessage(getString(R.string.purge_confirm, getString(R.string.manga)))
.setMessage(
getString(
R.string.purge_confirm,
getString(R.string.manga)
)
)
.setPositiveButton(R.string.yes) { dialog, _ ->
val downloadsManager = Injekt.get<DownloadsManager>()
downloadsManager.purgeDownloads(MediaType.MANGA)
@ -103,7 +108,12 @@ class SettingsMangaActivity: AppCompatActivity(){
onClick = {
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.purge_novel_downloads)
.setMessage(getString(R.string.purge_confirm, getString(R.string.novels)))
.setMessage(
getString(
R.string.purge_confirm,
getString(R.string.novels)
)
)
.setPositiveButton(R.string.yes) { dialog, _ ->
val downloadsManager = Injekt.get<DownloadsManager>()
downloadsManager.purgeDownloads(MediaType.NOVEL)
@ -121,7 +131,7 @@ class SettingsMangaActivity: AppCompatActivity(){
desc = getString(R.string.include_list),
icon = R.drawable.view_list_24,
isChecked = PrefManager.getVal(PrefName.IncludeMangaList),
switch = {isChecked, _ ->
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.IncludeMangaList, isChecked)
restartApp()
}

View file

@ -25,7 +25,7 @@ import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
class SettingsNotificationActivity: AppCompatActivity(){
class SettingsNotificationActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingsNotificationsBinding
override fun onCreate(savedInstanceState: Bundle?) {
@ -68,22 +68,32 @@ class SettingsNotificationActivity: AppCompatActivity(){
arrayListOf(
Settings(
type = 1,
name = getString(R.string.subscriptions_checking_time_s, timeNames[curTime]),
name = getString(
R.string.subscriptions_checking_time_s,
timeNames[curTime]
),
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 ->
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()
val dialog =
speedDialog.setSingleChoiceItems(timeNames, curTime) { dialog, 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)
},
onLongClick = {
@ -100,11 +110,15 @@ class SettingsNotificationActivity: AppCompatActivity(){
onClick = {
val types = NotificationType.entries.map { it.name }
val filteredTypes =
PrefManager.getVal<Set<String>>(PrefName.AnilistFilteredTypes).toMutableSet()
PrefManager.getVal<Set<String>>(PrefName.AnilistFilteredTypes)
.toMutableSet()
val selected = types.map { filteredTypes.contains(it) }.toBooleanArray()
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.anilist_notification_filters)
.setMultiChoiceItems(types.toTypedArray(), selected) { _, which, isChecked ->
.setMultiChoiceItems(
types.toTypedArray(),
selected
) { _, which, isChecked ->
val type = types[which]
if (isChecked) {
filteredTypes.add(type)
@ -130,13 +144,20 @@ class SettingsNotificationActivity: AppCompatActivity(){
),
icon = R.drawable.ic_round_notifications_none_24,
onClick = {
val selected = PrefManager.getVal<Int>(PrefName.AnilistNotificationInterval)
val selected =
PrefManager.getVal<Int>(PrefName.AnilistNotificationInterval)
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.subscriptions_checking_time)
.setSingleChoiceItems(aItems.toTypedArray(), selected) { dialog, i ->
.setSingleChoiceItems(
aItems.toTypedArray(),
selected
) { dialog, i ->
PrefManager.setVal(PrefName.AnilistNotificationInterval, i)
it.settingsTitle.text =
getString(R.string.anilist_notifications_checking_time, aItems[i])
getString(
R.string.anilist_notifications_checking_time,
aItems[i]
)
dialog.dismiss()
TaskScheduler.create(
context, PrefManager.getVal(PrefName.UseAlarmManager)
@ -158,13 +179,20 @@ class SettingsNotificationActivity: AppCompatActivity(){
),
icon = R.drawable.ic_round_notifications_none_24,
onClick = {
val selected = PrefManager.getVal<Int>(PrefName.CommentNotificationInterval)
val selected =
PrefManager.getVal<Int>(PrefName.CommentNotificationInterval)
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.subscriptions_checking_time)
.setSingleChoiceItems(cItems.toTypedArray(), selected) { dialog, i ->
.setSingleChoiceItems(
cItems.toTypedArray(),
selected
) { dialog, i ->
PrefManager.setVal(PrefName.CommentNotificationInterval, i)
it.settingsTitle.text =
getString(R.string.comment_notification_checking_time, cItems[i])
getString(
R.string.comment_notification_checking_time,
cItems[i]
)
dialog.dismiss()
TaskScheduler.create(
context, PrefManager.getVal(PrefName.UseAlarmManager)
@ -181,7 +209,10 @@ class SettingsNotificationActivity: AppCompatActivity(){
icon = R.drawable.ic_round_smart_button_24,
isChecked = PrefManager.getVal(PrefName.SubscriptionCheckingNotifications),
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.SubscriptionCheckingNotifications, isChecked)
PrefManager.setVal(
PrefName.SubscriptionCheckingNotifications,
isChecked
)
},
onLongClick = {
openSettings(context, null)
@ -193,7 +224,7 @@ class SettingsNotificationActivity: AppCompatActivity(){
desc = getString(R.string.use_alarm_manager_reliable),
icon = R.drawable.ic_anilist,
isChecked = PrefManager.getVal(PrefName.UseAlarmManager),
switch = {isChecked, view ->
switch = { isChecked, view ->
if (isChecked) {
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
.setTitle(R.string.use_alarm_manager)
@ -212,7 +243,7 @@ class SettingsNotificationActivity: AppCompatActivity(){
}.setNegativeButton(R.string.cancel) { dialog, _ ->
view.settingsButton.isChecked = false
PrefManager.setVal(PrefName.UseAlarmManager, false)
dialog.dismiss()
}.create()
alertDialog.window?.setDimAmount(0.8f)

View file

@ -164,14 +164,17 @@ class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultLi
icon = R.drawable.ic_palette,
onClick = {
val originalColor: Int = PrefManager.getVal(PrefName.CustomThemeInt)
class CustomColorDialog : SimpleColorDialog() {
override fun onPositiveButtonClick() {
reload()
super.onPositiveButtonClick()
}
}
val tag = "colorPicker"
CustomColorDialog().title(R.string.custom_theme).colorPreset(originalColor)
CustomColorDialog().title(R.string.custom_theme)
.colorPreset(originalColor)
.colors(context, SimpleColorDialog.MATERIAL_COLOR_PALLET)
.allowCustom(true).showOutline(0x46000000).gridNumColumn(5)
.choiceMode(SimpleColorDialog.SINGLE_CHOICE).neg()
@ -198,7 +201,8 @@ class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultLi
}
return true
}
fun reload(){
fun reload() {
PrefManager.setCustomVal("reload", true)
restartApp()
}

View file

@ -105,7 +105,7 @@ class UserInterfaceSettingsActivity : AppCompatActivity() {
PrefManager.setVal(PrefName.BlurBanners, isChecked)
restartApp()
}
binding.uiSettingsBlurRadius.value = (PrefManager.getVal(PrefName.BlurRadius) as Float)
binding.uiSettingsBlurRadius.value = (PrefManager.getVal(PrefName.BlurRadius) as Float)
binding.uiSettingsBlurRadius.addOnChangeListener { _, value, _ ->
PrefManager.setVal(PrefName.BlurRadius, value)
restartApp()

View file

@ -102,7 +102,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
UseProxyForTimeStamps(Pref(Location.Player, Boolean::class, false)),
ShowTimeStampButton(Pref(Location.Player, Boolean::class, true)),
AutoSkipOPED(Pref(Location.Player, Boolean::class, false)),
AutoSkipRecap(Pref(Location.Player, Boolean::class, false )),
AutoSkipRecap(Pref(Location.Player, Boolean::class, false)),
AutoPlay(Pref(Location.Player, Boolean::class, true)),
AutoSkipFiller(Pref(Location.Player, Boolean::class, false)),
AskIndividualPlayer(Pref(Location.Player, Boolean::class, true)),

View file

@ -82,6 +82,7 @@ class SharedPreferenceStringSetLiveData(
fun SharedPreferences.intLiveData(key: String, defValue: Int): SharedPreferenceLiveData<Int> {
return SharedPreferenceIntLiveData(this, key, defValue)
}
@Suppress("unused")
fun SharedPreferences.stringLiveData(