-
-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color segments depending on what type they are #4055
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0f81ee4
Color segments depending on what type they are
33fa8dc
Added ability to customize colors and switch to enable this option
ad701e4
Added translatable strings
eb3d988
Made requested changes
821e562
Added visible in seek bar mode and improved setting descriptions
f472713
Removed manual toast that was added in this pr
b15b454
Improved color picker
77f9c88
refactor
fb1f321
changed to binding and refactored
06dd971
xml formatting
3bddd11
Refactored code and fixed inital val bug
6b84a32
Improve appearance of SponsorBlock color picker dialog
Bnyro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package com.github.libretube.enums | |
|
||
enum class SbSkipOptions { | ||
OFF, | ||
VISIBLE, | ||
MANUAL, | ||
AUTOMATIC | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
app/src/main/java/com/github/libretube/ui/dialogs/ColorPickerDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.github.libretube.ui.dialogs | ||
|
||
import android.app.Dialog | ||
import android.content.Context | ||
import android.graphics.Color | ||
import android.os.Bundle | ||
import android.text.Editable | ||
import android.text.TextWatcher | ||
import android.view.View | ||
import android.widget.SeekBar | ||
import android.widget.Toast | ||
import androidx.fragment.app.DialogFragment | ||
import com.github.libretube.R | ||
import com.github.libretube.databinding.DialogColorPickerBinding | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
|
||
class ColorPickerDialog( | ||
private val context: Context, | ||
private val initialColor: Int, | ||
private val onColorSelectedListener: OnColorSelectedListener | ||
) : DialogFragment(), SeekBar.OnSeekBarChangeListener { | ||
|
||
private var _binding: DialogColorPickerBinding? = null | ||
private val binding get() = _binding!! | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
_binding = DialogColorPickerBinding.inflate(layoutInflater) | ||
|
||
// Set initial color | ||
setColor(initialColor) | ||
|
||
binding.alphaSeekBar.setOnSeekBarChangeListener(this) | ||
binding.redSeekBar.setOnSeekBarChangeListener(this) | ||
binding.greenSeekBar.setOnSeekBarChangeListener(this) | ||
binding.blueSeekBar.setOnSeekBarChangeListener(this) | ||
|
||
// Add listener to text input | ||
binding.colorHexInput.addTextChangedListener(object : TextWatcher { | ||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, | ||
after: Int) = Unit | ||
|
||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, | ||
count: Int) = Unit | ||
|
||
var isValid = true | ||
var oldHex = "" | ||
|
||
override fun afterTextChanged(s: Editable?) { | ||
// Update color when text input changes | ||
val hexColor = s.toString() | ||
if (hexColor.length == 9 && oldHex != hexColor) { | ||
isValid = try { | ||
oldHex = hexColor | ||
val color = Color.parseColor(hexColor) | ||
setColor(color, true) | ||
true | ||
} catch (e: IllegalArgumentException) { | ||
if (isValid) { | ||
showInvalidColorMessage() | ||
} | ||
false | ||
} | ||
} | ||
} | ||
}) | ||
|
||
return MaterialAlertDialogBuilder(requireContext()) | ||
.setView(binding.root) | ||
.setPositiveButton(R.string.okay) { _, _ -> | ||
onColorSelectedListener.onColorSelected(getColor()) | ||
} | ||
.setNegativeButton(R.string.cancel, null) | ||
.show() | ||
} | ||
|
||
Bnyro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { | ||
// Update color preview when SeekBar progress changes | ||
setColorPreview(getColor()) | ||
} | ||
|
||
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit | ||
|
||
override fun onStopTrackingTouch(seekBar: SeekBar?) { | ||
val newColorString = colorToString(getColor()) | ||
|
||
if (newColorString != binding.colorHexInput.text.toString()) { | ||
binding.colorHexInput.setText(newColorString) | ||
} | ||
} | ||
|
||
private fun showInvalidColorMessage() { | ||
Toast.makeText(context, R.string.invalid_color, Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
// Get the color from the SeekBar progress values | ||
private fun getColor() = Color.argb(binding.alphaSeekBar.progress, binding.redSeekBar.progress, | ||
binding.greenSeekBar.progress, binding.blueSeekBar.progress) | ||
|
||
private fun setColor(color: Int, textUpdate: Boolean = false) { | ||
// Set the SeekBar progress values based on the color | ||
binding.alphaSeekBar.progress = Color.alpha(color) | ||
binding.redSeekBar.progress = Color.red(color) | ||
binding.greenSeekBar.progress = Color.green(color) | ||
binding.blueSeekBar.progress = Color.blue(color) | ||
|
||
// Set the hex color input value | ||
if (!textUpdate) { | ||
binding.colorHexInput.setText(colorToString(color)) | ||
} | ||
binding.colorPreview.setBackgroundColor(color) | ||
} | ||
|
||
private fun setColorPreview(color: Int) { | ||
// Set the color preview | ||
binding.colorPreview.setBackgroundColor(color) | ||
} | ||
|
||
private fun colorToString(color: Int): String { | ||
return String.format("#%08X", color) | ||
} | ||
|
||
fun interface OnColorSelectedListener { | ||
fun onColorSelected(color: Int) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -672,7 +672,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { | |
} | ||
return | ||
} | ||
|
||
} | ||
|
||
private fun playVideo() { | ||
|
74 changes: 74 additions & 0 deletions
74
app/src/main/java/com/github/libretube/ui/views/ColorPreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.github.libretube.ui.views | ||
|
||
import android.content.Context | ||
import android.content.res.TypedArray | ||
import android.graphics.Color | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import android.widget.LinearLayout | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceViewHolder | ||
import com.github.libretube.R | ||
import com.github.libretube.ui.dialogs.ColorPickerDialog | ||
|
||
class ColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs) { | ||
private lateinit var circleView: View | ||
private var currentColor: Int? = null | ||
|
||
init { | ||
layoutResource = R.layout.color_preference | ||
} | ||
|
||
override fun onBindViewHolder(holder: PreferenceViewHolder) { | ||
super.onBindViewHolder(holder) | ||
|
||
holder.itemView.findViewById<TextView>(android.R.id.title)?.text = title | ||
circleView = holder.itemView.findViewById(R.id.circle) | ||
updateColorView() | ||
|
||
holder.itemView.setOnClickListener { | ||
showColorPickerDialog() | ||
} | ||
} | ||
|
||
private fun setColor(color: Int) { | ||
currentColor = color | ||
persistInt(color) | ||
updateColorView() | ||
} | ||
|
||
|
||
override fun onGetDefaultValue(ta: TypedArray, index: Int): Any { | ||
return Color.parseColor(ta.getString(index)) | ||
} | ||
|
||
override fun onSetInitialValue(defaultValue: Any?) { | ||
val color = if (defaultValue is Int) { | ||
getPersistedInt(defaultValue) | ||
} else { | ||
getPersistedInt(Color.WHITE) | ||
} | ||
currentColor = color | ||
persistInt(color) | ||
} | ||
|
||
private fun updateColorView() { | ||
(if (currentColor is Int) currentColor else Color.WHITE)?.let { | ||
circleView.setBackgroundColor(it) | ||
} | ||
} | ||
|
||
private fun showColorPickerDialog() { | ||
(if (currentColor is Int) currentColor else Color.BLACK)?.let { | ||
val dialog = ColorPickerDialog(context, it) { color -> setColor(color) } | ||
dialog.show((context as AppCompatActivity).supportFragmentManager, this::class.java.name) | ||
} | ||
} | ||
|
||
override fun getTitle(): CharSequence? { | ||
return "${super.getTitle()}:" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="oval"> | ||
|
||
<solid android:color="#000" /> | ||
|
||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:paddingStart="?android:attr/listPreferredItemPaddingStart" | ||
android:paddingTop="10dp" | ||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" | ||
android:paddingBottom="10dp"> | ||
|
||
|
||
<TextView | ||
android:id="@android:id/title" | ||
style="?android:attr/preferenceStyle" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="5dp" | ||
android:layout_weight="1" | ||
android:ellipsize="end" | ||
android:fadingEdge="horizontal" | ||
android:singleLine="true" | ||
android:text="Title" | ||
android:textAlignment="textEnd" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:textSize="14sp" | ||
android:textStyle="italic" /> | ||
|
||
<View | ||
android:id="@+id/circle" | ||
android:layout_width="20sp" | ||
android:layout_height="20sp" | ||
android:layout_alignParentEnd="true" | ||
android:background="@drawable/circle" | ||
android:layout_marginStart="16dp"/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:orientation="vertical" | ||
android:paddingHorizontal="20dp" | ||
android:paddingTop="30dp"> | ||
|
||
<androidx.cardview.widget.CardView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_marginVertical="10dp" | ||
app:cardCornerRadius="10dp"> | ||
|
||
<View | ||
android:id="@+id/colorPreview" | ||
android:layout_width="100dp" | ||
android:layout_height="100dp" | ||
android:background="#000000" /> | ||
|
||
</androidx.cardview.widget.CardView> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="R" | ||
tools:ignore="HardcodedText" /> | ||
|
||
<SeekBar | ||
android:id="@+id/redSeekBar" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="5dp" | ||
android:paddingBottom="5dp" | ||
android:max="255" | ||
android:progress="0" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="G" | ||
tools:ignore="HardcodedText" /> | ||
|
||
<SeekBar | ||
android:id="@+id/greenSeekBar" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="5dp" | ||
android:paddingBottom="5dp" | ||
android:max="255" | ||
android:progress="0" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="B" | ||
tools:ignore="HardcodedText" /> | ||
|
||
<SeekBar | ||
android:id="@+id/blueSeekBar" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="5dp" | ||
android:paddingBottom="5dp" | ||
android:max="255" | ||
android:progress="0" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="A" | ||
tools:ignore="HardcodedText" /> | ||
|
||
<SeekBar | ||
android:id="@+id/alphaSeekBar" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingVertical="5dp" | ||
android:max="255" | ||
android:progress="255" /> | ||
|
||
<EditText | ||
android:id="@+id/colorHexInput" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginVertical="5dp" | ||
android:hint="#00000000" | ||
tools:ignore="HardcodedText" /> | ||
|
||
</LinearLayout> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please add a new line before that one