mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 20:19:05 +01:00
Clean up global chapter settings code
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.bluelinelabs.conductor.Router
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.databinding.CommonTabbedSheetBinding
|
||||
import eu.kanade.tachiyomi.ui.manga.chapter.SetChapterSettingsDialog
|
||||
import eu.kanade.tachiyomi.util.view.popupMenu
|
||||
|
||||
abstract class TabbedBottomSheetDialog(private val activity: Activity, private val manga: Manga? = null) : BottomSheetDialog(activity) {
|
||||
val binding: CommonTabbedSheetBinding = CommonTabbedSheetBinding.inflate(activity.layoutInflater)
|
||||
abstract class TabbedBottomSheetDialog(private val router: Router) : BottomSheetDialog(router.activity!!) {
|
||||
|
||||
val binding: CommonTabbedSheetBinding = CommonTabbedSheetBinding.inflate(router.activity!!.layoutInflater)
|
||||
|
||||
init {
|
||||
val adapter = LibrarySettingsSheetAdapter()
|
||||
@@ -19,34 +16,9 @@ abstract class TabbedBottomSheetDialog(private val activity: Activity, private v
|
||||
binding.pager.adapter = adapter
|
||||
binding.tabs.setupWithViewPager(binding.pager)
|
||||
|
||||
// currently, we only need to show the overflow menu if this is a ChaptersSettingsSheet
|
||||
if (manga != null) {
|
||||
binding.menu.visibility = View.VISIBLE
|
||||
binding.menu.setOnClickListener { it.post { showPopupMenu(it) } }
|
||||
} else {
|
||||
binding.menu.visibility = View.GONE
|
||||
}
|
||||
|
||||
setContentView(binding.root)
|
||||
}
|
||||
|
||||
private fun showPopupMenu(view: View) {
|
||||
view.popupMenu(
|
||||
R.menu.default_chapter_filter,
|
||||
{
|
||||
},
|
||||
{
|
||||
when (this.itemId) {
|
||||
R.id.save_as_default -> {
|
||||
manga?.let { SetChapterSettingsDialog(context, it).showDialog() }
|
||||
true
|
||||
}
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
abstract fun getTabViews(): List<View>
|
||||
|
||||
abstract fun getTabTitles(): List<Int>
|
||||
@@ -62,7 +34,7 @@ abstract class TabbedBottomSheetDialog(private val activity: Activity, private v
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence {
|
||||
return activity.resources!!.getString(getTabTitles()[position])
|
||||
return router.activity!!.resources!!.getString(getTabTitles()[position])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user