-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Options to choose which categories are skipped automatically or manua…
…lly (#4021) Co-authored-by: general-a <404aaronm@gmail.com> Co-authored-by: Bnyro <bnyro@tutanota.com>
- Loading branch information
1 parent
0582c94
commit 0e6ef50
Showing
10 changed files
with
212 additions
and
102 deletions.
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/github/libretube/enums/SbSkipOptions.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,7 @@ | ||
package com.github.libretube.enums | ||
|
||
enum class SbSkipOptions { | ||
OFF, | ||
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
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
70 changes: 70 additions & 0 deletions
70
app/src/main/java/com/github/libretube/ui/views/SbSpinnerPreference.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,70 @@ | ||
package com.github.libretube.ui.views | ||
import android.content.Context | ||
import android.content.res.TypedArray | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import android.widget.AdapterView | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceViewHolder | ||
import android.widget.ArrayAdapter | ||
import android.widget.Spinner | ||
import android.widget.TextView | ||
import com.github.libretube.R | ||
|
||
class SbSpinnerPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs) { | ||
private lateinit var adapter: ArrayAdapter<CharSequence> | ||
private var selectedItem: CharSequence? = null | ||
|
||
init { | ||
layoutResource = R.layout.spinner_preference | ||
} | ||
|
||
override fun onBindViewHolder(holder: PreferenceViewHolder) { | ||
super.onBindViewHolder(holder) | ||
val spinner: Spinner = holder.itemView.findViewById(R.id.spinner) | ||
|
||
holder.itemView.findViewById<TextView>(android.R.id.title)?.text = super.getTitle() | ||
holder.itemView.findViewById<TextView>(android.R.id.summary)?.text = super.getSummary() | ||
|
||
// Set the spinner adapter | ||
adapter = ArrayAdapter.createFromResource( | ||
context, | ||
R.array.sb_skip_options, | ||
android.R.layout.simple_spinner_item | ||
) | ||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | ||
spinner.adapter = adapter | ||
|
||
// Set the initial selected item | ||
selectedItem?.let { selectedItem -> | ||
val position = getEntryValues().indexOf(selectedItem) | ||
spinner.setSelection(position) | ||
} | ||
|
||
// Set a listener to handle item selection | ||
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { | ||
override fun onItemSelected( | ||
parent: AdapterView<*>, | ||
view: View?, | ||
position: Int, | ||
id: Long | ||
) { | ||
persistString(getEntryValues()[position]) | ||
} | ||
|
||
override fun onNothingSelected(parent: AdapterView<*>) = Unit | ||
} | ||
} | ||
|
||
override fun onGetDefaultValue(ta: TypedArray, index: Int): Any { | ||
// Get the default value from the XML attribute, if specified | ||
return ta.getString(index).orEmpty() | ||
} | ||
|
||
override fun onSetInitialValue(defaultValue: Any?) { | ||
// Set the initial selected item from the persisted value, if available | ||
selectedItem = getPersistedString(defaultValue?.toString()) | ||
} | ||
|
||
private fun getEntryValues() = context.resources.getStringArray(R.array.sb_skip_options_values) | ||
} |
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,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingStart="?android:attr/listPreferredItemPaddingStart" | ||
android:paddingTop="10dp" | ||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" | ||
android:paddingBottom="10dp"> | ||
|
||
<LinearLayout | ||
android:id="@+id/left_container" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentStart="true" | ||
android:layout_alignParentTop="true" | ||
android:layout_marginStart="55dp" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@android:id/title" | ||
style="?android:attr/preferenceStyle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:ellipsize="marquee" | ||
android:fadingEdge="horizontal" | ||
android:gravity="center" | ||
android:singleLine="true" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:textSize="14sp" | ||
android:textStyle="bold" | ||
tools:text="Title" /> | ||
|
||
<TextView | ||
android:id="@android:id/summary" | ||
style="?android:attr/preferenceStyle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="8dp" | ||
android:ellipsize="marquee" | ||
android:fadingEdge="horizontal" | ||
android:lineSpacingExtra="4dp" | ||
android:textAppearance="?android:attr/textAppearanceSmall" | ||
android:textSize="14sp" | ||
tools:text="Summary" /> | ||
|
||
</LinearLayout> | ||
|
||
<Spinner | ||
android:id="@+id/spinner" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignTop="@android:id/title" | ||
android:layout_alignBottom="@android:id/title" | ||
android:layout_alignParentEnd="true" | ||
android:layout_marginTop="-2dp" | ||
android:textAlignment="textEnd" | ||
android:layout_marginEnd="-10dp" | ||
android:paddingStart="0dp" | ||
android:paddingEnd="35dp" /> | ||
|
||
</RelativeLayout> |
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
Oops, something went wrong.