From 586bc51a9cf922022c660ef8b3135ff4285afc08 Mon Sep 17 00:00:00 2001 From: Nite Date: Sat, 5 Feb 2022 11:06:20 +0100 Subject: [PATCH] Revert "Merge pull request #667 from ultrasonic/patchBranch" This reverts commit 41a462708d4a696d988d67f79d59f9424d3b0a05, reversing changes made to fd239e8e72a1361321f1f268d90e3474a2f2685e. --- .../ultrasonic/activity/NavigationActivity.kt | 4 +- .../ultrasonic/adapters/ServerRowAdapter.kt | 4 +- .../org/moire/ultrasonic/data/AppDatabase.kt | 2 +- .../moire/ultrasonic/data/ServerSetting.kt | 5 +- .../ultrasonic/fragment/EditServerFragment.kt | 71 +++++++++---------- .../ultrasonic/model/ServerSettingsModel.kt | 1 + 6 files changed, 43 insertions(+), 44 deletions(-) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt index 3dfbe830..2a915be3 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt @@ -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, null) - val backgroundColor = ServerColor.getBackgroundColor(this, null) + val foregroundColor = ServerColor.getForegroundColor(this, activeServer.color) + val backgroundColor = ServerColor.getBackgroundColor(this, activeServer.color) if (activeServer.index == 0) selectServerButton?.icon = diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/ServerRowAdapter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/ServerRowAdapter.kt index 1247ac66..89c7a5ea 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/ServerRowAdapter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/ServerRowAdapter.kt @@ -108,8 +108,8 @@ internal class ServerRowAdapter( } // Set colors - icon?.setTint(ServerColor.getForegroundColor(context, null)) - background?.setTint(ServerColor.getBackgroundColor(context, null)) + icon?.setTint(ServerColor.getForegroundColor(context, setting?.color)) + background?.setTint(ServerColor.getBackgroundColor(context, setting?.color)) // Set the final drawables image?.setImageDrawable(icon) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/AppDatabase.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/AppDatabase.kt index e12339ae..2eecb7d7 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/AppDatabase.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/AppDatabase.kt @@ -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 = 3) +@Database(entities = [ServerSetting::class], version = 4) abstract class AppDatabase : RoomDatabase() { /** diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/ServerSetting.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/ServerSetting.kt index 705f526a..e3fb9b04 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/ServerSetting.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/ServerSetting.kt @@ -23,6 +23,7 @@ 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, @@ -36,9 +37,9 @@ data class ServerSetting( @ColumnInfo(name = "podcastSupport") var podcastSupport: Boolean? = null ) { constructor() : this ( - -1, 0, "", "", "", "", false, false, false, null, null + -1, 0, "", "", null, "", "", false, false, false, null, null ) constructor(name: String, url: String) : this( - -1, 0, name, url, "", "", false, false, false, null, null + -1, 0, name, url, null, "", "", false, false, false, null, null ) } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EditServerFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EditServerFragment.kt index 916c93ca..29de1289 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EditServerFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EditServerFragment.kt @@ -6,13 +6,15 @@ 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 @@ -41,6 +43,8 @@ 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 */ @@ -68,8 +72,6 @@ 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) @@ -97,7 +99,6 @@ 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, @@ -146,7 +147,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()) { @@ -162,37 +163,33 @@ 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?.isVisible = false - editServerColorText?.isVisible = false + 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() + } } - @Suppress("unused") - private fun updateColor() { + private fun updateColor(color: Int?) { val image = ContextCompat.getDrawable(requireContext(), R.drawable.thumb_drawable) - currentColor = ServerColor.getBackgroundColor(requireContext(), null) + currentColor = ServerColor.getBackgroundColor(requireContext(), color) image?.setTint(currentColor) serverColorImageView?.background = image } @@ -257,7 +254,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) @@ -276,7 +273,7 @@ class EditServerFragment : Fragment(), OnBackPressedHandler { selfSignedSwitch!!.isChecked = currentServerSetting!!.allowSelfSignedCertificate ldapSwitch!!.isChecked = currentServerSetting!!.ldapSupport jukeboxSwitch!!.isChecked = currentServerSetting!!.jukeboxByDefault - // updateColor(currentServerSetting!!.color) + updateColor(currentServerSetting!!.color) } /** @@ -325,7 +322,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 diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/ServerSettingsModel.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/ServerSettingsModel.kt index 9261c6c2..2f520617 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/ServerSettingsModel.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/ServerSettingsModel.kt @@ -212,6 +212,7 @@ 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),