Merge pull request #667 from ultrasonic/patchBranch

Deactivate custom color and set DB to version 3
This commit is contained in:
Óscar García Amor 2022-01-18 10:53:17 +01:00 committed by GitHub
commit 41a462708d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 43 deletions

View File

@ -208,8 +208,8 @@ class NavigationActivity : AppCompatActivity() {
selectServerButton?.text = getString(R.string.main_setup_server, activeServer.name)
else selectServerButton?.text = activeServer.name
val foregroundColor = ServerColor.getForegroundColor(this, activeServer.color)
val backgroundColor = ServerColor.getBackgroundColor(this, activeServer.color)
val foregroundColor = ServerColor.getForegroundColor(this, null)
val backgroundColor = ServerColor.getBackgroundColor(this, null)
if (activeServer.index == 0)
selectServerButton?.icon =

View File

@ -108,8 +108,8 @@ internal class ServerRowAdapter(
}
// Set colors
icon?.setTint(ServerColor.getForegroundColor(context, setting?.color))
background?.setTint(ServerColor.getBackgroundColor(context, setting?.color))
icon?.setTint(ServerColor.getForegroundColor(context, null))
background?.setTint(ServerColor.getBackgroundColor(context, null))
// Set the final drawables
image?.setImageDrawable(icon)

View File

@ -9,7 +9,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
* Room Database to be used to store global data for the whole app.
* This could be settings or data that are not specific to any remote music database
*/
@Database(entities = [ServerSetting::class], version = 4)
@Database(entities = [ServerSetting::class], version = 3)
abstract class AppDatabase : RoomDatabase() {
/**

View File

@ -23,7 +23,6 @@ data class ServerSetting(
@ColumnInfo(name = "index") var index: Int,
@ColumnInfo(name = "name") var name: String,
@ColumnInfo(name = "url") var url: String,
@ColumnInfo(name = "color") var color: Int? = null,
@ColumnInfo(name = "userName") var userName: String,
@ColumnInfo(name = "password") var password: String,
@ColumnInfo(name = "jukeboxByDefault") var jukeboxByDefault: Boolean,
@ -37,9 +36,9 @@ data class ServerSetting(
@ColumnInfo(name = "podcastSupport") var podcastSupport: Boolean? = null
) {
constructor() : this (
-1, 0, "", "", null, "", "", false, false, false, null, null
-1, 0, "", "", "", "", false, false, false, null, null
)
constructor(name: String, url: String) : this(
-1, 0, name, url, null, "", "", false, false, false, null, null
-1, 0, name, url, "", "", false, false, false, null, null
)
}

View File

@ -6,15 +6,13 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.google.android.material.switchmaterial.SwitchMaterial
import com.google.android.material.textfield.TextInputLayout
import com.skydoves.colorpickerview.ColorPickerDialog
import com.skydoves.colorpickerview.flag.BubbleFlag
import com.skydoves.colorpickerview.flag.FlagMode
import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
import java.io.IOException
import java.net.MalformedURLException
import java.net.URL
@ -43,8 +41,6 @@ import org.moire.ultrasonic.util.Util
import retrofit2.Response
import timber.log.Timber
private const val DIALOG_PADDING = 12
/**
* Displays a form where server settings can be created / edited
*/
@ -72,6 +68,8 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
private var currentColor: Int = 0
private var selectedColor: Int? = null
private var editServerColorText: TextView? = null
@Override
override fun onCreate(savedInstanceState: Bundle?) {
Util.applyTheme(this.context)
@ -99,6 +97,7 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
jukeboxSwitch = view.findViewById(R.id.edit_jukebox)
saveButton = view.findViewById(R.id.edit_save)
testButton = view.findViewById(R.id.edit_test)
editServerColorText = view.findViewById(R.id.edit_server_color_text)
val index = arguments?.getInt(
EDIT_SERVER_INTENT_INDEX,
@ -147,7 +146,7 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
} else {
// Creating a new server
FragmentTitle.setTitle(this, R.string.server_editor_new_label)
updateColor(null)
// updateColor(null)
currentServerSetting = ServerSetting()
saveButton!!.setOnClickListener {
if (getFields()) {
@ -163,33 +162,37 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
}
}
serverColorImageView!!.setOnClickListener {
val bubbleFlag = BubbleFlag(context)
bubbleFlag.flagMode = FlagMode.LAST
ColorPickerDialog.Builder(context).apply {
this.colorPickerView.setInitialColor(currentColor)
this.colorPickerView.flagView = bubbleFlag
}
.attachAlphaSlideBar(false)
.setPositiveButton(
getString(R.string.common_ok),
ColorEnvelopeListener { envelope, _ ->
selectedColor = envelope.color
updateColor(envelope.color)
}
)
.setNegativeButton(getString(R.string.common_cancel)) {
dialogInterface, _ ->
dialogInterface.dismiss()
}
.setBottomSpace(DIALOG_PADDING)
.show()
}
// serverColorImageView!!.setOnClickListener {
// val bubbleFlag = BubbleFlag(context)
// bubbleFlag.flagMode = FlagMode.LAST
// ColorPickerDialog.Builder(context).apply {
// this.colorPickerView.setInitialColor(currentColor)
// this.colorPickerView.flagView = bubbleFlag
// }
// .attachAlphaSlideBar(false)
// .setPositiveButton(
// getString(R.string.common_ok),
// ColorEnvelopeListener { envelope, _ ->
// selectedColor = envelope.color
// updateColor(envelope.color)
// }
// )
// .setNegativeButton(getString(R.string.common_cancel)) {
// dialogInterface, _ ->
// dialogInterface.dismiss()
// }
// .setBottomSpace(DIALOG_PADDING)
// .show()
// }
serverColorImageView?.isVisible = false
editServerColorText?.isVisible = false
}
private fun updateColor(color: Int?) {
@Suppress("unused")
private fun updateColor() {
val image = ContextCompat.getDrawable(requireContext(), R.drawable.thumb_drawable)
currentColor = ServerColor.getBackgroundColor(requireContext(), color)
currentColor = ServerColor.getBackgroundColor(requireContext(), null)
image?.setTint(currentColor)
serverColorImageView?.background = image
}
@ -254,7 +257,7 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
selfSignedSwitch!!.isChecked = savedInstanceState.getBoolean(::selfSignedSwitch.name)
ldapSwitch!!.isChecked = savedInstanceState.getBoolean(::ldapSwitch.name)
jukeboxSwitch!!.isChecked = savedInstanceState.getBoolean(::jukeboxSwitch.name)
updateColor(savedInstanceState.getInt(::serverColorImageView.name))
// updateColor(savedInstanceState.getInt(::serverColorImageView.name))
if (savedInstanceState.containsKey(::selectedColor.name))
selectedColor = savedInstanceState.getInt(::selectedColor.name)
isInstanceStateSaved = savedInstanceState.getBoolean(::isInstanceStateSaved.name)
@ -273,7 +276,7 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
selfSignedSwitch!!.isChecked = currentServerSetting!!.allowSelfSignedCertificate
ldapSwitch!!.isChecked = currentServerSetting!!.ldapSupport
jukeboxSwitch!!.isChecked = currentServerSetting!!.jukeboxByDefault
updateColor(currentServerSetting!!.color)
// updateColor(currentServerSetting!!.color)
}
/**
@ -322,7 +325,7 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
if (isValid) {
currentServerSetting!!.name = serverNameEditText!!.editText?.text.toString()
currentServerSetting!!.url = serverAddressEditText!!.editText?.text.toString()
currentServerSetting!!.color = selectedColor
// currentServerSetting!!.color = selectedColor
currentServerSetting!!.userName = userNameEditText!!.editText?.text.toString()
currentServerSetting!!.password = passwordEditText!!.editText?.text.toString()
currentServerSetting!!.allowSelfSignedCertificate = selfSignedSwitch!!.isChecked

View File

@ -212,7 +212,6 @@ class ServerSettingsModel(
serverId,
settings.getString(PREFERENCES_KEY_SERVER_NAME + preferenceId, "")!!,
url,
null,
userName,
settings.getString(PREFERENCES_KEY_PASSWORD + preferenceId, "")!!,
settings.getBoolean(PREFERENCES_KEY_JUKEBOX_BY_DEFAULT + preferenceId, false),