2021-02-08 21:46:31 +01:00
|
|
|
package org.moire.ultrasonic.fragment
|
2020-09-18 09:37:19 +02:00
|
|
|
|
|
|
|
import android.app.AlertDialog
|
|
|
|
import android.os.Bundle
|
2021-02-08 21:46:31 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2020-09-18 09:37:19 +02:00
|
|
|
import android.widget.Button
|
2021-02-08 21:46:31 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
2020-09-18 09:37:19 +02:00
|
|
|
import androidx.lifecycle.Observer
|
2021-02-08 21:46:31 +01:00
|
|
|
import androidx.navigation.fragment.findNavController
|
2020-09-18 09:37:19 +02:00
|
|
|
import com.google.android.material.switchmaterial.SwitchMaterial
|
|
|
|
import com.google.android.material.textfield.TextInputLayout
|
2020-09-25 11:04:48 +02:00
|
|
|
import org.koin.android.ext.android.inject
|
2021-05-27 12:15:56 +02:00
|
|
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
2020-09-18 09:37:19 +02:00
|
|
|
import org.moire.ultrasonic.BuildConfig
|
|
|
|
import org.moire.ultrasonic.R
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicClientConfiguration
|
2020-09-25 11:04:48 +02:00
|
|
|
import org.moire.ultrasonic.data.ActiveServerProvider
|
2020-09-18 09:37:19 +02:00
|
|
|
import org.moire.ultrasonic.data.ServerSetting
|
2021-02-08 21:46:31 +01:00
|
|
|
import org.moire.ultrasonic.service.ApiCallResponseChecker
|
2020-09-25 11:04:48 +02:00
|
|
|
import org.moire.ultrasonic.service.MusicServiceFactory
|
2020-09-18 09:37:19 +02:00
|
|
|
import org.moire.ultrasonic.util.Constants
|
|
|
|
import org.moire.ultrasonic.util.ErrorDialog
|
|
|
|
import org.moire.ultrasonic.util.ModalBackgroundTask
|
|
|
|
import org.moire.ultrasonic.util.Util
|
2021-05-29 15:00:46 +02:00
|
|
|
import retrofit2.Call
|
2020-09-30 14:47:59 +02:00
|
|
|
import timber.log.Timber
|
2021-05-29 15:00:46 +02:00
|
|
|
import java.io.IOException
|
|
|
|
import java.net.MalformedURLException
|
|
|
|
import java.net.URL
|
2020-09-18 09:37:19 +02:00
|
|
|
|
2021-03-01 17:24:25 +01:00
|
|
|
/**
|
|
|
|
* Displays a form where server settings can be created / edited
|
|
|
|
*/
|
2021-02-25 18:40:41 +01:00
|
|
|
class EditServerFragment : Fragment(), OnBackPressedHandler {
|
2020-09-18 09:37:19 +02:00
|
|
|
companion object {
|
|
|
|
const val EDIT_SERVER_INTENT_INDEX = "index"
|
|
|
|
}
|
|
|
|
|
|
|
|
private val serverSettingsModel: ServerSettingsModel by viewModel()
|
2020-09-25 11:04:48 +02:00
|
|
|
private val activeServerProvider: ActiveServerProvider by inject()
|
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
private var currentServerSetting: ServerSetting? = null
|
|
|
|
|
|
|
|
private var serverNameEditText: TextInputLayout? = null
|
|
|
|
private var serverAddressEditText: TextInputLayout? = null
|
|
|
|
private var userNameEditText: TextInputLayout? = null
|
|
|
|
private var passwordEditText: TextInputLayout? = null
|
|
|
|
private var selfSignedSwitch: SwitchMaterial? = null
|
|
|
|
private var ldapSwitch: SwitchMaterial? = null
|
|
|
|
private var jukeboxSwitch: SwitchMaterial? = null
|
|
|
|
private var saveButton: Button? = null
|
|
|
|
private var testButton: Button? = null
|
2020-11-02 17:13:38 +01:00
|
|
|
private var isInstanceStateSaved: Boolean = false
|
2020-09-18 09:37:19 +02:00
|
|
|
|
2021-02-08 21:46:31 +01:00
|
|
|
@Override
|
2020-09-18 09:37:19 +02:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
2021-02-08 21:46:31 +01:00
|
|
|
Util.applyTheme(this.context)
|
2020-09-18 09:37:19 +02:00
|
|
|
super.onCreate(savedInstanceState)
|
2021-02-08 21:46:31 +01:00
|
|
|
}
|
2020-09-18 09:37:19 +02:00
|
|
|
|
2021-02-14 15:55:16 +01:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
2021-02-08 21:46:31 +01:00
|
|
|
return inflater.inflate(R.layout.server_edit, container, false)
|
|
|
|
}
|
2020-09-18 09:37:19 +02:00
|
|
|
|
2021-02-08 21:46:31 +01:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2020-09-18 09:37:19 +02:00
|
|
|
|
2021-02-08 21:46:31 +01:00
|
|
|
serverNameEditText = view.findViewById(R.id.edit_server_name)
|
|
|
|
serverAddressEditText = view.findViewById(R.id.edit_server_address)
|
|
|
|
userNameEditText = view.findViewById(R.id.edit_server_username)
|
|
|
|
passwordEditText = view.findViewById(R.id.edit_server_password)
|
|
|
|
selfSignedSwitch = view.findViewById(R.id.edit_self_signed)
|
|
|
|
ldapSwitch = view.findViewById(R.id.edit_ldap)
|
|
|
|
jukeboxSwitch = view.findViewById(R.id.edit_jukebox)
|
|
|
|
saveButton = view.findViewById(R.id.edit_save)
|
|
|
|
testButton = view.findViewById(R.id.edit_test)
|
2020-09-18 09:37:19 +02:00
|
|
|
|
2021-02-08 21:46:31 +01:00
|
|
|
val index = arguments?.getInt(
|
|
|
|
EDIT_SERVER_INTENT_INDEX,
|
|
|
|
-1
|
|
|
|
) ?: -1
|
2020-09-18 09:37:19 +02:00
|
|
|
|
|
|
|
if (index != -1) {
|
|
|
|
// Editing an existing server
|
2021-02-08 21:46:31 +01:00
|
|
|
FragmentTitle.setTitle(this, R.string.server_editor_label)
|
2020-09-18 09:37:19 +02:00
|
|
|
val serverSetting = serverSettingsModel.getServerSetting(index)
|
|
|
|
serverSetting.observe(
|
2021-02-08 21:46:31 +01:00
|
|
|
viewLifecycleOwner,
|
2020-09-18 09:37:19 +02:00
|
|
|
Observer { t ->
|
|
|
|
if (t != null) {
|
|
|
|
currentServerSetting = t
|
2020-11-02 17:13:38 +01:00
|
|
|
if (!isInstanceStateSaved) setFields()
|
2020-10-15 10:22:15 +02:00
|
|
|
// Remove the minimum API version so it can be detected again
|
|
|
|
if (currentServerSetting?.minimumApiVersion != null) {
|
|
|
|
currentServerSetting!!.minimumApiVersion = null
|
|
|
|
serverSettingsModel.updateItem(currentServerSetting)
|
2020-10-15 14:34:10 +02:00
|
|
|
if (
|
|
|
|
activeServerProvider.getActiveServer().id ==
|
|
|
|
currentServerSetting!!.id
|
|
|
|
) {
|
|
|
|
MusicServiceFactory.resetMusicService()
|
|
|
|
}
|
2020-10-15 10:22:15 +02:00
|
|
|
}
|
2020-09-18 09:37:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
saveButton!!.setOnClickListener {
|
|
|
|
if (currentServerSetting != null) {
|
|
|
|
if (getFields()) {
|
|
|
|
serverSettingsModel.updateItem(currentServerSetting)
|
2020-09-25 11:04:48 +02:00
|
|
|
// Apply modifications if the current server was modified
|
|
|
|
if (
|
|
|
|
activeServerProvider.getActiveServer().id ==
|
|
|
|
currentServerSetting!!.id
|
|
|
|
) {
|
|
|
|
MusicServiceFactory.resetMusicService()
|
|
|
|
}
|
2021-02-08 21:46:31 +01:00
|
|
|
findNavController().navigateUp()
|
2020-09-18 09:37:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Creating a new server
|
2021-02-08 21:46:31 +01:00
|
|
|
FragmentTitle.setTitle(this, R.string.server_editor_new_label)
|
2020-09-19 11:56:10 +02:00
|
|
|
currentServerSetting = ServerSetting()
|
2020-09-18 09:37:19 +02:00
|
|
|
saveButton!!.setOnClickListener {
|
|
|
|
if (getFields()) {
|
|
|
|
serverSettingsModel.saveNewItem(currentServerSetting)
|
2021-02-08 21:46:31 +01:00
|
|
|
findNavController().navigateUp()
|
2020-09-18 09:37:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testButton!!.setOnClickListener {
|
|
|
|
if (getFields()) {
|
|
|
|
testConnection()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-25 18:40:41 +01:00
|
|
|
override fun onBackPressed() {
|
|
|
|
finishActivity()
|
|
|
|
}
|
|
|
|
|
2020-11-02 17:13:38 +01:00
|
|
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
|
|
|
savedInstanceState.putString(
|
|
|
|
::serverNameEditText.name, serverNameEditText!!.editText?.text.toString()
|
|
|
|
)
|
|
|
|
savedInstanceState.putString(
|
|
|
|
::serverAddressEditText.name, serverAddressEditText!!.editText?.text.toString()
|
|
|
|
)
|
|
|
|
savedInstanceState.putString(
|
|
|
|
::userNameEditText.name, userNameEditText!!.editText?.text.toString()
|
|
|
|
)
|
|
|
|
savedInstanceState.putString(
|
|
|
|
::passwordEditText.name, passwordEditText!!.editText?.text.toString()
|
|
|
|
)
|
|
|
|
savedInstanceState.putBoolean(
|
|
|
|
::selfSignedSwitch.name, selfSignedSwitch!!.isChecked
|
|
|
|
)
|
|
|
|
savedInstanceState.putBoolean(
|
|
|
|
::ldapSwitch.name, ldapSwitch!!.isChecked
|
|
|
|
)
|
|
|
|
savedInstanceState.putBoolean(
|
|
|
|
::jukeboxSwitch.name, jukeboxSwitch!!.isChecked
|
|
|
|
)
|
|
|
|
savedInstanceState.putBoolean(
|
|
|
|
::isInstanceStateSaved.name, true
|
|
|
|
)
|
|
|
|
|
|
|
|
super.onSaveInstanceState(savedInstanceState)
|
|
|
|
}
|
|
|
|
|
2021-02-08 21:46:31 +01:00
|
|
|
override fun onViewStateRestored(savedInstanceState: Bundle?) {
|
|
|
|
super.onViewStateRestored(savedInstanceState)
|
|
|
|
|
|
|
|
if (savedInstanceState == null) return
|
2020-11-02 17:13:38 +01:00
|
|
|
|
|
|
|
serverNameEditText!!.editText?.setText(
|
|
|
|
savedInstanceState.getString(::serverNameEditText.name)
|
|
|
|
)
|
|
|
|
serverAddressEditText!!.editText?.setText(
|
|
|
|
savedInstanceState.getString(::serverAddressEditText.name)
|
|
|
|
)
|
|
|
|
userNameEditText!!.editText?.setText(
|
|
|
|
savedInstanceState.getString(::userNameEditText.name)
|
|
|
|
)
|
|
|
|
passwordEditText!!.editText?.setText(
|
|
|
|
savedInstanceState.getString(::passwordEditText.name)
|
|
|
|
)
|
|
|
|
selfSignedSwitch!!.isChecked = savedInstanceState.getBoolean(::selfSignedSwitch.name)
|
|
|
|
ldapSwitch!!.isChecked = savedInstanceState.getBoolean(::ldapSwitch.name)
|
|
|
|
jukeboxSwitch!!.isChecked = savedInstanceState.getBoolean(::jukeboxSwitch.name)
|
|
|
|
isInstanceStateSaved = savedInstanceState.getBoolean(::isInstanceStateSaved.name)
|
|
|
|
}
|
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
/**
|
|
|
|
* Sets the values of the Form from the current Server Setting instance
|
|
|
|
*/
|
|
|
|
private fun setFields() {
|
|
|
|
if (currentServerSetting == null) return
|
|
|
|
|
|
|
|
serverNameEditText!!.editText?.setText(currentServerSetting!!.name)
|
|
|
|
serverAddressEditText!!.editText?.setText(currentServerSetting!!.url)
|
|
|
|
userNameEditText!!.editText?.setText(currentServerSetting!!.userName)
|
|
|
|
passwordEditText!!.editText?.setText(currentServerSetting!!.password)
|
|
|
|
selfSignedSwitch!!.isChecked = currentServerSetting!!.allowSelfSignedCertificate
|
|
|
|
ldapSwitch!!.isChecked = currentServerSetting!!.ldapSupport
|
|
|
|
jukeboxSwitch!!.isChecked = currentServerSetting!!.jukeboxByDefault
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the values in the Form to the current Server Setting instance
|
|
|
|
* This function also does some basic validation on the fields
|
|
|
|
*/
|
|
|
|
private fun getFields(): Boolean {
|
|
|
|
if (currentServerSetting == null) return false
|
|
|
|
var isValid = true
|
|
|
|
var url: URL? = null
|
|
|
|
|
|
|
|
if (serverAddressEditText!!.editText?.text.isNullOrBlank()) {
|
|
|
|
serverAddressEditText!!.error = getString(R.string.server_editor_required)
|
|
|
|
isValid = false
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
val urlString = serverAddressEditText!!.editText?.text.toString()
|
|
|
|
url = URL(urlString)
|
2020-09-23 17:14:14 +02:00
|
|
|
if (
|
|
|
|
urlString != urlString.trim(' ') ||
|
|
|
|
urlString.contains("@") ||
|
|
|
|
url.host.isNullOrBlank()
|
|
|
|
) {
|
2020-09-18 09:37:19 +02:00
|
|
|
throw MalformedURLException()
|
|
|
|
}
|
|
|
|
serverAddressEditText!!.error = null
|
|
|
|
} catch (exception: MalformedURLException) {
|
|
|
|
serverAddressEditText!!.error = getString(R.string.settings_invalid_url)
|
|
|
|
isValid = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serverNameEditText!!.editText?.text.isNullOrBlank()) {
|
|
|
|
if (isValid && url != null) {
|
|
|
|
serverNameEditText!!.editText?.setText(url.host)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userNameEditText!!.editText?.text.isNullOrBlank()) {
|
|
|
|
userNameEditText!!.error = getString(R.string.server_editor_required)
|
|
|
|
isValid = false
|
|
|
|
} else {
|
|
|
|
userNameEditText!!.error = null
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isValid) {
|
|
|
|
currentServerSetting!!.name = serverNameEditText!!.editText?.text.toString()
|
|
|
|
currentServerSetting!!.url = serverAddressEditText!!.editText?.text.toString()
|
|
|
|
currentServerSetting!!.userName = userNameEditText!!.editText?.text.toString()
|
|
|
|
currentServerSetting!!.password = passwordEditText!!.editText?.text.toString()
|
|
|
|
currentServerSetting!!.allowSelfSignedCertificate = selfSignedSwitch!!.isChecked
|
|
|
|
currentServerSetting!!.ldapSupport = ldapSwitch!!.isChecked
|
|
|
|
currentServerSetting!!.jukeboxByDefault = jukeboxSwitch!!.isChecked
|
|
|
|
}
|
|
|
|
|
|
|
|
return isValid
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether any value in the fields are changed according to their original values.
|
|
|
|
*/
|
|
|
|
private fun areFieldsChanged(): Boolean {
|
2020-09-25 20:02:59 +02:00
|
|
|
if (currentServerSetting == null || currentServerSetting!!.id == -1) {
|
2021-02-25 18:40:41 +01:00
|
|
|
return serverNameEditText!!.editText?.text!!.isNotBlank() ||
|
2020-09-19 11:56:10 +02:00
|
|
|
serverAddressEditText!!.editText?.text.toString() != "http://" ||
|
2021-02-25 18:40:41 +01:00
|
|
|
userNameEditText!!.editText?.text!!.isNotBlank() ||
|
|
|
|
passwordEditText!!.editText?.text!!.isNotBlank()
|
2020-09-18 09:37:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return currentServerSetting!!.name != serverNameEditText!!.editText?.text.toString() ||
|
|
|
|
currentServerSetting!!.url != serverAddressEditText!!.editText?.text.toString() ||
|
|
|
|
currentServerSetting!!.userName != userNameEditText!!.editText?.text.toString() ||
|
|
|
|
currentServerSetting!!.password != passwordEditText!!.editText?.text.toString() ||
|
|
|
|
currentServerSetting!!.allowSelfSignedCertificate != selfSignedSwitch!!.isChecked ||
|
|
|
|
currentServerSetting!!.ldapSupport != ldapSwitch!!.isChecked ||
|
|
|
|
currentServerSetting!!.jukeboxByDefault != jukeboxSwitch!!.isChecked
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests if the network connection to the entered Server Settings can be made
|
|
|
|
*/
|
|
|
|
private fun testConnection() {
|
2021-05-24 23:25:12 +02:00
|
|
|
val task: ModalBackgroundTask<String> = object : ModalBackgroundTask<String>(
|
2021-02-08 21:46:31 +01:00
|
|
|
activity,
|
2020-09-18 09:37:19 +02:00
|
|
|
false
|
|
|
|
) {
|
2021-05-29 15:00:46 +02:00
|
|
|
fun boolToMark(value: Boolean?): String {
|
|
|
|
if (value == null)
|
|
|
|
return "⌛"
|
|
|
|
return if (value) "✔️" else "❌"
|
|
|
|
}
|
2020-09-18 09:37:19 +02:00
|
|
|
|
2021-05-29 15:00:46 +02:00
|
|
|
fun getProgress(): String {
|
|
|
|
return String.format(
|
|
|
|
"""
|
2021-05-24 23:25:12 +02:00
|
|
|
|%s - ${activity.resources.getString(R.string.button_bar_chat)}
|
|
|
|
|%s - ${activity.resources.getString(R.string.button_bar_bookmarks)}
|
|
|
|
|%s - ${activity.resources.getString(R.string.button_bar_shares)}
|
|
|
|
|%s - ${activity.resources.getString(R.string.button_bar_podcasts)}
|
2021-05-29 15:00:46 +02:00
|
|
|
""".trimMargin(),
|
|
|
|
boolToMark(currentServerSetting!!.chatSupport),
|
|
|
|
boolToMark(currentServerSetting!!.bookmarkSupport),
|
|
|
|
boolToMark(currentServerSetting!!.shareSupport),
|
|
|
|
boolToMark(currentServerSetting!!.podcastSupport)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Throws(Throwable::class)
|
|
|
|
override fun doInBackground(): String {
|
|
|
|
|
|
|
|
currentServerSetting!!.chatSupport = null
|
|
|
|
currentServerSetting!!.bookmarkSupport = null
|
|
|
|
currentServerSetting!!.shareSupport = null
|
|
|
|
currentServerSetting!!.podcastSupport = null
|
|
|
|
|
|
|
|
updateProgress(getProgress())
|
2021-05-24 23:25:12 +02:00
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
val configuration = SubsonicClientConfiguration(
|
|
|
|
currentServerSetting!!.url,
|
|
|
|
currentServerSetting!!.userName,
|
|
|
|
currentServerSetting!!.password,
|
|
|
|
SubsonicAPIVersions.getClosestKnownClientApiVersion(
|
|
|
|
Constants.REST_PROTOCOL_VERSION
|
|
|
|
),
|
|
|
|
Constants.REST_CLIENT_ID,
|
|
|
|
currentServerSetting!!.allowSelfSignedCertificate,
|
|
|
|
currentServerSetting!!.ldapSupport,
|
|
|
|
BuildConfig.DEBUG
|
|
|
|
)
|
|
|
|
val subsonicApiClient = SubsonicAPIClient(configuration)
|
2020-10-13 21:41:01 +02:00
|
|
|
|
2020-10-15 10:22:15 +02:00
|
|
|
// Execute a ping to retrieve the API version.
|
|
|
|
// This is accepted to fail if the authentication is incorrect yet.
|
2020-10-13 21:41:01 +02:00
|
|
|
var pingResponse = subsonicApiClient.api.ping().execute()
|
2021-05-06 12:40:49 +02:00
|
|
|
if (pingResponse.body() != null) {
|
2020-10-13 21:41:01 +02:00
|
|
|
val restApiVersion = pingResponse.body()!!.version.restApiVersion
|
|
|
|
currentServerSetting!!.minimumApiVersion = restApiVersion
|
|
|
|
Timber.i("Server minimum API version set to %s", restApiVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute a ping to check the authentication, now using the correct API version.
|
|
|
|
pingResponse = subsonicApiClient.api.ping().execute()
|
2021-02-08 21:46:31 +01:00
|
|
|
ApiCallResponseChecker.checkResponseSuccessful(pingResponse)
|
2020-09-18 09:37:19 +02:00
|
|
|
|
2021-05-24 23:25:12 +02:00
|
|
|
currentServerSetting!!.chatSupport = try {
|
|
|
|
subsonicApiClient.api.getChatMessages().execute()
|
|
|
|
true
|
2021-05-25 19:30:02 +02:00
|
|
|
} catch (e: IOException) { false }
|
2021-05-24 23:25:12 +02:00
|
|
|
|
2021-05-29 15:00:46 +02:00
|
|
|
updateProgress(getProgress())
|
2021-05-24 23:25:12 +02:00
|
|
|
|
|
|
|
currentServerSetting!!.bookmarkSupport = try {
|
|
|
|
subsonicApiClient.api.getBookmarks().execute()
|
|
|
|
true
|
2021-05-25 19:30:02 +02:00
|
|
|
} catch (e: IOException) { false }
|
2021-05-24 23:25:12 +02:00
|
|
|
|
2021-05-29 15:00:46 +02:00
|
|
|
updateProgress(getProgress())
|
2021-05-24 23:25:12 +02:00
|
|
|
|
|
|
|
currentServerSetting!!.shareSupport = try {
|
|
|
|
subsonicApiClient.api.getShares().execute()
|
|
|
|
true
|
2021-05-25 19:30:02 +02:00
|
|
|
} catch (e: IOException) { false }
|
2021-05-24 23:25:12 +02:00
|
|
|
|
2021-05-29 15:00:46 +02:00
|
|
|
updateProgress(getProgress())
|
2021-05-24 23:25:12 +02:00
|
|
|
|
|
|
|
currentServerSetting!!.podcastSupport = try {
|
|
|
|
subsonicApiClient.api.getPodcasts().execute()
|
|
|
|
true
|
2021-05-25 19:30:02 +02:00
|
|
|
} catch (e: IOException) { false }
|
2021-05-24 23:25:12 +02:00
|
|
|
|
2021-05-29 15:00:46 +02:00
|
|
|
updateProgress(getProgress())
|
2021-05-24 23:25:12 +02:00
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
val licenseResponse = subsonicApiClient.api.getLicense().execute()
|
2021-02-08 21:46:31 +01:00
|
|
|
ApiCallResponseChecker.checkResponseSuccessful(licenseResponse)
|
2021-05-24 23:25:12 +02:00
|
|
|
if (!licenseResponse.body()!!.license.valid) {
|
2021-05-29 15:00:46 +02:00
|
|
|
return getProgress() + "\n" +
|
2021-05-25 18:51:00 +02:00
|
|
|
activity.resources.getString(R.string.settings_testing_unlicensed)
|
2021-05-24 23:25:12 +02:00
|
|
|
}
|
2021-05-29 15:00:46 +02:00
|
|
|
return getProgress()
|
2020-09-18 09:37:19 +02:00
|
|
|
}
|
|
|
|
|
2021-05-24 23:25:12 +02:00
|
|
|
override fun done(responseString: String) {
|
|
|
|
Util.showDialog(
|
2021-05-25 18:51:00 +02:00
|
|
|
activity,
|
|
|
|
android.R.drawable.ic_dialog_info,
|
|
|
|
R.string.settings_testing_ok,
|
|
|
|
responseString
|
|
|
|
)
|
2020-09-18 09:37:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun error(error: Throwable) {
|
2020-09-30 14:47:59 +02:00
|
|
|
Timber.w(error)
|
2020-09-18 09:37:19 +02:00
|
|
|
ErrorDialog(
|
|
|
|
activity,
|
|
|
|
String.format(
|
|
|
|
"%s %s",
|
|
|
|
resources.getString(R.string.settings_connection_failure),
|
|
|
|
getErrorMessage(error)
|
|
|
|
),
|
|
|
|
false
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
task.execute()
|
|
|
|
}
|
|
|
|
|
2020-09-19 11:56:10 +02:00
|
|
|
/**
|
|
|
|
* Finishes the Activity, after confirmation from the user if needed
|
|
|
|
*/
|
|
|
|
private fun finishActivity() {
|
|
|
|
if (areFieldsChanged()) {
|
2021-02-08 21:46:31 +01:00
|
|
|
AlertDialog.Builder(context)
|
2020-09-19 11:56:10 +02:00
|
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
.setTitle(R.string.common_confirm)
|
|
|
|
.setMessage(R.string.server_editor_leave_confirmation)
|
|
|
|
.setPositiveButton(R.string.common_ok) { dialog, _ ->
|
|
|
|
dialog.dismiss()
|
2021-02-25 18:40:41 +01:00
|
|
|
Util.hideKeyboard(activity)
|
2021-02-08 21:46:31 +01:00
|
|
|
findNavController().navigateUp()
|
2020-09-19 11:56:10 +02:00
|
|
|
}
|
|
|
|
.setNegativeButton(R.string.common_cancel) { dialog, _ ->
|
|
|
|
dialog.dismiss()
|
|
|
|
}
|
|
|
|
.show()
|
|
|
|
} else {
|
2021-02-25 18:40:41 +01:00
|
|
|
Util.hideKeyboard(activity)
|
2021-02-08 21:46:31 +01:00
|
|
|
findNavController().navigateUp()
|
2020-09-19 11:56:10 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-14 15:55:16 +01:00
|
|
|
}
|