random option

This commit is contained in:
Finnley Somdahl 2023-12-05 01:05:36 -06:00
parent ea83b722a6
commit e26a6c647f
6 changed files with 50 additions and 2 deletions

View file

@ -300,6 +300,19 @@ class MediaAdaptor(
return type return type
} }
fun randomOptionClick() { //used for user list
val media = mediaList?.random()
if (media != null) {
mediaList?.let {
clicked(
it.indexOf(media),
null
)
}
}
}
inner class MediaViewHolder(val binding: ItemMediaCompactBinding) : inner class MediaViewHolder(val binding: ItemMediaCompactBinding) :
RecyclerView.ViewHolder(binding.root) { RecyclerView.ViewHolder(binding.root) {
init { init {

View file

@ -162,5 +162,15 @@ class ListActivity : AppCompatActivity() {
popup.inflate(R.menu.list_sort_menu) popup.inflate(R.menu.list_sort_menu)
popup.show() popup.show()
} }
binding.random.setOnClickListener {
//get the current tab
val currentTab =
binding.listTabLayout.getTabAt(binding.listTabLayout.selectedTabPosition)
val currentViewePager = binding.listViewPager.getChildAt(0)
val currentFragment =
supportFragmentManager.findFragmentByTag("f" + currentTab?.position.toString()) as? ListFragment
currentFragment?.randomOptionClick()
}
} }
} }

View file

@ -76,6 +76,11 @@ class ListFragment : Fragment() {
} }
} }
fun randomOptionClick() {
val adapter = binding.listRecyclerView.adapter as MediaAdaptor
adapter.randomOptionClick()
}
companion object { companion object {
fun newInstance(pos: Int, calendar: Boolean = false): ListFragment = fun newInstance(pos: Int, calendar: Boolean = false): ListFragment =
ListFragment().apply { ListFragment().apply {

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M560,800v-80h104L537,593l57,-57 126,126v-102h80v240L560,800ZM216,800 L160,744 664,240L560,240v-80h240v240h-80v-104L216,800ZM367,423L160,216l56,-56 207,207 -56,56Z"/>
</vector>

View file

@ -44,12 +44,21 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" /> android:layout_weight="1" />
<ImageButton
android:id="@+id/random"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/random_selection"
app:tint="?attr/colorOnBackground"
app:srcCompat="@drawable/ic_shuffle_24" />
<ImageButton <ImageButton
android:id="@+id/listSort" android:id="@+id/listSort"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_marginLeft="16dp" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/sort_by" android:contentDescription="@string/sort_by"
app:tint="?attr/colorOnBackground" app:tint="?attr/colorOnBackground"

View file

@ -640,5 +640,6 @@
<string name="available_anime">Available Anime</string> <string name="available_anime">Available Anime</string>
<string name="installed_manga">Installed Manga</string> <string name="installed_manga">Installed Manga</string>
<string name="color_picker">Color Picker</string> <string name="color_picker">Color Picker</string>
<string name="random_selection">Random Selection</string>
</resources> </resources>