2021-06-10 23:00:22 +00:00
|
|
|
package com.lagradost.cloudstream3.ui.settings
|
|
|
|
|
2021-11-03 19:38:50 +00:00
|
|
|
|
2021-10-30 18:14:12 +00:00
|
|
|
import android.app.UiModeManager
|
|
|
|
import android.content.Context
|
2021-11-07 22:10:19 +00:00
|
|
|
import android.content.Intent
|
2021-10-30 18:14:12 +00:00
|
|
|
import android.content.res.Configuration
|
2021-11-07 22:10:19 +00:00
|
|
|
import android.net.Uri
|
2021-12-16 23:45:20 +00:00
|
|
|
import android.os.Build
|
2021-06-10 23:00:22 +00:00
|
|
|
import android.os.Bundle
|
2021-11-01 15:33:46 +00:00
|
|
|
import android.os.Environment
|
2021-11-07 22:10:19 +00:00
|
|
|
import android.widget.ImageView
|
|
|
|
import android.widget.TextView
|
2021-08-15 17:38:41 +00:00
|
|
|
import android.widget.Toast
|
2021-11-01 15:33:46 +00:00
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
2021-09-07 19:16:12 +00:00
|
|
|
import androidx.appcompat.app.AlertDialog
|
2021-08-07 01:53:45 +00:00
|
|
|
import androidx.preference.Preference
|
2021-06-10 23:00:22 +00:00
|
|
|
import androidx.preference.PreferenceFragmentCompat
|
2021-08-30 21:42:58 +00:00
|
|
|
import androidx.preference.PreferenceManager
|
2021-11-08 18:13:39 +00:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2021-11-01 15:33:46 +00:00
|
|
|
import com.hippo.unifile.UniFile
|
2021-09-23 18:08:57 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.apis
|
2021-09-12 14:10:22 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings
|
2021-09-23 18:08:57 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
|
|
|
|
import com.lagradost.cloudstream3.APIHolder.restrictedApis
|
2021-11-01 15:33:46 +00:00
|
|
|
import com.lagradost.cloudstream3.AcraApplication
|
2021-12-16 23:45:20 +00:00
|
|
|
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.CommonActivity.setLocale
|
|
|
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
2021-09-12 14:10:22 +00:00
|
|
|
import com.lagradost.cloudstream3.DubStatus
|
2021-06-10 23:00:22 +00:00
|
|
|
import com.lagradost.cloudstream3.R
|
2021-12-05 16:22:30 +00:00
|
|
|
import com.lagradost.cloudstream3.app
|
2021-09-02 14:06:43 +00:00
|
|
|
import com.lagradost.cloudstream3.mvvm.logError
|
2022-01-13 21:09:05 +00:00
|
|
|
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
2021-11-12 16:55:54 +00:00
|
|
|
import com.lagradost.cloudstream3.syncproviders.AccountManager
|
|
|
|
import com.lagradost.cloudstream3.syncproviders.OAuth2API
|
|
|
|
import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.aniListApi
|
|
|
|
import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.malApi
|
2021-09-12 14:10:22 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.APIRepository
|
2021-08-07 01:53:45 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment
|
2021-11-05 22:08:47 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.HOMEPAGE_API
|
2021-08-15 17:38:41 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
|
2021-09-04 11:38:35 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.Qualities
|
|
|
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
|
2021-09-02 14:06:43 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
|
2021-09-12 14:10:22 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
|
2021-09-23 18:08:57 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.SubtitleHelper
|
2021-12-12 02:33:17 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
2021-08-04 13:30:34 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
2021-11-07 22:10:19 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
2021-11-01 15:33:46 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath
|
|
|
|
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getDownloadDir
|
|
|
|
import java.io.File
|
2021-08-15 17:38:41 +00:00
|
|
|
import kotlin.concurrent.thread
|
2021-06-10 23:00:22 +00:00
|
|
|
|
2021-09-02 14:06:43 +00:00
|
|
|
|
2021-06-10 23:00:22 +00:00
|
|
|
class SettingsFragment : PreferenceFragmentCompat() {
|
2021-10-30 18:14:12 +00:00
|
|
|
companion object {
|
|
|
|
fun Context.isTvSettings(): Boolean {
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
var value = settingsManager.getInt(this.getString(R.string.app_layout_key), -1)
|
|
|
|
if (value == -1) {
|
|
|
|
value = if (isAutoTv()) 1 else 0
|
|
|
|
}
|
|
|
|
return value == 1
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun Context.isAutoTv(): Boolean {
|
|
|
|
val uiModeManager = getSystemService(Context.UI_MODE_SERVICE) as UiModeManager?
|
|
|
|
return uiModeManager?.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION
|
|
|
|
}
|
2021-11-07 22:10:19 +00:00
|
|
|
|
|
|
|
private const val accountEnabled = false
|
2021-10-30 18:14:12 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 11:38:35 +00:00
|
|
|
private var beneneCount = 0
|
|
|
|
|
2021-11-01 15:33:46 +00:00
|
|
|
// Open file picker
|
|
|
|
private val pathPicker = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->
|
2021-11-04 16:36:12 +00:00
|
|
|
// It lies, it can be null if file manager quits.
|
|
|
|
if (uri == null) return@registerForActivityResult
|
2021-11-02 14:25:12 +00:00
|
|
|
val context = context ?: AcraApplication.context ?: return@registerForActivityResult
|
2021-11-01 15:33:46 +00:00
|
|
|
// RW perms for the path
|
|
|
|
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
|
|
|
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
|
|
|
|
|
|
|
context.contentResolver.takePersistableUriPermission(uri, flags)
|
|
|
|
|
|
|
|
val file = UniFile.fromUri(context, uri)
|
|
|
|
println("Selected URI path: $uri - Full path: ${file.filePath}")
|
|
|
|
|
|
|
|
// Stores the real URI using download_path_key
|
|
|
|
// Important that the URI is stored instead of filepath due to permissions.
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
.edit().putString(getString(R.string.download_path_key), uri.toString()).apply()
|
|
|
|
|
|
|
|
// From URI -> File path
|
|
|
|
// File path here is purely for cosmetic purposes in settings
|
|
|
|
(file.filePath ?: uri.toString()).let {
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
.edit().putString(getString(R.string.download_path_pref), it).apply()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 22:52:39 +00:00
|
|
|
// idk, if you find a way of automating this it would be great
|
2021-09-04 11:38:35 +00:00
|
|
|
private val languages = arrayListOf(
|
2021-09-20 21:11:36 +00:00
|
|
|
Triple("\uD83C\uDDEA\uD83C\uDDF8", "Spanish", "es"),
|
2021-09-04 11:38:35 +00:00
|
|
|
Triple("\uD83C\uDDEC\uD83C\uDDE7", "English", "en"),
|
2021-09-13 10:36:18 +00:00
|
|
|
Triple("\uD83C\uDDFB\uD83C\uDDF3", "Viet Nam", "vi"),
|
2021-09-04 11:38:35 +00:00
|
|
|
Triple("\uD83C\uDDF3\uD83C\uDDF1", "Dutch", "nl"),
|
|
|
|
Triple("\uD83C\uDDEB\uD83C\uDDF7", "French", "fr"),
|
|
|
|
Triple("\uD83C\uDDEC\uD83C\uDDF7", "Greek", "gr"),
|
|
|
|
Triple("\uD83C\uDDF8\uD83C\uDDEA", "Swedish", "sv"),
|
|
|
|
Triple("\uD83C\uDDF5\uD83C\uDDED", "Tagalog", "tl"),
|
2021-09-12 14:10:22 +00:00
|
|
|
Triple("\uD83C\uDDF5\uD83C\uDDF1", "Polish", "pl"),
|
2021-09-06 10:22:06 +00:00
|
|
|
Triple("\uD83C\uDDEE\uD83C\uDDF3", "Hindi", "hi"),
|
2021-09-06 17:49:52 +00:00
|
|
|
Triple("\uD83C\uDDEE\uD83C\uDDF3", "Malayalam", "ml"),
|
2021-10-23 11:59:14 +00:00
|
|
|
Triple("\uD83C\uDDF3\uD83C\uDDF4", "Norsk", "no"),
|
2021-10-23 16:33:46 +00:00
|
|
|
Triple("\ud83c\udde9\ud83c\uddea", "German", "de"),
|
2022-01-10 21:43:36 +00:00
|
|
|
Triple("\ud83c\uddf1\ud83c\udde7", "Arabic", "ar"),
|
2021-12-08 21:36:49 +00:00
|
|
|
Triple("\ud83c\uddf9\ud83c\uddf7", "Turkish", "tr"),
|
|
|
|
Triple("\ud83c\uddf2\ud83c\uddf0", "Macedonian", "mk"),
|
2021-12-08 21:37:51 +00:00
|
|
|
Triple("\ud83c\udde7\ud83c\uddf7", "Portuguese (Brazil)", "pt"),
|
|
|
|
Triple("\ud83c\uddf7\ud83c\uddf4", "Romanian", "ro"),
|
2021-09-19 22:52:39 +00:00
|
|
|
).sortedBy { it.second } //ye, we go alphabetical, so ppl don't put their lang on top
|
2021-08-30 21:42:58 +00:00
|
|
|
|
2021-11-12 16:55:54 +00:00
|
|
|
private fun showAccountSwitch(context: Context, api: AccountManager) {
|
2021-12-16 23:45:20 +00:00
|
|
|
val accounts = api.getAccounts() ?: return
|
|
|
|
|
2021-11-08 18:13:39 +00:00
|
|
|
val builder =
|
|
|
|
AlertDialog.Builder(context, R.style.AlertDialogCustom).setView(R.layout.account_switch)
|
|
|
|
val dialog = builder.show()
|
|
|
|
|
|
|
|
dialog.findViewById<TextView>(R.id.account_add)?.setOnClickListener {
|
2021-12-16 23:45:20 +00:00
|
|
|
api.authenticate()
|
2021-11-08 18:13:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
val ogIndex = api.accountIndex
|
|
|
|
|
2021-11-12 16:55:54 +00:00
|
|
|
val items = ArrayList<OAuth2API.LoginInfo>()
|
2021-11-08 18:13:39 +00:00
|
|
|
|
|
|
|
for (index in accounts) {
|
|
|
|
api.accountIndex = index
|
2021-12-16 23:45:20 +00:00
|
|
|
val accountInfo = api.loginInfo()
|
2021-11-08 18:13:39 +00:00
|
|
|
if (accountInfo != null) {
|
|
|
|
items.add(accountInfo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
api.accountIndex = ogIndex
|
|
|
|
val adapter = AccountAdapter(items, R.layout.account_single) {
|
2021-12-12 02:33:17 +00:00
|
|
|
dialog?.dismissSafe(activity)
|
2021-12-16 23:45:20 +00:00
|
|
|
api.changeAccount(it.card.accountIndex)
|
2021-11-08 18:13:39 +00:00
|
|
|
}
|
|
|
|
val list = dialog.findViewById<RecyclerView>(R.id.account_list)
|
|
|
|
list?.adapter = adapter
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
private fun showLoginInfo(api: AccountManager, info: OAuth2API.LoginInfo) {
|
2021-11-07 22:10:19 +00:00
|
|
|
val builder =
|
2021-12-16 23:45:20 +00:00
|
|
|
AlertDialog.Builder(context ?: return, R.style.AlertDialogCustom).setView(R.layout.account_managment)
|
2021-11-07 22:10:19 +00:00
|
|
|
val dialog = builder.show()
|
|
|
|
|
|
|
|
dialog.findViewById<ImageView>(R.id.account_profile_picture)?.setImage(info.profilePicture)
|
|
|
|
dialog.findViewById<TextView>(R.id.account_logout)?.setOnClickListener {
|
2021-12-16 23:45:20 +00:00
|
|
|
api.logOut()
|
|
|
|
dialog.dismissSafe(activity)
|
2021-11-07 22:10:19 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
(info.name ?: context?.getString(R.string.no_data))?.let {
|
|
|
|
dialog.findViewById<TextView>(R.id.account_name)?.text = it
|
|
|
|
}
|
2021-11-07 22:10:19 +00:00
|
|
|
dialog.findViewById<TextView>(R.id.account_site)?.text = api.name
|
2021-11-08 18:13:39 +00:00
|
|
|
dialog.findViewById<TextView>(R.id.account_switch_account)?.setOnClickListener {
|
2021-12-12 02:33:17 +00:00
|
|
|
dialog.dismissSafe(activity)
|
2021-11-08 18:13:39 +00:00
|
|
|
showAccountSwitch(it.context, api)
|
|
|
|
}
|
2021-11-07 22:10:19 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 23:00:22 +00:00
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
2021-08-04 13:30:34 +00:00
|
|
|
hideKeyboard()
|
2021-06-10 23:00:22 +00:00
|
|
|
setPreferencesFromResource(R.xml.settings, rootKey)
|
2021-12-12 02:33:17 +00:00
|
|
|
|
2021-09-02 14:06:43 +00:00
|
|
|
val updatePreference = findPreference<Preference>(getString(R.string.manual_check_update_key))!!
|
|
|
|
val localePreference = findPreference<Preference>(getString(R.string.locale_key))!!
|
|
|
|
val benenePreference = findPreference<Preference>(getString(R.string.benene_count))!!
|
2021-09-04 11:38:35 +00:00
|
|
|
val watchQualityPreference = findPreference<Preference>(getString(R.string.quality_pref_key))!!
|
2021-10-18 14:02:05 +00:00
|
|
|
val dnsPreference = findPreference<Preference>(getString(R.string.dns_key))!!
|
2021-09-07 19:16:12 +00:00
|
|
|
val legalPreference = findPreference<Preference>(getString(R.string.legal_notice_key))!!
|
2021-09-12 14:10:22 +00:00
|
|
|
val subdubPreference = findPreference<Preference>(getString(R.string.display_sub_key))!!
|
2021-09-23 18:08:57 +00:00
|
|
|
val providerLangPreference = findPreference<Preference>(getString(R.string.provider_lang_key))!!
|
2021-11-01 15:33:46 +00:00
|
|
|
val downloadPathPreference = findPreference<Preference>(getString(R.string.download_path_key))!!
|
2021-10-30 18:14:12 +00:00
|
|
|
val allLayoutPreference = findPreference<Preference>(getString(R.string.app_layout_key))!!
|
2021-10-31 01:17:56 +00:00
|
|
|
val colorPrimaryPreference = findPreference<Preference>(getString(R.string.primary_color_key))!!
|
2021-10-31 17:51:39 +00:00
|
|
|
val preferedMediaTypePreference = findPreference<Preference>(getString(R.string.prefer_media_type_key))!!
|
2021-10-31 14:14:01 +00:00
|
|
|
val appThemePreference = findPreference<Preference>(getString(R.string.app_theme_key))!!
|
2021-12-12 02:33:17 +00:00
|
|
|
val subPreference = findPreference<Preference>(getString(R.string.subtitle_settings_key))!!
|
|
|
|
|
|
|
|
subPreference.setOnPreferenceClickListener {
|
|
|
|
SubtitlesFragment.push(activity, false)
|
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-09-07 19:16:12 +00:00
|
|
|
|
2021-11-07 22:10:19 +00:00
|
|
|
val syncApis = listOf(Pair(R.string.mal_key, malApi), Pair(R.string.anilist_key, aniListApi))
|
|
|
|
for (sync in syncApis) {
|
|
|
|
findPreference<Preference>(getString(sync.first))?.apply {
|
|
|
|
isVisible = accountEnabled
|
|
|
|
val api = sync.second
|
|
|
|
title = getString(R.string.login_format).format(api.name, getString(R.string.account))
|
|
|
|
setOnPreferenceClickListener { pref ->
|
|
|
|
pref.context?.let { ctx ->
|
2021-12-16 23:45:20 +00:00
|
|
|
val info = api.loginInfo()
|
2021-11-07 22:10:19 +00:00
|
|
|
if (info != null) {
|
2021-12-16 23:45:20 +00:00
|
|
|
showLoginInfo(api, info)
|
2021-11-07 22:10:19 +00:00
|
|
|
} else {
|
2021-12-16 23:45:20 +00:00
|
|
|
api.authenticate()
|
2021-11-07 22:10:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-07 19:16:12 +00:00
|
|
|
legalPreference.setOnPreferenceClickListener {
|
|
|
|
val builder: AlertDialog.Builder = AlertDialog.Builder(it.context)
|
|
|
|
builder.setTitle(R.string.legal_notice)
|
|
|
|
builder.setMessage(R.string.legal_notice_text)
|
|
|
|
builder.show()
|
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-09-04 11:38:35 +00:00
|
|
|
|
2021-09-12 14:10:22 +00:00
|
|
|
subdubPreference.setOnPreferenceClickListener {
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
|
|
|
|
activity?.getApiDubstatusSettings()?.let { current ->
|
|
|
|
val dublist = DubStatus.values()
|
|
|
|
val names = dublist.map { it.name }
|
|
|
|
|
|
|
|
val currentList = ArrayList<Int>()
|
|
|
|
for (i in current) {
|
|
|
|
currentList.add(dublist.indexOf(i))
|
|
|
|
}
|
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
activity?.showMultiDialog(
|
2021-09-12 14:10:22 +00:00
|
|
|
names,
|
|
|
|
currentList,
|
|
|
|
getString(R.string.display_subbed_dubbed_settings),
|
|
|
|
{}) { selectedList ->
|
|
|
|
APIRepository.dubStatusActive = selectedList.map { dublist[it] }.toHashSet()
|
|
|
|
|
|
|
|
settingsManager.edit().putStringSet(
|
|
|
|
this.getString(R.string.display_sub_key),
|
|
|
|
selectedList.map { names[it] }.toMutableSet()
|
|
|
|
).apply()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-23 18:08:57 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
|
|
|
|
|
|
|
providerLangPreference.setOnPreferenceClickListener {
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
|
|
|
|
activity?.getApiProviderLangSettings()?.let { current ->
|
|
|
|
val allLangs = HashSet<String>()
|
|
|
|
for (api in apis) {
|
|
|
|
allLangs.add(api.lang)
|
|
|
|
}
|
|
|
|
for (api in restrictedApis) {
|
|
|
|
allLangs.add(api.lang)
|
|
|
|
}
|
|
|
|
|
|
|
|
val currentList = ArrayList<Int>()
|
|
|
|
for (i in current) {
|
|
|
|
currentList.add(allLangs.indexOf(i))
|
|
|
|
}
|
2021-09-12 14:10:22 +00:00
|
|
|
|
2021-09-24 17:13:13 +00:00
|
|
|
val names = allLangs.mapNotNull {
|
|
|
|
val fullName = SubtitleHelper.fromTwoLettersToLanguage(it)
|
|
|
|
if (fullName.isNullOrEmpty()) {
|
|
|
|
return@mapNotNull null
|
|
|
|
}
|
|
|
|
|
|
|
|
Pair(it, fullName)
|
|
|
|
}
|
2021-09-23 18:08:57 +00:00
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
activity?.showMultiDialog(
|
2021-09-24 17:13:13 +00:00
|
|
|
names.map { it.second },
|
2021-09-23 18:08:57 +00:00
|
|
|
currentList,
|
|
|
|
getString(R.string.provider_lang_settings),
|
|
|
|
{}) { selectedList ->
|
|
|
|
settingsManager.edit().putStringSet(
|
|
|
|
this.getString(R.string.provider_lang_key),
|
2021-09-24 17:13:13 +00:00
|
|
|
selectedList.map { names[it].first }.toMutableSet()
|
2021-09-23 18:08:57 +00:00
|
|
|
).apply()
|
2022-01-29 21:25:12 +00:00
|
|
|
//APIRepository.providersActive = it.context.getApiSettings()
|
2021-09-23 18:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-12 14:10:22 +00:00
|
|
|
|
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-11-07 22:10:19 +00:00
|
|
|
|
2021-11-01 15:33:46 +00:00
|
|
|
fun getDownloadDirs(): List<String> {
|
2022-01-13 21:09:05 +00:00
|
|
|
return normalSafeApiCall {
|
|
|
|
val defaultDir = getDownloadDir()?.filePath
|
|
|
|
|
|
|
|
// app_name_download_path = Cloudstream and does not change depending on release.
|
|
|
|
// DOES NOT WORK ON SCOPED STORAGE.
|
|
|
|
val secondaryDir = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) null else Environment.getExternalStorageDirectory().absolutePath +
|
|
|
|
File.separator + resources.getString(R.string.app_name_download_path)
|
|
|
|
val first = listOf(defaultDir, secondaryDir)
|
|
|
|
(try {
|
|
|
|
val currentDir = context?.getBasePath()?.let { it.first?.filePath ?: it.second }
|
|
|
|
|
|
|
|
(first +
|
|
|
|
requireContext().getExternalFilesDirs("").mapNotNull { it.path } +
|
|
|
|
currentDir)
|
|
|
|
} catch (e: Exception) {
|
|
|
|
first
|
|
|
|
}).filterNotNull().distinct()
|
|
|
|
} ?: emptyList()
|
2021-11-01 15:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
downloadPathPreference.setOnPreferenceClickListener {
|
|
|
|
val dirs = getDownloadDirs()
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
|
|
|
|
val currentDir =
|
|
|
|
settingsManager.getString(getString(R.string.download_path_pref), null) ?: getDownloadDir().toString()
|
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
activity?.showBottomDialog(
|
2021-11-01 15:33:46 +00:00
|
|
|
dirs + listOf("Custom"),
|
|
|
|
dirs.indexOf(currentDir),
|
|
|
|
getString(R.string.download_path_pref),
|
|
|
|
true,
|
|
|
|
{}) {
|
|
|
|
// Last = custom
|
|
|
|
if (it == dirs.size) {
|
|
|
|
pathPicker.launch(Uri.EMPTY)
|
|
|
|
} else {
|
|
|
|
// Sets both visual and actual paths.
|
|
|
|
// key = used path
|
|
|
|
// pref = visual path
|
|
|
|
settingsManager.edit().putString(getString(R.string.download_path_key), dirs[it]).apply()
|
|
|
|
settingsManager.edit().putString(getString(R.string.download_path_pref), dirs[it]).apply()
|
2021-11-04 10:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-11-07 22:10:19 +00:00
|
|
|
|
2021-11-05 22:08:47 +00:00
|
|
|
preferedMediaTypePreference.setOnPreferenceClickListener {
|
|
|
|
val prefNames = resources.getStringArray(R.array.media_type_pref)
|
|
|
|
val prefValues = resources.getIntArray(R.array.media_type_pref_values)
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
2021-11-03 19:38:50 +00:00
|
|
|
|
2021-11-05 22:08:47 +00:00
|
|
|
val currentPrefMedia =
|
2021-12-16 23:45:20 +00:00
|
|
|
settingsManager.getInt(getString(R.string.prefer_media_type_key), 0)
|
2021-11-05 22:08:47 +00:00
|
|
|
|
2021-12-12 02:33:17 +00:00
|
|
|
activity?.showBottomDialog(
|
2021-11-05 22:08:47 +00:00
|
|
|
prefNames.toList(),
|
|
|
|
prefValues.indexOf(currentPrefMedia),
|
|
|
|
getString(R.string.preferred_media_settings),
|
|
|
|
true,
|
|
|
|
{}) {
|
|
|
|
settingsManager.edit()
|
2021-12-16 23:45:20 +00:00
|
|
|
.putInt(getString(R.string.prefer_media_type_key), prefValues[it])
|
2021-11-05 22:08:47 +00:00
|
|
|
.apply()
|
2021-12-16 23:45:20 +00:00
|
|
|
|
|
|
|
removeKey(HOMEPAGE_API)
|
2021-12-05 16:22:30 +00:00
|
|
|
(context ?: AcraApplication.context)?.let { ctx -> app.initClient(ctx) }
|
2021-10-31 17:51:39 +00:00
|
|
|
}
|
2021-11-05 22:08:47 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
2021-11-04 10:42:51 +00:00
|
|
|
}
|
2021-10-31 17:51:39 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
allLayoutPreference.setOnPreferenceClickListener {
|
|
|
|
val prefNames = resources.getStringArray(R.array.app_layout)
|
|
|
|
val prefValues = resources.getIntArray(R.array.app_layout_values)
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
2021-10-30 18:14:12 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
val currentLayout =
|
|
|
|
settingsManager.getInt(getString(R.string.app_layout_key), -1)
|
2021-12-12 02:33:17 +00:00
|
|
|
|
|
|
|
activity?.showBottomDialog(
|
2021-11-04 10:42:51 +00:00
|
|
|
prefNames.toList(),
|
|
|
|
prefValues.indexOf(currentLayout),
|
|
|
|
getString(R.string.app_layout),
|
|
|
|
true,
|
|
|
|
{}) {
|
|
|
|
try {
|
|
|
|
settingsManager.edit().putInt(getString(R.string.app_layout_key), prefValues[it])
|
|
|
|
.apply()
|
|
|
|
activity?.recreate()
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
2021-10-30 18:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-10-30 18:14:12 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
colorPrimaryPreference.setOnPreferenceClickListener {
|
|
|
|
val prefNames = resources.getStringArray(R.array.themes_overlay_names)
|
|
|
|
val prefValues = resources.getStringArray(R.array.themes_overlay_names_values)
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
2021-10-31 01:17:56 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
val currentLayout =
|
|
|
|
settingsManager.getString(getString(R.string.primary_color_key), prefValues.first())
|
2021-12-12 02:33:17 +00:00
|
|
|
|
|
|
|
activity?.showBottomDialog(
|
2021-11-04 10:42:51 +00:00
|
|
|
prefNames.toList(),
|
|
|
|
prefValues.indexOf(currentLayout),
|
|
|
|
getString(R.string.primary_color_settings),
|
|
|
|
true,
|
|
|
|
{}) {
|
|
|
|
try {
|
|
|
|
settingsManager.edit().putString(getString(R.string.primary_color_key), prefValues[it])
|
|
|
|
.apply()
|
|
|
|
activity?.recreate()
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
2021-10-31 01:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-10-31 01:17:56 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
appThemePreference.setOnPreferenceClickListener {
|
|
|
|
val prefNames = resources.getStringArray(R.array.themes_names)
|
|
|
|
val prefValues = resources.getStringArray(R.array.themes_names_values)
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
2021-10-31 14:14:01 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
val currentLayout =
|
|
|
|
settingsManager.getString(getString(R.string.app_theme_key), prefValues.first())
|
2021-12-12 02:33:17 +00:00
|
|
|
|
|
|
|
activity?.showBottomDialog(
|
2021-11-04 10:42:51 +00:00
|
|
|
prefNames.toList(),
|
|
|
|
prefValues.indexOf(currentLayout),
|
|
|
|
getString(R.string.app_theme_settings),
|
|
|
|
true,
|
|
|
|
{}) {
|
|
|
|
try {
|
|
|
|
settingsManager.edit().putString(getString(R.string.app_theme_key), prefValues[it])
|
2021-11-04 10:22:06 +00:00
|
|
|
.apply()
|
2021-11-04 10:42:51 +00:00
|
|
|
activity?.recreate()
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
2021-11-01 15:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-11-01 15:33:46 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
watchQualityPreference.setOnPreferenceClickListener {
|
|
|
|
val prefNames = resources.getStringArray(R.array.quality_pref)
|
|
|
|
val prefValues = resources.getIntArray(R.array.quality_pref_values)
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
2021-09-04 11:38:35 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
val currentQuality =
|
|
|
|
settingsManager.getInt(
|
2022-01-07 19:27:25 +00:00
|
|
|
getString(R.string.quality_pref_key),
|
2021-11-04 10:42:51 +00:00
|
|
|
Qualities.values().last().value
|
|
|
|
)
|
2021-12-12 02:33:17 +00:00
|
|
|
|
|
|
|
activity?.showBottomDialog(
|
2021-11-04 10:42:51 +00:00
|
|
|
prefNames.toList(),
|
|
|
|
prefValues.indexOf(currentQuality),
|
|
|
|
getString(R.string.watch_quality_pref),
|
|
|
|
true,
|
|
|
|
{}) {
|
2022-01-07 19:27:25 +00:00
|
|
|
settingsManager.edit().putInt(getString(R.string.quality_pref_key), prefValues[it])
|
2021-11-04 10:42:51 +00:00
|
|
|
.apply()
|
2021-09-04 11:38:35 +00:00
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-10-18 14:02:05 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
dnsPreference.setOnPreferenceClickListener {
|
|
|
|
val prefNames = resources.getStringArray(R.array.dns_pref)
|
|
|
|
val prefValues = resources.getIntArray(R.array.dns_pref_values)
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
2021-10-18 14:02:05 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
val currentDns =
|
|
|
|
settingsManager.getInt(getString(R.string.dns_pref), 0)
|
2021-12-12 02:33:17 +00:00
|
|
|
|
|
|
|
activity?.showBottomDialog(
|
2021-11-04 10:42:51 +00:00
|
|
|
prefNames.toList(),
|
|
|
|
prefValues.indexOf(currentDns),
|
|
|
|
getString(R.string.dns_pref),
|
|
|
|
true,
|
|
|
|
{}) {
|
|
|
|
settingsManager.edit().putInt(getString(R.string.dns_pref), prefValues[it]).apply()
|
2021-12-05 16:22:30 +00:00
|
|
|
(context ?: AcraApplication.context)?.let { ctx -> app.initClient(ctx) }
|
2021-11-04 10:42:51 +00:00
|
|
|
}
|
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-08-30 22:07:39 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
try {
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
|
|
|
|
beneneCount = settingsManager.getInt(getString(R.string.benene_count), 0)
|
|
|
|
|
|
|
|
benenePreference.summary =
|
|
|
|
if (beneneCount <= 0) getString(R.string.benene_count_text_none) else getString(R.string.benene_count_text).format(
|
|
|
|
beneneCount
|
|
|
|
)
|
2021-12-12 02:33:17 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
benenePreference.setOnPreferenceClickListener {
|
|
|
|
try {
|
|
|
|
beneneCount++
|
|
|
|
settingsManager.edit().putInt(getString(R.string.benene_count), beneneCount).apply()
|
|
|
|
it.summary = getString(R.string.benene_count_text).format(beneneCount)
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
2021-08-30 21:42:58 +00:00
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
|
|
|
|
return@setOnPreferenceClickListener true
|
2021-08-30 21:42:58 +00:00
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
} catch (e: Exception) {
|
|
|
|
e.printStackTrace()
|
|
|
|
}
|
2021-08-30 21:42:58 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
updatePreference.setOnPreferenceClickListener {
|
|
|
|
thread {
|
|
|
|
if (!requireActivity().runAutoUpdate(false)) {
|
|
|
|
activity?.runOnUiThread {
|
|
|
|
showToast(activity, R.string.no_update_found, Toast.LENGTH_SHORT)
|
2021-08-15 17:38:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
|
|
|
}
|
2021-09-02 14:06:43 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
localePreference.setOnPreferenceClickListener { pref ->
|
|
|
|
val tempLangs = languages.toMutableList()
|
|
|
|
if (beneneCount > 100) {
|
|
|
|
tempLangs.add(Triple("\uD83E\uDD8D", "mmmm... monke", "mo"))
|
|
|
|
}
|
|
|
|
val current = getCurrentLocale()
|
|
|
|
val languageCodes = tempLangs.map { it.third }
|
|
|
|
val languageNames = tempLangs.map { "${it.first} ${it.second}" }
|
|
|
|
val index = languageCodes.indexOf(current)
|
2021-12-12 02:33:17 +00:00
|
|
|
|
|
|
|
activity?.showDialog(
|
2021-11-04 10:42:51 +00:00
|
|
|
languageNames, index, getString(R.string.app_language), true, { }
|
|
|
|
) { languageIndex ->
|
|
|
|
try {
|
|
|
|
val code = languageCodes[languageIndex]
|
|
|
|
setLocale(activity, code)
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(pref.context)
|
|
|
|
settingsManager.edit().putString(getString(R.string.locale_key), code).apply()
|
|
|
|
activity?.recreate()
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
2021-11-04 10:22:06 +00:00
|
|
|
}
|
2021-09-02 14:06:43 +00:00
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
2021-09-02 14:06:43 +00:00
|
|
|
}
|
2021-11-04 10:42:51 +00:00
|
|
|
}
|
2021-09-02 14:06:43 +00:00
|
|
|
|
2021-11-04 10:42:51 +00:00
|
|
|
private fun getCurrentLocale(): String {
|
|
|
|
val res = context!!.resources
|
2021-09-02 14:06:43 +00:00
|
|
|
// Change locale settings in the app.
|
2021-11-04 10:42:51 +00:00
|
|
|
// val dm = res.displayMetrics
|
|
|
|
val conf = res.configuration
|
|
|
|
return conf?.locale?.language ?: "en"
|
|
|
|
}
|
|
|
|
}
|