feat: scanlation bulk ticker (#218)
* feat: scanlation mass tick (WIP) * feat: scanlation mass tick * fix: togglebutton on scanlation scrollview * fix: fix ImageButton padding + overlay * fix: minor padding adjustment
This commit is contained in:
parent
51beea1dc8
commit
be1711b51e
5 changed files with 84 additions and 12 deletions
|
@ -13,6 +13,7 @@ import android.widget.LinearLayout
|
||||||
import android.widget.NumberPicker
|
import android.widget.NumberPicker
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.ContextCompat.startActivity
|
import androidx.core.content.ContextCompat.startActivity
|
||||||
|
import androidx.core.view.children
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import ani.dantotsu.*
|
import ani.dantotsu.*
|
||||||
|
@ -255,17 +256,41 @@ class MangaReadAdapter(
|
||||||
if (options.count() > 1) View.VISIBLE else View.GONE
|
if (options.count() > 1) View.VISIBLE else View.GONE
|
||||||
dialogBinding.scanlatorNo.text = "${options.count()}"
|
dialogBinding.scanlatorNo.text = "${options.count()}"
|
||||||
dialogBinding.animeScanlatorTop.setOnClickListener {
|
dialogBinding.animeScanlatorTop.setOnClickListener {
|
||||||
val dialogView2 =
|
val dialogView2 = LayoutInflater.from(currContext()).inflate(R.layout.custom_dialog_layout, null)
|
||||||
LayoutInflater.from(currContext()).inflate(R.layout.custom_dialog_layout, null)
|
val checkboxContainer = dialogView2.findViewById<LinearLayout>(R.id.checkboxContainer)
|
||||||
val checkboxContainer =
|
val tickAllButton = dialogView2.findViewById<ImageButton>(R.id.toggleButton)
|
||||||
dialogView2.findViewById<LinearLayout>(R.id.checkboxContainer)
|
|
||||||
|
// Function to get the right image resource for the toggle button
|
||||||
|
fun getToggleImageResource(container: ViewGroup): Int {
|
||||||
|
var allChecked = true
|
||||||
|
var allUnchecked = true
|
||||||
|
|
||||||
|
for (i in 0 until container.childCount) {
|
||||||
|
val checkBox = container.getChildAt(i) as CheckBox
|
||||||
|
if (!checkBox.isChecked) {
|
||||||
|
allChecked = false
|
||||||
|
} else {
|
||||||
|
allUnchecked = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return when {
|
||||||
|
allChecked -> R.drawable.untick_all_boxes
|
||||||
|
allUnchecked -> R.drawable.tick_all_boxes
|
||||||
|
else -> R.drawable.invert_all_boxes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Dynamically add checkboxes
|
// Dynamically add checkboxes
|
||||||
options.forEach { option ->
|
options.forEach { option ->
|
||||||
val checkBox = CheckBox(currContext()).apply {
|
val checkBox = CheckBox(currContext()).apply {
|
||||||
text = option
|
text = option
|
||||||
|
setOnCheckedChangeListener { _, _ ->
|
||||||
|
// Update image resource when you change a checkbox
|
||||||
|
tickAllButton.setImageResource(getToggleImageResource(checkboxContainer))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//set checked if it's already selected
|
|
||||||
|
// Set checked if its already selected
|
||||||
if (media.selected!!.scanlators != null) {
|
if (media.selected!!.scanlators != null) {
|
||||||
checkBox.isChecked = media.selected!!.scanlators?.contains(option) != true
|
checkBox.isChecked = media.selected!!.scanlators?.contains(option) != true
|
||||||
scanlatorSelectionListener?.onScanlatorsSelected()
|
scanlatorSelectionListener?.onScanlatorsSelected()
|
||||||
|
@ -279,7 +304,6 @@ class MangaReadAdapter(
|
||||||
val dialog = AlertDialog.Builder(currContext(), R.style.MyPopup)
|
val dialog = AlertDialog.Builder(currContext(), R.style.MyPopup)
|
||||||
.setView(dialogView2)
|
.setView(dialogView2)
|
||||||
.setPositiveButton("OK") { _, _ ->
|
.setPositiveButton("OK") { _, _ ->
|
||||||
//add unchecked to hidden
|
|
||||||
hiddenScanlators.clear()
|
hiddenScanlators.clear()
|
||||||
for (i in 0 until checkboxContainer.childCount) {
|
for (i in 0 until checkboxContainer.childCount) {
|
||||||
val checkBox = checkboxContainer.getChildAt(i) as CheckBox
|
val checkBox = checkboxContainer.getChildAt(i) as CheckBox
|
||||||
|
@ -293,6 +317,21 @@ class MangaReadAdapter(
|
||||||
.setNegativeButton("Cancel", null)
|
.setNegativeButton("Cancel", null)
|
||||||
.show()
|
.show()
|
||||||
dialog.window?.setDimAmount(0.8f)
|
dialog.window?.setDimAmount(0.8f)
|
||||||
|
|
||||||
|
// Standard image resource
|
||||||
|
tickAllButton.setImageResource(getToggleImageResource(checkboxContainer))
|
||||||
|
|
||||||
|
// Listens to ticked checkboxes and changes image resource accordingly
|
||||||
|
tickAllButton.setOnClickListener {
|
||||||
|
// Toggle checkboxes
|
||||||
|
for (i in 0 until checkboxContainer.childCount) {
|
||||||
|
val checkBox = checkboxContainer.getChildAt(i) as CheckBox
|
||||||
|
checkBox.isChecked = !checkBox.isChecked
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update image resource
|
||||||
|
tickAllButton.setImageResource(getToggleImageResource(checkboxContainer))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nestedDialog = AlertDialog.Builder(fragment.requireContext(), R.style.MyPopup)
|
nestedDialog = AlertDialog.Builder(fragment.requireContext(), R.style.MyPopup)
|
||||||
|
|
7
app/src/main/res/drawable/invert_all_boxes.xml
Normal file
7
app/src/main/res/drawable/invert_all_boxes.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||||
|
|
||||||
|
<path android:fillAlpha="0.6" android:fillColor="@android:color/white" android:pathData="M8,16h12V4H8V16zM10.4,9.09l2.07,2.08L17.6,6L19,7.41L12.47,14L9,10.5L10.4,9.09z" android:strokeAlpha="0.3"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M20,2H8C6.9,2 6,2.9 6,4v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4C22,2.9 21.1,2 20,2zM20,16H8V4h12V16zM12.47,14L9,10.5l1.4,-1.41l2.07,2.08L17.6,6L19,7.41L12.47,14zM4,20h14v2H4c-1.1,0 -2,-0.9 -2,-2V6h2V20z"/>
|
||||||
|
|
||||||
|
</vector>
|
5
app/src/main/res/drawable/tick_all_boxes.xml
Normal file
5
app/src/main/res/drawable/tick_all_boxes.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM12.47,14L9,10.5l1.4,-1.41 2.07,2.08L17.6,6 19,7.41 12.47,14zM4,6L2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6z"/>
|
||||||
|
|
||||||
|
</vector>
|
5
app/src/main/res/drawable/untick_all_boxes.xml
Normal file
5
app/src/main/res/drawable/untick_all_boxes.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M20,4v12H8V4H20M20,2H8C6.9,2 6,2.9 6,4v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4C22,2.9 21.1,2 20,2L20,2zM12.47,14L9,10.5l1.4,-1.41l2.07,2.08L17.6,6L19,7.41L12.47,14zM4,6H2v14c0,1.1 0.9,2 2,2h14v-2H4V6z"/>
|
||||||
|
|
||||||
|
</vector>
|
|
@ -1,5 +1,6 @@
|
||||||
<!-- custom_dialog_layout.xml -->
|
<!-- custom_dialog_layout.xml -->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
@ -16,15 +17,30 @@
|
||||||
android:textColor="?attr/colorOnBackground"
|
android:textColor="?attr/colorOnBackground"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
<ScrollView
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<LinearLayout
|
<ScrollView
|
||||||
android:id="@+id/checkboxContainer"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:orientation="vertical" />
|
|
||||||
</ScrollView>
|
<LinearLayout
|
||||||
|
android:id="@+id/checkboxContainer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/toggleButton"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:background="@null"
|
||||||
|
android:src="@drawable/untick_all_boxes"
|
||||||
|
app:tint="?attr/colorPrimary" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue