feat(network): socks5 proxy support (#530)

This commit is contained in:
Sadwhy 2024-11-19 22:22:13 +06:00 committed by GitHub
parent a4bd367f98
commit ff3372754a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 399 additions and 7 deletions

View file

@ -0,0 +1,71 @@
package ani.dantotsu.settings
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import ani.dantotsu.BottomSheetDialogFragment
import ani.dantotsu.databinding.BottomSheetProxyBinding
import ani.dantotsu.snackString
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.restartApp
class ProxyDialogFragment : BottomSheetDialogFragment() {
private var _binding: BottomSheetProxyBinding? = null
private val binding get() = _binding!!
private var proxyHost: String? = PrefManager.getVal<String>(PrefName.Socks5ProxyHost) ?: ""
private var proxyPort: String? = PrefManager.getVal<String>(PrefName.Socks5ProxyPort) ?: ""
private var proxyUsername: String? = PrefManager.getVal<String>(PrefName.Socks5ProxyUsername) ?: ""
private var proxyPassword: String? = PrefManager.getVal<String>(PrefName.Socks5ProxyPassword) ?: ""
private var authEnabled: Boolean = PrefManager.getVal<Boolean>(PrefName.ProxyAuthEnabled)
private val proxyEnabled: Boolean = PrefManager.getVal<Boolean>(PrefName.EnableSocks5Proxy)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = BottomSheetProxyBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.proxyHost.setText(proxyHost)
binding.proxyPort.setText(proxyPort)
binding.proxyUsername.setText(proxyUsername)
binding.proxyPassword.setText(proxyPassword)
binding.proxyAuthentication.isChecked = authEnabled
binding.proxySave.setOnClickListener {
proxyHost = binding.proxyHost.text.toString() ?: ""
proxyPort = binding.proxyPort.text.toString() ?: ""
proxyUsername = binding.proxyUsername.text.toString() ?: ""
proxyPassword = binding.proxyPassword.text.toString() ?: ""
PrefManager.setVal(PrefName.Socks5ProxyHost, proxyHost)
PrefManager.setVal(PrefName.Socks5ProxyPort, proxyPort)
PrefManager.setVal(PrefName.Socks5ProxyUsername, proxyUsername)
PrefManager.setVal(PrefName.Socks5ProxyPassword, proxyPassword)
dismiss()
if (proxyEnabled) activity?.restartApp()
}
binding.proxyAuthentication.setOnCheckedChangeListener { _, isChecked ->
PrefManager.setVal(PrefName.ProxyAuthEnabled, isChecked)
binding.proxyUsername.isEnabled = isChecked
binding.proxyPassword.isEnabled = isChecked
binding.proxyUsernameLayout.isEnabled = isChecked
binding.proxyPasswordLayout.isEnabled = isChecked
}
}
override fun onDestroyView() {
_binding = null
super.onDestroyView()
}
}

View file

@ -23,9 +23,11 @@ import ani.dantotsu.initActivity
import ani.dantotsu.media.MediaType
import ani.dantotsu.navBarHeight
import ani.dantotsu.parsers.ParserTestActivity
import ani.dantotsu.restartApp
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.statusBarHeight
import ani.dantotsu.others.CustomBottomDialog
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.util.customAlertDialog
import eu.kanade.domain.base.BasePreferences
@ -271,6 +273,26 @@ class SettingsExtensionsActivity : AppCompatActivity() {
}
),
Settings(
type = 2,
name = getString(R.string.proxy),
desc = getString(R.string.proxy_desc),
icon = R.drawable.swap_horizontal_circle_24,
isChecked = PrefManager.getVal(PrefName.EnableSocks5Proxy),
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.EnableSocks5Proxy, isChecked)
restartApp()
}
),
Settings(
type = 1,
name = getString(R.string.proxy_setup),
desc = getString(R.string.proxy_setup_desc),
icon = R.drawable.lan_24,
onClick = {
ProxyDialogFragment().show(supportFragmentManager, "dialog")
}
),
Settings(
type = 2,
name = getString(R.string.force_legacy_installer),
desc = getString(R.string.force_legacy_installer_desc),

View file

@ -47,6 +47,8 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
IncludeMangaList(Pref(Location.General, Boolean::class, true)),
AdultOnly(Pref(Location.General, Boolean::class, false)),
CommentsEnabled(Pref(Location.General, Int::class, 0)),
EnableSocks5Proxy(Pref(Location.General, Boolean::class, false)),
ProxyAuthEnabled(Pref(Location.General, Boolean::class, false)),
//User Interface
UseOLED(Pref(Location.UI, Boolean::class, false)),
@ -197,6 +199,8 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
RefreshStatus(Pref(Location.Irrelevant, Boolean::class, false)),
rpcEnabled(Pref(Location.Irrelevant, Boolean::class, true)),
//testing
//Protected
DiscordToken(Pref(Location.Protected, String::class, "")),
DiscordId(Pref(Location.Protected, String::class, "")),
@ -210,4 +214,8 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
AppPassword(Pref(Location.Protected, String::class, "")),
BiometricToken(Pref(Location.Protected, String::class, "")),
OverridePassword(Pref(Location.Protected, Boolean::class, false)),
Socks5ProxyHost(Pref(Location.Protected, String::class, "")),
Socks5ProxyPort(Pref(Location.Protected, String::class, "")),
Socks5ProxyUsername(Pref(Location.Protected, String::class, "")),
Socks5ProxyPassword(Pref(Location.Protected, String::class, "")),
}