feat: WIP new settings UI
This commit is contained in:
parent
f8a6fad513
commit
91d1d2cf1d
20 changed files with 1061 additions and 1503 deletions
|
@ -14,7 +14,9 @@ import androidx.activity.result.contract.ActivityResultContracts
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.connections.anilist.Anilist
|
||||
import ani.dantotsu.databinding.ActivitySettingsCommonBinding
|
||||
import ani.dantotsu.download.DownloadsManager
|
||||
import ani.dantotsu.initActivity
|
||||
|
@ -32,6 +34,7 @@ import ani.dantotsu.toast
|
|||
import ani.dantotsu.util.LauncherWrapper
|
||||
import ani.dantotsu.util.StoragePermissions
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -41,6 +44,7 @@ import uy.kohesive.injekt.api.get
|
|||
class SettingsCommonActivity: AppCompatActivity(){
|
||||
private lateinit var binding: ActivitySettingsCommonBinding
|
||||
private lateinit var launcher: LauncherWrapper
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
ThemeManager(this).applyTheme()
|
||||
|
@ -88,10 +92,7 @@ class SettingsCommonActivity: AppCompatActivity(){
|
|||
}
|
||||
val contract = ActivityResultContracts.OpenDocumentTree()
|
||||
launcher = LauncherWrapper(this, contract)
|
||||
val managers = arrayOf("Default", "1DM", "ADM")
|
||||
val downloadManagerDialog =
|
||||
AlertDialog.Builder(this, R.style.MyPopup).setTitle(R.string.download_manager)
|
||||
var downloadManager: Int = PrefManager.getVal(PrefName.DownloadManager)
|
||||
|
||||
binding.apply {
|
||||
|
||||
settingsCommonLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
|
@ -101,66 +102,6 @@ class SettingsCommonActivity: AppCompatActivity(){
|
|||
commonSettingsBack.setOnClickListener {
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
}
|
||||
settingsDownloadManager.setOnClickListener {
|
||||
val dialog = downloadManagerDialog.setSingleChoiceItems(
|
||||
managers, downloadManager
|
||||
) { dialog, count ->
|
||||
downloadManager = count
|
||||
PrefManager.setVal(PrefName.DownloadManager, downloadManager)
|
||||
dialog.dismiss()
|
||||
}.show()
|
||||
dialog.window?.setDimAmount(0.8f)
|
||||
}
|
||||
|
||||
importExportSettings.setOnClickListener {
|
||||
StoragePermissions.downloadsPermission(context)
|
||||
val selectedArray = mutableListOf(false)
|
||||
val filteredLocations = Location.entries.filter { it.exportable }
|
||||
selectedArray.addAll(List(filteredLocations.size - 1) { false })
|
||||
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
|
||||
.setTitle(R.string.backup_restore).setMultiChoiceItems(
|
||||
filteredLocations.map { it.name }.toTypedArray(),
|
||||
selectedArray.toBooleanArray()
|
||||
) { _, which, isChecked ->
|
||||
selectedArray[which] = isChecked
|
||||
}.setPositiveButton(R.string.button_restore) { dialog, _ ->
|
||||
openDocumentLauncher.launch(arrayOf("*/*"))
|
||||
dialog.dismiss()
|
||||
}.setNegativeButton(R.string.button_backup) { dialog, _ ->
|
||||
if (!selectedArray.contains(true)) {
|
||||
toast(R.string.no_location_selected)
|
||||
return@setNegativeButton
|
||||
}
|
||||
dialog.dismiss()
|
||||
val selected =
|
||||
filteredLocations.filterIndexed { index, _ -> selectedArray[index] }
|
||||
if (selected.contains(Location.Protected)) {
|
||||
passwordAlertDialog(true) { password ->
|
||||
if (password != null) {
|
||||
savePrefsToDownloads(
|
||||
"DantotsuSettings",
|
||||
PrefManager.exportAllPrefs(selected),
|
||||
context,
|
||||
password
|
||||
)
|
||||
} else {
|
||||
toast(R.string.password_cannot_be_empty)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
savePrefsToDownloads(
|
||||
"DantotsuSettings",
|
||||
PrefManager.exportAllPrefs(selected),
|
||||
context,
|
||||
null
|
||||
)
|
||||
}
|
||||
}.setNeutralButton(R.string.cancel) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}.create()
|
||||
dialog.window?.setDimAmount(0.8f)
|
||||
dialog.show()
|
||||
}
|
||||
val exDns = listOf(
|
||||
"None",
|
||||
"Cloudflare",
|
||||
|
@ -189,60 +130,181 @@ class SettingsCommonActivity: AppCompatActivity(){
|
|||
restartApp(binding.root)
|
||||
}
|
||||
|
||||
settingsContinueMedia.isChecked = PrefManager.getVal(PrefName.ContinueMedia)
|
||||
settingsContinueMedia.setOnCheckedChangeListener { _, isChecked ->
|
||||
PrefManager.setVal(PrefName.ContinueMedia, isChecked)
|
||||
}
|
||||
|
||||
settingsSearchSources.isChecked = PrefManager.getVal(PrefName.SearchSources)
|
||||
settingsSearchSources.setOnCheckedChangeListener { _, isChecked ->
|
||||
PrefManager.setVal(PrefName.SearchSources, isChecked)
|
||||
}
|
||||
|
||||
settingsRecentlyListOnly.isChecked = PrefManager.getVal(PrefName.RecentlyListOnly)
|
||||
settingsRecentlyListOnly.setOnCheckedChangeListener { _, isChecked ->
|
||||
PrefManager.setVal(PrefName.RecentlyListOnly, isChecked)
|
||||
}
|
||||
settingsAdultAnimeOnly.isChecked = PrefManager.getVal(PrefName.AdultOnly)
|
||||
settingsAdultAnimeOnly.setOnCheckedChangeListener { _, isChecked ->
|
||||
PrefManager.setVal(PrefName.AdultOnly, isChecked)
|
||||
restartApp(binding.root)
|
||||
}
|
||||
|
||||
settingsDownloadLocation.setOnClickListener {
|
||||
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
|
||||
.setTitle(R.string.change_download_location)
|
||||
.setMessage(R.string.download_location_msg)
|
||||
.setPositiveButton(R.string.ok) { dialog, _ ->
|
||||
val oldUri = PrefManager.getVal<String>(PrefName.DownloadsDir)
|
||||
launcher.registerForCallback { success ->
|
||||
if (success) {
|
||||
toast(getString(R.string.please_wait))
|
||||
val newUri = PrefManager.getVal<String>(PrefName.DownloadsDir)
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
Injekt.get<DownloadsManager>().moveDownloadsDir(
|
||||
context, Uri.parse(oldUri), Uri.parse(newUri)
|
||||
) { finished, message ->
|
||||
if (finished) {
|
||||
toast(getString(R.string.success))
|
||||
settingsRecyclerView.adapter = SettingsAdapter(
|
||||
arrayListOf(
|
||||
Settings(
|
||||
type = 1,
|
||||
name = getString(R.string.ui_settings),
|
||||
desc = getString(R.string.ui_settings),
|
||||
icon = R.drawable.ic_round_auto_awesome_24,
|
||||
onClick = {
|
||||
startActivity(Intent(context, UserInterfaceSettingsActivity::class.java))
|
||||
},
|
||||
isActivity = true
|
||||
),
|
||||
Settings(
|
||||
type = 1,
|
||||
name = getString(R.string.download_manager_select),
|
||||
desc = getString(R.string.download_manager_select),
|
||||
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)
|
||||
}
|
||||
),
|
||||
Settings(
|
||||
type = 1,
|
||||
name = getString(R.string.backup_restore),
|
||||
desc = getString(R.string.backup_restore),
|
||||
icon = R.drawable.backup_restore,
|
||||
onClick = {
|
||||
StoragePermissions.downloadsPermission(context)
|
||||
val selectedArray = mutableListOf(false)
|
||||
val filteredLocations = Location.entries.filter { it.exportable }
|
||||
selectedArray.addAll(List(filteredLocations.size - 1) { false })
|
||||
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
|
||||
.setTitle(R.string.backup_restore).setMultiChoiceItems(
|
||||
filteredLocations.map { it.name }.toTypedArray(),
|
||||
selectedArray.toBooleanArray()
|
||||
) { _, which, isChecked ->
|
||||
selectedArray[which] = isChecked
|
||||
}.setPositiveButton(R.string.button_restore) { dialog, _ ->
|
||||
openDocumentLauncher.launch(arrayOf("*/*"))
|
||||
dialog.dismiss()
|
||||
}.setNegativeButton(R.string.button_backup) { dialog, _ ->
|
||||
if (!selectedArray.contains(true)) {
|
||||
toast(R.string.no_location_selected)
|
||||
return@setNegativeButton
|
||||
}
|
||||
dialog.dismiss()
|
||||
val selected =
|
||||
filteredLocations.filterIndexed { index, _ -> selectedArray[index] }
|
||||
if (selected.contains(Location.Protected)) {
|
||||
passwordAlertDialog(true) { password ->
|
||||
if (password != null) {
|
||||
savePrefsToDownloads(
|
||||
"DantotsuSettings",
|
||||
PrefManager.exportAllPrefs(selected),
|
||||
context,
|
||||
password
|
||||
)
|
||||
} else {
|
||||
toast(R.string.password_cannot_be_empty)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
savePrefsToDownloads(
|
||||
"DantotsuSettings",
|
||||
PrefManager.exportAllPrefs(selected),
|
||||
context,
|
||||
null
|
||||
)
|
||||
}
|
||||
}.setNeutralButton(R.string.cancel) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}.create()
|
||||
dialog.window?.setDimAmount(0.8f)
|
||||
dialog.show()
|
||||
},
|
||||
),
|
||||
Settings(
|
||||
type = 1,
|
||||
name = getString(R.string.change_download_location),
|
||||
desc = getString(R.string.change_download_location),
|
||||
icon = R.drawable.ic_round_source_24,
|
||||
onClick = {
|
||||
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
|
||||
.setTitle(R.string.change_download_location)
|
||||
.setMessage(R.string.download_location_msg)
|
||||
.setPositiveButton(R.string.ok) { dialog, _ ->
|
||||
val oldUri = PrefManager.getVal<String>(PrefName.DownloadsDir)
|
||||
launcher.registerForCallback { success ->
|
||||
if (success) {
|
||||
toast(getString(R.string.please_wait))
|
||||
val newUri = PrefManager.getVal<String>(PrefName.DownloadsDir)
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
Injekt.get<DownloadsManager>().moveDownloadsDir(
|
||||
context, Uri.parse(oldUri), Uri.parse(newUri)
|
||||
) { finished, message ->
|
||||
if (finished) {
|
||||
toast(getString(R.string.success))
|
||||
} else {
|
||||
toast(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(message)
|
||||
toast(getString(R.string.error))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(getString(R.string.error))
|
||||
}
|
||||
launcher.launch()
|
||||
dialog.dismiss()
|
||||
}.setNeutralButton(R.string.cancel) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}.create()
|
||||
dialog.window?.setDimAmount(0.8f)
|
||||
dialog.show()
|
||||
}
|
||||
launcher.launch()
|
||||
dialog.dismiss()
|
||||
}.setNeutralButton(R.string.cancel) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}.create()
|
||||
dialog.window?.setDimAmount(0.8f)
|
||||
dialog.show()
|
||||
}
|
||||
),
|
||||
Settings(
|
||||
type = 2,
|
||||
name = getString(R.string.always_continue_content),
|
||||
desc = getString(R.string.always_continue_content),
|
||||
icon = R.drawable.ic_round_delete_24,
|
||||
isChecked = PrefManager.getVal(PrefName.ContinueMedia),
|
||||
switch = {isChecked, _ ->
|
||||
PrefManager.setVal(PrefName.ContinueMedia, isChecked)
|
||||
}
|
||||
),
|
||||
Settings(
|
||||
type = 2,
|
||||
name = getString(R.string.search_source_list),
|
||||
desc = getString(R.string.search_source_list),
|
||||
icon = R.drawable.ic_round_search_sources_24,
|
||||
isChecked = PrefManager.getVal(PrefName.SearchSources),
|
||||
switch = {isChecked, _ ->
|
||||
PrefManager.setVal(PrefName.SearchSources, isChecked)
|
||||
}
|
||||
),
|
||||
Settings(
|
||||
type = 2,
|
||||
name = getString(R.string.recentlyListOnly),
|
||||
desc = getString(R.string.recentlyListOnly),
|
||||
icon = R.drawable.ic_round_new_releases_24,
|
||||
isChecked = PrefManager.getVal(PrefName.RecentlyListOnly),
|
||||
switch = {isChecked, _ ->
|
||||
PrefManager.setVal(PrefName.RecentlyListOnly, isChecked)
|
||||
}
|
||||
),
|
||||
Settings(
|
||||
type = 2,
|
||||
name = getString(R.string.adult_only_content),
|
||||
desc = getString(R.string.adult_only_content),
|
||||
icon = R.drawable.ic_round_nsfw_24,
|
||||
isChecked = PrefManager.getVal(PrefName.AdultOnly),
|
||||
switch = {isChecked, _ ->
|
||||
PrefManager.setVal(PrefName.AdultOnly, isChecked)
|
||||
restartApp(binding.root)
|
||||
},
|
||||
isVisible = Anilist.adult
|
||||
|
||||
),
|
||||
)
|
||||
)
|
||||
settingsRecyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
||||
setHasFixedSize(true)
|
||||
}
|
||||
var previousStart: View = when (PrefManager.getVal<Int>(PrefName.DefaultStartUpTab)) {
|
||||
0 -> uiSettingsAnime
|
||||
1 -> uiSettingsHome
|
||||
|
@ -270,13 +332,6 @@ class SettingsCommonActivity: AppCompatActivity(){
|
|||
uiDefault(2, it)
|
||||
}
|
||||
|
||||
settingsUi.setOnClickListener {
|
||||
startActivity(
|
||||
Intent(
|
||||
context, UserInterfaceSettingsActivity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun passwordAlertDialog(isExporting: Boolean, callback: (CharArray?) -> Unit) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue