|
@@ -9,11 +9,13 @@ import android.util.AttributeSet
|
|
import android.view.LayoutInflater
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
|
+import android.widget.AdapterView
|
|
|
|
+import android.widget.ArrayAdapter
|
|
import android.widget.RadioButton
|
|
import android.widget.RadioButton
|
|
import com.bomostory.sceneeditmodule.SceneDrawer
|
|
import com.bomostory.sceneeditmodule.SceneDrawer
|
|
import com.bomostory.sceneeditmodule.basicdata.Project
|
|
import com.bomostory.sceneeditmodule.basicdata.Project
|
|
-import com.bomostory.sceneeditmodule.basicdata.Scene
|
|
|
|
import com.bomostory.sceneeditmodule.utils.Utils
|
|
import com.bomostory.sceneeditmodule.utils.Utils
|
|
|
|
+import com.bomostory.sceneeditmodule.utils.Utils.crop
|
|
import com.example.tfat.myapplication.R
|
|
import com.example.tfat.myapplication.R
|
|
import kotlinx.android.synthetic.main.item_front_cover_scene_chooser.view.*
|
|
import kotlinx.android.synthetic.main.item_front_cover_scene_chooser.view.*
|
|
import kotlinx.android.synthetic.main.view_front_cover_scene_chooser.view.*
|
|
import kotlinx.android.synthetic.main.view_front_cover_scene_chooser.view.*
|
|
@@ -24,6 +26,11 @@ class FrontCoverSceneChooserView @JvmOverloads constructor(
|
|
defStyleAttr: Int = 0
|
|
defStyleAttr: Int = 0
|
|
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
|
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
|
|
|
|
|
|
|
+ private val alignStyleStringMap = HashMap<AlignStyle, Int>().apply {
|
|
|
|
+ put(AlignStyle.Center, R.string.front_cover_scene_choose_dialog_align_center)
|
|
|
|
+ put(AlignStyle.Left, R.string.front_cover_scene_choose_dialog_align_left)
|
|
|
|
+ put(AlignStyle.Right, R.string.front_cover_scene_choose_dialog_align_right)
|
|
|
|
+ }
|
|
var selected: Int = 0
|
|
var selected: Int = 0
|
|
private set
|
|
private set
|
|
private var project: Project? = null
|
|
private var project: Project? = null
|
|
@@ -31,6 +38,11 @@ class FrontCoverSceneChooserView @JvmOverloads constructor(
|
|
field = value
|
|
field = value
|
|
update()
|
|
update()
|
|
}
|
|
}
|
|
|
|
+ val alignStyle: AlignStyle
|
|
|
|
+ get() {
|
|
|
|
+ val position = spinner_frontCoverSceneChooserDialog_align.selectedItemPosition
|
|
|
|
+ return AlignStyle.values()[position]
|
|
|
|
+ }
|
|
var title: String = ""
|
|
var title: String = ""
|
|
set(value) {
|
|
set(value) {
|
|
tv_frontCoverSceneChooserDialog_coverTitle.text = value
|
|
tv_frontCoverSceneChooserDialog_coverTitle.text = value
|
|
@@ -57,6 +69,23 @@ class FrontCoverSceneChooserView @JvmOverloads constructor(
|
|
orientation = LinearLayoutManager.VERTICAL
|
|
orientation = LinearLayoutManager.VERTICAL
|
|
}
|
|
}
|
|
recyclerView_frontCoverSceneChooserDialog_sceneList.adapter = adapter
|
|
recyclerView_frontCoverSceneChooserDialog_sceneList.adapter = adapter
|
|
|
|
+
|
|
|
|
+ // align style spinner
|
|
|
|
+ val itemLayoutResId = android.R.layout.simple_dropdown_item_1line
|
|
|
|
+ spinner_frontCoverSceneChooserDialog_align.adapter = ArrayAdapter<String>(context, itemLayoutResId).apply {
|
|
|
|
+ AlignStyle.values().forEach {
|
|
|
|
+ val resId = alignStyleStringMap[it] ?: return@forEach
|
|
|
|
+ val s = context.getString(resId)
|
|
|
|
+ add(s)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ spinner_frontCoverSceneChooserDialog_align.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
|
|
|
+ override fun onNothingSelected(p0: AdapterView<*>?) {}
|
|
|
|
+
|
|
|
|
+ override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
|
|
|
|
+ updateCover()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
fun setProjectAndSelected(project: Project, selected: Int) {
|
|
fun setProjectAndSelected(project: Project, selected: Int) {
|
|
@@ -81,25 +110,25 @@ class FrontCoverSceneChooserView @JvmOverloads constructor(
|
|
lastSelectedData?.isSelected = true
|
|
lastSelectedData?.isSelected = true
|
|
project?.story?.scenes?.also { scenes ->
|
|
project?.story?.scenes?.also { scenes ->
|
|
selected = dataList.indexOf(data)
|
|
selected = dataList.indexOf(data)
|
|
- val s = scenes[selected]
|
|
|
|
- onSceneSelected(s)
|
|
|
|
|
|
+ updateCover()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
val data = Data(isSelected, bitmap, name, onSelectedListener)
|
|
val data = Data(isSelected, bitmap, name, onSelectedListener)
|
|
dataList.add(data)
|
|
dataList.add(data)
|
|
- if (isSelected) {
|
|
|
|
- onSceneSelected(scene)
|
|
|
|
- }
|
|
|
|
i++
|
|
i++
|
|
}
|
|
}
|
|
adapter.notifyDataSetChanged()
|
|
adapter.notifyDataSetChanged()
|
|
|
|
+ updateCover()
|
|
}
|
|
}
|
|
|
|
|
|
- private fun onSceneSelected(scene: Scene) {
|
|
|
|
|
|
+ private fun updateCover() {
|
|
|
|
+ val scenes = project?.story?.scenes ?: return
|
|
|
|
+ val scene = scenes[selected]
|
|
val width = context.resources.getDimension(R.dimen.share_dialog_screenshot_width).toInt()
|
|
val width = context.resources.getDimension(R.dimen.share_dialog_screenshot_width).toInt()
|
|
val height = context.resources.getDimension(R.dimen.share_dialog_screenshot_height).toInt()
|
|
val height = context.resources.getDimension(R.dimen.share_dialog_screenshot_height).toInt()
|
|
- val bitmap = SceneDrawer.drawScene(context, scene, 0, width, height) ?: return
|
|
|
|
|
|
+ val bitmap = SceneDrawer.drawScene(context, scene, 0, width, height)?.crop(alignStyle)
|
|
|
|
+ ?: return
|
|
iv_frontCoverSceneChooserDialog_cover.setImageBitmap(bitmap)
|
|
iv_frontCoverSceneChooserDialog_cover.setImageBitmap(bitmap)
|
|
}
|
|
}
|
|
|
|
|