|
@@ -0,0 +1,82 @@
|
|
|
+package com.bomostory.sceneeditmodule.cover
|
|
|
+
|
|
|
+import android.os.Bundle
|
|
|
+import android.support.design.widget.TabLayout
|
|
|
+import android.support.v4.app.DialogFragment
|
|
|
+import android.support.v4.app.FragmentManager
|
|
|
+import android.support.v4.view.PagerAdapter
|
|
|
+import android.view.LayoutInflater
|
|
|
+import android.view.View
|
|
|
+import android.view.ViewGroup
|
|
|
+import com.example.tfat.myapplication.R
|
|
|
+import kotlinx.android.synthetic.main.dialog_cover_editor.*
|
|
|
+import kotlinx.android.synthetic.main.dialog_cover_editor.view.*
|
|
|
+
|
|
|
+class CoverEditorDialog : DialogFragment() {
|
|
|
+ companion object {
|
|
|
+ const val PAGE_COUNT = 2
|
|
|
+ }
|
|
|
+
|
|
|
+ private val dialogTag = this::class.java.simpleName
|
|
|
+
|
|
|
+ var onSave: View.OnClickListener? = null
|
|
|
+ var onCancel: View.OnClickListener? = null
|
|
|
+ var storyName = frontCoverEditorView_coverEditorDialog.storyName
|
|
|
+ var author = frontCoverEditorView_coverEditorDialog.author
|
|
|
+ var frontCoverColor = frontCoverEditorView_coverEditorDialog.selectedColor
|
|
|
+ var backCoverColor = backCoverEditorView_coverEditorDialog.selectedColor
|
|
|
+
|
|
|
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
|
+ return inflater.inflate(R.layout.dialog_cover_editor, container, false).apply {
|
|
|
+ val viewPager = viewPager_coverEditorDialog_content
|
|
|
+ val tabLayout = tabLayout_coverEditorDialog_header
|
|
|
+ viewPager.adapter = object : PagerAdapter() {
|
|
|
+ override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
|
|
+ return container.getChildAt(position)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun isViewFromObject(p0: View, p1: Any): Boolean {
|
|
|
+ return p0 == p1
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun getCount(): Int {
|
|
|
+ return PAGE_COUNT
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
|
|
|
+ // no super
|
|
|
+ }
|
|
|
+ }
|
|
|
+ viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabLayout))
|
|
|
+ tabLayout.apply {
|
|
|
+ addTab(newTab().setText(R.string.cover_editor_dialog_tab_front))
|
|
|
+ addTab(newTab().setText(R.string.cover_editor_dialog_tab_back))
|
|
|
+ addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
|
|
+ override fun onTabReselected(tab: TabLayout.Tab?) {}
|
|
|
+ override fun onTabUnselected(tab: TabLayout.Tab?) {}
|
|
|
+ override fun onTabSelected(tab: TabLayout.Tab?) {
|
|
|
+ tab?.let { viewPager.currentItem = it.position }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ frontCoverEditorView_coverEditorDialog.apply {
|
|
|
+ this.onSave = this@CoverEditorDialog.onSave
|
|
|
+ this.onCancel = this@CoverEditorDialog.onCancel
|
|
|
+ }
|
|
|
+ backCoverEditorView_coverEditorDialog.apply {
|
|
|
+ this.onSave = this@CoverEditorDialog.onSave
|
|
|
+ this.onCancel = this@CoverEditorDialog.onCancel
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun show(manager: FragmentManager?) {
|
|
|
+ manager?.apply {
|
|
|
+ val ft = beginTransaction()
|
|
|
+ findFragmentByTag(dialogTag)?.let { ft.remove(it) }
|
|
|
+ ft.addToBackStack(null)
|
|
|
+ ft.commit()
|
|
|
+ }
|
|
|
+ super.show(manager, dialogTag)
|
|
|
+ }
|
|
|
+}
|